List of usage examples for com.vaadin.ui Button addStyleName
@Override public void addStyleName(String style)
From source file:dhbw.clippinggorilla.userinterface.windows.GroupProfileWindow.java
private Component getAddTagGroup(GroupInterestProfile profile, boolean included) { CssLayout newTagGroup = new CssLayout(); newTagGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP); TextField textFieldTag = new TextField(); textFieldTag.setWidth("325px"); textFieldTag.setMaxLength(255);/*from w w w .j a v a 2s . com*/ Language.setCustom(Word.NEW_TAG, s -> textFieldTag.setPlaceholder(s)); Button buttonAddTag = new Button(VaadinIcons.PLUS); buttonAddTag.addStyleName(ValoTheme.BUTTON_PRIMARY); buttonAddTag.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); buttonAddTag.addClickListener(event -> { addRow(profile, included, textFieldTag.getValue(), true); profile.getTags().put(textFieldTag.getValue(), included); textFieldTag.clear(); }); textFieldTag.addFocusListener(f -> buttonAddTag.setClickShortcut(ShortcutAction.KeyCode.ENTER, null)); textFieldTag.addBlurListener(f -> buttonAddTag.removeClickShortcut()); newTagGroup.addComponents(textFieldTag, buttonAddTag); newTagGroup.setWidth("100%"); return newTagGroup; }
From source file:dhbw.clippinggorilla.userinterface.windows.GroupProfileWindow.java
private void addRow(GroupInterestProfile profile, boolean included, String value, boolean isAdmin) { GridLayout tagLayout = new GridLayout(2, 1); tagLayout.setWidth("100%"); Label labelTagName = new Label(value, ContentMode.HTML); labelTagName.setWidth("100%"); labelTagName.addStyleName(ValoTheme.LABEL_H3); labelTagName.addStyleName(ValoTheme.LABEL_NO_MARGIN); tagLayout.addComponent(labelTagName); tagLayout.setComponentAlignment(labelTagName, Alignment.MIDDLE_LEFT); if (isAdmin) { Button buttonDeleteTag = new Button(VaadinIcons.TRASH); buttonDeleteTag.addStyleName(ValoTheme.BUTTON_DANGER); buttonDeleteTag.addClickListener(ev -> { profile.getTags().remove(value); if (included) { includedTagsLayouts.get(profile).removeComponent(tagLayout); } else { excludedTagsLayouts.get(profile).removeComponent(tagLayout); }/* w w w. j av a2s .c o m*/ }); tagLayout.addComponent(buttonDeleteTag); tagLayout.setComponentAlignment(buttonDeleteTag, Alignment.MIDDLE_RIGHT); } tagLayout.setWidth("100%"); tagLayout.setColumnExpandRatio(0, 5); tagLayout.setSpacing(true); tagLayout.setMargin(false); if (included) { if (isAdmin) { includedTagsLayouts.get(profile).addComponent(tagLayout, 2); } else { includedTagsLayouts.get(profile).addComponent(tagLayout, 1); } } else { if (isAdmin) { excludedTagsLayouts.get(profile).addComponent(tagLayout, 2); } else { excludedTagsLayouts.get(profile).addComponent(tagLayout, 1); } } }
From source file:dhbw.clippinggorilla.userinterface.windows.ManageSourcesWindow.java
public Component getSourcesList() { VerticalLayout windowLayout = new VerticalLayout(); windowLayout.setSizeFull();/*from w w w. jav a 2 s . co m*/ sourcesLayout = new VerticalLayout(); sourcesLayout.setWidth("100%"); Panel sourcesPanel = new Panel(sourcesLayout); refreshSources(); sourcesPanel.setContent(sourcesLayout); sourcesPanel.setHeight("100%"); windowLayout.addComponent(sourcesPanel); windowLayout.setExpandRatio(sourcesPanel, 1); windowLayout.setSpacing(false); windowLayout.setMargin(false); TextField textFieldSearch = new TextField(); 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); } }); }); Button buttonAddSource = new Button(Language.get(Word.ADD_SOURCE), VaadinIcons.PLUS); buttonAddSource.addClickListener(ce -> UI.getCurrent().addWindow(NewSourceWindow.create())); Button buttonSave = new Button(); Language.set(Word.SAVE, buttonSave); buttonSave.setIcon(VaadinIcons.CHECK); buttonSave.addStyleName(ValoTheme.BUTTON_PRIMARY); buttonSave.addClickListener(ce -> { close(); }); buttonSave.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); Label placeholder = new Label(); GridLayout footer = new GridLayout(4, 1); footer.setSpacing(true); footer.setSizeUndefined(); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); footer.addStyleName("menubar"); footer.setWidth(100.0f, Unit.PERCENTAGE); footer.addComponents(textFieldSearch, placeholder, buttonAddSource, buttonSave); footer.setComponentAlignment(textFieldSearch, Alignment.MIDDLE_CENTER); footer.setComponentAlignment(buttonAddSource, Alignment.MIDDLE_CENTER); footer.setComponentAlignment(buttonSave, Alignment.MIDDLE_CENTER); footer.setColumnExpandRatio(1, 5); windowLayout.addComponent(footer); return windowLayout; }
From source file:dhbw.clippinggorilla.userinterface.windows.ManageSourcesWindow.java
public void refreshSources() { sourcesLayout.removeAllComponents(); SourceUtils.getSources().stream().sorted((s1, s2) -> s1.getName().compareToIgnoreCase(s2.getName())) .forEach(source -> {/*from ww w .j a va2 s . c o m*/ try { GridLayout sourceLayout = new GridLayout(4, 1); sourceLayout.setSizeFull(); Image sourceLogo = new Image(); URL url = source.getLogo(); if (url != null) { sourceLogo.setSource(new ExternalResource(url)); } sourceLogo.setWidth("150px"); VerticalLayout sourceText = new VerticalLayout(); sourceText.setSizeFull(); Label labelHeadLine = new Label( source.getCategory().getIcon().getHtml() + " " + source.getName(), ContentMode.HTML); labelHeadLine.addStyleName(ValoTheme.LABEL_H2); Label labelDescription = new Label(source.getDescription(), ContentMode.HTML); labelDescription.addStyleName(ValoTheme.LABEL_SMALL); labelDescription.setWidth("100%"); sourceText.setMargin(false); sourceText.addComponents(labelHeadLine, labelDescription); Button buttonEdit = new Button(VaadinIcons.EDIT); buttonEdit.addStyleName(ValoTheme.BUTTON_PRIMARY); buttonEdit.addClickListener( ce -> UI.getCurrent().addWindow(NewSourceWindow.createEditMode(source))); Button buttonDelete = new Button(VaadinIcons.TRASH); buttonDelete.addStyleName(ValoTheme.BUTTON_DANGER); buttonDelete.addClickListener(ce -> { sourcesLayout.removeComponent(sourceLayout); sourceLayouts.remove(source.getName().toLowerCase().replaceAll(" ", "") .replaceAll("-", "").replaceAll("_", "")); SourceUtils.removeSource(source); }); sourceLayout.addComponents(sourceLogo, sourceText, buttonEdit, buttonDelete); sourceLayout.setComponentAlignment(sourceLogo, Alignment.MIDDLE_CENTER); sourceLayout.setComponentAlignment(buttonEdit, Alignment.MIDDLE_CENTER); sourceLayout.setComponentAlignment(buttonDelete, Alignment.MIDDLE_CENTER); sourceLayout.setColumnExpandRatio(1, 5); sourceLayout.setSpacing(true); sourceLayouts.put(source.getName().toLowerCase().replaceAll(" ", "").replaceAll("-", "") .replaceAll("_", ""), sourceLayout); sourcesLayout.addComponent(sourceLayout); } catch (Exception e) { Log.error("Skipping Source! ", e); } }); }
From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java
/** * Value is optional/*from w w w .j a v a2s. c o m*/ * * @param action * @param content * @param value * @return */ private Component getRow(Layout parent, Runnable onDelete, String action, String content, String value) { Panel panelRow = new Panel(); GridLayout layoutRow = new GridLayout(2, 1); Label labelInfo = new Label("", ContentMode.HTML); String stringInfo = action.toUpperCase() + "<br>"; if (value != null) { stringInfo += content + " = " + value; } else { stringInfo += content + " "; } labelInfo.setValue(stringInfo); Button buttonDelete = new Button(VaadinIcons.TRASH); buttonDelete.addStyleName(ValoTheme.BUTTON_DANGER); buttonDelete.addClickListener(ce -> { onDelete.run(); parent.removeComponent(panelRow); }); layoutRow.addComponents(labelInfo, buttonDelete); layoutRow.setComponentAlignment(buttonDelete, Alignment.MIDDLE_RIGHT); layoutRow.setComponentAlignment(labelInfo, Alignment.MIDDLE_LEFT); layoutRow.setWidth("100%"); layoutRow.setMargin(true); layoutRow.addStyleName("crawler"); panelRow.setContent(layoutRow); panelRow.setWidth("100%"); return panelRow; }
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);// www .ja v a2 s .com 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.userinterface.windows.PreferencesWindow.java
private Component getTimeRow(User user, LocalTime time) { HorizontalLayout layoutTimeRow = new HorizontalLayout(); layoutTimeRow.setWidth("100%"); DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT); Label labelTime = new Label(time.format(formatter)); Button buttonDelete = new Button(VaadinIcons.TRASH); buttonDelete.addStyleName(ValoTheme.BUTTON_DANGER); buttonDelete.setWidth("80px"); buttonDelete.addClickListener(e -> { if (layoutClippingTimes.getComponentCount() > 1) { layoutClippingTimes.removeComponent(layoutTimeRow); UserUtils.removeClippingSendTime(user, time); } else {//from w ww. j a v a 2 s . co m VaadinUtils.errorNotification(Language.get(Word.AT_LREAST_ONE_TIME)); } }); layoutTimeRow.addComponents(labelTime, buttonDelete); layoutTimeRow.setComponentAlignment(labelTime, Alignment.MIDDLE_LEFT); layoutTimeRow.setComponentAlignment(buttonDelete, Alignment.MIDDLE_CENTER); layoutTimeRow.setExpandRatio(labelTime, 5); return layoutTimeRow; }
From source file:dhbw.clippinggorilla.userinterface.windows.PreferencesWindow.java
private Component buildSupportTab(User user) { VerticalLayout root = new VerticalLayout(); root.setCaption(Language.get(Word.SUPPORT)); root.setIcon(VaadinIcons.HEADSET);/*from ww w . j av a2 s . co m*/ root.setWidth("100%"); root.setHeight("100%"); root.setSpacing(true); root.setMargin(true); TextArea textAreaMessage = new TextArea(Language.get(Word.MESSAGE)); textAreaMessage.setWidth("100%"); textAreaMessage.setHeight("100%"); Button buttonSend = new Button(Language.get(Word.SEND), VaadinIcons.ENVELOPE); buttonSend.addStyleName(ValoTheme.BUTTON_PRIMARY); buttonSend.addClickListener(ce -> { try { if (emailsSend.containsKey(user)) { Map<LocalDate, Integer> times = emailsSend.get(user); if (times.containsKey(LocalDate.now())) { if (times.get(LocalDate.now()) > 3) { if (times.get(LocalDate.now()) > 15) { UserUtils.banUser(user); VaadinUtils.errorNotification("BANNED DUE TO TOO MUCH EMAILS"); } else { VaadinUtils.errorNotification("TOO MUCH EMAILS"); } return; } else { times.put(LocalDate.now(), times.get(LocalDate.now()) + 1); } } else { times.put(LocalDate.now(), 1); } } else { HashMap<LocalDate, Integer> times = new HashMap<>(); times.put(LocalDate.now(), 1); emailsSend.put(user, times); } Mail.send(Props.get("supportmail"), "SUPPORT", user.toString() + "\n" + textAreaMessage.getValue()); VaadinUtils.middleInfoNotification(Language.get(Word.SUCCESSFULLY_SEND)); textAreaMessage.clear(); } catch (EmailException ex) { VaadinUtils.errorNotification(Language.get(Word.SEND_FAILED)); Log.error("Could not send Supportmail: ", ex); } }); root.addComponents(textAreaMessage, buttonSend); root.setExpandRatio(textAreaMessage, 5); root.setComponentAlignment(buttonSend, Alignment.MIDDLE_LEFT); return root; }
From source file:dhbw.clippinggorilla.userinterface.windows.RegisterWindow.java
public RegisterWindow() { setModal(true);/*from ww w . j ava2 s .co m*/ setResizable(false); setDraggable(false); setCaption(Language.get(Word.REGISTER)); addCloseShortcut(KeyCode.ENTER, null); Button save = new Button(Language.get(Word.REGISTER)); VerticalLayout windowLayout = new VerticalLayout(); windowLayout.setMargin(false); windowLayout.setSizeUndefined(); FormLayout forms = new FormLayout(); forms.setMargin(true); forms.setSizeUndefined(); TextField firstName = new TextField(Language.get(Word.FIRST_NAME)); firstName.focus(); firstName.setMaxLength(20); firstName.addValueChangeListener(event -> { String firstNameError = UserUtils.checkName(event.getValue()); if (!firstNameError.isEmpty()) { firstName.setComponentError(new UserError(firstNameError, AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION)); VaadinUtils.infoNotification(firstNameError); save.setEnabled(setError(firstName, true)); } else { firstName.setComponentError(null); boolean enabled = setError(firstName, false); save.setEnabled(enabled); } }); forms.addComponent(firstName); TextField lastName = new TextField(Language.get(Word.LAST_NAME)); lastName.setMaxLength(20); lastName.addValueChangeListener(event -> { String lastNameError = UserUtils.checkName(event.getValue()); if (!lastNameError.isEmpty()) { lastName.setComponentError(new UserError(lastNameError, AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION)); VaadinUtils.infoNotification(lastNameError); save.setEnabled(setError(lastName, true)); } else { lastName.setComponentError(null); save.setEnabled(setError(lastName, false)); } }); forms.addComponent(lastName); TextField userName = new TextField(Language.get(Word.USERNAME)); userName.setMaxLength(20); userName.addValueChangeListener(event -> { String userNameError = UserUtils.checkUsername(event.getValue()); if (!userNameError.isEmpty()) { userName.setComponentError(new UserError(userNameError, AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION)); VaadinUtils.infoNotification(userNameError); save.setEnabled(setError(userName, true)); } else { userName.setComponentError(null); save.setEnabled(setError(userName, false)); } }); forms.addComponent(userName); TextField email1 = new TextField(Language.get(Word.EMAIL)); email1.setMaxLength(256); email1.addValueChangeListener(event -> { String email1Error = UserUtils.checkEmail(event.getValue().toLowerCase()); if (!email1Error.isEmpty()) { email1.setComponentError(new UserError(email1Error, AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION)); VaadinUtils.infoNotification(email1Error); save.setEnabled(setError(email1, true)); } else { email1.setComponentError(null); save.setEnabled(setError(email1, false)); } }); forms.addComponent(email1); TextField email2 = new TextField(Language.get(Word.EMAIL_AGAIN)); email2.setMaxLength(256); email2.addValueChangeListener(event -> { String email2Error = UserUtils.checkEmail(event.getValue().toLowerCase()) + UserUtils.checkSecondEmail(email1.getValue().toLowerCase(), event.getValue().toLowerCase()); if (!email2Error.isEmpty()) { email2.setComponentError(new UserError(email2Error, AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION)); VaadinUtils.infoNotification(email2Error); save.setEnabled(setError(email2, true)); } else { email2.setComponentError(null); save.setEnabled(setError(email2, false)); } }); forms.addComponent(email2); ProgressBar strength = new ProgressBar(); PasswordField password1 = new PasswordField(Language.get(Word.PASSWORD)); password1.setMaxLength(51); password1.addValueChangeListener(event -> { String password1Error = UserUtils.checkPassword(event.getValue()); strength.setValue(UserUtils.calculatePasswordStrength(event.getValue())); if (!password1Error.isEmpty()) { password1.setComponentError(new UserError(password1Error, AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION)); VaadinUtils.infoNotification(password1Error); save.setEnabled(setError(password1, true)); } else { password1.setComponentError(null); save.setEnabled(setError(password1, false)); } }); forms.addComponent(password1); strength.setWidth("184px"); strength.setHeight("1px"); forms.addComponent(strength); PasswordField password2 = new PasswordField(Language.get(Word.PASSWORD_AGAIN)); password2.setMaxLength(51); password2.addValueChangeListener(event -> { String password2Error = UserUtils.checkPassword(event.getValue()) + UserUtils.checkSecondPassword(password1.getValue(), event.getValue()); if (!password2Error.isEmpty()) { password2.setComponentError(new UserError(password2Error, AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION)); VaadinUtils.infoNotification(password2Error); save.setEnabled(setError(password2, true)); } else { password2.setComponentError(null); save.setEnabled(setError(password2, false)); } }); forms.addComponent(password2); GridLayout footer = new GridLayout(3, 1); footer.setSpacing(true); footer.setSizeUndefined(); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); footer.setWidth(100.0f, Unit.PERCENTAGE); Label placeholder = new Label(); Button cancel = new Button(Language.get(Word.CANCEL)); cancel.setIcon(VaadinIcons.CLOSE); cancel.addClickListener(ce -> { close(); }); cancel.setClickShortcut(KeyCode.ESCAPE, null); save.setEnabled(false); save.setIcon(VaadinIcons.CHECK); save.addStyleName(ValoTheme.BUTTON_PRIMARY); save.addClickListener(ce -> { try { User user = UserUtils.registerUser(userName.getValue(), password1.getValue(), password2.getValue(), email1.getValue().toLowerCase(), email2.getValue().toLowerCase(), firstName.getValue(), lastName.getValue()); UserUtils.setCurrentUser(user); close(); UI.getCurrent().addWindow(ActivateWindow.get()); } catch (UserCreationException ex) { Log.error("Registration failed", ex); VaadinUtils.errorNotification(Language.get(Word.REG_FAILED)); } }); save.setClickShortcut(KeyCode.ENTER, null); 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); setContent(windowLayout); }
From source file:dhbw.ka.mwi.businesshorizon2.ui.process.navigation.NavigationViewImpl.java
License:Open Source License
private void addOverviewButton() { Button overviewButton = new Button("Projektbersicht"); overviewButton.addStyleName("default"); overviewButton.addListener(new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override//from ww w .ja v a 2s.c om public void buttonClick(ClickEvent event) { presenter.showProjectList(); } }); this.topbarinnerlayout.addComponent(overviewButton); this.topbarinnerlayout.setComponentAlignment(overviewButton, Alignment.MIDDLE_CENTER); }