com.vaadin.flow.component.page.Push Java Examples

The following examples show how to use com.vaadin.flow.component.page.Push. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UIInternals.java    From flow with Apache License 2.0 6 votes vote down vote up
private void configurePush(HasElement root) {
    DeploymentConfiguration deploymentConfiguration = getSession()
            .getService().getDeploymentConfiguration();
    if (!deploymentConfiguration.useV14Bootstrap()) {
        return;
    }
    PushConfiguration pushConfiguration = ui.getPushConfiguration();
    Optional<Push> push = AnnotationReader.getAnnotationFor(root.getClass(),
            Push.class);
    PushMode pushMode = push.map(Push::value)
            .orElseGet(deploymentConfiguration::getPushMode);
    pushConfiguration.setPushMode(pushMode);
    if (push.isPresent()) {
        pushConfiguration.setTransport(push.get().transport());
    }
}
 
Example #2
Source File: MakeComponentVisibleWithPushUI.java    From flow with Apache License 2.0 6 votes vote down vote up
@Override
protected void init(VaadinRequest request) {
    /*
     * Read push settings from the UI instead of the the navigation target /
     * router layout to preserve the structure of these legacy testing UIs
     */
    Push push = getClass().getAnnotation(Push.class);

    getPushConfiguration().setPushMode(push.value());
    getPushConfiguration().setTransport(push.transport());

    rootLayout = new Div();
    add(rootLayout);

    input = new Input();
    input.setVisible(false);
    input.setValue("foo");
    input.setId("input");
    rootLayout.add(input);

    NativeButton doUpdateButton = new NativeButton("Do Update",
            event -> doUpdate());
    doUpdateButton.setId("update");

    rootLayout.add(doUpdateButton);
}
 
Example #3
Source File: BootstrapContextTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Test
public void getPushAnnotation_routeTargetPresents_pushFromTheClassDefinitionIsUsed() {
    ui.getRouter().getRegistry().setRoute("foo", MainView.class,
            Collections.emptyList());
    Mockito.when(request.getPathInfo()).thenReturn("/foo");

    BootstrapContext context = new BootstrapContext(request,
            Mockito.mock(VaadinResponse.class), session, ui, callback);

    Optional<Push> push = context
            .getPageConfigurationAnnotation(Push.class);
    Assert.assertTrue(push.isPresent());
    Push pushAnnotation = push.get();
    Assert.assertEquals(PushMode.MANUAL, pushAnnotation.value());
    Assert.assertEquals(Transport.LONG_POLLING, pushAnnotation.transport());
}
 
Example #4
Source File: BootstrapContextTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Test
public void getPushAnnotation_routeTargetPresents_pushDefinedOnParentLayout_pushFromTheClassDefinitionIsUsed() {
    ui.getRouter().getRegistry().setRoute("foo", OtherView.class,
            Collections.singletonList(MainView.class));
    Mockito.when(request.getPathInfo()).thenReturn("/foo");

    BootstrapContext context = new BootstrapContext(request,
            Mockito.mock(VaadinResponse.class), session, ui, callback);

    Optional<Push> push = context
            .getPageConfigurationAnnotation(Push.class);
    Assert.assertTrue(push.isPresent());
    Push pushAnnotation = push.get();
    Assert.assertEquals(PushMode.MANUAL, pushAnnotation.value());
    Assert.assertEquals(Transport.LONG_POLLING, pushAnnotation.transport());
}
 
Example #5
Source File: BootstrapContextTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Test
public void getPushAnnotation_routeTargetIsAbsent_pushFromTheErrorNavigationTargetIsUsed() {
    Mockito.when(request.getPathInfo()).thenReturn("/bar");

    ApplicationRouteRegistry registry = ApplicationRouteRegistry
            .getInstance(ui.getSession().getService().getContext());
    registry.setErrorNavigationTargets(
            Collections.singleton(CustomRouteNotFound.class));

    BootstrapContext context = new BootstrapContext(request,
            Mockito.mock(VaadinResponse.class), session, ui, request -> "");

    Optional<Push> push = context
            .getPageConfigurationAnnotation(Push.class);
    Assert.assertTrue(push.isPresent());
    Push pushAnnotation = push.get();
    Assert.assertEquals(PushMode.AUTOMATIC, pushAnnotation.value());
    Assert.assertEquals(Transport.WEBSOCKET, pushAnnotation.transport());
}
 
Example #6
Source File: BootstrapContextTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Test
public void getPushAnnotation_routeTargetIsAbsent_pushIsDefinedOnParentLayout_pushFromTheErrorNavigationTargetParentLayoutIsUsed() {
    Mockito.when(request.getPathInfo()).thenReturn("/bar");

    ApplicationRouteRegistry registry = ApplicationRouteRegistry
            .getInstance(ui.getSession().getService().getContext());
    registry.setErrorNavigationTargets(
            Collections.singleton(AnotherCustomRouteNotFound.class));

    BootstrapContext context = new BootstrapContext(request,
            Mockito.mock(VaadinResponse.class), session, ui, request -> "");

    Optional<Push> push = context
            .getPageConfigurationAnnotation(Push.class);
    Assert.assertTrue(push.isPresent());
    Push pushAnnotation = push.get();
    Assert.assertEquals(PushMode.MANUAL, pushAnnotation.value());
    Assert.assertEquals(Transport.LONG_POLLING, pushAnnotation.transport());
}
 
Example #7
Source File: BootstrapHandlerPushConfigurationTest.java    From flow with Apache License 2.0 6 votes vote down vote up
private void assertPushConfigurationForComponent(
        Class<? extends Component> annotatedClazz,
        Class<? extends PushConnection> pushConnectionType)
        throws InvalidRouteConfigurationException {
    BootstrapHandler bootstrapHandler = new BootstrapHandler();
    VaadinResponse response = mock(VaadinResponse.class);
    RouteConfiguration routeConfiguration = RouteConfiguration
            .forRegistry(service.getRouteRegistry());
    routeConfiguration.update(() -> {
        routeConfiguration.getHandledRegistry().clean();
        routeConfiguration.setAnnotatedRoute(annotatedClazz);
    });

    final BootstrapHandler.BootstrapContext context = bootstrapHandler
            .createAndInitUI(UI.class, createVaadinRequest(), response,
                    session);
    Push pushAnnotation = annotatedClazz.getAnnotation(Push.class);
    Assert.assertNotNull("Should have @Push annotated component",
            pushAnnotation);
    PushConfiguration pushConfiguration = context.getUI()
            .getPushConfiguration();
    assertPushConfiguration(pushConfiguration, pushAnnotation);
    assertThat(context.getUI().getInternals().getPushConnection(),
            instanceOf(pushConnectionType));
}
 
Example #8
Source File: SendMultibyteCharactersUI.java    From flow with Apache License 2.0 6 votes vote down vote up
@Override
protected void init(VaadinRequest request) {
    Push push = getClass().getAnnotation(Push.class);

    getPushConfiguration().setPushMode(push.value());
    getPushConfiguration().setTransport(push.transport());

    Div div = new Div();
    div.setText("Just a label");
    div.setId("label");
    add(div);
    Element area = ElementFactory.createTextarea();
    area.addPropertyChangeListener("value", "change", event -> {
    });
    area.setAttribute("id", "text");
    getElement().appendChild(area);
}
 
Example #9
Source File: WebComponentProviderTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@Test
public void setExporters_exportersHasOnePush_pushIsSet() {
    WebComponentConfigurationRegistry registry = setupConfigurations(
            ThemedComponentExporter.class, MyComponentExporter.class);
    Assert.assertTrue(registry.getEmbeddedApplicationAnnotation(Push.class)
            .isPresent());
}
 
Example #10
Source File: BasicPushUI.java    From flow with Apache License 2.0 5 votes vote down vote up
@Override
protected void init(VaadinRequest request) {
    /*
     * Read push settings from the UI instead of the the navigation target /
     * router layout to preserve the structure of these legacy testing UIs
     */
    Push push = getClass().getAnnotation(Push.class);

    getPushConfiguration().setPushMode(push.value());
    getPushConfiguration().setTransport(push.transport());

    super.init(request);
}
 
Example #11
Source File: AbstractTestUIWithLog.java    From flow with Apache License 2.0 5 votes vote down vote up
@Override
protected void init(VaadinRequest request) {
    /*
     * Read push settings from the UI instead of the the navigation target /
     * router layout to preserve the structure of these legacy testing UIs
     */
    Push push = getClass().getAnnotation(Push.class);

    if (push != null) {
        getPushConfiguration().setPushMode(push.value());
        getPushConfiguration().setTransport(push.transport());
    }

    add(log);
}
 
Example #12
Source File: PushWithRequireJSUI.java    From flow with Apache License 2.0 5 votes vote down vote up
@Override
protected void init(VaadinRequest request) {
    Push push = getClass().getAnnotation(Push.class);

    getPushConfiguration().setPushMode(push.value());
    getPushConfiguration().setTransport(push.transport());

    // https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.20/require.min.js
    getPage().addJavaScript("require.min.js");
}
 
Example #13
Source File: AddDivUI.java    From flow with Apache License 2.0 5 votes vote down vote up
@Override
protected void init(VaadinRequest request) {
    /*
     * Read push settings from the UI instead of the the navigation target /
     * router layout to preserve the structure of these legacy testing UIs
     */
    Push push = getClass().getAnnotation(Push.class);

    getPushConfiguration().setPushMode(push.value());
    getPushConfiguration().setTransport(push.transport());

    ip = request.getRemoteAddr();
    addDiv();

    ScheduledExecutorService ses = Executors.newScheduledThreadPool(1);
    long delay = 10;
    ses.scheduleAtFixedRate(() -> {

        access(() -> {
            addDiv();
        });

        if (msgId > 500) {
            throw new RuntimeException("Done");
        }
    }, delay, delay, TimeUnit.MILLISECONDS);
}
 
Example #14
Source File: WebComponentProviderTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@Test
public void setExporters_exportersHasSamePushDeclarations_pushIsSet() {
    WebComponentConfigurationRegistry registry = setupConfigurations(
            ThemedComponentExporter.class,
            SameThemedComponentExporter.class);
    Assert.assertEquals(PushMode.AUTOMATIC, registry
            .getEmbeddedApplicationAnnotation(Push.class).get().value());
}
 
Example #15
Source File: AppShellRegistry.java    From flow with Apache License 2.0 5 votes vote down vote up
/**
 * Modifies PushConfiguration instance based on the {@link Push} annotation
 * on {@link AppShellConfigurator}.
 *
 * @param pushConfiguration
 *            the PushConfigration instance to modify
 */
public void modifyPushConfiguration(PushConfiguration pushConfiguration) {
    List<Push> pushAnnotations = getAnnotations(Push.class);
    if (pushAnnotations.size() > 1) {
        throw new InvalidApplicationConfigurationException(
                String.format(AppShellRegistry.ERROR_MULTIPLE_ANNOTATION,
                        Push.class.getSimpleName()));
    } else if (!pushAnnotations.isEmpty()) {
        Push push = pushAnnotations.get(0);
        pushConfiguration.setPushMode(push.value());
        pushConfiguration.setTransport(push.transport());
    }
}
 
Example #16
Source File: WebComponentExporterAwareValidatorTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@Test
public void process_all_failing_anotations_are_reported()
        throws ServletException {
    try {
        annotationValidator.process(
                Collections.singleton(ThemeViewportWithParent.class),
                servletContext);
        Assert.fail("No exception was thrown for faulty setup.");
    } catch (InvalidApplicationConfigurationException iace) {
        String errorMessage = iace.getMessage();
        assertHint(errorMessage, Push.class);
    }
}
 
Example #17
Source File: BootstrapHandler.java    From flow with Apache License 2.0 5 votes vote down vote up
protected BootstrapContext createAndInitUI(Class<? extends UI> uiClass,
        VaadinRequest request, VaadinResponse response,
        VaadinSession session) {

    UI ui = ReflectTools.createInstance(uiClass);
    ui.getInternals().setContextRoot(
            request.getService().getContextRootRelativePath(request));

    PushConfiguration pushConfiguration = ui.getPushConfiguration();

    ui.getInternals().setSession(session);
    ui.setLocale(session.getLocale());

    BootstrapContext context = createBootstrapContext(request, response, ui,
            request.getService()::getContextRootRelativePath);

    Optional<Push> push = context
            .getPageConfigurationAnnotation(Push.class);

    DeploymentConfiguration deploymentConfiguration = context.getSession()
            .getService().getDeploymentConfiguration();
    PushMode pushMode = push.map(Push::value)
            .orElseGet(deploymentConfiguration::getPushMode);
    setupPushConnectionFactory(pushConfiguration, context);
    pushConfiguration.setPushMode(pushMode);
    pushConfiguration.setPushUrl(deploymentConfiguration.getPushURL());
    push.map(Push::transport).ifPresent(pushConfiguration::setTransport);

    // Set thread local here so it is available in init
    UI.setCurrent(ui);
    ui.doInit(request, session.getNextUIid());
    session.addUI(ui);

    // After init and adding UI to session fire init listeners.
    session.getService().fireUIInitListeners(ui);

    initializeUIWithRouter(request, ui);

    return context;
}
 
Example #18
Source File: BootstrapHandlerPushConfigurationTest.java    From flow with Apache License 2.0 4 votes vote down vote up
private static void assertPushConfiguration(
        PushConfiguration pushConfiguration, Push pushAnnotation) {
    assertPushConfiguration(pushConfiguration, pushAnnotation.value(),
            pushAnnotation.transport(), Transport.LONG_POLLING);
}
 
Example #19
Source File: WebComponentExporterAwareValidatorTest.java    From flow with Apache License 2.0 4 votes vote down vote up
@Test
public void process_non_linked_push_throws() throws ServletException {
    assertNon_linked_theme_throws(NonRoutePush.class, Push.class);
}