List of usage examples for com.vaadin.server VaadinSession getCurrent
public static VaadinSession getCurrent()
From source file:com.toptal.ui.AuthenticationService.java
License:Open Source License
/** * Login./* w ww .j a v a 2 s .c o m*/ * @param usr User name. * @param pwd Password. */ public void login(final String usr, final String pwd) { final User user = this.dao.findByName(usr); if (user == null || !this.encoder.matches(pwd, user.getPassword())) { AbstractException.throwInvalidLoginPassword(); } VaadinSession.getCurrent().setAttribute(User.class, user); }
From source file:com.toptal.ui.AuthenticationService.java
License:Open Source License
/** * Logout. */ public void logout() { VaadinSession.getCurrent().close(); Page.getCurrent().reload(); }
From source file:com.vaadHL.example.jpa.MainW.java
License:Apache License
public MainW(final IAppContext appContext) { super();// w ww. j ava 2 s . co m Design.read("MainDes.html", this); this.appContext = appContext; em = ENTITY_MANAGER_FACTORY.createEntityManager(); m = appContext.getI18(); // ========== list window launch mode ============= chkReadOnly.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = -5304522804592982630L; @Override public void valueChange(ValueChangeEvent event) { listReadOnly = (boolean) event.getProperty().getValue(); } }); ComponentHelper.populateWIds(cbChoosingMode, m.getArryString("choosingModeS")); cbChoosingMode.setNullSelectionAllowed(false); cbChoosingMode.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 2649106479371080195L; @Override public void valueChange(ValueChangeEvent event) { if (disableListeners) return; Object o = cbChoosingMode.getValue(); if (o == null) return; int val = (int) o; listChoosingMode = (ChoosingMode.values()[val]); if (val == 0) { laCustNCM.setVisible(true); laCustChM.setVisible(false); } else { laCustNCM.setVisible(false); laCustChM.setVisible(true); } } }); cbChoosingMode.setValue(0); String[] lanuageS = { "Default language", "Deutsch", "English", "Polski" }; final Locale[] locale = { Locale.getDefault(), new Locale("de", "DE"), new Locale("en", "US"), new Locale("pl", "PL") }; ComponentHelper.populateWIds(cbLanguage, lanuageS); cbLanguage.setValue(0); cbLanguage.setNullSelectionAllowed(false); cbLanguage.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { int val = (int) cbLanguage.getValue(); setLocale(locale[val]); } }); CustomizerFactory customizerFactory = new CustomizerFactory(); appContext.setWinCustomizerFactory(customizerFactory); // ========== list window customization ============= // no-choose mode final LWCustomizeLM customizeLWNoCh = new LWCustomizeLM(); BeanItem<LWCustomizeLM> customizeLWNoChBI = new BeanItem<LWCustomizeLM>(customizeLWNoCh); chkAutoSaveNCM.setPropertyDataSource(customizeLWNoChBI.getItemProperty("autoSaveState")); chkAutoRestoreNCM.setPropertyDataSource(customizeLWNoChBI.getItemProperty("autoRestoreState")); chkShowMenuNCM.setPropertyDataSource(customizeLWNoChBI.getItemProperty("showMenu")); chkDetails.setPropertyDataSource(customizeLWNoChBI.getItemProperty("detailsFunc")); chkAddRec.setPropertyDataSource(customizeLWNoChBI.getItemProperty("addFunc")); chkDeleteRec.setPropertyDataSource(customizeLWNoChBI.getItemProperty("deleteFunc")); chkEditRec.setPropertyDataSource(customizeLWNoChBI.getItemProperty("editFunc")); chkViewRec.setPropertyDataSource(customizeLWNoChBI.getItemProperty("viewFunc")); ComponentHelper.populateWIdsSkip(cbDoubleClick, m.getArryString("doubleClickModeS"), new Integer[] { 5 }); cbDoubleClick.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 2649106479371080195L; @Override public void valueChange(ValueChangeEvent event) { if (disableListeners) return; customizeLWNoCh.setDoubleClickAc(((DoubleClickAc.values()[((int) cbDoubleClick.getValue())]))); } }); cbDoubleClick.setNullSelectionAllowed(false); cbDoubleClick.setValue(0); // choose mode final LWCustomizeLM customizeLWChMo = new LWCustomizeLM(); BeanItem<LWCustomizeLM> customizeLWBIChMo = new BeanItem<LWCustomizeLM>(customizeLWChMo); chkAutoSaveChM.setPropertyDataSource(customizeLWBIChMo.getItemProperty("autoSaveState")); chkAutoRestoreChM.setPropertyDataSource(customizeLWBIChMo.getItemProperty("autoRestoreState")); chkShowMenuChM.setPropertyDataSource(customizeLWBIChMo.getItemProperty("showMenu")); chkDetailsChM.setPropertyDataSource(customizeLWBIChMo.getItemProperty("detailsFunc")); chkAddRecChM.setPropertyDataSource(customizeLWBIChMo.getItemProperty("addFunc")); chkDeleteRecChM.setPropertyDataSource(customizeLWBIChMo.getItemProperty("deleteFunc")); chkEditRecChM.setPropertyDataSource(customizeLWBIChMo.getItemProperty("editFunc")); chkViewRecChM.setPropertyDataSource(customizeLWBIChMo.getItemProperty("viewFunc")); cbDoubleClickChM.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = -5472665008056617982L; @Override public void valueChange(ValueChangeEvent event) { if (disableListeners) return; customizeLWChMo.setDoubleClickAc((DoubleClickAc.values()[((int) cbDoubleClickChM.getValue())])); } }); cbDoubleClickChM.setNullSelectionAllowed(false); final LWCustomize customizeLW = new LWCustomize(customizeLWChMo, customizeLWNoCh); customizerFactory.put("L001", customizeLW); // ========== form window customization ============= customizeFWin = new CustomizeFWin(); final BeanItem<CustomizeFWin> customizeFWinBI = new BeanItem<CustomizeFWin>(customizeFWin); chkAutoSave.setPropertyDataSource(customizeFWinBI.getItemProperty("autoSaveState")); chkAutoRestore.setPropertyDataSource(customizeFWinBI.getItemProperty("autoRestoreState")); chkShowMenu.setPropertyDataSource(customizeFWinBI.getItemProperty("showMenu")); chkAskCreate.setPropertyDataSource(customizeFWinBI.getItemProperty("askCreate")); chkAskDelete.setPropertyDataSource(customizeFWinBI.getItemProperty("askDelete")); chkAskDiscard.setPropertyDataSource(customizeFWinBI.getItemProperty("askDiscard")); chkAskSave.setPropertyDataSource(customizeFWinBI.getItemProperty("askSave")); chkPrevNext.setPropertyDataSource(customizeFWinBI.getItemProperty("prevNextFunc")); ComponentHelper.populateWIds(cbAutoSaveDiscard, m.getArryString("autoSaveDiscard")); cbAutoSaveDiscard.setNullSelectionAllowed(false); cbAutoSaveDiscard.setValue(0); cbAutoSaveDiscard.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = -5304522804592982630L; @Override public void valueChange(ValueChangeEvent event) { if (disableListeners) return; customizeFWin.setAutoSaveDiscard(AutoSaveDiscard.values()[((int) cbAutoSaveDiscard.getValue())]); } }); ComponentHelper.populateWIds(cbClosingMethod, m.getArryString("closinMethod")); cbClosingMethod.setValue(0); cbClosingMethod.setNullSelectionAllowed(false); cbClosingMethod.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = -8412527417505085156L; @Override public void valueChange(ValueChangeEvent event) { if (disableListeners) return; customizeFWin.setShowOKCancel(((int) cbClosingMethod.getValue()) == 0 ? true : false); } }); customizerFactory.put("M001", customizeFWin); // ========== mock permissions ============= permissions = new TestPermCheckerB(appContext); appContext.setWinPermFactory(permissions); permissions.put("L001", MyActionsIds.MOCK_ID, false); BeanContainer<String, PermItem> permContainer = new BeanContainer<String, PermItem>(PermItem.class); permContainer.setBeanIdResolver(new BeanIdResolver<String, TestPermCheckerB.PermItem>() { private static final long serialVersionUID = -2858748109465649052L; @Override public String getIdForBean(PermItem bean) { return bean.getWinId() + Integer.toString(bean.getPermId()); } }); permContainer.addAll(permissions.getContainer().values()); tPerm.setContainerDataSource(permContainer); tPerm.setPageLength(15); // immediately tPerm.setEditable(true); tPerm.setSelectable(false); tPerm.setColumnReorderingAllowed(true); tPerm.setColumnCollapsingAllowed(true); /* * tPerm.addGeneratedColumn("permission", new ColumnGenerator() { * private static final long serialVersionUID = 8174249667866723293L; * * @Override public Object generateCell(Table source, Object itemId, * Object columnId) { Item itm = source.getItem(itemId); int acId = * (int) itm.getItemProperty("permId").getValue(); return * MyActionsIds.getName(appContext.getI18(), acId); * * } }); */ /* * tPerm.addGeneratedColumn("winIdShow", new ColumnGenerator() { private * static final long serialVersionUID = 7789570007862946545L; * * @Override public Object generateCell(Table source, Object itemId, * Object columnId) { Item itm = source.getItem(itemId); String v = * (String) itm.getItemProperty("winId").getValue(); * * return v; * * } }); */ tPerm.setTableFieldFactory(new TableFieldFactory() { private static final long serialVersionUID = 7459048926545235356L; public Field<?> createField(Container container, Object itemId, Object propertyId, Component uiContext) { Field<?> f = DefaultFieldFactory.get().createField(container, itemId, propertyId, uiContext); if ("enabled".equals(propertyId)) f.setCaption(""); else if ("permission".equals(propertyId)) f.setWidth("170px"); else if ("winIdShow".equals(propertyId)) f.setWidth("70px"); return f; } }); tPerm.setVisibleColumns("winIdShow", "permission", "enabled"); tPerm.setColumnWidth("winIdShow", 80); tPerm.setColumnWidth("permission", -1); tPerm.setColumnWidth("enabled", 60); // ==========List selection results ============= // ========== run the test ============================ btRunTest.addClickListener(new ClickListener() { private static final long serialVersionUID = -5384467222048646753L; @Override public void buttonClick(ClickEvent event) { ListTst sub = new ListTst(listChoosingMode, listReadOnly, em, appContext); sub.addCloseListener(new CloseListener() { /** * */ private static final long serialVersionUID = -5625061490326702522L; @Override public void windowClose(CloseEvent e) { CloseCause clcs = ((BaseListWindow) e.getSource()).getCloseCause(); if (clcs == null) return; Object items = clcs.addInfo; switch (clcs.cause) { case CHOOSE: StringBuffer sb = new StringBuffer(); sb.append(m.getStringNE("ChoosenS")); if (items == null) sb.append(m.getStringNE("nothing")); else { Set<Object> se; if (items instanceof Set<?>) se = (Set<Object>) items; else { se = new HashSet<Object>(); se.add(items); } for (Object it : se) { ItemHelper item = new ItemHelper((Item) it); sb.append('\n'); sb.append(item.getString("firstName")); sb.append(" "); sb.append(item.getString("lastName")); sb.append(" "); sb.append(item.getString("yearOfBirth")); } } taChoosen.setReadOnly(false); taChoosen.setValue(sb.toString()); taChoosen.setReadOnly(true); break; case CANCEL: taChoosen.setReadOnly(false); taChoosen.setValue(m.getStringNE("canceledN")); taChoosen.setReadOnly(true); break; case NOCHOOSE: taChoosen.setReadOnly(false); taChoosen.setValue(m.getStringNE("clNoSel")); taChoosen.setReadOnly(true); default: break; } } }); UI.getCurrent().addWindow(sub); } }); // exit btExit.addClickListener(new ClickListener() { private static final long serialVersionUID = 3384397496569551149L; @Override public void buttonClick(ClickEvent event) { for (final UI ui : VaadinSession.getCurrent().getUIs()) ui.access(new Runnable() { @Override public void run() { ui.getPage().setLocation("http://vaadhl.mromaniuk.me"); } }); getSession().close(); } }); // versions info lbDemoVer.setValue(Version.getFullVersion()); lbHLVer.setValue(com.vaadHL.Version.getFullVersion()); lbVaadVer.setValue(com.vaadin.shared.Version.getFullVersion()); }
From source file:com.wintindustries.pfserver.interfaces.view.dashboard.DashboardMenu.java
private PFUser getCurrentUser() { return (PFUser) VaadinSession.getCurrent().getAttribute(PFUser.class.getName()); }
From source file:com.ws.provider.CxfWsClientInInterceptor.java
@Override public void handleMessage(Message message) throws Fault { // Logger log = getMessageLogger(message); // if ((this.writer != null) || (log.isLoggable(Level.INFO))) { // logging(log, message); // }//from www . j a va2 s.c o m try { String id = (String) message.getExchange().get(LoggingMessage.ID_KEY); if (id == null) { id = LoggingMessage.nextId(); message.getExchange().put(LoggingMessage.ID_KEY, id); } String method = CxfWsClientOutInterceptor.mapMethodWS.get(id); String startLog = CxfWsClientOutInterceptor.mapLogWS.get(id); Date startDate = CxfWsClientOutInterceptor.mapDateWS.get(id); Date endDate = new Date(); // System.out.println(startDate); // System.out.println(endDate); // System.out.println(endDate.getTime() - startDate.getTime()); Long responeTime = (endDate.getTime() - startDate.getTime()) / 1000; // UserTokenGNOC user = (UserTokenGNOC) VaadinSession.getCurrent().getSession().getAttribute(Constants.vsaUserTokenAttribute); String endLog = "end_action|GNOC" + "|" + DateTimeUtils.convertDateToString(new Date(), "dd/MM/yyyy HH:mm:ss") // + "|" + user.getUserName() + "|" + UI.getCurrent().getPage().getWebBrowser().getAddress() + "|" + UI.getCurrent().getPage().getLocation().getHost() + ":" + UI.getCurrent().getPage().getLocation().getPort() + "|" + method + ".do" + "|" + "" + "|" + method + "|" + responeTime + "|[RequestId=" + VaadinSession.getCurrent().getCsrfToken() + "_" + id // + "][Unit=" + user.getUnitCode() + "][VTS-KPIID=null]"; logger.info(startLog.replace("{responeTime}", responeTime.toString())); logger.info(endLog); CxfWsClientOutInterceptor.mapLogWS.remove(id); CxfWsClientOutInterceptor.mapDateWS.remove(id); CxfWsClientOutInterceptor.mapMethodWS.remove(id); } catch (Exception e) { // e.printStackTrace(); } }
From source file:com.ws.provider.CxfWsClientOutInterceptor.java
@Override public void handleMessage(Message message) { try {/* w w w. j a v a 2 s .co m*/ // UserTokenGNOC user = (UserTokenGNOC) VaadinSession.getCurrent().getSession().getAttribute(Constants.vsaUserTokenAttribute); String id = (String) message.getExchange().get(LoggingMessage.ID_KEY); if (id == null) { id = LoggingMessage.nextId(); message.getExchange().put(LoggingMessage.ID_KEY, id); System.out.println("id: " + id); } try { List<String> listRequest = new ArrayList<>(); listRequest.add(VaadinSession.getCurrent().getCsrfToken() + "_" + id); Map<String, List<String>> protocolHeader = (TreeMap) message.get(Message.PROTOCOL_HEADERS); if (protocolHeader == null) { protocolHeader = new TreeMap<>(); } protocolHeader.put("RequestId", listRequest); message.put(Message.PROTOCOL_HEADERS, protocolHeader); } catch (Exception e) { // ex.printStackTrace(); } String log = "start_action|GNOC" + "|" + DateTimeUtils.convertDateToString(new Date(), "dd/MM/yyyy HH:mm:ss") // + "|" + user.getUserName() + "|" + UI.getCurrent().getPage().getWebBrowser().getAddress() + "|" + UI.getCurrent().getPage().getLocation().getHost() + ":" + UI.getCurrent().getPage().getLocation().getPort() + "|" + getMethod(message) + ".do" + "|" + "" + "|" + getMethod(message) + "|{responeTime}|[RequestId=" + VaadinSession.getCurrent().getCsrfToken() + "_" + id // + "][Unit=" + user.getUnitCode() + "][VTS-KPIID=null]"; mapDateWS.put(id, new Date()); mapMethodWS.put(id, getMethod(message)); mapLogWS.put(id, log); } catch (Exception ex) { // ex.printStackTrace(); } }
From source file:cz.lzaruba.icu4j.spring.vaadin.VaadinICUMessageSource.java
License:Apache License
protected Locale getCurrentLocale() { return VaadinSession.getCurrent().getLocale(); }
From source file:de.gedoplan.webclients.vaadin.base.BaseView.java
@Override public void enter(ViewChangeListener.ViewChangeEvent event) { try {//from w ww . j ava2 s .co m myenter(event); } catch (Exception e) { VaadinSession.getCurrent().getErrorHandler().error(new com.vaadin.server.ErrorEvent(e)); } }
From source file:de.gedoplan.webclients.vaadin.VaadinDemoUi.java
public MenuBar createMenu() { User user = userProvider.get();/*from w w w . j a va 2 s .co m*/ MenuBar mainMenu = new MenuBar(); mainMenu.setWidth(100, Unit.PERCENTAGE); mainMenu.setStyleName("main"); mainMenu.addItem("", new ThemeResource("images/vaadin-logo.png"), e -> navigator.navigateTo(Konstanten.VAADIN_VIEW_INDEX)).setStyleName("logo"); if (user.isInRole(User.UserRole.ADMIN)) { mainMenu.addItem(Messages.menu_customer.value(), e -> navigator.navigateTo(Konstanten.VAADIN_VIEW_CUSTOMERS)); } mainMenu.addItem(Messages.menu_orders.value(), e -> navigator.navigateTo(Konstanten.VAADIN_VIEW_ORDERS)); if (user.isInRole(User.UserRole.CUSTOMER)) { mainMenu.addItem(Messages.menu_customerdetails.value(), e -> navigator .navigateTo(Konstanten.VAADIN_VIEW_CUSTOMER_DETAILS + "/" + user.getCustomerID())); } MenuBar.MenuItem userMenu = mainMenu.addItem(user.getLogin(), null); userMenu.setStyleName("align-right"); userMenu.addItem(Messages.logout.value(), e -> { try { JaasAccessControl.logout(); VaadinSession.getCurrent().close(); Page.getCurrent().setLocation(Konstanten.VAADIN_LOGIN_PATH); } catch (ServletException ex) { Logger.getLogger(VaadinDemoUi.class.getName()).log(Level.SEVERE, null, ex); } }); return mainMenu; }
From source file:de.kaiserpfalzEdv.vaadin.menu.impl.MenuImpl.java
License:Apache License
@Inject public MenuImpl(final Authenticator accessControl, final EventBus bus, final I18NHandler i18n, final List<View> allViews) { this.accessControl = accessControl; this.bus = bus; this.i18n = i18n; this.allViews = allViews; setPrimaryStyleName(ValoTheme.MENU_ROOT); menuPart = new CssLayout(); menuPart.addStyleName(ValoTheme.MENU_PART); // header of the menu final HorizontalLayout top = new HorizontalLayout(); top.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); top.addStyleName(ValoTheme.MENU_TITLE); top.setSpacing(true);//from ww w . ja v a 2s .co m Label title = new Label(translate("application.name")); title.addStyleName(ValoTheme.LABEL_H3); title.setSizeUndefined(); Image image = new Image(null, new ThemeResource("img/table-logo.png")); image.setStyleName("logo"); top.addComponent(image); top.addComponent(title); menuPart.addComponent(top); // logout menu item MenuBar logoutMenu = new MenuBar(); logoutMenu.addItem(translate("button.logout.caption"), FontAwesome.valueOf(translate("button.logout.icon")), selectedItem -> { VaadinSession.getCurrent().getSession().invalidate(); Page.getCurrent().reload(); }); logoutMenu.addStyleName("user-menu"); menuPart.addComponent(logoutMenu); // button for toggling the visibility of the menu when on a small screen final Button showMenu = new Button(translate("application.name"), new ClickListener() { @Override public void buttonClick(final ClickEvent event) { if (menuPart.getStyleName().contains(VALO_MENU_VISIBLE)) { menuPart.removeStyleName(VALO_MENU_VISIBLE); } else { menuPart.addStyleName(VALO_MENU_VISIBLE); } } }); showMenu.addStyleName(ValoTheme.BUTTON_PRIMARY); showMenu.addStyleName(ValoTheme.BUTTON_SMALL); showMenu.addStyleName(VALO_MENU_TOGGLE); showMenu.setIcon(FontAwesome.NAVICON); menuPart.addComponent(showMenu); // container for the navigation buttons, which are added by addView() menuItemsLayout = new CssLayout(); menuItemsLayout.setPrimaryStyleName(VALO_MENUITEMS); menuPart.addComponent(menuItemsLayout); addComponent(menuPart); }