List of usage examples for com.vaadin.server Page getCurrent
public static Page getCurrent()
From source file:annis.gui.admin.NewPasswordWindow.java
License:Apache License
public NewPasswordWindow(final String userName, final List<UserListView.Listener> listeners) { setCaption("Set new password for user \"" + userName + "\""); setModal(true);/* w w w. jav a 2 s . c o m*/ FormLayout layout = new FormLayout(); setContent(layout); final PasswordField txtPassword1 = new PasswordField("Enter new password"); final PasswordField txtPassword2 = new PasswordField("Repeat new password"); txtPassword1.setValidationVisible(true); txtPassword1.setRequired(true); txtPassword2.addValidator(new Validator() { @Override public void validate(Object value) throws Validator.InvalidValueException { String asString = (String) value; if (asString != null && !asString.equals(txtPassword1.getValue())) { throw new InvalidValueException("Passwords are not the same"); } } }); txtPassword2.setRequired(true); txtPassword2.setValidationVisible(true); Button btOk = new Button("Ok"); btOk.setClickShortcut(ShortcutAction.KeyCode.ENTER); btOk.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { try { txtPassword1.validate(); txtPassword2.validate(); if (txtPassword1.isValid() && txtPassword2.isValid()) { for (UserListView.Listener l : listeners) { l.passwordChanged(userName, txtPassword1.getValue()); } UI.getCurrent().removeWindow(NewPasswordWindow.this); Notification.show("Password for user \"" + userName + "\" was changed"); } else { } } catch (Validator.InvalidValueException ex) { Notification n = new Notification("Validation failed", ex.getHtmlMessage(), Type.ERROR_MESSAGE, true); n.show(Page.getCurrent()); } } }); Button btCancel = new Button("Cancel"); btCancel.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { UI.getCurrent().removeWindow(NewPasswordWindow.this); } }); HorizontalLayout actionLayout = new HorizontalLayout(btOk, btCancel); layout.addComponent(txtPassword1); layout.addComponent(txtPassword2); layout.addComponent(actionLayout); }
From source file:annis.gui.AdminView.java
License:Apache License
public AdminView(AnnisUI ui) { Page.getCurrent().setTitle("ANNIS Adminstration"); UserManagement userManagement = new UserManagement(); userManagement.setWebResourceProvider(AdminView.this); GroupManagement groupManagement = new GroupManagement(); groupManagement.setWebResourceProvider(AdminView.this); CorpusManagement corpusManagement = new CorpusManagement(); corpusManagement.setWebResourceProvider(AdminView.this); boolean isLoggedIn = Helper.getUser() != null; corpusAdminPanel = new CorpusAdminPanel(); corpusController = new CorpusController(corpusManagement, corpusAdminPanel, this, isLoggedIn); userManagementPanel = new UserManagementPanel(); userController = new UserController(userManagement, userManagementPanel, this, isLoggedIn); groupManagementPanel = new GroupManagementPanel(); groupManagementController = new GroupController(groupManagement, corpusManagement, groupManagementPanel, this, userManagementPanel, isLoggedIn); importPanel = new ImportPanel(); tabSheet = new TabSheet(); tabSheet.addTab(importPanel, "Import Corpus", FontAwesome.UPLOAD); tabSheet.addTab(corpusAdminPanel, "Corpus management", FontAwesome.LIST_ALT); tabSheet.addTab(userManagementPanel, "User management", FontAwesome.USER); tabSheet.addTab(groupManagementPanel, "Group management", FontAwesome.USERS); tabSheet.setSizeFull();//w w w .ja va 2 s .co m tabSheet.addSelectedTabChangeListener(AdminView.this); addComponents(tabSheet); setSizeFull(); setExpandRatio(tabSheet, 1.0f); tabSheet.addStyleName(ValoTheme.TABSHEET_FRAMED); }
From source file:annis.gui.AdminView.java
License:Apache License
private void setFragmentParameter(String param) { Page.getCurrent().setUriFragment("!" + NAME + "/" + param, false); }
From source file:annis.gui.exporter.CSVExporter.java
License:Apache License
@Override public boolean convertText(String queryAnnisQL, int contextLeft, int contextRight, Set<String> corpora, List<String> keys, String argsAsString, WebResource annisResource, Writer out, EventBus eventBus) { //this is a full result export try {//from www . ja va 2s . c o m WebResource res = annisResource.path("search").path("matrix").queryParam("csv", "true") .queryParam("corpora", StringUtils.join(corpora, ",")) .queryParam("q", Helper.encodeJersey(queryAnnisQL)); if (argsAsString.startsWith("metakeys=")) { res = res.queryParam("metakeys", argsAsString.substring("metakeys".length() + 1)); } try (InputStream result = res.get(InputStream.class)) { IOUtils.copy(result, out); } out.flush(); return true; } catch (UniformInterfaceException ex) { log.error(null, ex); Notification n = new Notification("Service exception", ex.getResponse().getEntity(String.class), Notification.Type.WARNING_MESSAGE, true); n.show(Page.getCurrent()); } catch (ClientHandlerException ex) { log.error(null, ex); } catch (IOException ex) { log.error(null, ex); } return false; }
From source file:annis.gui.exporter.TextColumnExporter.java
License:Apache License
/** * Writes the specified record (if applicable, as multiple result lines) from * query result set to the output file./*from w w w . ja v a 2 s.c om*/ * * @param graph the org.corpus_tools.salt.common.SDocumentGraph * representation of a specified record * @param alignmc a boolean, which indicates, whether the data should be * aligned by match numbers or not * @param recordNumber the number of record within the record set * @param out the specified Writer * * @throws IOException, if an I/O error occurs * */ @Override public void outputText(SDocumentGraph graph, boolean alignmc, int recordNumber, Writer out) throws IOException { String currSpeakerName = ""; String prevSpeakerName = ""; if (graph != null) { List<SToken> orderedToken = graph.getSortedTokenByText(); if (orderedToken != null) { // iterate over token ListIterator<SToken> it = orderedToken.listIterator(); long lastTokenWasMatched = -1; boolean noPreviousTokenInLine = false; // if match number == 0, reset global variables and output warning, if necessary if (recordNumber == 0) { isFirstSpeakerWithMatch = true; counterGlobal = 0; // create warning message String numbersString = ""; String warnMessage = ""; StringBuilder sb = new StringBuilder(); List<Integer> copyOfFilterNumbersSetByUser = new ArrayList<Integer>(); for (Long filterNumber : filterNumbersSetByUser) { copyOfFilterNumbersSetByUser.add(Integer.parseInt(String.valueOf(filterNumber))); } for (Integer matchNumberGlobal : matchNumbersGlobal) { copyOfFilterNumbersSetByUser.remove(matchNumberGlobal); } Collections.sort(copyOfFilterNumbersSetByUser); if (!copyOfFilterNumbersSetByUser.isEmpty()) { for (Integer filterNumber : copyOfFilterNumbersSetByUser) { sb.append(filterNumber + ", "); } if (copyOfFilterNumbersSetByUser.size() == 1) { numbersString = "number"; } else { numbersString = "numbers"; } warnMessage = "1. Filter " + numbersString + " " + sb.toString().substring(0, sb.lastIndexOf(",")) + " couldn't be represented."; } if (alignmc && !dataIsAlignable) { if (!warnMessage.isEmpty()) { warnMessage += (NEWLINE + NEWLINE + "2. "); } else { warnMessage += "1. "; } warnMessage += "You have tried to align matches by node number via check box." + "Unfortunately this option is not applicable for this data set, " + "so the data couldn't be aligned."; } if (!warnMessage.isEmpty()) { String warnCaption = "Some export options couldn't be realized."; Notification warn = new Notification(warnCaption, warnMessage, Notification.Type.WARNING_MESSAGE); warn.setDelayMsec(20000); warn.show(Page.getCurrent()); } } // global variables reset; warning issued int matchesWrittenForSpeaker = 0; while (it.hasNext()) { SToken tok = it.next(); counterGlobal++; // get current speaker name String name; if ((name = CommonHelper.getTextualDSForNode(tok, graph).getName()) == null) { name = ""; } currSpeakerName = (recordNumber + 1) + "_" + name; // if speaker has no matches, skip token if (speakerHasMatches.get(currSpeakerName) == false) { prevSpeakerName = currSpeakerName; // continue; } // if speaker has matches else { // if the current speaker is new, write header and append his name if (!currSpeakerName.equals(prevSpeakerName)) { // reset the counter of matches, which were written for this speaker matchesWrittenForSpeaker = 0; if (isFirstSpeakerWithMatch) { out.append("match_number" + TAB_MARK); out.append("speaker" + TAB_MARK); // write header for meta data columns if (!listOfMetakeys.isEmpty()) { for (String metakey : listOfMetakeys) { out.append(metakey + TAB_MARK); } } out.append("left_context" + TAB_MARK); String prefixAlignmc = "match_"; String prefix = "match_column"; String middle_context = "middle_context_"; if (alignmc && dataIsAlignable) { for (int i = 0; i < orderedMatchNumbersGlobal.size(); i++) { out.append(prefixAlignmc + orderedMatchNumbersGlobal.get(i) + TAB_MARK); if (i < orderedMatchNumbersGlobal.size() - 1) { out.append(middle_context + (i + 1) + TAB_MARK); } } } else { for (int i = 0; i < maxMatchesPerLine; i++) { out.append(prefix + TAB_MARK); if (i < (maxMatchesPerLine - 1)) { out.append(middle_context + (i + 1) + TAB_MARK); } } } out.append("right_context"); out.append(NEWLINE); isFirstSpeakerWithMatch = false; } else { out.append(NEWLINE); } out.append(String.valueOf(recordNumber + 1) + TAB_MARK); String trimmedName = ""; if (currSpeakerName.indexOf("_") < currSpeakerName.length()) { trimmedName = currSpeakerName.substring(currSpeakerName.indexOf("_") + 1); } out.append(trimmedName + TAB_MARK); // write meta data if (!listOfMetakeys.isEmpty()) { // get metadata String docName = graph.getDocument().getName(); List<String> corpusPath = CommonHelper.getCorpusPath(graph.getDocument().getGraph(), graph.getDocument()); String corpusName = corpusPath.get(corpusPath.size() - 1); corpusName = urlPathEscape.escape(corpusName); List<Annotation> metadata = Helper.getMetaData(corpusName, docName); Map<String, String> annosWithoutNamespace = new HashMap<String, String>(); Map<String, Map<String, String>> annosWithNamespace = new HashMap<String, Map<String, String>>(); // put metadata annotations into hash maps for better access for (Annotation metaAnno : metadata) { String ns; Map<String, String> data = new HashMap<String, String>(); data.put(metaAnno.getName(), metaAnno.getValue()); // a namespace is present if ((ns = metaAnno.getNamespace()) != null && !ns.isEmpty()) { Map<String, String> nsMetadata = new HashMap<String, String>(); if (annosWithNamespace.get(ns) != null) { nsMetadata = annosWithNamespace.get(ns); } nsMetadata.putAll(data); annosWithNamespace.put(ns, nsMetadata); } else { annosWithoutNamespace.putAll(data); } } for (String metakey : listOfMetakeys) { String metaValue = ""; // try to get meta value specific for current speaker if (!trimmedName.isEmpty() && annosWithNamespace.containsKey(trimmedName)) { Map<String, String> speakerAnnos = annosWithNamespace.get(trimmedName); if (speakerAnnos.containsKey(metakey)) { metaValue = speakerAnnos.get(metakey).trim(); } } // try to get meta value, if metaValue is not set if (metaValue.isEmpty() && annosWithoutNamespace.containsKey(metakey)) { metaValue = annosWithoutNamespace.get(metakey).trim(); } out.append(metaValue + TAB_MARK); } } // metadata written lastTokenWasMatched = -1; noPreviousTokenInLine = true; } // header, speaker name and metadata ready String separator = SPACE; // default to space as separator Long matchedNode; // token matched if ((matchedNode = tokenToMatchNumber.get(counterGlobal)) != null) { // is dominated by a (new) matched node, thus use tab to separate the // non-matches from the matches if (lastTokenWasMatched < 0) { if (alignmc && dataIsAlignable) { int orderInList = orderedMatchNumbersGlobal.indexOf(matchedNode); if (orderInList >= matchesWrittenForSpeaker) { int diff = orderInList - matchesWrittenForSpeaker; matchesWrittenForSpeaker++; StringBuilder sb = new StringBuilder(TAB_MARK); for (int i = 0; i < diff; i++) { sb.append(TAB_MARK + TAB_MARK); matchesWrittenForSpeaker++; } separator = sb.toString(); } } else { separator = TAB_MARK; } } else if (lastTokenWasMatched != matchedNode) { // always leave an empty column between two matches, even if there is no actual // context if (alignmc && dataIsAlignable) { int orderInList = orderedMatchNumbersGlobal.indexOf(matchedNode); if (orderInList >= matchesWrittenForSpeaker) { int diff = orderInList - matchesWrittenForSpeaker; matchesWrittenForSpeaker++; StringBuilder sb = new StringBuilder(TAB_MARK + TAB_MARK); for (int i = 0; i < diff; i++) { sb.append(TAB_MARK + TAB_MARK); matchesWrittenForSpeaker++; } separator = sb.toString(); } } else { separator = TAB_MARK + TAB_MARK; } } lastTokenWasMatched = matchedNode; } // token not matched, but last token matched else if (lastTokenWasMatched >= 0) { // handle crossing edges if (!tokenToMatchNumber.containsKey(counterGlobal) && tokenToMatchNumber.containsKey(counterGlobal - 1) && tokenToMatchNumber.containsKey(counterGlobal + 1)) { if (Objects.equals(tokenToMatchNumber.get(counterGlobal - 1), tokenToMatchNumber.get(counterGlobal + 1))) { separator = SPACE; lastTokenWasMatched = tokenToMatchNumber.get(counterGlobal + 1); } else { separator = TAB_MARK; lastTokenWasMatched = -1; } } // mark the end of a match with the tab else { separator = TAB_MARK; lastTokenWasMatched = -1; } } // if tok is the first token in the line and not matched, set separator to empty // string if (noPreviousTokenInLine && separator.equals(SPACE)) { separator = ""; } out.append(separator); // append the current token out.append(graph.getText(tok)); noPreviousTokenInLine = false; prevSpeakerName = currSpeakerName; } } } } }
From source file:annis.gui.exporter.WekaExporter.java
License:Apache License
@Override public boolean convertText(String queryAnnisQL, int contextLeft, int contextRight, Set<String> corpora, List<String> keys, String argsAsString, WebResource annisResource, Writer out, EventBus eventBus) { //this is a full result export try {//from ww w. j a v a2 s .c o m WebResource res = annisResource.path("search").path("matrix") .queryParam("corpora", StringUtils.join(corpora, ",")) .queryParam("q", Helper.encodeJersey(queryAnnisQL)); if (argsAsString.startsWith("metakeys=")) { res = res.queryParam("metakeys", argsAsString.substring("metakeys".length() + 1)); } try (InputStream result = res.get(InputStream.class)) { IOUtils.copy(result, out); } out.flush(); return true; } catch (UniformInterfaceException ex) { log.error(null, ex); Notification n = new Notification("Service exception", ex.getResponse().getEntity(String.class), Notification.Type.WARNING_MESSAGE, true); n.show(Page.getCurrent()); } catch (ClientHandlerException ex) { log.error(null, ex); } catch (IOException ex) { log.error(null, ex); } return false; }
From source file:annis.gui.ReportBugWindow.java
License:Apache License
private boolean sendBugReport(String bugEMailAddress, byte[] screenImage, String imageMimeType) { MultiPartEmail mail = new MultiPartEmail(); try {//from w w w .j av a 2s . co m // server setup mail.setHostName("localhost"); // content of the mail mail.addReplyTo(form.getField("email").getValue().toString(), form.getField("name").getValue().toString()); mail.setFrom(bugEMailAddress); mail.addTo(bugEMailAddress); mail.setSubject("[ANNIS BUG] " + form.getField("summary").getValue().toString()); // TODO: add info about version etc. StringBuilder sbMsg = new StringBuilder(); sbMsg.append("Reporter: ").append(form.getField("name").getValue().toString()).append(" (") .append(form.getField("email").getValue().toString()).append(")\n"); sbMsg.append("Version: ").append(VersionInfo.getVersion()).append("\n"); sbMsg.append("Vaadin Version: ").append(Version.getFullVersion()).append("\n"); sbMsg.append("Browser: ").append(Page.getCurrent().getWebBrowser().getBrowserApplication()) .append("\n"); sbMsg.append("URL: ").append(UI.getCurrent().getPage().getLocation().toASCIIString()).append("\n"); sbMsg.append("\n"); sbMsg.append(form.getField("description").getValue().toString()); mail.setMsg(sbMsg.toString()); if (screenImage != null) { try { mail.attach(new ByteArrayDataSource(screenImage, imageMimeType), "screendump.png", "Screenshot of the browser content at time of problem report"); } catch (IOException ex) { log.error(null, ex); } } File logfile = new File(VaadinService.getCurrent().getBaseDirectory(), "/WEB-INF/log/annis-gui.log"); if (logfile.exists() && logfile.isFile() && logfile.canRead()) { mail.attach(new FileDataSource(logfile), "annis-gui.log", "Logfile of the GUI (shared by all users)"); } if (cause != null) { try { mail.attach(new ByteArrayDataSource(Helper.convertExceptionToMessage(cause), "text/plain"), "exception.txt", "Exception that caused the user to report the problem"); } catch (IOException ex) { log.error(null, ex); } } mail.send(); return true; } catch (EmailException ex) { Notification.show("E-Mail not configured on server", "If this is no Kickstarter version please ask the administrator (" + bugEMailAddress + ") of this ANNIS-instance for assistance. " + "Problem reports are not available for ANNIS Kickstarter", Notification.Type.ERROR_MESSAGE); log.error(null, ex); return false; } }
From source file:annis.gui.SearchView.java
License:Apache License
@Override public void enter(ViewChangeListener.ViewChangeEvent event) { if (event.getOldView() == event.getNewView()) { return;/* w w w. j a v a 2 s.c o m*/ } InstanceConfig config = ui.getInstanceConfig(); Page.getCurrent().setTitle(config.getInstanceDisplayName() + " (ANNIS Corpus Search)"); Page.getCurrent().addUriFragmentChangedListener(this); getSession().addRequestHandler(new CitationRequestHandler()); getSession().setAttribute(MediaController.class, new MediaControllerImpl()); getSession().setAttribute(PDFController.class, new PDFControllerImpl()); // the following shoul checkCitation(); lastEvaluatedFragment = ""; Background.run(new VersionChecker()); evaluateFragment(Page.getCurrent().getUriFragment()); if (config.isLoginOnStart() && toolbar != null && Helper.getUser() == null) { toolbar.showLoginWindow(false); } }
From source file:annis.gui.SearchView.java
License:Apache License
@Override public void notifyCannotPlayMimeType(String mimeType) { if (mimeType == null) { return;//from w w w. ja v a2 s . c o m } if (mimeType.startsWith("audio/ogg") || mimeType.startsWith("video/web")) { String browserList = "<ul>" + "<li>Mozilla Firefox: <a href=\"http://www.mozilla.org/firefox\" target=\"_blank\">http://www.mozilla.org/firefox</a></li>" + "<li>Google Chrome: <a href=\"http://www.google.com/chrome\" target=\"_blank\">http://www.google.com/chrome</a></li>" + "</ul>"; WebBrowser browser = Page.getCurrent().getWebBrowser(); // IE9 users can install a plugin Set<String> supportedByIE9Plugin = new HashSet<>(); supportedByIE9Plugin.add("video/webm"); supportedByIE9Plugin.add("audio/ogg"); supportedByIE9Plugin.add("video/ogg"); if (browser.isIE() && browser.getBrowserMajorVersion() >= 9 && supportedByIE9Plugin.contains(mimeType)) { Notification n = new Notification("Media file type unsupported by your browser", "Please install the WebM plugin for Internet Explorer 9 from " + "<a target=\"_blank\" href=\"https://tools.google.com/dlpage/webmmf\">https://tools.google.com/dlpage/webmmf</a> " + " or use a browser from the following list " + "(these are known to work with WebM or OGG files)<br/>" + browserList + "<br/><br /><strong>Click on this message to hide it</strong>", Notification.Type.WARNING_MESSAGE, true); n.setDelayMsec(15000); n.show(Page.getCurrent()); } else { Notification n = new Notification("Media file type unsupported by your browser", "Please use a browser from the following list " + "(these are known to work with WebM or OGG files)<br/>" + browserList + "<br/><br /><strong>Click on this message to hide it</strong>", Notification.Type.WARNING_MESSAGE, true); n.setDelayMsec(15000); n.show(Page.getCurrent()); } } else { Notification.show("Media file type \"" + mimeType + "\" unsupported by your browser!", "Try to check your browsers documentation how to enable " + "support for the media type or inform the corpus creator about this problem.", Notification.Type.WARNING_MESSAGE); } }
From source file:annis.gui.SearchView.java
License:Apache License
@Override public void onLogin() { getControlPanel().getCorpusList().updateCorpusSetList(true); // re-evaluate the fragment in case a corpus is now accessible evaluateFragment(Page.getCurrent().getUriFragment()); }