List of usage examples for com.vaadin.server VaadinSession getAttribute
public <T> T getAttribute(Class<T> type)
From source file:annis.gui.QueryController.java
License:Apache License
/** * Executes a query.//from w ww. j a v a 2 s . co m * @param replaceOldTab * @param freshQuery If true the offset and the selected matches are reset before executing the query. */ public void executeSearch(boolean replaceOldTab, boolean freshQuery) { if (freshQuery) { getState().getOffset().setValue(0l); getState().getSelectedMatches().setValue(new TreeSet<Long>()); // get the value for the visible segmentation from the configured context Set<String> selectedCorpora = getState().getSelectedCorpora().getValue(); CorpusConfig config = new CorpusConfig(); if (selectedCorpora != null && !selectedCorpora.isEmpty()) { config = ui.getCorpusConfigWithCache(selectedCorpora.iterator().next()); } if (config.containsKey(SearchOptionsPanel.KEY_DEFAULT_BASE_TEXT_SEGMENTATION)) { String configVal = config.getConfig(SearchOptionsPanel.KEY_DEFAULT_BASE_TEXT_SEGMENTATION); if ("".equals(configVal) || "tok".equals(configVal)) { configVal = null; } getState().getVisibleBaseText().setValue(configVal); } else { getState().getVisibleBaseText().setValue(getState().getContextSegmentation().getValue()); } } // construct a query from the current properties DisplayedResultQuery displayedQuery = getSearchQuery(); searchView.getControlPanel().getQueryPanel().setStatus("Searching..."); cancelSearch(); // cleanup resources VaadinSession session = VaadinSession.getCurrent(); session.setAttribute(IFrameResourceMap.class, new IFrameResourceMap()); if (session.getAttribute(MediaController.class) != null) { session.getAttribute(MediaController.class).clearMediaPlayers(); } searchView.updateFragment(displayedQuery); if (displayedQuery.getCorpora() == null || displayedQuery.getCorpora().isEmpty()) { Notification.show("Please select a corpus", Notification.Type.WARNING_MESSAGE); return; } if ("".equals(displayedQuery.getQuery())) { Notification.show("Empty query", Notification.Type.WARNING_MESSAGE); return; } addHistoryEntry(displayedQuery); AsyncWebResource res = Helper.getAnnisAsyncWebResource(); // // begin execute match fetching // ResultViewPanel oldPanel = searchView.getLastSelectedResultView(); if (replaceOldTab) { // remove old panel from view searchView.closeTab(oldPanel); } ResultViewPanel newResultView = new ResultViewPanel(ui, ui, ui.getInstanceConfig(), displayedQuery); newResultView.getPaging() .addCallback(new SpecificPagingCallback(ui, searchView, newResultView, displayedQuery)); TabSheet.Tab newTab; List<ResultViewPanel> existingResultPanels = getResultPanels(); String caption = existingResultPanels.isEmpty() ? "Query Result" : "Query Result #" + (existingResultPanels.size() + 1); newTab = searchView.getMainTab().addTab(newResultView, caption); newTab.setClosable(true); newTab.setIcon(FontAwesome.SEARCH); searchView.getMainTab().setSelectedTab(newResultView); searchView.notifiyQueryStarted(); Background.run(new ResultFetchJob(displayedQuery, newResultView, ui)); // // end execute match fetching // // // begin execute count // // start count query searchView.getControlPanel().getQueryPanel().setCountIndicatorEnabled(true); AsyncWebResource countRes = res.path("query").path("search").path("count") .queryParam("q", Helper.encodeJersey(displayedQuery.getQuery())) .queryParam("corpora", Helper.encodeJersey(StringUtils.join(displayedQuery.getCorpora(), ","))); Future<MatchAndDocumentCount> futureCount = countRes.get(MatchAndDocumentCount.class); state.getExecutedTasks().put(QueryUIState.QueryType.COUNT, futureCount); Background.run(new CountCallback(newResultView, displayedQuery.getLimit(), ui)); // // end execute count // }
From source file:annis.libgui.visualizers.AbstractIFrameVisualizer.java
License:Apache License
@Override public Component createComponent(final VisualizerInput vis, VisualizationToggle visToggle) { VaadinSession session = VaadinSession.getCurrent(); if (session.getAttribute(IFrameResourceMap.class) == null) { session.setAttribute(IFrameResourceMap.class, new IFrameResourceMap()); }/*from w w w . ja v a2s. c o m*/ ByteArrayOutputStream outStream = new ByteArrayOutputStream(); writeOutput(vis, outStream); IFrameResource res = new IFrameResource(); res.setData(outStream.toByteArray()); res.setMimeType(getContentType()); UUID uuid = UUID.randomUUID(); session.getAttribute(IFrameResourceMap.class).put(uuid, res); URI base = UI.getCurrent().getPage().getLocation(); AutoHeightIFrame iframe = new AutoHeightIFrame(base.resolve("vis-iframe-res/" + uuid.toString())); return iframe; }
From source file:annis.visualizers.component.pdf.PDFVisualizer.java
License:Apache License
@Override public Panel createComponent(VisualizerInput input, VisualizationToggle visToggle) { PDFViewer pdfViewer = null;//ww w.j ava2 s. c om try { if (VaadinSession.getCurrent().getAttribute(PDFController.class) != null) { VaadinSession session = VaadinSession.getCurrent(); PDFController pdfController = session.getAttribute(PDFController.class); pdfViewer = new PDFViewerImpl(input, visToggle); pdfController.addPDF(input.getId(), pdfViewer); } } catch (Exception ex) { log.error("could not create pdf vis", ex); } return (Panel) pdfViewer; }
From source file:com.foc.vaadin.FocWebApplication.java
License:Apache License
public FocWebSession getFocWebSession() { //MultiTab//from ww w .ja v a2 s . c o m FocWebSession focWebSession = null; if (getHttpSession() != null) { focWebSession = (FocWebSession) getHttpSession().getAttribute(ATT_WEB_SESSION); } else { VaadinSession vaadinSession = getSession(); focWebSession = vaadinSession != null ? (FocWebSession) vaadinSession.getAttribute(ATT_WEB_SESSION) : focSession_ForNonVaadinAndHTTP; } return focWebSession; }
From source file:com.freebox.engeneering.application.system.ApplicationScope.java
License:Apache License
@Override public Object get(String name, ObjectFactory<?> objectFactory) { final VaadinSession current = VaadinSession.getCurrent(); String uiId = getCurrentUiId(); Object bean = current.getAttribute(APPLICATION_SCOPE + uiId + name); if (bean == null) { bean = objectFactory.getObject(); current.setAttribute(APPLICATION_SCOPE + uiId + name, bean); }/*from w ww . jav a2s.c o m*/ return bean; }
From source file:com.freebox.engeneering.application.system.ApplicationScope.java
License:Apache License
@Override public Object remove(String name) { final VaadinSession current = VaadinSession.getCurrent(); String uiId = getCurrentUiId(); Object bean = current.getAttribute(APPLICATION_SCOPE + uiId + name); if (bean != null) { current.setAttribute(APPLICATION_SCOPE + uiId + name, null); this.destructionCallbacks.remove(name); }//from ww w . j ava2 s. co m return bean; }
From source file:com.freebox.engeneering.application.web.common.AbstractController.java
License:Apache License
public String getFreeboxTokenSession() { final VaadinSession current = VaadinSession.getCurrent(); String tokenSession = (String) current.getAttribute(FREEBOX_TOKEN_SESSION); return tokenSession; }
From source file:com.haulmont.cuba.web.App.java
License:Apache License
/** * @return Current App instance. Can be invoked anywhere in application code. * @throws IllegalStateException if no application instance is bound to the current {@link VaadinSession} *//*from w ww.j ava2 s . c o m*/ public static App getInstance() { VaadinSession vSession = VaadinSession.getCurrent(); if (vSession == null) { throw new IllegalStateException("No VaadinSession found"); } if (!vSession.hasLock()) { throw new IllegalStateException("VaadinSession is not owned by the current thread"); } App app = vSession.getAttribute(App.class); if (app == null) { throw new IllegalStateException("No App is bound to the current VaadinSession"); } return app; }
From source file:com.haulmont.cuba.web.App.java
License:Apache License
/** * @return true if an {@link App} instance is currently bound and can be safely obtained by {@link #getInstance()} *//* ww w . ja v a 2s .c o m*/ public static boolean isBound() { VaadinSession vSession = VaadinSession.getCurrent(); return vSession != null && vSession.hasLock() && vSession.getAttribute(App.class) != null; }
From source file:com.haulmont.cuba.web.settings.WebSettingsClient.java
License:Apache License
protected Map<String, Optional<String>> getCache() { VaadinSession session = VaadinSession.getCurrent(); @SuppressWarnings("unchecked") Map<String, Optional<String>> settings = (Map<String, Optional<String>>) session .getAttribute(SettingsClient.NAME); if (settings == null) { settings = new ConcurrentHashMap<>(); session.setAttribute(SettingsClient.NAME, settings); }/*from w ww. j a va 2s . c o m*/ return settings; }