List of usage examples for com.vaadin.server Page getCurrent
public static Page getCurrent()
From source file:annis.gui.SearchView.java
License:Apache License
private void evaluateFragment(String fragment) { // do nothing if not changed if (fragment == null || fragment.isEmpty() || fragment.equals(lastEvaluatedFragment)) { return;/*from w w w. j ava 2 s . com*/ } Map<String, String> args = Helper.parseFragment(fragment); if (args.containsKey("c")) { String[] originalCorpusNames = args.get("c").split("\\s*,\\s*"); Set<String> corpora = getMappedCorpora(Arrays.asList(originalCorpusNames)); if (corpora.isEmpty()) { if (Helper.getUser() == null && toolbar != null) { // not logged in, show login window boolean onlyCorpusSelected = args.containsKey("c") && args.size() == 1; toolbar.showLoginWindow(!onlyCorpusSelected); } else { // already logged in or no login system available, just display a message new Notification("Linked corpus does not exist", "<div><p>The corpus you wanted to access unfortunally does not (yet) exist" + " in ANNIS.</p>" + "<h2>possible reasons are:</h2>" + "<ul>" + "<li>that it has not been imported yet,</li>" + "<li>you don't have the access rights to see this corpus,</li>" + "<li>or the ANNIS service is not running.</li>" + "</ul>" + "<p>Please ask the responsible person of the site that contained " + "the link to import the corpus.</p></div>", Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent()); } } // end if corpus list returned from service is empty else { if (args.containsKey("c") && args.size() == 1) { // special case: we were called from outside and should only select, // but not query, the selected corpora ui.getQueryState().getSelectedCorpora().setValue(corpora); } else if (args.get("cl") != null && args.get("cr") != null) { // make sure the properties are not overwritten by the background process getControlPanel().getSearchOptions().setUpdateStateFromConfig(false); DisplayedResultQuery query = QueryGenerator.displayed().left(Integer.parseInt(args.get("cl"))) .right(Integer.parseInt(args.get("cr"))).offset(Integer.parseInt(args.get("s"))) .limit(Integer.parseInt(args.get("l"))).segmentation(args.get("seg")) .baseText(args.get("bt")).query(args.get("q")).corpora(corpora).build(); if (query.getBaseText() == null && query.getSegmentation() != null) { // if no explicit visible segmentation was given use the same as the context query.setBaseText(query.getSegmentation()); } if (query.getBaseText() != null && query.getBaseText().isEmpty()) { // empty string means "null" query.setBaseText(null); } String matchSelectionRaw = args.get("m"); if (matchSelectionRaw != null) { for (String selectedMatchNr : Splitter.on(',').omitEmptyStrings().trimResults() .split(matchSelectionRaw)) { try { long nr = Long.parseLong(selectedMatchNr); query.getSelectedMatches().add(nr); } catch (NumberFormatException ex) { log.warn("Invalid long provided as selected match", ex); } } } if (args.get("o") != null) { try { query.setOrder(OrderType.valueOf(args.get("o").toLowerCase())); } catch (IllegalArgumentException ex) { log.warn("Could not parse query fragment argument for order", ex); } } // full query with given context ui.getQueryController().setQuery(query); ui.getQueryController().executeSearch(true, false); } else if (args.get("q") != null) { // use default context ui.getQueryController().setQuery(new Query(args.get("q"), corpora)); ui.getQueryController().executeSearch(true, true); } getControlPanel().getCorpusList().scrollToSelectedCorpus(); } // end if corpus list from server was non-empty } // end if there is a corpus definition }
From source file:annis.gui.SearchView.java
License:Apache License
/** * Updates the browser address bar with the current query parameters and the * query itself./* w w w .ja v a 2 s .c o m*/ * * This is for convenient reloading the vaadin app and easy copying citation * links. * * @param q The query where the parameters are extracted from. */ public void updateFragment(DisplayedResultQuery q) { List<String> args = Helper.citationFragment(q.getQuery(), q.getCorpora(), q.getLeftContext(), q.getRightContext(), q.getSegmentation(), q.getBaseText(), q.getOffset(), q.getLimit(), q.getOrder(), q.getSelectedMatches()); // set our fragment lastEvaluatedFragment = StringUtils.join(args, "&"); UI.getCurrent().getPage().setUriFragment(lastEvaluatedFragment, false); // reset title Page.getCurrent().setTitle(ui.getInstanceConfig().getInstanceDisplayName() + " (ANNIS Corpus Search)"); }
From source file:annis.libgui.AnnisBaseUI.java
License:Apache License
/** * Inject CSS into the UI. /* www . j av a2s. c o m*/ * This function will not add multiple style-elements if the * exact CSS string was already added. * @param cssContent * @param wrapperClass Name of the wrapper class (a CSS class that is applied to a parent element) */ public void injectUniqueCSS(String cssContent, String wrapperClass) { if (alreadyAddedCSS == null) { alreadyAddedCSS = new TreeSet<String>(); } if (wrapperClass != null) { cssContent = wrapCSS(cssContent, wrapperClass); } String hashForCssContent = Hashing.md5().hashString(cssContent, Charsets.UTF_8).toString(); if (!alreadyAddedCSS.contains(hashForCssContent)) { // CSSInject cssInject = new CSSInject(UI.getCurrent()); // cssInject.setStyles(cssContent); Page.getCurrent().getStyles().add(cssContent); alreadyAddedCSS.add(hashForCssContent); } }
From source file:annis.libgui.Helper.java
License:Apache License
public static DocumentBrowserConfig getDocBrowserConfig(String corpus) { try {/*from w w w . j a va 2 s .c o m*/ DocumentBrowserConfig docBrowserConfig = Helper.getAnnisWebResource().path("query").path("corpora") .path("doc_browser_config").path(urlPathEscape.escape(corpus)).get(DocumentBrowserConfig.class); return docBrowserConfig; } catch (UniformInterfaceException ex) { new Notification(ERROR_MESSAGE_DOCUMENT_BROWSER_HEADER, ERROR_MESSAGE_DOCUMENT_BROWSER_BODY, Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent()); log.error("problems with fetching document browsing", ex); } catch (ClientHandlerException ex) { new Notification(ERROR_MESSAGE_DOCUMENT_BROWSER_HEADER, ERROR_MESSAGE_DOCUMENT_BROWSER_BODY, Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent()); log.error("problems with fetching document browsing", ex); } return null; }
From source file:annis.libgui.Helper.java
License:Apache License
/** * Loads the corpus config of a specific corpus. * * @param corpus The name of the corpus, for which the config is fetched. * @return A {@link CorpusConfig} object, which wraps a {@link Properties} * object. This Properties object stores the corpus configuration as simple * key-value pairs./*from www.j a v a 2 s . c om*/ */ public static CorpusConfig getCorpusConfig(String corpus) { if (corpus == null || corpus.isEmpty()) { Notification.show("no corpus is selected", "please select at leas one corpus and execute query again", Notification.Type.WARNING_MESSAGE); return null; } CorpusConfig corpusConfig = new CorpusConfig(); try { corpusConfig = Helper.getAnnisWebResource().path("query").path("corpora") .path(urlPathEscape.escape(corpus)).path("config").get(CorpusConfig.class); } catch (UniformInterfaceException | ClientHandlerException ex) { new Notification(ERROR_MESSAGE_CORPUS_PROPS_HEADER, ERROR_MESSAGE_CORPUS_PROPS, Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent()); } return corpusConfig; }
From source file:annis.libgui.Helper.java
License:Apache License
public static CorpusConfig getDefaultCorpusConfig() { CorpusConfig defaultCorpusConfig = new CorpusConfig(); try {/*from w ww .j av a 2 s . c o m*/ defaultCorpusConfig = Helper.getAnnisWebResource().path("query").path("corpora").path(DEFAULT_CONFIG) .get(CorpusConfig.class); } catch (UniformInterfaceException ex) { new Notification(ERROR_MESSAGE_CORPUS_PROPS_HEADER, ERROR_MESSAGE_CORPUS_PROPS, Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent()); } catch (ClientHandlerException ex) { new Notification(ERROR_MESSAGE_CORPUS_PROPS_HEADER, ERROR_MESSAGE_CORPUS_PROPS, Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent()); } return defaultCorpusConfig; }
From source file:annis.libgui.Helper.java
License:Apache License
/** * Loads the all available corpus configurations. * * * @return A {@link CorpusConfigMap} object, which wraps a Map of * {@link Properties} objects. The keys to the properties are the corpus * names. A Properties object stores the corpus configuration as simple * key-value pairs. The Map includes also the default corpus configuration. *//* ww w.ja v a 2s . com*/ public static CorpusConfigMap getCorpusConfigs() { CorpusConfigMap corpusConfigurations = null; try { corpusConfigurations = Helper.getAnnisWebResource().path("query").path("corpora").path("config") .get(CorpusConfigMap.class); } catch (UniformInterfaceException | ClientHandlerException ex) { UI.getCurrent().access(new Runnable() { @Override public void run() { new Notification(ERROR_MESSAGE_CORPUS_PROPS_HEADER, ERROR_MESSAGE_CORPUS_PROPS, Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent()); } }); } if (corpusConfigurations == null) { corpusConfigurations = new CorpusConfigMap(); } corpusConfigurations.put(DEFAULT_CONFIG, getDefaultCorpusConfig()); return corpusConfigurations; }
From source file:at.jku.ce.adaptivetesting.vaadin.ui.core.VaadinUI.java
License:LGPL
public static void setCurrentPageTitle(ViewChangeEvent e) { Page.getCurrent().setTitle((e.getViewName().length() == 0 ? Views.DEFAULT.toString() : e.getViewName()) + " - " + VaadinUI.getProductData().getProduct() + " v" + VaadinUI.getProductData().getVersion()); }
From source file:badoo.action.OpenPageAction.java
License:Open Source License
@Override public void execute() throws ActionExecutionException { Page.getCurrent().open("https://badoo.com/profile/" + item.getItemProperty("user_id").getValue(), "_blank", false);//from ww w .j av a 2 s. c o m }
From source file:by.bigvova.ui.LoginUI.java
License:Apache License
private void notification() { Notification notification = new Notification("Welcome to Dashboard Demo"); notification.setDescription(// ww w . j a va 2 s . co m "<span>This application is not real, it only demonstrates an application built with the <a href=\"https://vaadin.com\">Vaadin framework</a>.</span> <span>No username or password is required, just click the <b>Sign In</b> button to continue.</span>"); notification.setHtmlContentAllowed(true); notification.setStyleName("tray dark small closable login-help"); notification.setPosition(Position.BOTTOM_CENTER); notification.setDelayMsec(20000); notification.show(Page.getCurrent()); }