List of usage examples for com.vaadin.server VaadinService getCurrentRequest
public static VaadinRequest getCurrentRequest()
From source file:de.symeda.sormas.ui.AboutView.java
License:Open Source License
public AboutView() { CustomLayout aboutContent = new CustomLayout("aboutview"); aboutContent.setStyleName("about-content"); // Info section VerticalLayout infoLayout = new VerticalLayout(); infoLayout.setSpacing(false);/* w w w. ja v a 2 s. c o m*/ infoLayout.setMargin(false); aboutContent.addComponent(infoLayout, "info"); Label versionLabel = new Label(VaadinIcons.INFO_CIRCLE.getHtml() + " " + I18nProperties.getCaption(Captions.aboutSormasVersion) + ": " + InfoProvider.get().getVersion(), ContentMode.HTML); infoLayout.addComponent(versionLabel); Link whatsNewLink = new Link(I18nProperties.getCaption(Captions.aboutWhatsNew), new ExternalResource( "https://github.com/hzi-braunschweig/SORMAS-Project/releases/tag/releases%2Fversion-" + InfoProvider.get().getBaseVersion())); whatsNewLink.setTargetName("_blank"); infoLayout.addComponent(whatsNewLink); Link sormasWebsiteLink = new Link(I18nProperties.getCaption(Captions.aboutSormasWebsite), new ExternalResource("https://sormasorg.helmholtz-hzi.de/")); sormasWebsiteLink.setTargetName("_blank"); infoLayout.addComponent(sormasWebsiteLink); Link sormasGithubLink = new Link("SORMAS Github", new ExternalResource("https://github.com/hzi-braunschweig/SORMAS-Project")); sormasGithubLink.setTargetName("_blank"); infoLayout.addComponent(sormasGithubLink); Link changelogLink = new Link(I18nProperties.getCaption(Captions.aboutChangelog), new ExternalResource("https://github.com/hzi-braunschweig/SORMAS-Project/releases")); changelogLink.setTargetName("_blank"); infoLayout.addComponent(changelogLink); // Documents section VerticalLayout documentsLayout = new VerticalLayout(); documentsLayout.setSpacing(false); documentsLayout.setMargin(false); aboutContent.addComponent(documentsLayout, "documents"); Button classificationDocumentButton = new Button( I18nProperties.getCaption(Captions.aboutCaseClassificationRules)); CssStyles.style(classificationDocumentButton, ValoTheme.BUTTON_LINK, CssStyles.BUTTON_COMPACT); documentsLayout.addComponent(classificationDocumentButton); try { String serverUrl = new URL(((VaadinServletRequest) VaadinService.getCurrentRequest()) .getHttpServletRequest().getRequestURL().toString()).getAuthority(); StreamResource classificationResource = DownloadUtil.createStringStreamResource( ClassificationHtmlRenderer.createHtmlForDownload(serverUrl, FacadeProvider.getDiseaseConfigurationFacade().getAllActivePrimaryDiseases()), "classification_rules.html", "text/html"); new FileDownloader(classificationResource).extend(classificationDocumentButton); } catch (MalformedURLException e) { } Button dataDictionaryButton = new Button(I18nProperties.getCaption(Captions.aboutDataDictionary)); CssStyles.style(dataDictionaryButton, ValoTheme.BUTTON_LINK, CssStyles.BUTTON_COMPACT); documentsLayout.addComponent(dataDictionaryButton); FileDownloader dataDictionaryDownloader = new FileDownloader( new ClassResource("/doc/SORMAS_Data_Dictionary.xlsx")); dataDictionaryDownloader.extend(dataDictionaryButton); Link technicalManualLink = new Link(I18nProperties.getCaption(Captions.aboutTechnicalManual), new ExternalResource( "https://github.com/hzi-braunschweig/SORMAS-Project/files/2585973/SORMAS_Technical_Manual_Webversion_20180911.pdf")); technicalManualLink.setTargetName("_blank"); documentsLayout.addComponent(technicalManualLink); setSizeFull(); setStyleName("about-view"); addComponent(aboutContent); setComponentAlignment(aboutContent, Alignment.MIDDLE_CENTER); }
From source file:de.unioninvestment.eai.portal.portlet.crud.domain.model.user.CurrentUser.java
License:Apache License
protected User currentUser() { VaadinRequest currentRequest = VaadinService.getCurrentRequest(); if (currentRequest != null) { String remoteUser = currentRequest.getRemoteUser(); if (remoteUser != null) { if (cachedUser == null || !cachedUser.getName().equals(remoteUser)) { cachedUser = new NamedUser(remoteUser, portalRoles); }//from w ww.ja v a2 s .c om return cachedUser; } } else { LOG.warn("No portlet request found - that's ok for unit testing. Returning anonymous user"); } return ANONYMOUS_USER; }
From source file:de.uni_tuebingen.qbic.qbicmainportlet.DatasetView.java
License:Open Source License
/** * Precondition: {DatasetView#table} has to be initialized. e.g. with * {DatasetView#buildFilterTable} If it is not, strange behaviour has to be expected. builds the * Layout of this view.//from ww w. j a v a2s. com */ private void buildLayout() { this.vert.removeAllComponents(); int browserWidth = UI.getCurrent().getPage().getBrowserWindowWidth(); int browserHeight = UI.getCurrent().getPage().getBrowserWindowHeight(); this.vert.setWidth("100%"); this.setWidth(String.format("%spx", (browserWidth * 0.6))); // this.setHeight(String.format("%spx", (browserHeight * 0.8))); VerticalLayout statistics = new VerticalLayout(); HorizontalLayout statContent = new HorizontalLayout(); statContent.setCaption("Statistics"); statContent.setIcon(FontAwesome.BAR_CHART_O); statContent.addComponent(new Label(String.format("%s registered dataset(s).", numberOfDatasets))); statContent.setMargin(true); statContent.setSpacing(true); statistics.addComponent(statContent); statistics.setMargin(true); this.vert.addComponent(statistics); // Table (containing datasets) section VerticalLayout tableSection = new VerticalLayout(); HorizontalLayout tableSectionContent = new HorizontalLayout(); tableSectionContent.setCaption("Registered Datasets"); tableSectionContent.setIcon(FontAwesome.FLASK); tableSectionContent.addComponent(this.table); tableSectionContent.setMargin(true); tableSection.setMargin(true); tableSection.addComponent(tableSectionContent); this.vert.addComponent(tableSection); table.setWidth("100%"); tableSection.setWidth("100%"); tableSectionContent.setWidth("100%"); // this.table.setSizeFull(); HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setHeight(null); buttonLayout.setWidth("100%"); buttonLayout.setSpacing(false); final Button visualize = new Button(VISUALIZE_BUTTON_CAPTION); buttonLayout.addComponent(this.download); buttonLayout.addComponent(visualize); Button checkAll = new Button("Select all datasets"); checkAll.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { for (Object itemId : table.getItemIds()) { ((CheckBox) table.getItem(itemId).getItemProperty("Select").getValue()).setValue(true); } } }); Button uncheckAll = new Button("Unselect all datasets"); uncheckAll.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { for (Object itemId : table.getItemIds()) { ((CheckBox) table.getItem(itemId).getItemProperty("Select").getValue()).setValue(false); } } }); buttonLayout.addComponent(checkAll); buttonLayout.addComponent(uncheckAll); /** * prepare download. */ download.setResource(new ExternalResource("javascript:")); download.setEnabled(false); visualize.setEnabled(false); for (final Object itemId : this.table.getItemIds()) { setCheckedBox(itemId, (String) this.table.getItem(itemId).getItemProperty("CODE").getValue()); } /* * Update the visualize button. It is only enabled, if the files can be visualized. */ this.table.addValueChangeListener(new ValueChangeListener() { /** * */ private static final long serialVersionUID = -4875903343717437913L; /** * check for what selection can be visualized. If so, enable the button. TODO change to * checked. */ @Override public void valueChange(ValueChangeEvent event) { // Nothing selected or more than one selected. Set<Object> selectedValues = (Set<Object>) event.getProperty().getValue(); if (selectedValues == null || selectedValues.size() == 0 || selectedValues.size() > 1) { visualize.setEnabled(false); return; } // if one selected check whether its dataset type is either fastqc or qcml. // For now we only visulize these two file types. Iterator<Object> iterator = selectedValues.iterator(); Object next = iterator.next(); String datasetType = (String) table.getItem(next).getItemProperty("Dataset Type").getValue(); String fileName = (String) table.getItem(next).getItemProperty("File Name").getValue(); // TODO: No hardcoding!! // if (datasetType.equals("FASTQC") || datasetType.equals("QCML") || // datasetType.equals("BAM") // || datasetType.equals("VCF")) { if (datasetType.equals("Q_WF_MS_QUALITYCONTROL_RESULTS") && (fileName.endsWith(".html") || fileName.endsWith(".qcML"))) { visualize.setEnabled(true); } else if (datasetType.equals("Q_WF_MS_QUALITYCONTROL_LOGS") && (fileName.endsWith(".err") || fileName.endsWith(".out"))) { visualize.setEnabled(true); } else { visualize.setEnabled(false); } } }); // TODO Workflow Views should get those data and be happy /* * Send message that in datasetview the following was selected. WorkflowViews get those messages * and save them, if it is valid information for them. */ this.table.addValueChangeListener(new ValueChangeListener() { /** * */ private static final long serialVersionUID = -3554627008191389648L; @Override public void valueChange(ValueChangeEvent event) { // Nothing selected or more than one selected. Set<Object> selectedValues = (Set<Object>) event.getProperty().getValue(); State state = (State) UI.getCurrent().getSession().getAttribute("state"); ArrayList<String> message = new ArrayList<String>(); message.add("DataSetView"); if (selectedValues != null && selectedValues.size() == 1) { Iterator<Object> iterator = selectedValues.iterator(); Object next = iterator.next(); String datasetType = (String) table.getItem(next).getItemProperty("Dataset Type").getValue(); message.add(datasetType); String project = (String) table.getItem(next).getItemProperty("Project").getValue(); String space = datahandler.getOpenBisClient().getProjectByCode(project).getSpaceCode();// .getIdentifier().split("/")[1]; message.add(project); message.add((String) table.getItem(next).getItemProperty("Sample").getValue()); // message.add((String) table.getItem(next).getItemProperty("Sample Type").getValue()); message.add((String) table.getItem(next).getItemProperty("dl_link").getValue()); message.add((String) table.getItem(next).getItemProperty("File Name").getValue()); message.add(space); // state.notifyObservers(message); } else { message.add("null"); } // TODO // state.notifyObservers(message); } }); // TODO get the GV to work here. Together with reverse proxy // Assumes that table Value Change listner is enabling or disabling the button if preconditions // are not fullfilled visualize.addClickListener(new ClickListener() { /** * */ private static final long serialVersionUID = 9015273307461506369L; @Override public void buttonClick(ClickEvent event) { Set<Object> selectedValues = (Set<Object>) table.getValue(); Iterator<Object> iterator = selectedValues.iterator(); Object next = iterator.next(); String datasetCode = (String) table.getItem(next).getItemProperty("CODE").getValue(); String datasetFileName = (String) table.getItem(next).getItemProperty("File Name").getValue(); URL url; try { Object parent = table.getParent(next); if (parent != null) { String parentDatasetFileName = (String) table.getItem(parent).getItemProperty("File Name") .getValue(); url = datahandler.getOpenBisClient().getUrlForDataset(datasetCode, parentDatasetFileName + "/" + datasetFileName); } else { url = datahandler.getOpenBisClient().getUrlForDataset(datasetCode, datasetFileName); } Window subWindow = new Window( "QC of Sample: " + (String) table.getItem(next).getItemProperty("Sample").getValue()); VerticalLayout subContent = new VerticalLayout(); subContent.setMargin(true); subWindow.setContent(subContent); QbicmainportletUI ui = (QbicmainportletUI) UI.getCurrent(); // Put some components in it Resource res = null; String datasetType = (String) table.getItem(next).getItemProperty("Dataset Type").getValue(); final RequestHandler rh = new ProxyForGenomeViewerRestApi(); boolean rhAttached = false; if (datasetType.equals("Q_WF_MS_QUALITYCONTROL_RESULTS") && datasetFileName.endsWith(".qcML")) { QcMlOpenbisSource re = new QcMlOpenbisSource(url); StreamResource streamres = new StreamResource(re, datasetFileName); streamres.setMIMEType("application/xml"); res = streamres; } else if (datasetType.equals("Q_WF_MS_QUALITYCONTROL_RESULTS") && datasetFileName.endsWith(".html")) { QcMlOpenbisSource re = new QcMlOpenbisSource(url); StreamResource streamres = new StreamResource(re, datasetFileName); streamres.setMIMEType("text/html"); res = streamres; } else if (datasetType.equals("Q_WF_MS_QUALITYCONTROL_LOGS") && (datasetFileName.endsWith(".err") || datasetFileName.endsWith(".out"))) { QcMlOpenbisSource re = new QcMlOpenbisSource(url); StreamResource streamres = new StreamResource(re, datasetFileName); streamres.setMIMEType("text/plain"); res = streamres; } else if (datasetType.equals("FASTQC")) { res = new ExternalResource(url); } else if (datasetType.equals("BAM") || datasetType.equals("VCF")) { String filePath = (String) table.getItem(next).getItemProperty("dl_link").getValue(); filePath = String.format("/store%s", filePath.split("store")[1]); String fileId = (String) table.getItem(next).getItemProperty("File Name").getValue(); // fileId = "control.1kg.panel.samples.vcf.gz"; // UI.getCurrent().getSession().addRequestHandler(rh); rhAttached = true; ThemeDisplay themedisplay = (ThemeDisplay) VaadinService.getCurrentRequest() .getAttribute(WebKeys.THEME_DISPLAY); String hostTmp = "http://localhost:7778/vizrest/rest";// "http://localhost:8080/web/guest/mainportlet?p_p_id=QbicmainportletApplicationPortlet_WAR_QBiCMainPortlet_INSTANCE_5pPd5JQ8uGOt&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_cacheability=cacheLevelPage&p_p_col_id=column-1&p_p_col_count=1"; // hostTmp += // "&qbicsession=" + UI.getCurrent().getSession().getAttribute("gv-restapi-session") // + "&someblabla="; // String hostTmp = themedisplay.getURLPortal() + // UI.getCurrent().getPage().getLocation().getPath() + "?qbicsession=" + // UI.getCurrent().getSession().getAttribute("gv-restapi-session") + "&someblabla=" ; // String host = Base64.encode(hostTmp.getBytes()); String title = (String) table.getItem(next).getItemProperty("Sample").getValue(); // res = // new ExternalResource( // String // .format( // "http://localhost:7778/genomeviewer/?host=%s&title=%s&fileid=%s&featuretype=alignments&filepath=%s&removeZeroGenotypes=false", // host, title, fileId, filePath)); } BrowserFrame frame = new BrowserFrame("", res); if (rhAttached) { frame.addDetachListener(new DetachListener() { /** * */ private static final long serialVersionUID = 1534523447730906543L; @Override public void detach(DetachEvent event) { UI.getCurrent().getSession().removeRequestHandler(rh); } }); } frame.setSizeFull(); subContent.addComponent(frame); // Center it in the browser window subWindow.center(); subWindow.setModal(true); subWindow.setSizeFull(); frame.setHeight((int) (ui.getPage().getBrowserWindowHeight() * 0.8), Unit.PIXELS); // Open it in the UI ui.addWindow(subWindow); } catch (MalformedURLException e) { LOGGER.error(String.format("Visualization failed because of malformedURL for dataset: %s", datasetCode)); Notification.show( "Given dataset has no file attached to it!! Please Contact your project manager. Or check whether it already has some data", Notification.Type.ERROR_MESSAGE); } } }); this.vert.addComponent(buttonLayout); }
From source file:de.uni_tuebingen.qbic.qbicmainportlet.QbicmainportletUI.java
License:Open Source License
/** * builds page if user is not logged in/* www .j a va 2 s . c o m*/ */ private void buildNotLoggedinLayout() { // Mail to qbic ExternalResource resource = new ExternalResource("mailto:info@qbic.uni-tuebingen.de"); Link mailToQbicLink = new Link("", resource); mailToQbicLink.setIcon(new ThemeResource("mail9.png")); ThemeDisplay themedisplay = (ThemeDisplay) VaadinService.getCurrentRequest() .getAttribute(WebKeys.THEME_DISPLAY); // redirect to liferay login page Link loginPortalLink = new Link("", new ExternalResource(themedisplay.getURLSignIn())); loginPortalLink.setIcon(new ThemeResource("lock12.png")); // left part of the page VerticalLayout signIn = new VerticalLayout(); signIn.addComponent( new Label("<h3>Sign in to manage your projects and access your data:</h3>", ContentMode.HTML)); signIn.addComponent(loginPortalLink); signIn.setStyleName("no-user-login"); // right part of the page VerticalLayout contact = new VerticalLayout(); contact.addComponent( new Label("<h3>If you are interested in doing projects get in contact:</h3>", ContentMode.HTML)); contact.addComponent(mailToQbicLink); contact.setStyleName("no-user-login"); // build final layout, with some gaps between HorizontalLayout notSignedInLayout = new HorizontalLayout(); Label expandingGap1 = new Label(); expandingGap1.setWidth("100%"); notSignedInLayout.addComponent(expandingGap1); notSignedInLayout.addComponent(signIn); notSignedInLayout.addComponent(contact); notSignedInLayout.setExpandRatio(expandingGap1, 0.16f); notSignedInLayout.setExpandRatio(signIn, 0.36f); notSignedInLayout.setExpandRatio(contact, 0.36f); notSignedInLayout.setWidth("100%"); notSignedInLayout.setSpacing(true); setContent(notSignedInLayout); }
From source file:de.uni_tuebingen.qbic.qbicmainportlet.QbicmainportletUI.java
License:Open Source License
/** * /*w ww. j av a2s . c om*/ * @return */ public PortletSession getPortletSession() { UI.getCurrent().getSession().getService(); VaadinRequest vaadinRequest = VaadinService.getCurrentRequest(); WrappedPortletSession wrappedPortletSession = (WrappedPortletSession) vaadinRequest.getWrappedSession(); return wrappedPortletSession.getPortletSession(); }
From source file:edu.nps.moves.mmowgli.MmowgliSessionGlobals.java
License:Open Source License
public String getVaadinSessionCookie() { if (sessionCookie == null) { // try once VaadinRequest req = VaadinService.getCurrentRequest(); if (req != null) sessionCookie = getCookie(req.getCookies()); }/*from ww w. j a va 2s. com*/ return (sessionCookie == null ? "null" : sessionCookie.getValue()); }
From source file:fr.univlorraine.mondossierweb.GenericUI.java
License:Apache License
public String getIpClient() { if (!StringUtils.hasText(ipClient)) { VaadinRequest vr = VaadinService.getCurrentRequest(); VaadinServletRequest vsRequest = (VaadinServletRequest) vr; HttpServletRequest hsRequest = vsRequest.getHttpServletRequest(); String ip = hsRequest.getHeader("x-forwarded-for"); if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = hsRequest.getHeader("X_FORWARDED_FOR"); } else {// w w w. ja v a 2 s.c om //Si x-forwarded-for contient plusieurs IP, on prend la deuxime if (ip.contains(",")) { ip = ip.split(",")[1]; } } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = hsRequest.getHeader("X-Forwarded-For"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = hsRequest.getHeader("HTTP_X_FORWARDED_FOR"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = hsRequest.getHeader("Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = hsRequest.getHeader("WL-Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = hsRequest.getRemoteAddr(); } ipClient = ip; } return ipClient; }
From source file:info.magnolia.ui.form.field.factory.RichTextFieldFactory.java
License:Open Source License
protected MagnoliaRichTextFieldConfig initializeCKEditorConfig() { MagnoliaRichTextFieldConfig config = new MagnoliaRichTextFieldConfig(); String path = VaadinService.getCurrentRequest().getContextPath(); // MAGNOLIA LINK PLUGIN may be used with/without customConfig config.addExternalPlugin(PLUGIN_NAME_MAGNOLIALINK, path + PLUGIN_PATH_MAGNOLIALINK); config.addListenedEvent(EVENT_GET_MAGNOLIA_LINK); // CUSTOM CONFIG.JS bypass further config because it can't be overridden otherwise if (StringUtils.isNotBlank(definition.getConfigJsFile())) { config.addExtraConfig("customConfig", "'" + path + definition.getConfigJsFile() + "'"); return config; }// w w w. jav a 2 s .co m // DEFINITION if (!definition.isAlignment()) { config.addToRemovePlugins("justify"); } if (!definition.isImages()) { config.addToRemovePlugins("image"); } if (!definition.isLists()) { // In CKEditor 4.1.1 enterkey depends on indent which itself depends on list config.addToRemovePlugins("enterkey"); config.addToRemovePlugins("indent"); config.addToRemovePlugins("list"); } if (!definition.isSource()) { config.addToRemovePlugins("sourcearea"); } if (!definition.isTables()) { config.addToRemovePlugins("table"); config.addToRemovePlugins("tabletools"); } if (definition.getColors() != null) { config.addExtraConfig("colorButton_colors", "'" + definition.getColors() + "'"); config.addExtraConfig("colorButton_enableMore", "false"); config.addToRemovePlugins("colordialog"); } else { config.addToRemovePlugins("colorbutton"); config.addToRemovePlugins("colordialog"); } if (definition.getFonts() != null) { config.addExtraConfig("font_names", "'" + definition.getFonts() + "'"); } else { config.addExtraConfig("removeButtons", "'Font'"); } if (definition.getFontSizes() != null) { config.addExtraConfig("fontSize_sizes", "'" + definition.getFontSizes() + "'"); } else { config.addExtraConfig("removeButtons", "'FontSize'"); } if (definition.getFonts() == null && definition.getFontSizes() == null) { config.addToRemovePlugins("font"); config.addToRemovePlugins("fontSize"); } // MAGNOLIA EXTRA CONFIG List<ToolbarGroup> toolbars = initializeToolbarConfig(); config.addToolbarLine(toolbars); config.addToExtraPlugins(PLUGIN_NAME_MAGNOLIALINK); config.addToRemovePlugins("elementspath"); config.setBaseFloatZIndex(150); config.setResizeEnabled(false); return config; }
From source file:net.sf.gazpachoquest.questionnaires.views.login.OldLoginView.java
License:Open Source License
@Override public void buttonClick(ClickEvent event) { logger.info("Submitting login"); // List<QuestionnaireDTO> questionnaires = questionnairResource.list(); // System.out.println(questionnaires); ///*ww w.j a v a 2 s. co m*/ // Validate the fields using the navigator. By using validors for the // fields we reduce the amount of queries we have to use to the database // for wrongly entered passwords // if (!invitationTextField.isValid()) { return; } String invitation = invitationTextField.getValue(); WrappedSession session = VaadinService.getCurrentRequest().getWrappedSession(); QuestionnaireResource proxy = JAXRSClientFactory.create("", QuestionnaireResource.class, Collections.singletonList(new JacksonJsonProvider()), "respondent", invitation, null); // // Validate username and password with database here. For examples sake // I use a dummy username and password. // boolean isValid = true; if (isValid) { // Store the current invitation in the service session getSession().setAttribute("invitation", invitation); session.setAttribute("username", "respondent"); session.setAttribute("password", invitation); // Navigate to main view getUI().getNavigator().navigateTo(QuestionnaireView.NAME); } else { // Wrong password clear the password field and refocuses it invitationTextField.setValue(null); invitationTextField.focus(); } }
From source file:nl.kpmg.lcm.ui.rest.RestClientService.java
License:Apache License
private void saveLoginToken(String loginToken) { VaadinService.getCurrentRequest().getWrappedSession().setAttribute("loginToken", loginToken); }