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:org.jumpmind.vaadin.ui.common.CommonUiUtils.java

License:Open Source License

public static void notify(String caption, String message, Throwable ex, Type type) {
    Page page = Page.getCurrent();
    if (page != null) {
        Notification notification = new Notification(caption,
                contactWithLineFeed(FormatUtils.wordWrap(message, 150)), Type.HUMANIZED_MESSAGE);
        notification.setPosition(Position.MIDDLE_CENTER);
        notification.setDelayMsec(-1);//  ww  w. j  av a 2  s . c  o m

        String style = ValoTheme.NOTIFICATION_SUCCESS;
        if (type == Type.ERROR_MESSAGE) {
            style = ValoTheme.NOTIFICATION_FAILURE;
        } else if (type == Type.WARNING_MESSAGE) {
            style = ValoTheme.NOTIFICATION_WARNING;
        }
        notification.setStyleName(
                notification.getStyleName() + " " + ValoTheme.NOTIFICATION_CLOSABLE + " " + style);
        notification.show(Page.getCurrent());
    }
}

From source file:org.jumpmind.vaadin.ui.common.ResizableWindow.java

License:Open Source License

public void showAtSize(double percentOfBrowserSize) {
    Page page = Page.getCurrent();

    setWindowMode(WindowMode.NORMAL);/* ww w.j  a  v a 2 s.  c o m*/

    int pageHeight = page.getBrowserWindowHeight();
    int pageWidth = page.getBrowserWindowWidth();

    setHeight((int) (pageHeight * percentOfBrowserSize), Unit.PIXELS);
    setWidth((int) (pageWidth * percentOfBrowserSize), Unit.PIXELS);

    show();

}

From source file:org.opencms.ui.apps.CmsAppWorkplaceUi.java

License:Open Source License

/**
* @see com.vaadin.ui.UI#init(com.vaadin.server.VaadinRequest)
*//*w w  w .  j a v  a2s .  c o m*/
@Override
protected void init(VaadinRequest req) {

    super.init(req);
    if (!OpenCms.getRoleManager().hasRole(getCmsObject(), CmsRole.EDITOR)) {
        Notification.show(CmsVaadinUtils.getMessageText(Messages.GUI_WORKPLACE_ACCESS_DENIED_TITLE_0),
                CmsVaadinUtils.getMessageText(Messages.GUI_WORKPLACE_ACCESS_DENIED_MESSAGE_0),
                Type.ERROR_MESSAGE);
        return;
    }
    getSession().setErrorHandler(new CmsVaadinErrorHandler(this));

    m_navigationStateManager = new Navigator.UriFragmentManager(getPage());
    CmsAppNavigator navigator = new CmsAppNavigator(this, m_navigationStateManager, this);
    navigator.addProvider(this);
    setNavigator(navigator);

    Page.getCurrent().addBrowserWindowResizeListener(this);
    m_history = new CmsHistoryExtension(getCurrent());
    CmsWindowCloseExtension windowClose = new CmsWindowCloseExtension(getCurrent());
    windowClose.addWindowCloseListener(this);
    navigator.addViewChangeListener(this);
    navigateToFragment();

    getReconnectDialogConfiguration().setDialogText(CmsVaadinUtils
            .getMessageText(org.opencms.ui.Messages.GUI_SYSTEM_CONNECTION_LOST_TRYING_RECONNECT_0));
    getReconnectDialogConfiguration().setDialogTextGaveUp(
            CmsVaadinUtils.getMessageText(org.opencms.ui.Messages.GUI_SYSTEM_CONNECTION_LOST_GIVING_UP_0));
}

From source file:org.opencms.ui.apps.CmsAppWorkplaceUi.java

License:Open Source License

/**
 * Navigates to the current URI fragment.<p>
 *//*  ww  w.  j a  va  2s  .com*/
private void navigateToFragment() {

    String fragment = getPage().getUriFragment();
    if (fragment != null) {
        getNavigator().navigateTo(fragment);
    } else {
        CmsObject cms = getCmsObject();
        String target = CmsLoginHelper.getStartView(cms);
        if (target != null) {
            if (target.startsWith("#")) {
                getNavigator().navigateTo(target.substring(1));
            } else {
                Page.getCurrent().setLocation(OpenCms.getLinkManager().substituteLink(cms, target));
            }
        } else {
            showHome();
        }
    }
}

From source file:org.opencms.ui.apps.CmsEditor.java

License:Open Source License

/**
 * Navigates to the back link target.<p>
 *
 * @param backlink the back link//from www .ja  va2 s. com
 */
public static void openBackLink(String backlink) {

    try {
        backlink = URLDecoder.decode(backlink, "UTF-8");
        String current = Page.getCurrent().getLocation().toString();
        if (current.contains("#")) {
            current = current.substring(0, current.indexOf("#"));
        }
        // check if the back link targets the workplace UI
        if (backlink.startsWith(current)) {
            // use the navigator to open the target
            String target = backlink.substring(backlink.indexOf("#") + 1);
            CmsAppWorkplaceUi.get().getNavigator().navigateTo(target);
        } else {
            // otherwise set the new location
            Page.getCurrent().setLocation(backlink);
        }
    } catch (UnsupportedEncodingException e) {
        // only in case of malformed charset
        LOG.error(e.getLocalizedMessage(), e);
    }
}

From source file:org.opencms.ui.apps.CmsFileExplorer.java

License:Open Source License

/**
 * Creates the site selector combo box.<p>
 *
 * @param cms the current cms context/* w  w  w.  ja v a 2s  .c o  m*/
 *
 * @return the combo box
 */
private ComboBox createSiteSelect(CmsObject cms) {

    final IndexedContainer availableSites = CmsVaadinUtils.getAvailableSitesContainer(cms, SITE_CAPTION);
    ComboBox combo = new ComboBox(null, availableSites);
    combo.setTextInputAllowed(true);
    combo.setNullSelectionAllowed(false);
    combo.setWidth("200px");
    combo.setInputPrompt(
            Messages.get().getBundle(UI.getCurrent().getLocale()).key(Messages.GUI_EXPLORER_CLICK_TO_EDIT_0));
    combo.setItemCaptionPropertyId(SITE_CAPTION);
    combo.select(cms.getRequestContext().getSiteRoot());
    combo.setFilteringMode(FilteringMode.CONTAINS);
    combo.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {

            String value = (String) event.getProperty().getValue();
            if (availableSites.containsId(value)) {
                changeSite(value, null);
                m_appContext.updateOnChange();
                availableSites.removeAllContainerFilters();
            }
        }
    });
    if (Page.getCurrent().getBrowserWindowHeight() > 650) {
        combo.setPageLength(20);
    }
    return combo;
}

From source file:org.opencms.ui.components.CmsBasicDialog.java

License:Open Source License

/**
 * Initializes the dialog window.<p>
 *
 * @param width the dialog width/*from   www  .  j a  v a2 s .c  o m*/
 *
 * @return the window to be used by dialogs
 */
public static Window prepareWindow(DialogWidth width) {

    Window window = new Window();
    window.setModal(true);
    window.setClosable(true);
    int pageWidth = Page.getCurrent().getBrowserWindowWidth();
    if (((width == DialogWidth.wide) && (pageWidth < 810))
            || ((width == DialogWidth.narrow) && (pageWidth < 610))) {
        // in case the available page width does not allow the desired width, use max
        width = DialogWidth.max;
    }
    if (width == DialogWidth.max) {
        // in case max width would result in a width very close to wide or narrow, use their static width instead of relative width
        if ((pageWidth >= 610) && (pageWidth < 670)) {
            width = DialogWidth.narrow;
        } else if ((pageWidth >= 810) && (pageWidth < 890)) {
            width = DialogWidth.wide;
        }
    }
    switch (width) {
    case content:
        // do nothing
        break;
    case wide:
        window.setWidth("800px");
        break;
    case max:
        window.setWidth("90%");
        break;
    case narrow:
    default:
        window.setWidth("600px");
        break;
    }
    window.center();
    return window;
}

From source file:org.opencms.ui.components.CmsToolBar.java

License:Open Source License

/**
 * Recalculates the space required by the toolbar buttons
 *///from w  w  w .ja  v  a 2  s . c  om
protected void updateFoldingThreshhold() {

    int left = estimateRequiredWidth(m_itemsLeft) + estimateRequiredWidth(m_leftButtons);
    int right = estimateRequiredWidth(m_itemsRight) + estimateRequiredWidth(m_rightButtons);
    int requiredWidth = left > right ? left : right;
    if (requiredWidth < 350) {
        // folding not required at any width
        m_foldingThreshhold = 0;
    } else if (requiredWidth < 400) {
        m_foldingThreshhold = 984;
    } else if (requiredWidth <= 520) {
        m_foldingThreshhold = 1240;
    } else {
        // always fold
        m_foldingThreshhold = 10000;
    }
    updateButtonVisibility(Page.getCurrent().getBrowserWindowWidth());
}

From source file:org.opencms.ui.dialogs.CmsSiteSelectDialog.java

License:Open Source License

/**
 * Submits the dialog action.<p>//  w w  w.j av a  2 s .  c o m
 */
void submit() {

    String siteRoot = (String) m_siteComboBox.getValue();
    if (!m_context.getCms().getRequestContext().getSiteRoot().equals(siteRoot)) {
        A_CmsUI.get().changeSite(siteRoot);
        if (CmsStringUtil.isEmptyOrWhitespaceOnly(siteRoot)
                || OpenCms.getSiteManager().isSharedFolder(siteRoot)) {
            // switch to explorer view when selecting shared or root site

            Page.getCurrent().open(CmsCoreService.getFileExplorerLink(A_CmsUI.getCmsObject(), siteRoot),
                    "_top");
            return;
        }
    } else {
        siteRoot = null;
    }
    m_context.finish(null, siteRoot);
}

From source file:org.opencms.ui.login.CmsLoginController.java

License:Open Source License

/**
 * Logs the current user out by invalidating the session an reloading the current URI.<p>
 * Important:  This works only within vaadin apps.<p>
 *///from w w w.  j  a  va  2s  . com
public static void logout() {

    CmsObject cms = A_CmsUI.getCmsObject();
    if (UI.getCurrent() instanceof CmsAppWorkplaceUi) {
        ((CmsAppWorkplaceUi) UI.getCurrent()).onWindowClose();
    }
    String loggedInUser = cms.getRequestContext().getCurrentUser().getName();
    UI.getCurrent().getSession().close();
    String loginLink = OpenCms.getLinkManager().substituteLinkForUnknownTarget(cms,
            CmsWorkplaceLoginHandler.LOGIN_HANDLER, false);
    VaadinService.getCurrentRequest().getWrappedSession().invalidate();
    Page.getCurrent().setLocation(loginLink);
    // logout was successful
    if (LOG.isInfoEnabled()) {
        LOG.info(org.opencms.jsp.Messages.get().getBundle().key(org.opencms.jsp.Messages.LOG_LOGOUT_SUCCESFUL_3,
                loggedInUser, "{workplace logout option}", cms.getRequestContext().getRemoteAddress()));
    }
}