Search in sources :

Example 1 with Push

use of com.vaadin.flow.component.page.Push in project flow by vaadin.

the class PushView method onAttach.

@Override
protected void onAttach(AttachEvent attachEvent) {
    super.onAttach(attachEvent);
    UI ui = attachEvent.getUI();
    // Fallback transport is forced to websocket so that we either get a
    // websocket connection or no push connection at all
    ui.getPushConfiguration().setFallbackTransport(Transport.WEBSOCKET);
    add(new NativeButton("Say hello", e -> {
        add(new Paragraph("Hello"));
        new Thread(new SayWorld(ui)).start();
    }));
}
Also used : Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) UI(com.vaadin.flow.component.UI) Transport(com.vaadin.flow.shared.ui.Transport) AttachEvent(com.vaadin.flow.component.AttachEvent) Paragraph(com.vaadin.flow.component.html.Paragraph) Push(com.vaadin.flow.component.page.Push) Route(com.vaadin.flow.router.Route) NativeButton(com.vaadin.flow.component.html.NativeButton) UI(com.vaadin.flow.component.UI) Paragraph(com.vaadin.flow.component.html.Paragraph)

Example 2 with Push

use of com.vaadin.flow.component.page.Push in project flow by vaadin.

the class BootstrapHandler method createAndInitUI.

protected BootstrapContext createAndInitUI(Class<? extends UI> uiClass, VaadinRequest request, VaadinResponse response, VaadinSession session) {
    UI ui = ReflectTools.createInstance(uiClass);
    PushConfiguration pushConfiguration = ui.getPushConfiguration();
    ui.getInternals().setSession(session);
    ui.setLocale(session.getLocale());
    BootstrapContext context = new BootstrapContext(request, response, session, ui);
    Optional<Push> push = context.getPageConfigurationAnnotation(Push.class);
    DeploymentConfiguration deploymentConfiguration = context.getSession().getService().getDeploymentConfiguration();
    PushMode pushMode = push.map(Push::value).orElseGet(deploymentConfiguration::getPushMode);
    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);
    return context;
}
Also used : PushConfiguration(com.vaadin.flow.component.PushConfiguration) UI(com.vaadin.flow.component.UI) Push(com.vaadin.flow.component.page.Push) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) PushMode(com.vaadin.flow.shared.communication.PushMode)

Example 3 with Push

use of com.vaadin.flow.component.page.Push in project flow by vaadin.

the class BasicPushUI method init.

@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);
}
Also used : Push(com.vaadin.flow.component.page.Push)

Aggregations

Push (com.vaadin.flow.component.page.Push)3 UI (com.vaadin.flow.component.UI)2 AttachEvent (com.vaadin.flow.component.AttachEvent)1 PushConfiguration (com.vaadin.flow.component.PushConfiguration)1 Div (com.vaadin.flow.component.html.Div)1 NativeButton (com.vaadin.flow.component.html.NativeButton)1 Paragraph (com.vaadin.flow.component.html.Paragraph)1 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)1 Route (com.vaadin.flow.router.Route)1 PushMode (com.vaadin.flow.shared.communication.PushMode)1 Transport (com.vaadin.flow.shared.ui.Transport)1