Example usage for com.vaadin.server Page getCurrent

List of usage examples for com.vaadin.server Page getCurrent

Introduction

In this page you can find the example usage for com.vaadin.server Page getCurrent.

Prototype

public static Page getCurrent() 

Source Link

Document

Gets the Page to which the current uI belongs.

Usage

From source file:de.gedoplan.webclients.vaadin.VaadinDemoUi.java

public MenuBar createMenu() {
    User user = userProvider.get();// w w w. ja v a  2s.  c  o  m
    MenuBar mainMenu = new MenuBar();
    mainMenu.setWidth(100, Unit.PERCENTAGE);
    mainMenu.setStyleName("main");
    mainMenu.addItem("", new ThemeResource("images/vaadin-logo.png"),
            e -> navigator.navigateTo(Konstanten.VAADIN_VIEW_INDEX)).setStyleName("logo");
    if (user.isInRole(User.UserRole.ADMIN)) {
        mainMenu.addItem(Messages.menu_customer.value(),
                e -> navigator.navigateTo(Konstanten.VAADIN_VIEW_CUSTOMERS));
    }
    mainMenu.addItem(Messages.menu_orders.value(), e -> navigator.navigateTo(Konstanten.VAADIN_VIEW_ORDERS));
    if (user.isInRole(User.UserRole.CUSTOMER)) {
        mainMenu.addItem(Messages.menu_customerdetails.value(), e -> navigator
                .navigateTo(Konstanten.VAADIN_VIEW_CUSTOMER_DETAILS + "/" + user.getCustomerID()));
    }
    MenuBar.MenuItem userMenu = mainMenu.addItem(user.getLogin(), null);
    userMenu.setStyleName("align-right");
    userMenu.addItem(Messages.logout.value(), e -> {
        try {
            JaasAccessControl.logout();
            VaadinSession.getCurrent().close();
            Page.getCurrent().setLocation(Konstanten.VAADIN_LOGIN_PATH);
        } catch (ServletException ex) {
            Logger.getLogger(VaadinDemoUi.class.getName()).log(Level.SEVERE, null, ex);
        }
    });
    return mainMenu;
}

From source file:de.gedoplan.webclients.vaadin.views.CustomerForm.java

private void configureActions() {
    speichern = new Button(Messages.save.value(), e -> {
        try {//from www  .  jav  a  2s .c  o m
            fieldGroup.commit();
            fieldGroup.setItemDataSource(
                    customerService.updateCustomer(fieldGroup.getItemDataSource().getBean()));
            Notification success = new Notification(Messages.save_success.value());
            success.setStyleName(ValoTheme.NOTIFICATION_SUCCESS);
            success.show(Page.getCurrent());
        } catch (FieldGroup.CommitException ex) {
            // Leer
        }
    });
    abbrechen = new Button(Messages.cancel.value(),
            e -> navigator.navigateTo(Konstanten.VAADIN_VIEW_CUSTOMERS));
}

From source file:de.kaiserpfalzEdv.vaadin.menu.impl.MenuImpl.java

License:Apache License

@Inject
public MenuImpl(final Authenticator accessControl, final EventBus bus, final I18NHandler i18n,
        final List<View> allViews) {
    this.accessControl = accessControl;
    this.bus = bus;
    this.i18n = i18n;
    this.allViews = allViews;

    setPrimaryStyleName(ValoTheme.MENU_ROOT);
    menuPart = new CssLayout();
    menuPart.addStyleName(ValoTheme.MENU_PART);

    // header of the menu
    final HorizontalLayout top = new HorizontalLayout();
    top.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    top.addStyleName(ValoTheme.MENU_TITLE);
    top.setSpacing(true);//from  w w w.j  a  va2  s. co m
    Label title = new Label(translate("application.name"));
    title.addStyleName(ValoTheme.LABEL_H3);
    title.setSizeUndefined();
    Image image = new Image(null, new ThemeResource("img/table-logo.png"));
    image.setStyleName("logo");
    top.addComponent(image);
    top.addComponent(title);
    menuPart.addComponent(top);

    // logout menu item
    MenuBar logoutMenu = new MenuBar();
    logoutMenu.addItem(translate("button.logout.caption"), FontAwesome.valueOf(translate("button.logout.icon")),
            selectedItem -> {
                VaadinSession.getCurrent().getSession().invalidate();
                Page.getCurrent().reload();
            });

    logoutMenu.addStyleName("user-menu");
    menuPart.addComponent(logoutMenu);

    // button for toggling the visibility of the menu when on a small screen
    final Button showMenu = new Button(translate("application.name"), new ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            if (menuPart.getStyleName().contains(VALO_MENU_VISIBLE)) {
                menuPart.removeStyleName(VALO_MENU_VISIBLE);
            } else {
                menuPart.addStyleName(VALO_MENU_VISIBLE);
            }
        }
    });
    showMenu.addStyleName(ValoTheme.BUTTON_PRIMARY);
    showMenu.addStyleName(ValoTheme.BUTTON_SMALL);
    showMenu.addStyleName(VALO_MENU_TOGGLE);
    showMenu.setIcon(FontAwesome.NAVICON);
    menuPart.addComponent(showMenu);

    // container for the navigation buttons, which are added by addView()
    menuItemsLayout = new CssLayout();
    menuItemsLayout.setPrimaryStyleName(VALO_MENUITEMS);
    menuPart.addComponent(menuItemsLayout);

    addComponent(menuPart);
}

From source file:de.metas.procurement.webui.LoggingConfiguration.java

License:Open Source License

public void updateMDC() {
    ////ww  w . ja va  2  s.  c o m
    // Remote address
    try {
        final VaadinRequest vaadinRequest = VaadinService.getCurrentRequest();
        if (vaadinRequest != null) {
            final String remoteAddr = vaadinRequest.getRemoteAddr();
            MDC.put(MDC_Param_RemoteAddr, remoteAddr);
        }
    } catch (final Exception e) {
        e.printStackTrace();
        MDC.put(MDC_Param_RemoteAddr, "?");
    }

    //
    // LoggedUser
    try {
        final MFSession mfSession = MFProcurementUI.getCurrentMFSession();
        if (mfSession != null) {
            final User user = mfSession.getUser();
            if (user != null) {
                final String email = user.getEmail();
                if (email != null) {
                    MDC.put(MDC_Param_LoggedUser, email);
                }
            }
        }

    } catch (final Exception e) {
        e.printStackTrace();
        MDC.put(MDC_Param_LoggedUser, "?");
    }

    //
    // UserAgent
    try {
        final Page page = Page.getCurrent();
        if (page != null) {
            final WebBrowser webBrowser = page.getWebBrowser();
            if (webBrowser != null) {
                final String userAgent = webBrowser.getBrowserApplication();
                MDC.put(MDC_Param_UserAgent, userAgent);
            }
        }
    } catch (final Exception e) {
        e.printStackTrace();
        MDC.put(MDC_Param_UserAgent, "?");
    }

    //
    // SessionId
    try {
        final VaadinSession session = VaadinSession.getCurrent();
        if (session != null) {
            final int sessionId = System.identityHashCode(session);
            MDC.put(MDC_Param_SessionId, Integer.toString(sessionId));
        }
    } catch (final Exception e) {
        e.printStackTrace();
        MDC.put(MDC_Param_SessionId, "?");
    }

    //
    // UI Id
    try {
        final UI ui = UI.getCurrent();
        if (ui != null) {
            final int uiId = ui.getUIId();
            MDC.put(MDC_Param_UIId, Integer.toString(uiId));
        }
    } catch (final Exception e) {
        e.printStackTrace();
        MDC.put(MDC_Param_UIId, "?");
    }
}

From source file:de.metas.procurement.webui.server.NotificationErrorHandler.java

License:Open Source License

@Override
protected void displayError(final ErrorMessage errorMessage, final ErrorEvent event) {
    final Notification notification = new Notification("", errorMessage.getFormattedHtmlMessage(), defaultType,
            true);/* ww  w  .j  a  v a 2s  .  com*/
    notification.show(Page.getCurrent());
}

From source file:de.metas.procurement.webui.service.impl.LoginRememberMeService.java

License:Open Source License

public boolean isEnabled() {
    if (!enabled) {
        return false;
    }//from ww  w  . j a va 2 s  .co  m

    final Page page = Page.getCurrent();
    if (page != null && page.getWebBrowser().isChrome()) {
        logger.trace(
                "Considering feature disabled for chome because Chrome's password manager is known to work");
        return false;
    }

    return true;
}

From source file:de.metas.procurement.webui.ui.component.MFNavigator.java

License:Open Source License

private final void showNextViewNotification() {
    final Notification notification = this.nextViewNotification;
    this.nextViewNotification = null;

    if (notification == null) {
        return;/*from w  w  w  . ja  v a  2 s  . com*/
    }

    notification.show(Page.getCurrent());
}

From source file:de.metas.procurement.webui.ui.view.LoginView.java

License:Open Source License

protected void onForgotPassword(final String email) {
    if (Strings.isNullOrEmpty(email)) {
        throw new PasswordResetFailedException(email, i18n.get("LoginView.passwordReset.error.fillEmail"));
    }/* w  w w. j  a v a2  s.  c  o  m*/

    final String passwordResetKey = loginService.generatePasswordResetKey(email);
    final URI passwordResetURI = PasswordResetView.buildPasswordResetURI(passwordResetKey);
    loginService.sendPasswordResetKey(email, passwordResetURI);

    final Notification notification = new Notification(i18n.get("LoginView.passwordReset.notification.title") // "Password reset"
            , i18n.get("LoginView.passwordReset.notification.message") // "Your password has been reset. Please check your email and click on that link"
            , Type.HUMANIZED_MESSAGE);
    notification.setDelayMsec(15 * 1000);
    notification.show(Page.getCurrent());
}

From source file:de.metas.procurement.webui.ui.view.PasswordResetView.java

License:Open Source License

public static final URI buildPasswordResetURI(final String passwordResetKey) {
    try {//w  ww.  ja v  a2s. c  o m
        final URI uri = Page.getCurrent().getLocation();
        final String query = null;
        final String fragment = MFNavigator.createURIFragment(NAME, passwordResetKey);
        final URI resetURI = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), query, fragment);
        System.out.println(resetURI);
        return resetURI;
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}

From source file:de.metas.procurement.webui.util.JavascriptUtils.java

License:Open Source License

/**
 * Inject a JavaScript code snippet which will select the text content when the text field gains focus.
 * //from  ww w .  ja va 2 s .  c  om
 * Please keep in mind:
 * <ul>
 * <li>This function requires {@link #RESOURCE_JQuery}.
 * <li><code>component</code> has to have the ID set.
 * </ul>
 * 
 * @param component
 */
public static void enableSelectAllOnFocus(final AbstractTextField component) {
    Preconditions.checkNotNull(component, "component is null");

    final String componentId = component.getId();
    Preconditions.checkNotNull(componentId, "componentId is null");

    Page.getCurrent().getJavaScript()
            .execute("$('#" + componentId + "').focus(function(){$(this).select();});");
}