private void injectMovieCoverStyles() { // Add all movie cover images as classes to CSSInject String styles = ""; for (Movie m : DashboardUI.getDataProvider().getMovies()) { WebBrowser webBrowser = Page.getCurrent().getWebBrowser(); String bg = "url(VAADIN/themes/" + UI.getCurrent().getTheme() + "/img/event-title-bg.png), url(" + m.getThumbUrl() + ")"; // IE8 doesn't support multiple background images if (webBrowser.isIE() && webBrowser.getBrowserMajorVersion() == 8) { bg = "url(" + m.getThumbUrl() + ")"; } styles += ".v-calendar-event-" + m.getId() + " .v-calendar-event-content {background-image:" + bg + ";}"; } Page.getCurrent().getStyles().add(styles); }
/** * Gets the operating system. * * @param webBrowser * the web browser * @return the operating system */ public static String getOperatingSystem(final WebBrowser webBrowser) { String osName = UNKNOWN; if (webBrowser.isLinux()) { osName = LINUX; } else if (webBrowser.isWindows()) { osName = WINDOWS2; } else if (webBrowser.isWindowsPhone()) { osName = WINDOWS_PHONE; } else if (webBrowser.isMacOSX()) { osName = MAC_OSX; } else if (webBrowser.isAndroid()) { osName = ANDROID; } else if (webBrowser.isIOS()) { osName = IOS; } else if (webBrowser.isIPad()) { osName = IPAD; } else if (webBrowser.isIPhone()) { osName = I_PHONE; } return osName; }
public AboutWindow() { MHorizontalLayout content = new MHorizontalLayout().withMargin(true).withFullWidth(); this.setContent(content); Image about = new Image("", new ExternalResource(StorageUtils.generateAssetRelativeLink(WebResourceIds._about))); MVerticalLayout rightPanel = new MVerticalLayout(); ELabel versionLbl = ELabel.h2(String.format("MyCollab Community Edition %s", Version.getVersion())); Label javaNameLbl = new Label(String.format("%s, %s", System.getProperty("java.vm.name"), System.getProperty("java.runtime.version"))); Label homeFolderLbl = new Label("Home folder: " + FileUtils.getHomeFolder().getAbsolutePath()); WebBrowser browser = Page.getCurrent().getWebBrowser(); Label osLbl = new Label(String.format("%s, %s", System.getProperty("os.name"), browser.getBrowserApplication())); osLbl.addStyleName(UIConstants.LABEL_WORD_WRAP); Div licenseDiv = new Div().appendChild(new Text("Powered by: ")) .appendChild(new A("https://www.mycollab.com") .appendText("MyCollab")).appendChild(new Text(". Open source under GPL license")); Label licenseLbl = ELabel.html(licenseDiv.write()); Label copyRightLbl = ELabel.html(String.format("© %s - %s MyCollab Ltd. All rights reserved", "2011", new GregorianCalendar().get(Calendar.YEAR) + "")); rightPanel.with(versionLbl, javaNameLbl, osLbl, homeFolderLbl, licenseLbl, copyRightLbl) .withAlign(copyRightLbl, Alignment.BOTTOM_LEFT); content.with(about, rightPanel).expand(rightPanel); }
@Override public int getScreenWidth() { WebBrowser browser = (Page.getCurrent() != null) ? Page.getCurrent().getWebBrowser() : null; if (browser != null) { return browser.getScreenWidth(); } return -1; }
@Override public int getScreenHeight() { WebBrowser browser = (Page.getCurrent() != null) ? Page.getCurrent().getWebBrowser() : null; if (browser != null) { return browser.getScreenHeight(); } return -1; }
protected String makeClientInfo() { // timezone info is passed only on VaadinSession creation WebBrowser webBrowser = getWebBrowserDetails(); //noinspection UnnecessaryLocalVariable String serverInfo = String.format("Web (%s:%s/%s) %s", globalConfig.getWebHostName(), globalConfig.getWebPort(), globalConfig.getWebContextName(), webBrowser.getBrowserApplication()); return serverInfo; }
protected TimeZone detectTimeZone() { WebBrowser webBrowser = getWebBrowserDetails(); int offset = webBrowser.getTimezoneOffset() / 1000 / 60; char sign = offset >= 0 ? '+' : '-'; int absOffset = Math.abs(offset); String hours = StringUtils.leftPad(String.valueOf(absOffset / 60), 2, '0'); String minutes = StringUtils.leftPad(String.valueOf(absOffset % 60), 2, '0'); return TimeZone.getTimeZone("GMT" + sign + hours + minutes); }
protected WebBrowser getWebBrowserDetails() { // timezone info is passed only on VaadinSession creation WebBrowser webBrowser = VaadinSession.getCurrent().getBrowser(); VaadinRequest currentRequest = VaadinService.getCurrentRequest(); // update web browser instance if current request is not null // it can be null in case of background/async processing of login request if (currentRequest != null) { webBrowser.updateRequestDetails(currentRequest); } return webBrowser; }
@Override public void attach() { super.attach(); WebBrowser webBrowser = Page.getCurrent().getWebBrowser(); if (webBrowser.isIE() || webBrowser.isEdge()) { CubaImageObjectFitPolyfillExtension.get(getUI()); } }
public WebFileUploadField() { fileUploading = AppBeans.get(FileUploadingAPI.NAME); exportDisplay = AppBeans.get(ExportDisplay.NAME); messages = AppBeans.get(Messages.NAME); WebBrowser webBrowser = Page.getCurrent().getWebBrowser(); if ((webBrowser.isIE() && !webBrowser.isEdge()) && webBrowser.getBrowserMajorVersion() < 10) { initOldUploadButton(); } else { initUploadButton(); } initComponent(); attachListener(component); }
public WebFileMultiUploadField() { fileUploading = AppBeans.get(FileUploadingAPI.NAME); WebBrowser webBrowser = Page.getCurrent().getWebBrowser(); if ((webBrowser.isIE() && !webBrowser.isEdge()) && webBrowser.getBrowserMajorVersion() < 10) { initOldComponent(); } else { initComponent(); } }
/** * Get browser time zone. * * @return TimeZone */ public static TimeZone getBrowserTimeZone() { final WebBrowser webBrowser = com.vaadin.server.Page.getCurrent().getWebBrowser(); final String[] timeZones = TimeZone.getAvailableIDs(webBrowser.getRawTimezoneOffset()); TimeZone tz = TimeZone.getDefault(); for (final String string : timeZones) { final TimeZone t = TimeZone.getTimeZone(string); if (t.getRawOffset() == webBrowser.getRawTimezoneOffset()) { tz = t; } } return tz; }
/** * Returns the ctrl or meta modifier depending on the platform. * * @return on mac return * {@link com.vaadin.event.ShortcutAction.ModifierKey#META} other * platform return * {@link com.vaadin.event.ShortcutAction.ModifierKey#CTRL} */ public static int getCtrlOrMetaModifier() { final WebBrowser webBrowser = Page.getCurrent().getWebBrowser(); if (webBrowser.isMacOSX()) { return ShortcutAction.ModifierKey.META; } return ShortcutAction.ModifierKey.CTRL; }
@Override protected void init(final VaadinRequest request) { VaadinSession.getCurrent().setErrorHandler(new UiInstanceErrorHandler(this)); setSizeFull(); springNavigator.addView("", 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.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()); } }
/** * Gets the ip information. * * @param webBrowser * the web browser * @return the ip information */ public static String getIpInformation(final WebBrowser webBrowser) { String ipInformation=webBrowser.getAddress(); final HttpServletRequest httpRequest=((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest(); final String xForwardedForHeader = httpRequest.getHeader(X_FORWARDED_FOR); if (xForwardedForHeader != null) { final String[] split = xForwardedForHeader.split(","); if (split.length != 0) { ipInformation = split[0]; } } return ipInformation; }
public DateTimeZone getClientTimeZone() { final UI ui = UI.getCurrent(); if (ui != null) { final Page page = ui.getPage(); if (page != null) { final WebBrowser br = page.getWebBrowser(); if (br != null) { final int timezoneOffset = br.getTimezoneOffset(); return DateTimeZone.forOffsetMillis(timezoneOffset); } } } return DateTimeZone.forID("Europe/Moscow"); }
protected boolean browserSupportCopy() { WebBrowser webBrowser = Page.getCurrent().getWebBrowser(); return !webBrowser.isSafari() && !webBrowser.isIOS() && !webBrowser.isWindowsPhone(); }
@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()); 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; }
private static boolean isUnsupportedBrowser() { final WebBrowser webBrowser = Page.getCurrent().getWebBrowser(); return webBrowser.isIE() && webBrowser.getBrowserMajorVersion() < 11; }
@Override public void enter(ViewChangeEvent event) { logger.debug("Entering {} view ", QuestionnaireView.NAME); addStyleName(Reindeer.LAYOUT_BLUE); addStyleName("questionnaires"); WebBrowser webBrowser = Page.getCurrent().getWebBrowser(); Integer screenWidth = webBrowser.getScreenWidth(); Integer heightWidth = webBrowser.getScreenHeight(); logger.debug("Browser screen settings {} x {}", screenWidth, heightWidth); if (heightWidth <= 480) { renderingMode = RenderingMode.QUESTION_BY_QUESTION; } // centralLayout.addStyleName("questionnaires"); // new Responsive(centralLayout); RespondentAccount respondent = (RespondentAccount) VaadinServletService.getCurrentServletRequest() .getUserPrincipal(); if (respondent.hasPreferredLanguage()) { preferredLanguage = Language.fromString(respondent.getPreferredLanguage()); } else { preferredLanguage = Language.fromLocale(webBrowser.getLocale()); } questionnaireId = respondent.getGrantedquestionnaireIds().iterator().next(); logger.debug("Trying to fetch questionnair identified with id = {} ", questionnaireId); QuestionnaireDefinitionDTO definition = questionnaireResource.getDefinition(questionnaireId); sectionInfoVisible = definition.isSectionInfoVisible(); QuestionnairePageDTO page = questionnaireResource.getPage(questionnaireId, renderingMode, preferredLanguage, NavigationAction.ENTERING); logger.debug("Displaying page {}/{} with {} questions", page.getMetadata().getNumber(), page.getMetadata() .getCount(), page.getQuestions().size()); questionsLayout = new VerticalLayout(); update(page); Label questionnaireTitle = new Label(definition.getLanguageSettings().getTitle()); questionnaireTitle.addStyleName(Reindeer.LABEL_H1); VerticalLayout mainLayout = new VerticalLayout(); mainLayout.setSizeFull(); mainLayout.setMargin(true); mainLayout.addComponent(questionnaireTitle); mainLayout.addComponent(questionsLayout); // Add the responsive capabilities to the components Panel centralLayout = new Panel(); centralLayout.setContent(mainLayout); centralLayout.setSizeFull(); centralLayout.getContent().setSizeUndefined(); Responsive.makeResponsive(questionnaireTitle); setCompositionRoot(centralLayout); setSizeFull(); }