List of usage examples for com.vaadin.ui Notification show
public static Notification show(String caption)
From source file:$.ExampleOperation.java
License:Open Source License
public Undoer execute(List<VertexRef> targets, OperationContext operationContext) { Notification.show("This is an Example Operation, there isn't much to it"); return null; }/* w ww . j ava 2 s.c om*/
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);/*from www. j a v a 2 s . co 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.components.HelpButton.java
License:Apache License
@Override public void buttonClick(ClickEvent event) { String caption = "Help"; if (getCaption() != null && !getCaption().isEmpty()) { caption = "Help for \"" + getCaption(); }/* w w w . jav a2 s. c o m*/ caption = caption + "<br/><br/>(Click here to close)"; Notification notify = new Notification(caption, Notification.Type.HUMANIZED_MESSAGE); notify.setHtmlContentAllowed(true); notify.setDescription(field.getDescription()); notify.setDelayMsec(-1); notify.show(UI.getCurrent().getPage()); }
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 {/*w w w .ja va2 s . 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 ww .j a va 2 s .c o m*/ * * @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 {/*w w w. j a v a 2 s .co 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.flatquerybuilder.FlatQueryBuilder.java
License:Apache License
public void updateQuery() { try {/*from www. jav a 2 s . co m*/ cp.setQuery(new Query(getAQLQuery(), cp.getState().getSelectedCorpora().getValue())); } catch (java.lang.NullPointerException ex) { Notification.show(INCOMPLETE_QUERY_WARNING); } }
From source file:annis.gui.flatquerybuilder.FlatQueryBuilder.java
License:Apache License
@Override public void buttonClick(Button.ClickEvent event) { if (cp.getState().getSelectedCorpora().getValue().isEmpty()) { Notification.show(NO_CORPORA_WARNING); } else {/*from ww w . ja v a2 s . co m*/ if (event.getButton() == btGo) { updateQuery(); } if (event.getButton() == btClear) { clear(); updateQuery(); launch(cp); } if (event.getComponent() == btInverse) { try { loadQuery(); } catch (EmptyReferenceException e) { log.error(null, e); } catch (EqualityConstraintException e) { log.error(null, e); } catch (InvalidCharacterSequenceException e) { log.error(null, e); } catch (MultipleAssignmentException e) { log.error(null, e); } catch (UnknownLevelException e) { log.error(null, e); } } if (event.getComponent() == btInitMeta || event.getComponent() == btInitSpan || event.getComponent() == btInitLanguage) { initialize(); } } }
From source file:annis.gui.flatquerybuilder.FlatQueryBuilder.java
License:Apache License
public void loadQuery() throws UnknownLevelException, EqualityConstraintException, MultipleAssignmentException, InvalidCharacterSequenceException, EmptyReferenceException /*//from w w w .ja v a2 s .c om * this method is called by btInverse * When the query has changed in the * textfield, the query represented by * the query builder is not equal to * the one delivered by the text field */ { /*get clean query from control panel text field*/ String tq = cp.getState().getAql().getValue().replace("\n", " ").replace("\r", ""); //TODO VALIDATE QUERY: (NOT SUFFICIENT YET) boolean valid = (!tq.equals("")); if (!(query.equals(tq)) & valid) { //PROBLEM: LINE BREAKS (simple without anything else) try { //the dot marks the end of the string - it is not read, it's just a place holder tq += "."; HashMap<Integer, Constraint> constraints = new HashMap<>(); ArrayList<Relation> pRelations = new ArrayList<>(); ArrayList<Relation> eRelations = new ArrayList<>(); Relation inclusion = null; Constraint conInclusion = null; ArrayList<Constraint> metaConstraints = new ArrayList<>(); //parse typed-in Query //Step 1: get indices of tq-chars, where constraints are separated (&) String tempCon = ""; int count = 1; int maxId = 0; boolean inclusionCheck = false; for (int i = 0; i < tq.length(); i++) { //improve this Algorithm (compare to constraint) char c = tq.charAt(i); if ((c != '&') & (i != tq.length() - 1)) { if (!((tempCon.length() == 0) & (c == ' '))) //avoids, that a constraint starts with a space { tempCon += c; } } else { while (tempCon.charAt(tempCon.length() - 1) == ' ') { tempCon = tempCon.substring(0, tempCon.length() - 1); } if (tempCon.startsWith("meta::")) { metaConstraints.add(new Constraint(tempCon)); } else if (tempCon.startsWith("#")) { Relation r = new Relation(tempCon); if (r.getType() == RelationType.EQUALITY) { eRelations.add(r); } else if (r.getType() == RelationType.PRECEDENCE) { pRelations.add(r); } else if ((r.getType() == RelationType.INCLUSION) & (!inclusionCheck)) { inclusion = r; if (constraints.containsKey(r.getFirst())) { conInclusion = constraints.get(r.getFirst()); constraints.remove(r.getFirst()); } inclusionCheck = true; } int newMax = (r.getFirst() > r.getSecond()) ? r.getFirst() : r.getSecond(); maxId = (maxId < newMax) ? newMax : maxId; } else { constraints.put(count++, new Constraint(tempCon)); } tempCon = ""; } } /*CHECK FOR EMPTY REFERENCE*/ /*IDEA: If the highest element-id is not empty, all lower ids can't be empty*/ /*one additional increment of count has to be taken into account*/ /*empty means, the element the id is refering to does not exist*/ if (maxId >= count) { throw new EmptyReferenceException(Integer.toString(maxId)); } /*CHECK FOR INVALID OR REDUNDANT MUTLIPLE VALUE ASSIGNMENT*/ for (Relation rel : eRelations) { Constraint con1 = constraints.get(rel.getFirst()); Constraint con2 = constraints.get(rel.getSecond()); if (con1.getLevel().equals(con2.getLevel())) { throw new MultipleAssignmentException(con1.toString() + " <-> " + con2.toString()); } } //create Vertical Nodes HashMap<Integer, VerticalNode> indexedVnodes = new HashMap<>(); VerticalNode vn = null; Collection<String> annonames = getAvailableAnnotationNames(); for (int i : constraints.keySet()) { Constraint con = constraints.get(i); if (!annonames.contains(con.getLevel())) { throw new UnknownLevelException(con.getLevel()); //is that a good idea? YES } if (!indexedVnodes.containsKey(i)) { vn = new VerticalNode(con.getLevel(), con.getValue(), this, con.isRegEx(), con.isNegative()); if (con.isRegEx()) { SearchBox sb = vn.getSearchBoxes().iterator().next(); /*CHECK FIRST IF WE REALLY HAVE A MULTIPLE VALUE EXPRESSION*/ Collection<String> mvalue = splitMultipleValueExpression(con.getValue()); if (mvalue.size() == 1) { sb.setValue(mvalue.iterator().next()); } else { sb.setValue(mvalue); } } indexedVnodes.put(i, vn); } for (Relation rel : eRelations) { if (rel.contains(i)) { int b = rel.whosMyFriend(i); if (!indexedVnodes.containsKey(b)) { indexedVnodes.put(b, null); Constraint bcon = constraints.get(b); SearchBox sb = new SearchBox(bcon.getLevel(), this, vn, bcon.isRegEx(), bcon.isNegative()); Collection<String> values = splitMultipleValueExpression(bcon.getValue()); if (values.size() > 1) { sb.setValue(values); } else { sb.setValue(bcon.getValue()); } vn.addSearchBox(sb); } } } } //clean query builder surface for (VerticalNode v : vnodes) { languagenodes.removeComponent(v); } vnodes.clear(); for (EdgeBox eb : eboxes) { languagenodes.removeComponent(eb); } eboxes.clear(); for (MetaBox mb : mboxes) { meta.removeComponent(mb); } mboxes.clear(); //remove SpanBox removeSpanBox(); VerticalNode first = null; int smP = (!pRelations.isEmpty()) ? pRelations.iterator().next().getFirst() : 0; int smE = (!eRelations.isEmpty()) ? eRelations.iterator().next().getFirst() : 0; if ((smP + smE) == 0) { if (!indexedVnodes.isEmpty()) { first = indexedVnodes.values().iterator().next(); } } else if ((smP != 0) & (smE != 0)) { first = indexedVnodes.get(Math.min(smE, smP)); } else { //one value is zero first = indexedVnodes.get(smE + smP); } if (first != null) { vnodes.add(first); languagenodes.addComponent(first); for (Relation rel : pRelations) { EdgeBox eb = new EdgeBox(this); eb.setValue(rel.getOperator()); eboxes.add(eb); VerticalNode v = indexedVnodes.get(rel.getSecond()); vnodes.add(v); languagenodes.addComponent(eb); languagenodes.addComponent(v); } } //build SpanBox if (inclusion != null) { addSpanBox(new SpanBox(conInclusion.getLevel(), this, conInclusion.isRegEx())); spbox.setValue(conInclusion.getValue()); } //build MetaBoxes for (Constraint mc : metaConstraints) { if (mc.isRegEx()) { Collection<String> values = splitMultipleValueExpression( unescape(unescapeSlQ(mc.getValue()))); MetaBox mb = new MetaBox(mc.getLevel(), this); mb.setValue(values); mboxes.add(mb); meta.addComponent(mb); } else { MetaBox mb = new MetaBox(mc.getLevel(), this); //for a particular reason (unknown) setValue() with a String parameter //is not accepted by OptionGroup Collection<String> values = new TreeSet<>(); values.add(unescapeSlQ(mc.getValue())); mb.setValue(values); mboxes.add(mb); meta.addComponent(mb); } } query = tq.substring(0, tq.length() - 1); } catch (EmptyReferenceException e) { Notification.show(e.getMessage()); } catch (EqualityConstraintException e) { Notification.show(e.getMessage()); } catch (InvalidCharacterSequenceException e) { Notification.show(e.getMessage()); } catch (MultipleAssignmentException e) { Notification.show(e.getMessage()); } catch (UnknownLevelException e) { Notification.show(e.getMessage()); } } }
From source file:annis.gui.flatquerybuilder.ReducingStringComparator.java
License:Apache License
private void readMappings() { ALLOGRAPHS = new HashMap<>(); ClassResource cr = new ClassResource(ReducingStringComparator.class, MAPPING_FILE); try {/* w w w . ja v a 2s . c o m*/ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document mappingD = db.parse(cr.getStream().getStream()); NodeList mappings = mappingD.getElementsByTagName("mapping"); for (int i = 0; i < mappings.getLength(); i++) { Element mapping = (Element) mappings.item(i); String mappingName = mapping.getAttribute("name"); HashMap mappingMap = initAlphabet(); NodeList variants = mapping.getElementsByTagName("variant"); for (int j = 0; j < variants.getLength(); j++) { Element var = (Element) variants.item(j); char varvalue = var.getAttribute("value").charAt(0); Element character = (Element) var.getParentNode(); char charactervalue = character.getAttribute("value").charAt(0); mappingMap.put(varvalue, charactervalue); } ALLOGRAPHS.put(mappingName, mappingMap); } } catch (SAXException e) { e = null; Notification.show(READING_ERROR_MESSAGE); } catch (IOException e) { e = null; Notification.show(READING_ERROR_MESSAGE); } catch (ParserConfigurationException e) { e = null; Notification.show(READING_ERROR_MESSAGE); } }