Java Code Examples for com.vaadin.server.Page#getCurrent()
The following examples show how to use
com.vaadin.server.Page#getCurrent() .
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: WebAbstractDataGrid.java From cuba with Apache License 2.0 | 6 votes |
protected void updateFooterVisibility(String style) { Page page = Page.getCurrent(); if (page == null) { return; } WebBrowser webBrowser = page.getWebBrowser(); boolean isPredefinedStyle = style.equals(BORDERLESS_STYLE) || style.equals(NO_HORIZONTAL_LINES_STYLE) || style.equals(NO_VERTICAL_LINES_STYLE); if (webBrowser.isSafari() && isPredefinedStyle && grid.getFooterRowCount() > 0 && grid.isFooterVisible()) { ((CubaEnhancedGrid) grid).updateFooterVisibility(); } }
Example 2
Source File: UrlTools.java From cuba with Apache License 2.0 | 5 votes |
/** * INTERNAL * * @return whether application is running in headless mode */ public static boolean headless() { Page current = Page.getCurrent(); if (current == null) { return true; } return current.getUI().getSession() == null; }
Example 3
Source File: CubaPickerField.java From cuba with Apache License 2.0 | 5 votes |
protected void initLayout() { container = new CubaCssActionsLayout(); container.setPrimaryStyleName(LAYOUT_STYLENAME); container.setWidth(100, Unit.PERCENTAGE); field.setWidth(100, Unit.PERCENTAGE); Page current = Page.getCurrent(); if (current != null) { WebBrowser browser = current.getWebBrowser(); if (browser != null && browser.isSafari()) { inputWrapper = new CssLayout(); inputWrapper.setWidth(100, Unit.PERCENTAGE); inputWrapper.setPrimaryStyleName("safari-input-wrap"); inputWrapper.addComponent(field); container.addComponent(inputWrapper); } else { container.addComponent(field); } } else { container.addComponent(field); } setFocusDelegate((Focusable) field); }
Example 4
Source File: CitizenIntelligenceAgencyUI.java From cia with Apache License 2.0 | 5 votes |
@Override protected void init(final VaadinRequest request) { VaadinSession.getCurrent().setErrorHandler(new UiInstanceErrorHandler(this)); setSizeFull(); springNavigator.addView(CRLF_REPLACEMENT, mainView); setNavigator(springNavigator); 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.setTimeZone(webBrowser.getTimeZoneId()); serviceRequest.setScreenSize(webBrowser.getScreenWidth() + "x" + webBrowser.getScreenHeight()); 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.replaceAll(CRLF,CRLF_REPLACEMENT),language.replaceAll(CRLF,CRLF_REPLACEMENT),ipInformation.replaceAll(CRLF,CRLF_REPLACEMENT),webBrowser.getBrowserApplication().replaceAll(CRLF,CRLF_REPLACEMENT),serviceRequest.getSessionId().replaceAll(CRLF,CRLF_REPLACEMENT),serviceResponse.getResult().toString().replaceAll(CRLF,CRLF_REPLACEMENT)); } }
Example 5
Source File: VaadinUtils.java From jdal with Apache License 2.0 | 5 votes |
/** * Exit application */ public static void exit() { VaadinSession.getCurrent().getSession().removeAttribute( HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY); UI.getCurrent().close(); VaadinSession.getCurrent().close(); Page page = Page.getCurrent(); page.setLocation(VaadinService.getCurrentRequest().getContextPath() + "/logout"); }
Example 6
Source File: WebDeviceInfoProvider.java From cuba with Apache License 2.0 | 4 votes |
@Nullable @Override 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()); di.setSafari(webBrowser.isSafari()); 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; }
Example 7
Source File: AuthorizationFailureEventListener.java From cia with Apache License 2.0 | 4 votes |
@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()); } if (authorizationFailureEvent.getSource() instanceof ReflectiveMethodInvocation) { final ReflectiveMethodInvocation methodInvocation = (ReflectiveMethodInvocation) authorizationFailureEvent .getSource(); if (methodInvocation != null && methodInvocation.getThis() != null) { methodInfo = new StringBuilder().append(methodInvocation.getThis().getClass().getSimpleName()) .append('.').append(methodInvocation.getMethod().getName()).toString(); } } final Collection<? extends GrantedAuthority> authorities = authorizationFailureEvent.getAuthentication() .getAuthorities(); final Collection<ConfigAttribute> configAttributes = authorizationFailureEvent.getConfigAttributes(); serviceRequest.setErrorMessage(MessageFormat.format(ERROR_MESSAGE_FORMAT, requestUrl, methodInfo, AUTHORITIES, authorities, REQUIRED_AUTHORITIES, configAttributes, authorizationFailureEvent.getSource())); serviceRequest.setApplicationMessage(ACCESS_DENIED); applicationManager.service(serviceRequest); LOGGER.info(LOG_MSG_AUTHORIZATION_FAILURE_SESSION_ID_AUTHORITIES_REQUIRED_AUTHORITIES, requestUrl.replaceAll(CRLF, CRLF_REPLACEMENT), methodInfo.replaceAll(CRLF, CRLF_REPLACEMENT), sessionId.replaceAll(CRLF, CRLF_REPLACEMENT), authorities, configAttributes); }