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:com.github.daytron.twaattin.presenter.LogoutBehaviour.java

License:Open Source License

@Override
public void buttonClick(Button.ClickEvent event) {
    VaadinSession.getCurrent().setAttribute(Principal.class, null);

    UI.getCurrent().setContent(new LoginScreen());

    Notification logoutNotification = new Notification("You've been logout",
            Notification.Type.TRAY_NOTIFICATION);
    logoutNotification.setPosition(Position.TOP_CENTER);
    logoutNotification.show(Page.getCurrent());
}

From source file:com.hack23.cia.web.impl.ui.application.CitizenIntelligenceAgencyUI.java

License:Apache License

@Override
protected void init(final VaadinRequest request) {
    VaadinSession.getCurrent().setErrorHandler(new UiInstanceErrorHandler(this));
    setSizeFull();//from w  ww  .  j a  v  a 2 s . c  om
    final DiscoveryNavigator navigator = new DiscoveryNavigator(this, this);
    navigator.addView("", mainView);
    setNavigator(navigator);

    final Page currentPage = Page.getCurrent();
    final String requestUrl = currentPage.getLocation().toString();
    final String language = request.getLocale().getLanguage();
    final UserConfiguration userConfiguration = configurationManager.getUserConfiguration(requestUrl, language);

    currentPage.setTitle(
            userConfiguration.getAgency().getAgencyName() + ":" + userConfiguration.getPortal().getPortalName()
                    + ":" + userConfiguration.getLanguage().getLanguageName());

    if (getSession().getUIs().isEmpty()) {
        final WebBrowser webBrowser = currentPage.getWebBrowser();

        final CreateApplicationSessionRequest serviceRequest = new CreateApplicationSessionRequest();
        serviceRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());

        final String ipInformation = WebBrowserUtil.getIpInformation(webBrowser);
        serviceRequest.setIpInformation(ipInformation);
        serviceRequest.setUserAgentInformation(webBrowser.getBrowserApplication());
        serviceRequest.setLocale(webBrowser.getLocale().toString());
        serviceRequest.setOperatingSystem(WebBrowserUtil.getOperatingSystem(webBrowser));
        serviceRequest.setSessionType(ApplicationSessionType.ANONYMOUS);

        final ServiceResponse serviceResponse = applicationManager.service(serviceRequest);
        LOGGER.info(LOG_INFO_BROWSER_ADDRESS_APPLICATION_SESSION_ID_RESULT, requestUrl, language, ipInformation,
                webBrowser.getBrowserApplication(), serviceRequest.getSessionId(),
                serviceResponse.getResult().toString());
    }
}

From source file:com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl.AbstractChartDataManagerImpl.java

License:Apache License

/**
 * Adds the chart.//from   w  ww . j av  a2s . c o  m
 *
 * @param content
 *            the content
 * @param caption
 *            the caption
 * @param chart
 *            the chart
 */
protected final void addChart(final AbstractOrderedLayout content, final String caption, final DCharts chart) {
    final HorizontalLayout horizontalLayout = new HorizontalLayout();

    final int browserWindowWidth = Page.getCurrent().getBrowserWindowWidth() - 50;
    final int browserWindowHeight = Page.getCurrent().getBrowserWindowHeight() - 200;

    horizontalLayout.setWidth(browserWindowWidth, Unit.PIXELS);
    horizontalLayout.setHeight(browserWindowHeight, Unit.PIXELS);

    final Panel formPanel = new Panel();
    formPanel.setSizeFull();
    formPanel.setContent(horizontalLayout);

    content.addComponent(formPanel);
    content.setExpandRatio(formPanel, ContentRatio.LARGE);

    chart.setWidth(browserWindowWidth - 50, Unit.PIXELS);
    chart.setHeight(browserWindowHeight - 100, Unit.PIXELS);
    chart.setMarginRight(5);
    chart.setMarginLeft(5);
    chart.setMarginBottom(5);
    chart.setMarginTop(5);

    chart.setEnableDownload(true);
    chart.setChartImageFormat(ChartImageFormat.PNG);

    horizontalLayout.addComponent(chart);
    chart.setCaption(caption);
}

From source file:com.hack23.cia.web.impl.ui.application.web.listener.AuthorizationFailureEventListener.java

License:Apache License

@Override
public void onApplicationEvent(final AuthorizationFailureEvent authorizationFailureEvent) {

    final String sessionId = RequestContextHolder.currentRequestAttributes().getSessionId();

    final CreateApplicationEventRequest serviceRequest = new CreateApplicationEventRequest();
    serviceRequest.setSessionId(sessionId);

    serviceRequest.setEventGroup(ApplicationEventGroup.APPLICATION);
    serviceRequest.setApplicationOperation(ApplicationOperationType.AUTHORIZATION);

    serviceRequest.setUserId(UserContextUtil.getUserIdFromSecurityContext());

    final Page currentPageIfAny = Page.getCurrent();
    final String requestUrl = UserContextUtil.getRequestUrl(currentPageIfAny);
    final UI currentUiIfAny = UI.getCurrent();
    String methodInfo = "";

    if (currentPageIfAny != null && currentUiIfAny != null && currentUiIfAny.getNavigator() != null
            && currentUiIfAny.getNavigator().getCurrentView() != null) {
        serviceRequest.setPage(currentUiIfAny.getNavigator().getCurrentView().getClass().getSimpleName());
        serviceRequest.setPageMode(currentPageIfAny.getUriFragment());
    }/*w  w  w .j  ava 2s.  c o m*/

    if (authorizationFailureEvent.getSource() instanceof ReflectiveMethodInvocation) {
        final ReflectiveMethodInvocation methodInvocation = (ReflectiveMethodInvocation) authorizationFailureEvent
                .getSource();
        if (methodInvocation.getMethod() != null && methodInvocation.getThis() != null) {
            methodInfo = methodInvocation.getThis().getClass().getSimpleName() + "."
                    + methodInvocation.getMethod().getName();
        }
    }

    serviceRequest.setErrorMessage("Url:" + requestUrl + " , Method" + methodInfo + " ," + AUTHORITIES
            + authorizationFailureEvent.getAuthentication().getAuthorities() + REQUIRED_AUTHORITIES
            + authorizationFailureEvent.getConfigAttributes() + " source:"
            + authorizationFailureEvent.getSource());
    serviceRequest.setApplicationMessage(ACCESS_DENIED);

    applicationManager.service(serviceRequest);

    LOGGER.info(LOG_MSG_AUTHORIZATION_FAILURE_SESSION_ID_AUTHORITIES_REQUIRED_AUTHORITIES, requestUrl,
            methodInfo, sessionId, authorizationFailureEvent.getAuthentication().getAuthorities().toString(),
            authorizationFailureEvent.getConfigAttributes().toString());
}

From source file:com.haulmont.cuba.web.config.WebDeviceInfoProvider.java

License:Apache License

@Nullable
@Override/*from w  w  w  .  ja v a2s.  c o m*/
public DeviceInfo getDeviceInfo() {
    // per request cache
    HttpServletRequest currentServletRequest = VaadinServletService.getCurrentServletRequest();
    if (currentServletRequest == null) {
        return null;
    }

    DeviceInfo deviceInfo = (DeviceInfo) currentServletRequest.getAttribute(DeviceInfoProvider.NAME);
    if (deviceInfo != null) {
        return deviceInfo;
    }

    Page page = Page.getCurrent();

    if (page == null) {
        return null;
    }

    WebBrowser webBrowser = page.getWebBrowser();

    DeviceInfo di = new DeviceInfo();

    di.setAddress(webBrowser.getAddress());
    di.setBrowserApplication(webBrowser.getBrowserApplication());
    di.setBrowserMajorVersion(webBrowser.getBrowserMajorVersion());
    di.setBrowserMinorVersion(webBrowser.getBrowserMinorVersion());

    di.setChrome(webBrowser.isChrome());
    di.setChromeFrame(webBrowser.isChromeFrame());
    di.setChromeFrameCapable(webBrowser.isChromeFrameCapable());
    di.setEdge(webBrowser.isEdge());
    di.setFirefox(webBrowser.isFirefox());
    di.setOpera(webBrowser.isOpera());
    di.setIE(webBrowser.isIE());

    if (webBrowser.isWindows()) {
        di.setOperatingSystem(OperatingSystem.WINDOWS);
    } else if (webBrowser.isAndroid()) {
        di.setOperatingSystem(OperatingSystem.ANDROID);
    } else if (webBrowser.isIOS()) {
        di.setOperatingSystem(OperatingSystem.IOS);
    } else if (webBrowser.isMacOSX()) {
        di.setOperatingSystem(OperatingSystem.MACOSX);
    } else if (webBrowser.isLinux()) {
        di.setOperatingSystem(OperatingSystem.LINUX);
    }

    di.setIPad(webBrowser.isIPad());
    di.setIPhone(webBrowser.isIPhone());
    di.setWindowsPhone(webBrowser.isWindowsPhone());

    di.setSecureConnection(webBrowser.isSecureConnection());
    di.setLocale(webBrowser.getLocale());

    di.setScreenHeight(webBrowser.getScreenHeight());
    di.setScreenWidth(webBrowser.getScreenWidth());

    currentServletRequest.setAttribute(DeviceInfoProvider.NAME, di);

    return di;
}

From source file:com.haulmont.cuba.web.exception.ExceptionDialog.java

License:Apache License

protected boolean browserSupportCopy() {
    WebBrowser webBrowser = Page.getCurrent().getWebBrowser();
    return !webBrowser.isSafari() && !webBrowser.isIOS() && !webBrowser.isWindowsPhone();
}

From source file:com.haulmont.cuba.web.exception.ExceptionDialog.java

License:Apache License

protected void forceLogout() {
    App app = AppUI.getCurrent().getApp();
    final WebWindowManager wm = app.getWindowManager();
    try {/* w  w w .  j a  v a  2  s  .co m*/
        Connection connection = wm.getApp().getConnection();
        if (connection.isConnected()) {
            connection.logout();
        }
    } catch (Exception e) {
        log.warn("Exception on forced logout", e);
    } finally {
        // always restart UI
        String url = ControllerUtils.getLocationWithoutParams() + "?restartApp";

        Page.getCurrent().open(url, "_self");
    }
}

From source file:com.haulmont.cuba.web.exception.NoUserSessionHandler.java

License:Apache License

protected void relogin() {
    String url = ControllerUtils.getLocationWithoutParams() + "?restartApp";
    Page.getCurrent().open(url, "_self");
}

From source file:com.haulmont.cuba.web.gui.components.CubaCurrencyField.java

License:Apache License

protected boolean useWrapper() {
    Page current = Page.getCurrent();
    if (current != null) {
        WebBrowser browser = current.getWebBrowser();
        return browser != null
                && (browser.isIE() && browser.getBrowserMajorVersion() <= 10 || browser.isSafari());
    } else {/*from   w ww .  j  a v a2 s . c  o  m*/
        return false;
    }
}

From source file:com.haulmont.cuba.web.gui.components.mainwindow.WebNewWindowButton.java

License:Apache License

public WebNewWindowButton() {
    component = new CubaButton();
    component.addStyleName(NEW_WINDOW_BUTTON_STYLENAME);
    component.setDescription(null);/*from www  . ja v  a  2 s.  c  o m*/

    URL pageUrl;
    try {
        pageUrl = Page.getCurrent().getLocation().toURL();
    } catch (MalformedURLException ignored) {
        LoggerFactory.getLogger(WebNewWindowButton.class).warn("Couldn't get URL of current Page");
        return;
    }

    ExternalResource currentPage = new ExternalResource(pageUrl);
    final BrowserWindowOpener opener = new BrowserWindowOpener(currentPage);
    opener.setWindowName("_blank");

    opener.extend(component);
}