List of usage examples for com.vaadin.ui Alignment MIDDLE_CENTER
Alignment MIDDLE_CENTER
To view the source code for com.vaadin.ui Alignment MIDDLE_CENTER.
Click Source Link
From source file:dhbw.clippinggorilla.userinterface.views.DocumentsView.java
private Component generateLine(Path file, GridLayout layout) { Label fileName = new Label(file.getFileName().toString()); layout.addComponent(fileName);/*from ww w . j a v a 2 s . c o m*/ layout.setComponentAlignment(fileName, Alignment.MIDDLE_LEFT); Button downloadButton = new Button(); downloadButton.setIcon(VaadinIcons.DOWNLOAD); FileDownloader downloader = new FileDownloader(new FileResource(file.toFile())); downloader.extend(downloadButton); layout.addComponent(downloadButton); layout.setComponentAlignment(downloadButton, Alignment.MIDDLE_CENTER); if (file.getFileName().toString().endsWith("pdf")) { Button viewButton = new Button(); viewButton.setIcon(VaadinIcons.EYE); viewButton.addClickListener(ce -> UI.getCurrent().addWindow(PDFWindow.get(file))); layout.addComponent(viewButton); layout.setComponentAlignment(viewButton, Alignment.MIDDLE_CENTER); } else { layout.addComponent(new Label(" ")); } return layout; }
From source file:dhbw.clippinggorilla.userinterface.views.FooterBar.java
public FooterBar() { setColumns(6);/* w ww .ja va 2s . c o m*/ setRows(1); addStyleName("menubar"); setWidth("100%"); setHeightUndefined(); setColumnExpandRatio(4, 5); setSpacing(true); setMargin(true); Image logo = new Image(); try { logo.setSource(new FileResource(FileUtils.getFile("images/logo_small.png").toFile())); } catch (FileNotFoundException ex) { Log.error("Could not find logo!", ex); } logo.setHeight("100%"); addComponent(logo); setComponentAlignment(logo, Alignment.MIDDLE_CENTER); Button aboutUs = new Button(); Language.set(Word.ABOUT_US, aboutUs); aboutUs.addClickListener((ce) -> { ClippingGorillaUI.getCurrent().setMainContent(AboutUsView.getCurrent()); }); aboutUs.setIcon(VaadinIcons.USERS); aboutUs.addStyleName(ValoTheme.BUTTON_BORDERLESS); addComponent(aboutUs); setComponentAlignment(aboutUs, Alignment.MIDDLE_CENTER); Button docs = new Button(); Language.set(Word.DOCUMENTS, docs); docs.addClickListener(ce -> { ClippingGorillaUI.getCurrent().setMainContent(DocumentsView.getCurrent()); }); docs.setIcon(VaadinIcons.ARCHIVE); docs.addStyleName(ValoTheme.BUTTON_BORDERLESS); addComponent(docs); setComponentAlignment(docs, Alignment.MIDDLE_CENTER); Button impressum = new Button(); Language.set(Word.IMPRESSUM, impressum); impressum.addClickListener(ce -> { ClippingGorillaUI.getCurrent().setMainContent(ImpressumView.getCurrent()); }); impressum.setIcon(VaadinIcons.SCALE); impressum.addStyleName(ValoTheme.BUTTON_BORDERLESS); addComponent(impressum); setComponentAlignment(impressum, Alignment.MIDDLE_CENTER); Label spacing = new Label(); addComponent(spacing); setComponentAlignment(spacing, Alignment.MIDDLE_CENTER); ComboBox<Locale> languages = new ComboBox<>(null, Language.getAllLanguages().keySet()); languages.setItemCaptionGenerator(loc -> loc.getDisplayLanguage(loc)); if (!Language.getAllLanguages().containsKey(VaadinSession.getCurrent().getLocale())) { languages.setValue(Locale.ENGLISH); } else { languages.setValue(VaadinSession.getCurrent().getLocale()); } languages.setEmptySelectionAllowed(false); languages.setItemIconGenerator(FooterBar::getIcon); languages.addValueChangeListener( (HasValue.ValueChangeEvent<Locale> loc) -> Language.setLanguage(loc.getValue())); languages.setTextInputAllowed(false); addComponent(languages); setComponentAlignment(languages, Alignment.MIDDLE_CENTER); SESSIONS.put(VaadinSession.getCurrent(), this); }
From source file:dhbw.clippinggorilla.userinterface.views.GroupView.java
public VerticalLayout createTab(Group g) { User u = UserUtils.getCurrent();//from ww w . j a va 2 s. co m VerticalLayout groupSettingsLayout = new VerticalLayout(); groupSettingsLayouts.put(g, groupSettingsLayout); GridLayout tabContent; TextField textFieldName = new TextField(); if (GroupUtils.isAdmin(g, u)) { tabContent = new GridLayout(3, 2); Language.set(Word.NAME, textFieldName); textFieldName.setWidth("100%"); textFieldName.setValue(g.getName()); textFieldName.setMaxLength(255); tabContent.addComponent(textFieldName); tabContent.setComponentAlignment(textFieldName, Alignment.MIDDLE_LEFT); } else { tabContent = new GridLayout(3, 1); } buttonLeave = new Button(); Language.set(Word.LEAVE, buttonLeave); buttonLeave.setIcon(VaadinIcons.MINUS); buttonLeave.addStyleName(ValoTheme.BUTTON_DANGER); buttonLeave.addClickListener(ce -> { ConfirmationDialog.show(Language.get(Word.REALLY_LEAVE_GROUP).replace("[GROUP]", g.getName()), () -> { long amountAdmins = g.getUsers().entrySet().stream().filter(e -> e.getValue()).count(); if (amountAdmins > 1 || !GroupUtils.isAdmin(g, u)) { GroupUtils.removeUser(g, u); refreshAll(g); } else { VaadinUtils.errorNotification(Language.get(Word.NOT_ENOUGH_ADMINS_IN_GROUP)); } }); }); buttonDelete = new Button(); Language.set(Word.DELETE, buttonDelete); buttonDelete.setIcon(VaadinIcons.TRASH); buttonDelete.addStyleName(ValoTheme.BUTTON_DANGER); buttonDelete.addClickListener(ce -> { ConfirmationDialog.show(Language.get(Word.REALLY_DELETE_GROUP).replace("[GROUP]", g.getName()), () -> { GroupUtils.removeGroup(g); refreshAll(g); }); }); Button buttonSave = new Button(); Language.set(Word.SAVE, buttonSave); buttonSave.setIcon(VaadinIcons.CHECK); buttonSave.addStyleName(ValoTheme.BUTTON_PRIMARY); buttonSave.addClickListener(ce -> { if (GroupUtils.isAdmin(g, u)) { GroupUtils.changeName(g, textFieldName.getValue()); accordion.getTab(groupSettingsLayout).setCaption(textFieldName.getValue()); } VaadinUtils.infoNotification(Language.get(Word.SUCCESSFULLY_SAVED)); }); buttonSave.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); Label placeholder = new Label(); Label placeholder2 = new Label(); placeholder2.setWidth("100%"); Label placeholder3 = new Label(); GridLayout footer = new GridLayout(4, 1); footer.setSpacing(true); footer.setMargin(new MarginInfo(false, true)); footer.setSizeUndefined(); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); footer.setWidth("100%"); footer.addStyleName("menubar"); if (GroupUtils.isAdmin(g, u)) { footer.addComponents(placeholder, buttonDelete, buttonLeave, buttonSave); footer.setComponentAlignment(buttonDelete, Alignment.MIDDLE_CENTER); } else { footer.addComponents(placeholder, placeholder3, buttonLeave, buttonSave); } footer.setColumnExpandRatio(0, 5); footer.setComponentAlignment(buttonLeave, Alignment.MIDDLE_CENTER); footer.setComponentAlignment(buttonSave, Alignment.MIDDLE_CENTER); if (GroupUtils.isAdmin(g, u)) { tabContent.addComponent(getProfiles(g), 0, 1, 1, 1); tabContent.addComponent(getMembers(g), 2, 1); } else { tabContent.addComponent(getProfiles(g), 0, 0, 1, 0); tabContent.addComponent(getMembers(g), 2, 0); } tabContent.setWidth("100%"); tabContent.setSpacing(true); tabContent.setMargin(true); tabContent.addStyleName("profiles"); groupSettingsLayout.addComponents(tabContent, footer); groupSettingsLayout.setMargin(false); groupSettingsLayout.setSpacing(false); groupSettingsLayout.setWidth("100%"); return groupSettingsLayout; }
From source file:dhbw.clippinggorilla.userinterface.views.GroupView.java
private void refreshProfiles(Group g, Layout layoutProfiles) { layoutProfiles.removeAllComponents(); GroupUtils.getAllInterestProfiles(g, UserUtils.getCurrent()).forEach((p, enabled) -> { HorizontalLayout layoutProfile = new HorizontalLayout(); layoutProfile.setWidth("100%"); CheckBox checkBoxEnabled = new CheckBox(); checkBoxEnabled.setValue(enabled); checkBoxEnabled.addValueChangeListener(v -> { GroupInterestProfileUtils.changeEnabled(p, UserUtils.getCurrent(), v.getValue()); refreshAll(g);/*from w w w . j av a2s. co m*/ }); long subscribers = p.getEnabledUsers().values().stream().filter(v -> v).count(); Label labelProfileInfo = new Label(); Language.setCustom(Word.SUBSCRIBERS, s -> { String info = p.getName() + " (" + subscribers + " "; info += subscribers == 1 ? Language.get(Word.SUBSCRIBER) + ")" : Language.get(Word.SUBSCRIBERS) + ")"; labelProfileInfo.setValue(info); }); boolean isAdmin = g.getUsers().getOrDefault(UserUtils.getCurrent(), false); Button buttonOpen = new Button(VaadinIcons.EXTERNAL_LINK); buttonOpen.addClickListener(ce -> { UI.getCurrent().addWindow(GroupProfileWindow.show(p, isAdmin, () -> { })); }); if (isAdmin) { Button buttonRemove = new Button(VaadinIcons.MINUS); buttonRemove.addStyleName(ValoTheme.BUTTON_DANGER); buttonRemove.addClickListener(ce -> { ConfirmationDialog.show( Language.get(Word.REALLY_DELETE_PROFILE).replace("[PROFILE]", p.getName()), () -> { GroupInterestProfileUtils.delete(p); refreshAll(g); }); }); layoutProfile.addComponents(checkBoxEnabled, labelProfileInfo, buttonOpen, buttonRemove); } else { layoutProfile.addComponents(checkBoxEnabled, labelProfileInfo, buttonOpen); } layoutProfile.setExpandRatio(labelProfileInfo, 5); layoutProfile.setComponentAlignment(checkBoxEnabled, Alignment.MIDDLE_CENTER); layoutProfile.setComponentAlignment(labelProfileInfo, Alignment.MIDDLE_LEFT); layoutProfiles.addComponent(layoutProfile); }); }
From source file:dhbw.clippinggorilla.userinterface.views.InterestProfileView.java
public VerticalLayout createTab(InterestProfile profile) { VerticalLayout profileSettingsLayout = new VerticalLayout(); GridLayout tabContent = new GridLayout(3, 3); TextField textFieldName = new TextField(); Language.set(Word.NAME, textFieldName); textFieldName.setWidth("100%"); textFieldName.setValue(profile.getName()); textFieldName.setMaxLength(255);/* www. ja v a 2s .co m*/ CheckBox checkBoxEnabled = new CheckBox(); checkBoxEnabled.setValue(profile.isEnabled()); Language.setCustom(Word.ENABLED, s -> checkBoxEnabled.setCaption(s)); Button buttonDelete = new Button(); Language.set(Word.DELETE, buttonDelete); buttonDelete.setIcon(VaadinIcons.TRASH); buttonDelete.addStyleName(ValoTheme.BUTTON_DANGER); buttonDelete.addClickListener(ce -> { InterestProfileUtils.delete(profile); accordion.removeTab(accordion.getTab(profileSettingsLayout)); }); Button buttonSave = new Button(); Language.set(Word.SAVE, buttonSave); buttonSave.setIcon(VaadinIcons.CHECK); buttonSave.addStyleName(ValoTheme.BUTTON_PRIMARY); buttonSave.addClickListener(ce -> { InterestProfileUtils.changeName(profile, textFieldName.getValue()); accordion.getTab(profileSettingsLayout).setCaption(textFieldName.getValue()); InterestProfileUtils.changeEnabled(profile, checkBoxEnabled.getValue()); InterestProfileUtils.changeSources(profile, profile.getSources()); InterestProfileUtils.changeCategories(profile, profile.getCategories()); InterestProfileUtils.changeAllTags(profile, profile.getTags()); VaadinUtils.infoNotification(Language.get(Word.SUCCESSFULLY_SAVED)); }); buttonSave.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); Label placeholder = new Label(); Label placeholder2 = new Label(); placeholder2.setWidth("100%"); Label labelHelp = new Label(Language.get(Word.HELP_TEXT), ContentMode.HTML); Language.setCustom(Word.HELP_TEXT, s -> labelHelp.setValue(s)); labelHelp.setWidth("500px"); PopupView popupHelp = new PopupView(null, labelHelp); Button buttonHelp = new Button(Language.get(Word.HELP), VaadinIcons.QUESTION); buttonHelp.addClickListener(ce -> { popupHelp.setPopupVisible(true); }); GridLayout footer = new GridLayout(5, 1); footer.setSpacing(true); footer.setSizeUndefined(); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); footer.setWidth("100%"); footer.addStyleName("menubar"); footer.addComponents(buttonHelp, popupHelp, placeholder, buttonDelete, buttonSave); footer.setColumnExpandRatio(2, 5); footer.setComponentAlignment(buttonDelete, Alignment.MIDDLE_CENTER); footer.setComponentAlignment(buttonSave, Alignment.MIDDLE_CENTER); tabContent.addComponents(textFieldName, checkBoxEnabled, placeholder2); tabContent.addComponent(getSources(profile), 0, 1, 1, 1); tabContent.addComponent(getCategories(profile), 2, 1); tabContent.addComponent(getTags(profile), 0, 2, 2, 2); tabContent.setWidth("100%"); tabContent.setSpacing(true); tabContent.setMargin(true); tabContent.addStyleName("profiles"); tabContent.setComponentAlignment(textFieldName, Alignment.MIDDLE_LEFT); tabContent.setComponentAlignment(checkBoxEnabled, Alignment.MIDDLE_CENTER); profileSettingsLayout.addComponents(tabContent, footer); profileSettingsLayout.setMargin(false); profileSettingsLayout.setSpacing(false); profileSettingsLayout.setWidth("100%"); return profileSettingsLayout; }
From source file:dhbw.clippinggorilla.userinterface.views.InterestProfileView.java
public Component getSources(InterestProfile profile) { VerticalLayout windowLayout = new VerticalLayout(); windowLayout.setWidth("100%"); VerticalLayout sourcesLayout = new VerticalLayout(); sourcesLayout.setWidth("100%"); Panel sourcesPanel = new Panel(sourcesLayout); List<CheckBox> checkBoxes = new ArrayList<>(); HashMap<String, GridLayout> sourceLayouts = new HashMap<>(); profile.getSources().entrySet().stream() .sorted((e1, e2) -> e1.getKey().getName().compareToIgnoreCase(e2.getKey().getName())).forEach(e -> { Source source = e.getKey(); boolean enabled = e.getValue(); GridLayout sourceLayout = new GridLayout(5, 1); sourceLayout.setSizeFull(); CheckBox sourceSelected = new CheckBox(); sourceSelected.setValue(enabled); sourceSelected.addStyleName(ValoTheme.CHECKBOX_LARGE); sourceSelected.addValueChangeListener(v -> profile.getSources().replace(source, v.getValue())); checkBoxes.add(sourceSelected); Image sourceLogo = new Image(); sourceLogo.addStyleName("logosmall"); sourceLogo.setSource(new ExternalResource(source.getLogo())); sourceLogo.addClickListener(c -> { sourceSelected.setValue(!sourceSelected.getValue()); profile.getSources().replace(source, sourceSelected.getValue()); });/*w w w . j a v a 2 s . co m*/ VerticalLayout layoutLogo = new VerticalLayout(sourceLogo); layoutLogo.setWidth("150px"); layoutLogo.setHeight("50px"); layoutLogo.setMargin(false); layoutLogo.setSpacing(false); layoutLogo.setComponentAlignment(sourceLogo, Alignment.MIDDLE_LEFT); Label labelHeadLine = new Label( source.getCategory().getIcon().getHtml() + " " + source.getName(), ContentMode.HTML); labelHeadLine.addStyleName(ValoTheme.LABEL_H3); Label labelDescription = new Label(source.getDescription(), ContentMode.HTML); labelDescription.setWidth("300px"); PopupView popup = new PopupView(null, labelDescription); Button buttonDescription = new Button(VaadinIcons.INFO_CIRCLE_O); buttonDescription.addClickListener(ce -> { popup.setPopupVisible(true); }); sourceLayout.addComponents(sourceSelected, layoutLogo, labelHeadLine, popup, buttonDescription); sourceLayout.setComponentAlignment(sourceSelected, Alignment.MIDDLE_CENTER); sourceLayout.setComponentAlignment(layoutLogo, Alignment.MIDDLE_CENTER); sourceLayout.setColumnExpandRatio(2, 5); sourceLayout.setSpacing(true); sourceLayouts.put(source.getName().toLowerCase().replaceAll(" ", "").replaceAll("-", "") .replaceAll("_", ""), sourceLayout); sourcesLayout.addComponent(sourceLayout); }); sourcesPanel.setContent(sourcesLayout); sourcesPanel.setHeight("100%"); sourcesPanel.setCaption(Language.get(Word.SOURCES)); Language.setCustom(Word.SOURCES, s -> sourcesPanel.setCaption(s)); windowLayout.addComponent(sourcesPanel); windowLayout.setExpandRatio(sourcesPanel, 1); windowLayout.setSpacing(false); windowLayout.setMargin(false); CheckBox checkBoxSelectAll = new CheckBox(); Language.setCustom(Word.SELECT_ALL, s -> checkBoxSelectAll.setCaption(s)); checkBoxSelectAll.setWidth("100%"); checkBoxSelectAll.addValueChangeListener(e -> { profile.getSources().replaceAll((c, enabled) -> checkBoxSelectAll.getValue()); checkBoxes.forEach(c -> c.setValue(checkBoxSelectAll.getValue())); }); TextField textFieldSearch = new TextField(); Language.setCustom(Word.SEARCH, s -> textFieldSearch.setPlaceholder(s)); textFieldSearch.setWidth("100%"); textFieldSearch.setMaxLength(255); textFieldSearch.setPlaceholder(Language.get(Word.SEARCH)); textFieldSearch.addValueChangeListener(searchValue -> { sourceLayouts.forEach((sourceName, sourceLayout) -> { if (!sourceName.contains(searchValue.getValue().toLowerCase().replaceAll(" ", "") .replaceAll("-", "").replaceAll("_", ""))) { sourcesLayout.removeComponent(sourceLayout); } else { sourcesLayout.addComponent(sourceLayout); } }); }); Label placeholder = new Label(); placeholder.setWidth("100%"); GridLayout footer = new GridLayout(3, 1); footer.setSpacing(true); footer.setMargin(new MarginInfo(true, false, false, false)); footer.addStyleName("menubar"); footer.setWidth("100%"); footer.addComponents(checkBoxSelectAll, textFieldSearch, placeholder); footer.setComponentAlignment(checkBoxSelectAll, Alignment.MIDDLE_LEFT); footer.setComponentAlignment(textFieldSearch, Alignment.MIDDLE_CENTER); windowLayout.addComponent(footer); windowLayout.setHeight("350px"); return windowLayout; }
From source file:dhbw.clippinggorilla.userinterface.views.InterestProfileView.java
public Component getCategories(InterestProfile profile) { Map<Category, Boolean> categories = profile.getCategories(); VerticalLayout categoriesLayout = new VerticalLayout(); categoriesLayout.setWidth("100%"); Panel categoriesPanel = new Panel(categoriesLayout); categories.entrySet().stream().sorted((e1, e2) -> e1.getKey().getName().compareTo(e2.getKey().getName())) .forEach(e -> {/*from w w w. j a v a 2 s . c om*/ Category category = e.getKey(); boolean enabled = e.getValue(); GridLayout categoryLayout = new GridLayout(3, 1); categoryLayout.setWidth("100%"); CheckBox categorySelected = new CheckBox(); categorySelected.setValue(enabled); categorySelected.addStyleName(ValoTheme.CHECKBOX_LARGE); categorySelected.addValueChangeListener(v -> categories.replace(category, v.getValue())); Label categoryIcon = new Label(category.getIcon().getHtml(), ContentMode.HTML); categoryIcon.addStyleName(ValoTheme.LABEL_H3); categoryIcon.addStyleName(ValoTheme.LABEL_NO_MARGIN); Label categoryName = new Label(category.getName(), ContentMode.HTML); Language.setCustom(null, s -> categoryName.setValue(category.getName())); categoryName.addStyleName(ValoTheme.LABEL_H3); categoryName.addStyleName(ValoTheme.LABEL_NO_MARGIN); categoryLayout.addComponents(categorySelected, categoryIcon, categoryName); categoryLayout.setComponentAlignment(categorySelected, Alignment.MIDDLE_CENTER); categoryLayout.setComponentAlignment(categoryIcon, Alignment.MIDDLE_LEFT); categoryLayout.setComponentAlignment(categoryName, Alignment.MIDDLE_LEFT); categoryLayout.setColumnExpandRatio(2, 5); categoryLayout.setSpacing(true); categoriesLayout.addComponent(categoryLayout); }); categoriesPanel.setContent(categoriesLayout); categoriesPanel.setHeight("100%"); categoriesPanel.setCaption(Language.get(Word.CATEGORIES)); Language.setCustom(Word.CATEGORIES, s -> categoriesPanel.setCaption(s)); return categoriesPanel; }
From source file:dhbw.clippinggorilla.userinterface.views.InterestProfileView.java
public Component getTags(InterestProfile profile) { GridLayout allTagsLayout = new GridLayout(2, 1); Panel allTagsPanel = new Panel(allTagsLayout); allTagsPanel.setWidth("100%"); allTagsPanel.setHeight("265px"); allTagsPanel.setCaption(Language.get(Word.TAGS)); Language.setCustom(Word.TAGS, s -> allTagsPanel.setCaption(s)); VerticalLayout includedTagsLayout = new VerticalLayout(); includedTagsLayouts.put(profile, includedTagsLayout); includedTagsLayout.setWidth("100%"); includedTagsLayout.addStyleName("tags"); Label labelIncludedTags = new Label(Language.get(Word.INCLUDE_TAGS));//Evtl only included Language.setCustom(Word.INCLUDE_TAGS, s -> labelIncludedTags.setValue(s)); Component addIncludeTagGroup = getAddTagGroup(profile, true); includedTagsLayout.addComponents(labelIncludedTags, addIncludeTagGroup); includedTagsLayout.setComponentAlignment(labelIncludedTags, Alignment.MIDDLE_CENTER); includedTagsLayout.setComponentAlignment(addIncludeTagGroup, Alignment.MIDDLE_CENTER); VerticalLayout excludedTagsLayout = new VerticalLayout(); excludedTagsLayouts.put(profile, excludedTagsLayout); excludedTagsLayout.setWidth("100%"); excludedTagsLayout.addStyleName("tags"); Label labelExcludedTags = new Label(Language.get(Word.EXCLUDE_TAGS));//Evtl only included Language.setCustom(Word.EXCLUDE_TAGS, s -> labelExcludedTags.setValue(s)); Component addExcludeTagGroup = getAddTagGroup(profile, false); excludedTagsLayout.addComponents(labelExcludedTags, addExcludeTagGroup); excludedTagsLayout.setComponentAlignment(labelExcludedTags, Alignment.MIDDLE_CENTER); excludedTagsLayout.setComponentAlignment(addExcludeTagGroup, Alignment.MIDDLE_CENTER); profile.getTags().forEach((tag, included) -> addRow(profile, included, tag)); allTagsLayout.addComponents(includedTagsLayout, excludedTagsLayout); allTagsLayout.setWidth("100%"); return allTagsPanel; }
From source file:dhbw.clippinggorilla.userinterface.windows.ActivateWindow.java
public static Window get() { Window window = new Window(); window.setModal(true);//from www. jav a 2 s . c o m window.setResizable(false); window.setDraggable(false); window.setCaption(Language.get(Word.ACTIVATION_CODE)); window.addCloseShortcut(ShortcutAction.KeyCode.ENTER, null); VerticalLayout windowLayout = new VerticalLayout(); windowLayout.setMargin(false); windowLayout.setSizeUndefined(); FormLayout forms = new FormLayout(); forms.setMargin(true); forms.setSizeUndefined(); Button save = new Button(Language.get(Word.ACTIVATE)); TextField activationCode = new TextField(Language.get(Word.ACTIVATION_CODE)); activationCode.setMaxLength(6); activationCode.focus(); activationCode.addValueChangeListener(e -> { if (activationCode.getValue().length() > 5) { save.setEnabled(true); activationCode.setComponentError(null); } else { save.setEnabled(false); activationCode.setComponentError(new UserError(Language.get(Word.ACTIVATION_CODE_SIX_CHARS), AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION)); VaadinUtils.infoNotification(Language.get(Word.ACTIVATION_CODE_SIX_CHARS)); } }); forms.addComponent(activationCode); Button resendMail = new Button(Language.get(Word.RESEND_ACTIVATION_CODE)); resendMail.addStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED); resendMail.addClickListener(ce -> { try { UserUtils.resendActivationMail(UserUtils.getCurrent()); VaadinUtils.infoNotification(Language.get(Word.RESEND_ACTIVATION_CODE_SUCCESSFUL)); } catch (EmailException ex) { VaadinUtils.errorNotification(Language.get(Word.RESEND_ACTIVATION_CODE_FAILED)); } }); forms.addComponent(resendMail); GridLayout footer = new GridLayout(3, 1); footer.setSpacing(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); footer.setWidth(100.0f, Sizeable.Unit.PERCENTAGE); Label placeholder = new Label(); Button cancel = new Button(Language.get(Word.CANCEL)); cancel.setIcon(VaadinIcons.CLOSE); cancel.addClickListener(ce -> { window.close(); }); cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); save.setEnabled(false); save.setIcon(VaadinIcons.CHECK); save.addStyleName(ValoTheme.BUTTON_PRIMARY); save.addClickListener(ce -> { try { String code = activationCode.getValue(); User user = UserUtils.getCurrent(); if (UserUtils.activateUser(user, code)) { VaadinUtils.infoNotification(Language.get(Word.ACTIVATION_SUCCESSFUL)); window.close(); } else { activationCode.setValue(""); VaadinUtils.errorNotification(Language.get(Word.ACTIVATION_FAILED)); } } catch (NumberFormatException e) { } }); save.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); footer.setSizeUndefined(); footer.setWidth("100%"); footer.addComponents(placeholder, cancel, save); footer.setColumnExpandRatio(0, 1);//ExpandRatio(placeholder, 1); footer.setComponentAlignment(cancel, Alignment.MIDDLE_CENTER); footer.setComponentAlignment(save, Alignment.MIDDLE_CENTER); windowLayout.addComponent(forms); windowLayout.addComponent(footer); window.setContent(windowLayout); return window; }
From source file:dhbw.clippinggorilla.userinterface.windows.ConfirmationDialog.java
public ConfirmationDialog(String confirmationText, Runnable onOk, Runnable onCancel) { addCloseListener(ce -> onCancel.run()); setCaption(Language.get(Word.CONFIRMATION)); VerticalLayout root = new VerticalLayout(); root.setSpacing(false);// w w w.jav a 2s .c o m root.setMargin(false); root.setSizeFull(); Label text = new Label(confirmationText); text.setStyleName(ValoTheme.LABEL_H3); text.setWidth("100%"); VerticalLayout layoutText = new VerticalLayout(text); layoutText.setSizeFull(); layoutText.addStyleName("tags"); layoutText.setSpacing(false); root.addComponent(layoutText); Label ignoreMe = new Label(); Button ok = new Button(Language.get(Word.OK)); ok.addClickListener(c -> { close(); onOk.run(); }); ok.addStyleName(ValoTheme.BUTTON_DANGER); Button cancel = new Button(Language.get(Word.CANCEL)); cancel.addClickListener(c -> { close(); onCancel.run(); }); cancel.addStyleName(ValoTheme.BUTTON_FRIENDLY); GridLayout footer = new GridLayout(3, 1); footer.setSpacing(true); footer.setSizeUndefined(); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); footer.setWidth("100%"); footer.addStyleName("menubar"); footer.addComponents(ignoreMe, ok, cancel); footer.setColumnExpandRatio(0, 5); footer.setComponentAlignment(ok, Alignment.MIDDLE_CENTER); footer.setComponentAlignment(cancel, Alignment.MIDDLE_CENTER); root.setExpandRatio(layoutText, 5); root.addComponent(footer); setContent(root); setModal(true); center(); setDraggable(false); setResizable(false); setWidth("350px"); setHeight("200px"); UI.getCurrent().addWindow(this); }