List of usage examples for com.vaadin.server VaadinSession getCurrent
public static VaadinSession getCurrent()
From source file:org.ripla.web.RiplaApplication.java
License:Open Source License
private void setSessionLocale(final Locale inLocale) { try {//from w w w . j a v a 2 s. co m VaadinSession.getCurrent().getLockInstance().lock(); VaadinSession.getCurrent().setLocale(inLocale); } finally { VaadinSession.getCurrent().getLockInstance().unlock(); } }
From source file:org.ripla.web.RiplaApplication.java
License:Open Source License
private void setSessionUser(final User inUser) { try {//from ww w. j a v a 2 s . c om VaadinSession.getCurrent().getLockInstance().lock(); VaadinSession.getCurrent().setAttribute(User.class, inUser); } finally { VaadinSession.getCurrent().getLockInstance().unlock(); } }
From source file:org.ripla.web.RiplaApplication.java
License:Open Source License
private RiplaRequestHandler setRequestHandler() { final RiplaRequestHandler out = new RiplaRequestHandler(); try {//from w ww . j a v a2 s.c o m VaadinSession.getCurrent().getLockInstance().lock(); VaadinSession.getCurrent().addRequestHandler(out); } finally { VaadinSession.getCurrent().getLockInstance().unlock(); } return out; }
From source file:org.ripla.web.RiplaApplication.java
License:Open Source License
/** * We want to save the locale to the preferences store. * /*from w w w . j a v a 2s . co m*/ * @see com.vaadin.Application#setLocale(java.util.Locale) */ @Override public void setLocale(final Locale inLocale) { if (initialized) { User lUser = null; try { VaadinSession.getCurrent().getLockInstance().lock(); lUser = VaadinSession.getCurrent().getAttribute(User.class); } finally { VaadinSession.getCurrent().getLockInstance().unlock(); } if (lUser == null) { preferences.setLocale(inLocale); } else { preferences.setLocale(inLocale, lUser); } } super.setLocale(inLocale); }
From source file:org.ripla.web.util.AbstractWebMessages.java
License:Open Source License
@Override protected Locale getLocaleChecked() { try {//from ww w .j a v a 2 s. c o m VaadinSession.getCurrent().getLockInstance().lock(); return VaadinSession.getCurrent().getLocale(); } finally { VaadinSession.getCurrent().getLockInstance().unlock(); } }
From source file:org.ripla.web.util.ControllerStack.java
License:Open Source License
/** * Convenience method to return the user's controller stack. * /*from w w w . j a v a 2s .com*/ * @return {@link ControllerStack} the user's unique controller stack */ public static ControllerStack getControllerStack() { try { VaadinSession.getCurrent().getLockInstance().lock(); ControllerStack out = VaadinSession.getCurrent().getAttribute(ControllerStack.class); if (out == null) { out = new ControllerStack(); VaadinSession.getCurrent().setAttribute(ControllerStack.class, out); } return out; } finally { VaadinSession.getCurrent().getLockInstance().unlock(); } }
From source file:org.ripla.web.util.LanguageSelect.java
License:Open Source License
/** * LanguageSelect constructor.//from ww w. j ava 2s. c om * * @param inPreferences * {@link PreferencesHelper} * @param inConfigManager * {@link ConfigManager} * @param inUser * {@link User} */ public LanguageSelect(final PreferencesHelper inPreferences, final ConfigManager inConfigManager, final User inUser) { super(); // initialize language form prefs (1) or config admin (2) // final String lActiveLanguage = inPreferences.getLocale(inUser, // new Locale(inConfigManager.getLanguage())).getLanguage(); setStyleName("ripla-language-select"); //$NON-NLS-1$ setSizeUndefined(); layout = new HorizontalLayout(); setCompositionRoot(layout); layout.setHeight(22, Unit.PIXELS); layout.setSpacing(true); final Label lLabel = new Label(Activator.getMessages().getMessage("toolbar.label.language"), //$NON-NLS-1$ ContentMode.HTML); lLabel.setStyleName("ripla-toolbar-label"); //$NON-NLS-1$ lLabel.setSizeUndefined(); layout.addComponent(lLabel); layout.setComponentAlignment(lLabel, Alignment.MIDDLE_LEFT); layout.setExpandRatio(lLabel, 1); select = createSelect(); select.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(final ValueChangeEvent inEvent) { final Locale lNew = ((LocaleAdapter) select.getValue()).getLocale(); Locale lOld = null; try { VaadinSession.getCurrent().getLockInstance().lock(); lOld = VaadinSession.getCurrent().getLocale(); } finally { VaadinSession.getCurrent().getLockInstance().unlock(); } if (lOld != null && !lOld.equals(lNew)) { try { VaadinSession.getCurrent().getLockInstance().lock(); VaadinSession.getCurrent().setLocale(lNew); } finally { VaadinSession.getCurrent().getLockInstance().unlock(); } if (listener != null) { listener.processAction(new IToolbarAction() { @Override public void run() { LOG.trace("Setting language preference to {}.", lNew.getLanguage()); VaadinSession.getCurrent().getAttribute(IRiplaEventDispatcher.class).dispatch( org.ripla.interfaces.IRiplaEventDispatcher.Event.REFRESH, new HashMap<String, Object>()); } }); } } } }); layout.addComponent(select); }
From source file:org.sensorhub.ui.AdminUI.java
License:Mozilla Public License
@Override protected void init(VaadinRequest request) { String configClass = null;//from w ww .j av a 2 s.c om moduleConfigLists.clear(); // retrieve module config try { Properties initParams = request.getService().getDeploymentConfiguration().getInitParameters(); String moduleID = initParams.getProperty(AdminUIModule.SERVLET_PARAM_MODULE_ID); uiConfig = (AdminUIConfig) SensorHub.getInstance().getModuleRegistry().getModuleById(moduleID) .getConfiguration(); } catch (Exception e) { throw new RuntimeException("Cannot get UI module configuration", e); } try { // load default form builders customForms.put(HttpServerConfig.class.getCanonicalName(), HttpServerConfigForm.class); customForms.put(StreamStorageConfig.class.getCanonicalName(), GenericStorageConfigForm.class); customForms.put(CommConfig.class.getCanonicalName(), CommConfigForm.class); customForms.put(SOSConfigForm.SOS_PACKAGE + "SOSServiceConfig", SOSConfigForm.class); customForms.put(SOSConfigForm.SOS_PACKAGE + "SOSProviderConfig", SOSConfigForm.class); // load custom form builders defined in config for (CustomUIConfig customForm : uiConfig.customForms) { configClass = customForm.configClass; Class<?> clazz = Class.forName(customForm.uiClass); customForms.put(configClass, (Class<IModuleConfigForm>) clazz); log.debug("Loaded custom form for " + configClass); } } catch (Exception e) { log.error("Error while instantiating form builder for config class " + configClass, e); } try { // load default panel builders customPanels.put(SensorConfig.class.getCanonicalName(), SensorAdminPanel.class); customPanels.put(StorageConfig.class.getCanonicalName(), StorageAdminPanel.class); // load custom panel builders defined in config for (CustomUIConfig customPanel : uiConfig.customPanels) { configClass = customPanel.configClass; Class<?> clazz = Class.forName(customPanel.uiClass); customPanels.put(configClass, (Class<IModuleAdminPanel<?>>) clazz); log.debug("Loaded custom panel for " + configClass); } } catch (Exception e) { log.error("Error while instantiating panel builder for config class " + configClass, e); } // register new field converter for interger numbers @SuppressWarnings("serial") ConverterFactory converterFactory = new DefaultConverterFactory() { @Override protected <PRESENTATION, MODEL> Converter<PRESENTATION, MODEL> findConverter( Class<PRESENTATION> presentationType, Class<MODEL> modelType) { // Handle String <-> Integer/Short/Long if (presentationType == String.class && (modelType == Long.class || modelType == Integer.class || modelType == Short.class)) { return (Converter<PRESENTATION, MODEL>) new StringToIntegerConverter() { @Override protected NumberFormat getFormat(Locale locale) { NumberFormat format = super.getFormat(Locale.US); format.setGroupingUsed(false); return format; } }; } // Let default factory handle the rest return super.findConverter(presentationType, modelType); } }; VaadinSession.getCurrent().setConverterFactory(converterFactory); // init main panels HorizontalSplitPanel splitPanel = new HorizontalSplitPanel(); splitPanel.setMinSplitPosition(300.0f, Unit.PIXELS); splitPanel.setMaxSplitPosition(30.0f, Unit.PERCENTAGE); splitPanel.setSplitPosition(350.0f, Unit.PIXELS); setContent(splitPanel); // build left pane VerticalLayout leftPane = new VerticalLayout(); leftPane.setSizeFull(); // header image and title Component header = buildHeader(); leftPane.addComponent(header); leftPane.setExpandRatio(header, 0); // toolbar Component toolbar = buildToolbar(); leftPane.addComponent(toolbar); leftPane.setExpandRatio(toolbar, 0); // accordion with several sections Accordion stack = new Accordion(); stack.setSizeFull(); VerticalLayout layout; Tab tab; layout = new VerticalLayout(); tab = stack.addTab(layout, "Sensors"); tab.setIcon(ACC_TAB_ICON); buildModuleList(layout, SensorConfig.class); layout = new VerticalLayout(); tab = stack.addTab(layout, "Storage"); tab.setIcon(ACC_TAB_ICON); buildModuleList(layout, StorageConfig.class); layout = new VerticalLayout(); tab = stack.addTab(layout, "Processing"); tab.setIcon(ACC_TAB_ICON); buildModuleList(layout, ProcessConfig.class); layout = new VerticalLayout(); tab = stack.addTab(layout, "Services"); tab.setIcon(ACC_TAB_ICON); buildModuleList(layout, ServiceConfig.class); layout = new VerticalLayout(); tab = stack.addTab(layout, "Clients"); tab.setIcon(ACC_TAB_ICON); buildModuleList(layout, ClientConfig.class); layout = new VerticalLayout(); tab = stack.addTab(layout, "Network"); tab.setIcon(ACC_TAB_ICON); buildNetworkConfig(layout); leftPane.addComponent(stack); leftPane.setExpandRatio(stack, 1); splitPanel.addComponent(leftPane); // init config area configArea = new VerticalLayout(); configArea.setMargin(true); splitPanel.addComponent(configArea); }
From source file:org.vaadin.spring.context.VaadinSessionFactory.java
License:Apache License
@Override public VaadinSession getObject() throws Exception { final VaadinSession session = VaadinSession.getCurrent(); if (session == null) { throw new IllegalStateException("No VaadinSession bound to current thread"); }/*w ww . j ava 2 s .c o m*/ return session; }
From source file:org.vaadin.spring.security.internal.VaadinManagedSecurity.java
License:Apache License
@Override public void logout() { VaadinSession.getCurrent().close(); Page.getCurrent().reload(); }