List of usage examples for com.vaadin.server VaadinSession getCurrent
public static VaadinSession getCurrent()
From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java
/** * If no value present, choose a empty string * * @param title//from ww w . j a v a2s . c o m * @param link * @param description * @param language * @param imageUrl * @return */ private Component getSecondStage(Source s) { Label header = new Label(Language.get(Word.SOURCE)); header.addStyleName(ValoTheme.LABEL_H1); FormLayout forms = new FormLayout(); forms.setSizeFull(); TextField textFieldId = new TextField(Language.get(Word.ID)); textFieldId.setEnabled(false); textFieldId.setValue(s.getId()); textFieldId.setWidth("750px"); TextField textFieldName = new TextField(Language.get(Word.NAME)); textFieldName.setValue(s.getName()); textFieldName.setWidth("750px"); TextField textFieldDescription = new TextField(Language.get(Word.DESCRIPTION)); textFieldDescription.setValue(s.getDescription()); textFieldDescription.setWidth("750px"); TextField textFieldURL = new TextField(Language.get(Word.URL)); if (s.getUrl() != null) { textFieldURL.setValue(s.getUrl().toExternalForm()); } textFieldURL.setWidth("750px"); ComboBox<Category> comboBoxCategories = new ComboBox<>(Language.get(Word.CATEGORY), EnumSet.allOf(Category.class)); comboBoxCategories.setItemCaptionGenerator(c -> c.getName()); comboBoxCategories.setItemIconGenerator(c -> c.getIcon()); comboBoxCategories.setEmptySelectionAllowed(false); comboBoxCategories.setTextInputAllowed(false); comboBoxCategories.setWidth("375px"); if (s.getCategory() != null) { comboBoxCategories.setSelectedItem(s.getCategory()); } ComboBox<Locale> comboBoxLanguage = new ComboBox<>(Language.get(Word.LANGUAGE), getLanguages()); comboBoxLanguage.setItemCaptionGenerator(l -> l.getDisplayLanguage(VaadinSession.getCurrent().getLocale())); comboBoxLanguage.setEmptySelectionAllowed(false); comboBoxLanguage.setWidth("375px"); if (!s.getLanguage().isEmpty()) { Locale selected = new Locale(s.getLanguage()); comboBoxLanguage.setSelectedItem(selected); } Locale loc = VaadinSession.getCurrent().getLocale(); Map<String, Locale> countries = getCountries(); List<Locale> locales = countries.values().parallelStream() .sorted((l1, l2) -> l1.getDisplayCountry(loc).compareTo(l2.getDisplayCountry(loc))) .collect(Collectors.toList()); ComboBox<Locale> comboBoxCountry = new ComboBox<>(Language.get(Word.COUNTRY), locales); comboBoxCountry.setItemCaptionGenerator(l -> l.getDisplayCountry(VaadinSession.getCurrent().getLocale())); comboBoxCountry.setItemIconGenerator(l -> FamFamFlags.fromLocale(l)); comboBoxCountry.setEmptySelectionAllowed(false); comboBoxCountry.setWidth("375px"); if (!s.getCountry().isEmpty()) { comboBoxCountry.setSelectedItem(countries.getOrDefault(s.getCountry(), Locale.ROOT)); } Image imageLogo = new Image(Language.get(Word.LOGO)); TextField textFieldLogo = new TextField(Language.get(Word.LOGO_URL)); if (s.getLogo() != null) { textFieldLogo.setValue(s.getLogo().toExternalForm()); imageLogo.setSource(new ExternalResource(s.getLogo())); } textFieldLogo.addValueChangeListener(ce -> imageLogo.setSource(new ExternalResource(ce.getValue()))); textFieldLogo.setWidth("750px"); if (imageLogo.getHeight() > 125) { imageLogo.setHeight("125px"); } forms.addComponents(textFieldId, textFieldName, textFieldDescription, textFieldURL, comboBoxCategories, comboBoxLanguage, comboBoxCountry, textFieldLogo, imageLogo); Runnable cancel = () -> close(); Runnable next = () -> validateSecondStage(s, textFieldId.getValue(), textFieldName.getValue(), textFieldURL.getValue(), textFieldDescription.getValue(), comboBoxCategories.getSelectedItem().orElse(null), comboBoxLanguage.getSelectedItem().orElse(Locale.ROOT), comboBoxCountry.getSelectedItem().orElse(Locale.ROOT), textFieldLogo.getValue()); VerticalLayout windowLayout = new VerticalLayout(); windowLayout.addComponents(header, forms, getFooter(cancel, next)); windowLayout.setComponentAlignment(header, Alignment.MIDDLE_CENTER); return windowLayout; }
From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java
public static List<Locale> getLanguages() { return Arrays.asList(Locale.getISOLanguages()).parallelStream().map(s -> new Locale(s)) .sorted((l1, l2) -> l1.getDisplayLanguage(VaadinSession.getCurrent().getLocale()) .compareTo(l2.getDisplayLanguage(VaadinSession.getCurrent().getLocale()))) .collect(Collectors.toList()); }
From source file:dhbw.clippinggorilla.userinterface.windows.PreferencesWindow.java
private Component buildClippingsTab(User user) { HorizontalLayout root = new HorizontalLayout(); root.setCaption(Language.get(Word.CLIPPINGS)); root.setIcon(VaadinIcons.NEWSPAPER); root.setWidth("100%"); root.setSpacing(true);//from ww w . j av a 2s . co m root.setMargin(true); FormLayout formLayoutClippingDetails = new FormLayout(); formLayoutClippingDetails.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); root.addComponent(formLayoutClippingDetails); CheckBox checkBoxReceiveEmails = new CheckBox(); checkBoxReceiveEmails.setValue(UserUtils.getEmailNewsletter(user)); checkBoxReceiveEmails.addValueChangeListener(v -> UserUtils.setEmailNewsletter(user, v.getValue())); HorizontalLayout layoutCheckBoxReceiveEmails = new HorizontalLayout(checkBoxReceiveEmails); layoutCheckBoxReceiveEmails.setCaption(Language.get(Word.EMAIL_SUBSCRIPTION)); layoutCheckBoxReceiveEmails.setMargin(false); layoutCheckBoxReceiveEmails.setSpacing(false); HorizontalLayout layoutAddNewClippingTime = new HorizontalLayout(); layoutAddNewClippingTime.setMargin(false); layoutAddNewClippingTime.setCaption(Language.get(Word.ADD_CLIPPING_TIME)); layoutAddNewClippingTime.setWidth("100%"); InlineDateTimeField dateFieldNewClippingTime = new InlineDateTimeField(); LocalDateTime value = LocalDateTime.now(ZoneId.of("Europe/Berlin")); dateFieldNewClippingTime.setValue(value); dateFieldNewClippingTime.setLocale(VaadinSession.getCurrent().getLocale()); dateFieldNewClippingTime.setResolution(DateTimeResolution.MINUTE); dateFieldNewClippingTime.addStyleName("time-only"); Button buttonAddClippingTime = new Button(); buttonAddClippingTime.setIcon(VaadinIcons.PLUS); buttonAddClippingTime.addStyleName(ValoTheme.BUTTON_PRIMARY); buttonAddClippingTime.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); buttonAddClippingTime.addClickListener(e -> { LocalTime generalTime = dateFieldNewClippingTime.getValue().toLocalTime(); layoutClippingTimes.addComponent(getTimeRow(user, generalTime)); UserUtils.addClippingSendTime(user, generalTime); }); layoutAddNewClippingTime.addComponents(dateFieldNewClippingTime, buttonAddClippingTime); layoutAddNewClippingTime.setComponentAlignment(dateFieldNewClippingTime, Alignment.MIDDLE_LEFT); layoutAddNewClippingTime.setComponentAlignment(buttonAddClippingTime, Alignment.MIDDLE_CENTER); layoutAddNewClippingTime.setExpandRatio(dateFieldNewClippingTime, 5); layoutClippingTimes = new VerticalLayout(); layoutClippingTimes.setMargin(new MarginInfo(true, false, false, true)); layoutClippingTimes.setCaption(Language.get(Word.CLIPPING_TIMES)); layoutClippingTimes.setWidth("100%"); layoutClippingTimes.addStyleName("times"); Set<LocalTime> userTimes = user.getClippingTime(); userTimes.forEach(t -> layoutClippingTimes.addComponent(getTimeRow(user, t))); formLayoutClippingDetails.addComponents(layoutCheckBoxReceiveEmails, layoutAddNewClippingTime, layoutClippingTimes); return root; }
From source file:dhbw.clippinggorilla.utilities.language.Language.java
/** * Returns a word in the language og the user User * {@link #set(dhbw.clippinggorilla.languages.Word, com.vaadin.ui.Component)} * to set a specific Components Text<br> * It is deprecated because changing the Language doesnt automatically * change/*from ww w.j ava 2s.com*/ * * @param word the word to be returned * @return The requested word in the user language */ public static final String get(Word word) { if (VaadinSession.getCurrent() == null || VaadinSession.getCurrent().getLocale() == null) { return Language.ENGLISH.words.getOrDefault(word, word.name()); } return LANGUAGES.getOrDefault(VaadinSession.getCurrent().getLocale(), Language.ENGLISH).words .getOrDefault(word, word.name()); }
From source file:dhbw.clippinggorilla.utilities.language.Language.java
/** * Automatically sets the value of the Vaadin Component, this is useful, if * the user changes the language, all components are changed * * @param word the word to be returned/*from ww w . ja v a 2 s . c o m*/ * @param component */ public static final void set(Word word, Component component) { Map<Component, Word> components = COMPONENTS.getOrDefault(VaadinSession.getCurrent(), new HashMap<>()); components.put(component, word); COMPONENTS.put(VaadinSession.getCurrent(), components); changeComponentTo(LANGUAGES.getOrDefault(VaadinSession.getCurrent().getLocale(), ENGLISH), component, word); }
From source file:dhbw.clippinggorilla.utilities.language.Language.java
/** * Sets a custom text to a custom object<br><br> * * If the User changes the Language:<br><br> * 1. The word is being translated<br> * 2. The translated word enters the Stringmodifier<br> * 3. The potentially modified word enters the ValueSetter which sets the * value<br><br>//from w ww . jav a2 s .c om * * The modifier can be null if you dont want to change the word.<br><br> * * Example:<br> * <pre> * {@code * Textfield field = ... ; * Language.setCustom(Word.TODAY_IS, s -> s + LocalDate.now().toString(), v -> field.setPlaceholder(v)); * } * </pre> In this Example you have a Textfield.<br> * You want to set a specific Text as Placeholder (If you dont want to * modify the word AND just want to use the Standard field.setValue(...) you * can use the {@link #set(Word, Component)} for that).<br> * You do this by modifying the string s by appending the local date as * example.<br> * In the end you set the modified string as placeholder for your textfield * as example. * * @param word the word to be returned * @param modifier * @param setter */ public static void setCustom(Word word, StringModifier modifier, ValueSetter setter) { List<Custom> customs = CUSTOMS.getOrDefault(VaadinSession.getCurrent(), new ArrayList<>()); customs.add(new Custom(word, modifier, setter)); CUSTOMS.put(VaadinSession.getCurrent(), customs); changeCustomTo(LANGUAGES.getOrDefault(VaadinSession.getCurrent().getLocale(), ENGLISH), word, modifier, setter); }
From source file:dhbw.clippinggorilla.utilities.language.Language.java
public static final void setLanguage(Locale Language) { VaadinSession.getCurrent().setLocale(Language); changeAllComponentsTo(LANGUAGES.getOrDefault(Language, ENGLISH)); changeAllCustomsTo(LANGUAGES.getOrDefault(Language, ENGLISH)); }
From source file:dhbw.clippinggorilla.utilities.language.Language.java
private static void changeAllCustomsTo(Language languageToBeChangedTo) { CUSTOMS.get(VaadinSession.getCurrent()).forEach((Custom c) -> { changeCustomTo(languageToBeChangedTo, c.word, c.modifier, c.setter); });//from w w w . j a v a2 s . c om }
From source file:dhbw.clippinggorilla.utilities.language.Language.java
private static void changeAllComponentsTo(Language languageToBeChangedTo) { COMPONENTS.get(VaadinSession.getCurrent()).forEach((Component k, Word v) -> { changeComponentTo(languageToBeChangedTo, k, v); });// w ww. j av a2 s .c o m }
From source file:edu.kit.dama.ui.admin.AdminUIMainView.java
License:Apache License
@Override protected void init(VaadinRequest request) { try {/*from w ww.ja v a 2 s . c om*/ //might be OAuth redirect String pendingAuthId = null; AbstractLoginComponent.AUTH_MODE type = AbstractLoginComponent.AUTH_MODE.LOGIN; if (VaadinSession.getCurrent().getAttribute("auth_pending") != null) { pendingAuthId = (String) VaadinSession.getCurrent().getAttribute("auth_pending"); } else if (VaadinSession.getCurrent().getAttribute("registration_pending") != null) { pendingAuthId = (String) VaadinSession.getCurrent().getAttribute("registration_pending"); type = AbstractLoginComponent.AUTH_MODE.REGISTRATION; } doBasicSetup(); boolean isLandingPage = request.getParameter("landing") != null; String landingObjectId = request.getParameter("oid"); //setup header setupHeader(isLandingPage, landingObjectId); //setup login form setupLoginForm(type, pendingAuthId, request); if (pendingAuthId != null && !type.equals(AbstractLoginComponent.AUTH_MODE.REGISTRATION)) { //auth will redirect to start page so we'll stop here return; } mainLayout = new VerticalLayout(); mainLayout.setMargin(false); mainLayout.setSizeFull(); //setup login bar loginInformationBar = new LoginInformationBar(this); loginInformationBar.reload(); setContent(mainLayout); setSizeFull(); if (isLandingPage) { //setup landing page LOGGER.debug("Showing landing page."); setupLandingPage(request); } else { refreshMainLayout(); } INITIALIZING = false; } catch (Throwable t) { LOGGER.error("Failed to init app.", t); } }