Java Code Examples for com.vaadin.ui.UI#access()

The following examples show how to use com.vaadin.ui.UI#access() . 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: HawkbitUIErrorHandler.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void error(final ErrorEvent event) {

    // filter upload exceptions
    if (event.getThrowable() instanceof UploadException) {
        return;
    }

    final HawkbitErrorNotificationMessage message = buildNotification(getRootExceptionFrom(event));
    if (event instanceof ConnectorErrorEvent) {
        final Connector connector = ((ConnectorErrorEvent) event).getConnector();
        if (connector instanceof UI) {
            final UI uiInstance = (UI) connector;
            uiInstance.access(() -> message.show(uiInstance.getPage()));
            return;
        }
    }

    final Optional<Page> originError = getPageOriginError(event);
    if (originError.isPresent()) {
        message.show(originError.get());
        return;
    }

    HawkbitErrorNotificationMessage.show(message.getCaption(), message.getDescription(), Type.HUMANIZED_MESSAGE);
}
 
Example 2
Source File: DefaultApp.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void redirectAfterLogout(String loggedOutUrl) {
    if (!Strings.isNullOrEmpty(loggedOutUrl)) {
        AppUI currentUi = AppUI.getCurrent();
        // it can be null if we handle request in a custom RequestHandler
        if (currentUi != null) {
            currentUi.setContent(null);
            currentUi.getPage().setLocation(loggedOutUrl);
        } else {
            VaadinResponse response = VaadinService.getCurrentResponse();
            try {
                ((VaadinServletResponse) response).getHttpServletResponse().
                        sendRedirect(loggedOutUrl);
            } catch (IOException e) {
                log.error("Error on send redirect to client", e);
            }
        }

        VaadinSession vaadinSession = VaadinSession.getCurrent();
        for (UI ui : vaadinSession.getUIs()) {
            if (ui != currentUi) {
                ui.access(() -> {
                    ui.setContent(null);
                    ui.getPage().setLocation(loggedOutUrl);
                });
            }
        }
    }
}