List of usage examples for com.vaadin.ui Notification show
public static Notification show(String caption, Type type)
From source file:annis.gui.controller.FrequencyBackgroundJob.java
License:Apache License
private FrequencyTable loadBeans() { FrequencyTable result = new FrequencyTable(); WebResource annisResource = Helper.getAnnisWebResource(); try {/*from ww w. ja va2s . c om*/ annisResource = annisResource.path("query").path("search").path("frequency") .queryParam("q", Helper.encodeJersey(query.getQuery())) .queryParam("corpora", StringUtils.join(query.getCorpora(), ",")) .queryParam("fields", query.getFrequencyDefinition().toString()); result = annisResource.get(FrequencyTable.class); } catch (UniformInterfaceException ex) { String message; if (ex.getResponse().getStatus() == 400) { message = ex.getResponse().getEntity(String.class); } else if (ex.getResponse().getStatus() == 504) { message = "Timeout: query exeuction took too long"; } else { message = "unknown error: " + ex; log.error(ex.getResponse().getEntity(String.class), ex); } Notification.show(message, Notification.Type.WARNING_MESSAGE); } catch (ClientHandlerException ex) { log.error("could not execute REST call to query frequency", ex); } return result; }
From source file:annis.gui.controlpanel.CorpusListPanel.java
License:Apache License
public CorpusListPanel(InstanceConfig instanceConfig, ExampleQueriesPanel autoGenQueries, final AnnisUI ui) { this.instanceConfig = instanceConfig; this.autoGenQueries = autoGenQueries; this.ui = ui; final CorpusListPanel finalThis = this; setSizeFull();/*from w w w . j a v a 2s . co m*/ selectionLayout = new HorizontalLayout(); selectionLayout.setWidth("100%"); selectionLayout.setHeight("-1px"); selectionLayout.setVisible(false); Label lblVisible = new Label("Visible: "); lblVisible.setSizeUndefined(); selectionLayout.addComponent(lblVisible); cbSelection = new ComboBox(); cbSelection.setDescription("Choose corpus selection set"); cbSelection.setWidth("100%"); cbSelection.setHeight("-1px"); cbSelection.addStyleName(ValoTheme.COMBOBOX_SMALL); cbSelection.setInputPrompt("Add new corpus selection set"); cbSelection.setNullSelectionAllowed(false); cbSelection.setNewItemsAllowed(true); cbSelection.setNewItemHandler((AbstractSelect.NewItemHandler) this); cbSelection.setImmediate(true); cbSelection.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { updateCorpusTable(); updateAutoGeneratedQueriesPanel(); } }); selectionLayout.addComponent(cbSelection); selectionLayout.setExpandRatio(cbSelection, 1.0f); selectionLayout.setSpacing(true); selectionLayout.setComponentAlignment(cbSelection, Alignment.MIDDLE_RIGHT); selectionLayout.setComponentAlignment(lblVisible, Alignment.MIDDLE_LEFT); addComponent(selectionLayout); txtFilter = new TextField(); txtFilter.setVisible(false); txtFilter.setInputPrompt("Filter"); txtFilter.setImmediate(true); txtFilter.setTextChangeTimeout(500); txtFilter.addTextChangeListener(new FieldEvents.TextChangeListener() { @Override public void textChange(FieldEvents.TextChangeEvent event) { BeanContainer<String, AnnisCorpus> availableCorpora = ui.getQueryState().getAvailableCorpora(); if (textFilter != null) { // remove the old filter availableCorpora.removeContainerFilter(textFilter); textFilter = null; } if (event.getText() != null && !event.getText().isEmpty()) { Set<String> selectedIDs = ui.getQueryState().getSelectedCorpora().getValue(); textFilter = new SimpleStringFilter("name", event.getText(), true, false); availableCorpora.addContainerFilter(textFilter); // select the first item List<String> filteredIDs = availableCorpora.getItemIds(); Set<String> selectedAndFiltered = new HashSet<>(selectedIDs); selectedAndFiltered.retainAll(filteredIDs); Set<String> selectedAndOutsideFilter = new HashSet<>(selectedIDs); selectedAndOutsideFilter.removeAll(filteredIDs); for (String id : selectedAndOutsideFilter) { tblCorpora.unselect(id); } if (selectedAndFiltered.isEmpty() && !filteredIDs.isEmpty()) { for (String id : selectedIDs) { tblCorpora.unselect(id); } tblCorpora.select(filteredIDs.get(0)); } } } }); txtFilter.setWidth("100%"); txtFilter.setHeight("-1px"); txtFilter.addStyleName(ValoTheme.TEXTFIELD_SMALL); addComponent(txtFilter); pbLoadCorpora = new ProgressBar(); pbLoadCorpora.setCaption("Loading corpus list..."); pbLoadCorpora.setIndeterminate(true); addComponent(pbLoadCorpora); tblCorpora = new Table(); addComponent(tblCorpora); tblCorpora.setVisible(false); // don't show list before it was not loaded tblCorpora.setContainerDataSource(ui.getQueryState().getAvailableCorpora()); tblCorpora.setMultiSelect(true); tblCorpora.setPropertyDataSource(ui.getQueryState().getSelectedCorpora()); tblCorpora.addGeneratedColumn("info", new InfoGenerator()); tblCorpora.addGeneratedColumn("docs", new DocLinkGenerator()); tblCorpora.setVisibleColumns("name", "textCount", "tokenCount", "info", "docs"); tblCorpora.setColumnHeaders("Name", "Texts", "Tokens", "", ""); tblCorpora.setHeight("100%"); tblCorpora.setWidth("100%"); tblCorpora.setSelectable(true); tblCorpora.setNullSelectionAllowed(false); tblCorpora.setColumnExpandRatio("name", 0.6f); tblCorpora.setColumnExpandRatio("textCount", 0.15f); tblCorpora.setColumnExpandRatio("tokenCount", 0.25f); tblCorpora.addStyleName(ValoTheme.TABLE_SMALL); tblCorpora.addActionHandler((Action.Handler) this); tblCorpora.setImmediate(true); tblCorpora.addItemClickListener(new ItemClickEvent.ItemClickListener() { @Override public void itemClick(ItemClickEvent event) { Set selections = (Set) tblCorpora.getValue(); if (selections.size() == 1 && event.isCtrlKey() && tblCorpora.isSelected(event.getItemId())) { tblCorpora.setValue(null); } } }); tblCorpora.setItemDescriptionGenerator(new TooltipGenerator()); tblCorpora.addValueChangeListener(new CorpusTableChangedListener(finalThis)); Button btReload = new Button(); btReload.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { updateCorpusSetList(false, false); Notification.show("Reloaded corpus list", Notification.Type.HUMANIZED_MESSAGE); } }); btReload.setIcon(FontAwesome.REFRESH); btReload.setDescription("Reload corpus list"); btReload.addStyleName(ValoTheme.BUTTON_ICON_ONLY); selectionLayout.addComponent(btReload); selectionLayout.setComponentAlignment(btReload, Alignment.MIDDLE_RIGHT); tblCorpora.setSortContainerPropertyId("name"); setExpandRatio(tblCorpora, 1.0f); updateCorpusSetList(true, true); }
From source file:annis.gui.controlpanel.CorpusListPanel.java
License:Apache License
private List<AnnisCorpus> getCorpusListFromServer() { List<AnnisCorpus> result = new LinkedList<>(); try {/* w w w.j a v a 2 s .c om*/ WebResource rootRes = Helper.getAnnisWebResource(); result = rootRes.path("query").path("corpora").get(new AnnisCorpusListType()); return result; } catch (ClientHandlerException ex) { log.error(null, ex); Notification.show("Service not available: " + ex.getLocalizedMessage(), Notification.Type.TRAY_NOTIFICATION); } catch (UniformInterfaceException ex) { if (ex.getResponse().getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) { Notification.show("You are not authorized to get the corpus list.", ex.getMessage(), Notification.Type.WARNING_MESSAGE); } else if (ex.getResponse().getStatus() == Response.Status.FORBIDDEN.getStatusCode()) { Notification.show("Your account has expired.", ex.getMessage(), Notification.Type.WARNING_MESSAGE); return result; } else { log.error(null, ex); Notification.show("Remote exception: " + ex.getLocalizedMessage(), Notification.Type.TRAY_NOTIFICATION); } } return null; }
From source file:annis.gui.controlpanel.CorpusListPanel.java
License:Apache License
@Override public void addNewItem(String newItemCaption) { if (!cbSelection.containsId(newItemCaption) && this.userConfig != null) { cbSelection.addItem(newItemCaption); cbSelection.setValue(newItemCaption); try {// w w w . j a v a 2 s.c o m UserConfig newUserConfig = getUserConfigFromRemote(); this.userConfig = newUserConfig; // add new corpus set to the config CorpusSet newSet = new CorpusSet(); newSet.setName(newItemCaption); this.userConfig.getCorpusSets().add(newSet); // store the config on the server storeChangesRemote(); // update everything else updateCorpusTable(); } catch (ClientHandlerException ex) { log.error("could not store new corpus set", ex); Notification.show("Could not store new corpus set: " + ex.getLocalizedMessage(), Type.WARNING_MESSAGE); } catch (UniformInterfaceException ex) { if (ex.getResponse().getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) { log.error(ex.getLocalizedMessage()); Notification.show("Not allowed", "you have not the permission to add a new corpus group", Type.WARNING_MESSAGE); } else { log.error("error occures while storing new corpus set", ex); Notification.show("error occures while storing new corpus set", "Maybe you will have to log in", Type.WARNING_MESSAGE); } } } // end if new item }
From source file:annis.gui.controlpanel.ExportPanel.java
License:Apache License
@Override public void buttonClick(ClickEvent event) { // clean up old export if (tmpOutputFile != null && tmpOutputFile.exists()) { if (!tmpOutputFile.delete()) { log.warn("Could not delete {}", tmpOutputFile.getAbsolutePath()); }/* ww w .ja v a 2 s .c o m*/ } tmpOutputFile = null; String exporterName = (String) cbExporter.getValue(); final Exporter exporter = exporterMap.get(exporterName); if (exporter != null) { if (corpusListPanel.getSelectedCorpora().isEmpty()) { Notification.show("Please select a corpus", Notification.Type.WARNING_MESSAGE); btExport.setEnabled(true); return; } Callable<File> callable = new Callable<File>() { @Override public File call() throws Exception { File currentTmpFile = File.createTempFile("annis-export", ".txt"); currentTmpFile.deleteOnExit(); exporter.convertText(queryPanel.getQuery(), Integer.parseInt((String) cbLeftContext.getValue()), Integer.parseInt((String) cbRightContext.getValue()), corpusListPanel.getSelectedCorpora(), null, (String) txtParameters.getValue(), Helper.getAnnisWebResource().path("query"), new OutputStreamWriter(new FileOutputStream(currentTmpFile), "UTF-8")); return currentTmpFile; } }; FutureTask<File> task = new FutureTask<File>(callable) { @Override protected void done() { VaadinSession session = VaadinSession.getCurrent(); session.lock(); try { btExport.setEnabled(true); progressIndicator.setEnabled(false); try { // copy the result to the class member in order to delete if // when not longer needed tmpOutputFile = get(); } catch (InterruptedException ex) { log.error(null, ex); } catch (ExecutionException ex) { log.error(null, ex); } if (tmpOutputFile == null) { Notification.show("Could not create the Exporter", "The server logs might contain more information about this " + "so you should contact the provider of this ANNIS installation " + "for help.", Notification.Type.ERROR_MESSAGE); } else { if (downloader != null && btDownload.getExtensions().contains(downloader)) { btDownload.removeExtension(downloader); } downloader = new FileDownloader(new FileResource(tmpOutputFile)); downloader.extend(btDownload); btDownload.setEnabled(true); Notification.show("Export finished", "Click on the button right to the export button to actually download the file.", Notification.Type.HUMANIZED_MESSAGE); } } finally { session.unlock(); } } }; progressIndicator.setEnabled(true); ExecutorService singleExecutor = Executors.newSingleThreadExecutor(); singleExecutor.submit(task); } }
From source file:annis.gui.CorpusBrowserPanel.java
License:Apache License
private List<AnnisAttribute> fetchAnnos(String toplevelCorpus) { Collection<AnnisAttribute> result = new ArrayList<>(); try {//from ww w. j av a2s .c o m WebResource service = Helper.getAnnisWebResource(); if (service != null) { WebResource query = service.path("query").path("corpora").path(urlPathEscape.escape(toplevelCorpus)) .path("annotations").queryParam("fetchvalues", "true") .queryParam("onlymostfrequentvalues", "true"); result = query.get(new AnnisAttributeListType()); } } catch (UniformInterfaceException ex) { log.error(null, ex); Notification.show("Remote exception: " + ex.getLocalizedMessage(), Notification.Type.WARNING_MESSAGE); } catch (ClientHandlerException ex) { log.error(null, ex); Notification.show("Remote exception: " + ex.getLocalizedMessage(), Notification.Type.WARNING_MESSAGE); } return new LinkedList<>(result); }
From source file:annis.gui.MainToolbar.java
License:Apache License
public MainToolbar() { String bugmail = (String) VaadinSession.getCurrent().getAttribute(BUG_MAIL_KEY); if (bugmail != null && !bugmail.isEmpty() && !bugmail.startsWith("${") && new EmailValidator("").isValid(bugmail)) { this.bugEMailAddress = bugmail; } else {/*from w w w . j a v a2 s . c om*/ this.bugEMailAddress = null; } UI ui = UI.getCurrent(); if (ui instanceof CommonUI) { ((CommonUI) ui).getSettings().addedLoadedListener(MainToolbar.this); } setWidth("100%"); setHeight("-1px"); addStyleName("toolbar"); addStyleName("border-layout"); btAboutAnnis = new Button("About ANNIS"); btAboutAnnis.addStyleName(ValoTheme.BUTTON_SMALL); btAboutAnnis.setIcon(new ThemeResource("images/annis_16.png")); btAboutAnnis.addClickListener(new AboutClickListener()); btSidebar = new Button(); btSidebar.setDisableOnClick(true); btSidebar.addStyleName(ValoTheme.BUTTON_SMALL); btSidebar.setDescription("Show and hide search sidebar"); btSidebar.setIconAlternateText(btSidebar.getDescription()); btBugReport = new Button("Report Problem"); btBugReport.addStyleName(ValoTheme.BUTTON_SMALL); btBugReport.setDisableOnClick(true); btBugReport.setIcon(FontAwesome.ENVELOPE_O); btBugReport.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { reportBug(); } }); btBugReport.setVisible(this.bugEMailAddress != null); btNavigate = new Button(); btNavigate.setVisible(false); btNavigate.setDisableOnClick(true); btNavigate.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { btNavigate.setEnabled(true); if (navigationTarget != null) { UI.getCurrent().getNavigator().navigateTo(navigationTarget.state); } } }); lblUserName = new Label("not logged in"); lblUserName.setWidth("-1px"); lblUserName.setHeight("-1px"); lblUserName.addStyleName("right-aligned-text"); btLogin = new Button("Login", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { showLoginWindow(false); } }); btLogout = new Button("Logout", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { // logout Helper.setUser(null); for (LoginListener l : loginListeners) { l.onLogout(); } Notification.show("Logged out", Notification.Type.TRAY_NOTIFICATION); updateUserInformation(); } }); btLogin.setSizeUndefined(); btLogin.setStyleName(ValoTheme.BUTTON_SMALL); btLogin.setIcon(FontAwesome.USER); btLogout.setSizeUndefined(); btLogout.setStyleName(ValoTheme.BUTTON_SMALL); btLogout.setIcon(FontAwesome.USER); btOpenSource = new Button("Help us to make ANNIS better!"); btOpenSource.setStyleName(BaseTheme.BUTTON_LINK); btOpenSource.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { Window w = new HelpUsWindow(); w.setCaption("Help us to make ANNIS better!"); w.setModal(true); w.setResizable(true); w.setWidth("600px"); w.setHeight("500px"); UI.getCurrent().addWindow(w); w.center(); } }); addComponent(btSidebar); setComponentAlignment(btSidebar, Alignment.MIDDLE_LEFT); addComponent(btAboutAnnis); addComponent(btBugReport); addComponent(btNavigate); addComponent(btOpenSource); setSpacing(true); setComponentAlignment(btAboutAnnis, Alignment.MIDDLE_LEFT); setComponentAlignment(btBugReport, Alignment.MIDDLE_LEFT); setComponentAlignment(btNavigate, Alignment.MIDDLE_LEFT); setComponentAlignment(btOpenSource, Alignment.MIDDLE_CENTER); setExpandRatio(btOpenSource, 1.0f); addLoginButton(); btSidebar.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { btSidebar.setEnabled(true); // decide new state switch (sidebarState) { case VISIBLE: if (event.isCtrlKey()) { sidebarState = SidebarState.AUTO_VISIBLE; } else { sidebarState = SidebarState.HIDDEN; } break; case HIDDEN: if (event.isCtrlKey()) { sidebarState = SidebarState.AUTO_HIDDEN; } else { sidebarState = SidebarState.VISIBLE; } break; case AUTO_VISIBLE: if (event.isCtrlKey()) { sidebarState = SidebarState.VISIBLE; } else { sidebarState = SidebarState.AUTO_HIDDEN; } break; case AUTO_HIDDEN: if (event.isCtrlKey()) { sidebarState = SidebarState.HIDDEN; } else { sidebarState = SidebarState.AUTO_VISIBLE; } break; } updateSidebarState(); } }); screenshotExtension = new ScreenshotMaker(this); JavaScript.getCurrent().addFunction("annis.gui.logincallback", new LoginCloseCallback()); updateSidebarState(); MainToolbar.this.updateUserInformation(); }
From source file:annis.gui.MainToolbar.java
License:Apache License
private void updateUserInformation() { if (lblUserName == null) { return;//from www.j ava 2s . c om } if (navigationTarget == NavigationTarget.ADMIN) { // don't show administration link per default btNavigate.setVisible(false); } AnnisUser user = Helper.getUser(); // always close the window if (windowLogin != null) { windowLogin.close(user != null); } if (user == null) { Object loginErrorOject = VaadinSession.getCurrent().getSession().getAttribute(USER_LOGIN_ERROR); if (loginErrorOject != null && loginErrorOject instanceof String) { Notification.show((String) loginErrorOject, Notification.Type.WARNING_MESSAGE); } VaadinSession.getCurrent().getSession().removeAttribute(AnnisBaseUI.USER_LOGIN_ERROR); lblUserName.setValue("not logged in"); if (getComponentIndex(btLogout) > -1) { replaceComponent(btLogout, btLogin); setComponentAlignment(btLogin, Alignment.MIDDLE_RIGHT); } } else { // logged in if (user.getUserName() != null) { Notification.show("Logged in as \"" + user.getUserName() + "\"", Notification.Type.TRAY_NOTIFICATION); lblUserName.setValue("logged in as \"" + user.getUserName() + "\""); } if (getComponentIndex(btLogin) > -1) { replaceComponent(btLogin, btLogout); setComponentAlignment(btLogout, Alignment.MIDDLE_RIGHT); } // do not show the logout button if the user cannot logout using ANNIS btLogout.setVisible(!user.isRemote()); if (navigationTarget == NavigationTarget.ADMIN) { // check in background if display is necessary if (user.getUserName() != null) { Background.run(new CheckIfUserIsAdministratorJob(user.getUserName(), UI.getCurrent())); } } } }
From source file:annis.gui.MainToolbar.java
License:Apache License
public void reportBug(Throwable cause) { lastBugReportCause = cause;//from w w w .j a v a 2 s . c o m if (screenshotExtension.isAttached()) { screenshotExtension.makeScreenshot(); btBugReport.setCaption("problem report is initialized..."); } else { Notification.show("This user interface does not allow screenshots. Can't report bug.", Notification.Type.ERROR_MESSAGE); } }
From source file:annis.gui.MetaDataPanel.java
License:Apache License
private List<Annotation> getAllSubcorpora(String toplevelCorpusName) { List<Annotation> result = new LinkedList<>(); WebResource res = Helper.getAnnisWebResource(); try {/* w w w . j av a 2s . c o m*/ res = res.path("meta").path("docnames").path(urlPathEscape.escape(toplevelCorpusName)); result = res.get(new Helper.AnnotationListType()); Collections.sort(result, new Comparator<Annotation>() { @Override public int compare(Annotation arg0, Annotation arg1) { return ComparisonChain.start().compare(arg0.getName(), arg1.getName()).result(); } }); } catch (UniformInterfaceException ex) { log.error(null, ex); Notification.show("Remote exception: " + ex.getLocalizedMessage(), Notification.Type.WARNING_MESSAGE); } catch (ClientHandlerException ex) { log.error(null, ex); Notification.show("Remote exception: " + ex.getLocalizedMessage(), Notification.Type.WARNING_MESSAGE); } return result; }