Example usage for com.vaadin.ui Button setIcon

List of usage examples for com.vaadin.ui Button setIcon

Introduction

In this page you can find the example usage for com.vaadin.ui Button setIcon.

Prototype

@Override
public void setIcon(Resource icon) 

Source Link

Document

Sets the component's icon.

Usage

From source file:dhbw.clippinggorilla.userinterface.windows.ActivateWindow.java

public static Window get() {
    Window window = new Window();
    window.setModal(true);//w ww .  j  ava  2 s. co  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.GroupProfileWindow.java

public GroupProfileWindow(GroupInterestProfile p, Runnable onClose, boolean isAdmin) {
    VerticalLayout profileSettingsLayout = new VerticalLayout();
    GridLayout windowContent;//ww w. ja  va  2 s  . c  om
    Button buttonSave = new Button();

    if (isAdmin) {
        windowContent = new GridLayout(3, 3);

        TextField textFieldName = new TextField();
        Language.set(Word.NAME, textFieldName);
        textFieldName.setWidth("100%");
        textFieldName.setValue(p.getName());
        textFieldName.setMaxLength(255);

        Language.set(Word.SAVE, buttonSave);
        buttonSave.setIcon(VaadinIcons.CHECK);
        buttonSave.addStyleName(ValoTheme.BUTTON_PRIMARY);
        buttonSave.addClickListener(ce -> {
            GroupInterestProfileUtils.changeName(p, textFieldName.getValue());
            GroupInterestProfileUtils.changeSources(p, p.getSources());
            GroupInterestProfileUtils.changeCategories(p, p.getCategories());
            GroupInterestProfileUtils.changeAllTags(p, p.getTags());
            VaadinUtils.infoNotification(Language.get(Word.SUCCESSFULLY_SAVED));
            close();
            onClose.run();
        });

        Label placeholder2 = new Label();
        placeholder2.setWidth("100%");
        windowContent.addComponents(textFieldName, placeholder2);
        windowContent.setComponentAlignment(textFieldName, Alignment.MIDDLE_LEFT);
        windowContent.addComponent(getSources(p, true), 0, 1, 1, 1);
        windowContent.addComponent(getCategories(p, true), 2, 1);
        windowContent.addComponent(getTags(p, true), 0, 2, 2, 2);
    } else {
        windowContent = new GridLayout(3, 2);

        Language.set(Word.CLOSE, buttonSave);
        buttonSave.setIcon(VaadinIcons.CLOSE);
        buttonSave.addStyleName(ValoTheme.BUTTON_PRIMARY);
        buttonSave.addClickListener(ce -> {
            close();
            onClose.run();
        });

        windowContent.addComponent(getSources(p, false), 0, 0, 1, 0);
        windowContent.addComponent(getCategories(p, false), 2, 0);
        windowContent.addComponent(getTags(p, false), 0, 1, 2, 1);
    }

    buttonSave.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);

    Label placeholder = new Label();

    Label labelHelp = new Label(Language.get(Word.HELP_TEXT), ContentMode.HTML);
    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;
    if (isAdmin) {
        footer = new GridLayout(4, 1);
        footer.addComponents(buttonHelp, popupHelp, placeholder, buttonSave);
        footer.setColumnExpandRatio(2, 5);
    } else {
        footer = new GridLayout(2, 1);
        footer.addComponents(placeholder, buttonSave);
        footer.setColumnExpandRatio(0, 5);

    }
    footer.setSpacing(true);
    footer.setSizeUndefined();
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    footer.setWidth("100%");
    footer.addStyleName("menubar");
    footer.setComponentAlignment(buttonSave, Alignment.MIDDLE_CENTER);

    windowContent.setWidth("100%");
    windowContent.setSpacing(true);
    windowContent.setMargin(true);
    windowContent.addStyleName("profiles");
    profileSettingsLayout.addComponents(windowContent, footer);
    profileSettingsLayout.setMargin(false);
    profileSettingsLayout.setSpacing(false);
    profileSettingsLayout.setWidth("100%");

    setContent(profileSettingsLayout);
    center();
    setWidthUndefined();
    setCaption(p.getName());
    setWidth("950px");
}

From source file:dhbw.clippinggorilla.userinterface.windows.ManageSourcesWindow.java

public Component getSourcesList() {
    VerticalLayout windowLayout = new VerticalLayout();
    windowLayout.setSizeFull();//  w w w .  j a v a2 s . c o 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.NewSourceWindow.java

public Component getThirdStage(Source s) {
    Label header = new Label(Language.get(Word.CRAWLER));
    header.addStyleName(ValoTheme.LABEL_H1);

    Crawler crawler;/*  ww w. j  av a 2s  .com*/
    if (s.getCrawler() != null) {
        crawler = s.getCrawler();
    } else {
        crawler = new Crawler(s);
        s.setCrawler(crawler);
    }

    GridLayout mainGrid = new GridLayout(2, 2);
    mainGrid.setSizeFull();
    mainGrid.setSpacing(true);

    FormLayout layoutForms = new FormLayout();

    //Exclude or Include
    RadioButtonGroup<Boolean> radios = new RadioButtonGroup<>();
    radios.setItems(true, false);
    radios.setItemCaptionGenerator(b -> b ? Language.get(Word.INCLUDE_TAGS) : Language.get(Word.EXCLUDE_TAGS));
    radios.setItemIconGenerator(b -> b ? VaadinIcons.CHECK : VaadinIcons.CLOSE);
    radios.setSelectedItem(true);
    radios.addValueChangeListener(event -> include = event.getValue());

    //By Class
    CssLayout addByClassGroup = new CssLayout();
    addByClassGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
    TextField textFieldAddByClass = new TextField();
    textFieldAddByClass.setWidth("465px");
    Button buttonAddByClass = new Button(VaadinIcons.PLUS);
    buttonAddByClass.addClickListener(e -> {
        crawler.addByClass(textFieldAddByClass.getValue(), include);
        refreshList(mainGrid, crawler);
        textFieldAddByClass.clear();
    });
    addByClassGroup.addComponents(textFieldAddByClass, buttonAddByClass);
    addByClassGroup.setCaption(Language.get(Word.BYCLASS));

    //ByTag
    CssLayout addByTagGroup = new CssLayout();
    addByTagGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
    TextField textFieldAddByTag = new TextField();
    Button buttonAddByTag = new Button(VaadinIcons.PLUS);
    textFieldAddByTag.setWidth("465px");
    buttonAddByTag.addClickListener(e -> {
        crawler.addByTag(textFieldAddByTag.getValue(), include);
        refreshList(mainGrid, crawler);
        textFieldAddByTag.clear();
    });
    addByTagGroup.addComponents(textFieldAddByTag, buttonAddByTag);
    addByTagGroup.setCaption(Language.get(Word.BYTAG));

    //ByID
    CssLayout addByIDGroup = new CssLayout();
    addByIDGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
    TextField textFieldAddByID = new TextField();
    textFieldAddByID.setWidth("465px");
    Button buttonAddByID = new Button(VaadinIcons.PLUS);
    buttonAddByID.addClickListener(e -> {
        crawler.addByID(textFieldAddByID.getValue(), include);
        refreshList(mainGrid, crawler);
        textFieldAddByID.clear();
    });
    addByIDGroup.addComponents(textFieldAddByID, buttonAddByID);
    addByIDGroup.setCaption(Language.get(Word.BYID));

    //ByAttribute
    CssLayout addByAttributeGroup = new CssLayout();
    addByAttributeGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
    TextField textFieldAddByAttributeKey = new TextField();
    textFieldAddByAttributeKey.setWidth("233px");
    TextField textFieldAddByAttributeValue = new TextField();
    textFieldAddByAttributeValue.setWidth("232px");
    Button buttonAddByAttribute = new Button(VaadinIcons.PLUS);
    buttonAddByAttribute.addClickListener(e -> {
        crawler.addByAttribute(textFieldAddByAttributeKey.getValue(), textFieldAddByAttributeValue.getValue(),
                include);
        refreshList(mainGrid, crawler);
        textFieldAddByAttributeKey.clear();
        textFieldAddByAttributeValue.clear();
    });
    addByAttributeGroup.addComponents(textFieldAddByAttributeKey, textFieldAddByAttributeValue,
            buttonAddByAttribute);
    addByAttributeGroup.setCaption(Language.get(Word.BYATTRIBUTEVALUE));

    layoutForms.addComponents(radios, addByClassGroup, addByTagGroup, addByIDGroup, addByAttributeGroup);
    mainGrid.addComponent(layoutForms);

    Label labelResult = new Label();
    Panel panelResult = new Panel(labelResult);
    labelResult.setWidth("100%");
    panelResult.setWidth("100%");
    panelResult.setHeight("175px");
    mainGrid.addComponent(panelResult, 0, 1, 1, 1);

    Button buttonTestURL = new Button();
    buttonTestURL.setIcon(VaadinIcons.EXTERNAL_LINK);
    buttonTestURL.setCaption(Language.get(Word.OPEN_LINK));

    Button buttonTest = new Button(Language.get(Word.TEST), VaadinIcons.CLIPBOARD_CHECK);
    buttonTest.addClickListener(ce -> {
        Article a = CrawlerUtils.executeRandom(crawler);
        labelResult.setValue(a.getBody());
        if (reg != null) {
            reg.remove();
        }
        reg = buttonTestURL
                .addClickListener(cev -> UI.getCurrent().getPage().open(a.getUrl(), "_blank", false));
    });

    refreshList(mainGrid, crawler);

    Runnable cancel = () -> close();
    Runnable next = () -> validateThirdStage(s);

    VerticalLayout windowLayout = new VerticalLayout();
    windowLayout.addComponents(header, mainGrid, getFooter(cancel, next, buttonTest, buttonTestURL));
    windowLayout.setComponentAlignment(header, Alignment.MIDDLE_CENTER);
    windowLayout.setExpandRatio(mainGrid, 5);
    windowLayout.setWidth("1250px");
    return windowLayout;
}

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);//  w  w  w.  j a v  a2  s . c o  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.userinterface.windows.PreferencesWindow.java

private Component buildFooter(User user) {
    HorizontalLayout footer = new HorizontalLayout();
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    footer.setWidth(100.0f, Unit.PERCENTAGE);

    Button cancelButton = new Button(Language.get(Word.CANCEL));
    cancelButton.setIcon(VaadinIcons.CLOSE);
    cancelButton.addClickListener(event -> {
        close();//from   w  ww  . j  ava2s.c om
    });

    saveButton = new Button(Language.get(Word.SAVE));
    saveButton.setIcon(VaadinIcons.CHECK);
    saveButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
    saveButton.addClickListener(event -> {
        boolean error = false;
        if (!user.getFirstName().equals(firstNameField.getValue())) {
            boolean success = UserUtils.changeFirstName(user, firstNameField.getValue());
            if (!success) {
                error = true;
            }
        }
        if (!user.getLastName().equals(lastNameField.getValue())) {
            boolean success = UserUtils.changeLastName(user, lastNameField.getValue());
            if (!success) {
                error = true;
            }
        }
        if (!user.getUsername().equals(usernameField.getValue())) {
            boolean success = UserUtils.changeUsername(user, usernameField.getValue());
            if (!success) {
                error = true;
            }
        }
        if (!user.getEmail().equals(emailField.getValue())) {
            UI.getCurrent().addWindow(ActivateWindow.get());
            boolean success = UserUtils.changeEmail(user, user.getEmail(), emailField.getValue(),
                    emailField.getValue());
            if (!success) {
                error = true;
            }
        }
        boolean wrongPW = false;
        if (!password1Field.isEmpty() && password1Field.getValue().equals(password2Field.getValue())) {
            wrongPW = !UserUtils.changePassword(user, oldPasswordField.getValue(), password1Field.getValue(),
                    password2Field.getValue());
        }
        if (error) {
            VaadinUtils.errorNotification(Language.get(Word.UNEXPECTED_ERROR));
        } else if (wrongPW) {
            VaadinUtils.errorNotification(Language.get(Word.WRONG_PASSWORD));
        } else {
            VaadinUtils.infoNotification(Language.get(Word.SUCCESSFULLY_SAVED));
            close();
        }
    });
    saveButton.focus();

    Label placeholder = new Label();

    footer.addComponents(placeholder, cancelButton, saveButton);
    footer.setExpandRatio(placeholder, 5);
    footer.setComponentAlignment(cancelButton, Alignment.TOP_CENTER);
    footer.setComponentAlignment(saveButton, Alignment.TOP_CENTER);
    return footer;
}

From source file:dhbw.clippinggorilla.userinterface.windows.RegisterWindow.java

public RegisterWindow() {
    setModal(true);//from w w  w  .ja  v  a 2 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:edu.kit.dama.ui.admin.ProfileView.java

License:Apache License

/**
 * Build the main layout.//w w  w  .j  a  v  a 2 s.c  om
 */
private void buildMainLayout() {
    //information area
    screenName = new Label();
    screenName.setCaption("Screen Name:");
    screenName.setStyleName("form");
    firstName = new Label();
    firstName.setCaption("First Name:");
    firstName.setStyleName("form");
    lastName = new Label();
    lastName.setCaption("Last Name:");
    lastName.setStyleName("form");
    email = new Label();
    email.setCaption("Email:");
    email.setStyleName("form");
    FormLayout userInformationForm = new FormLayout(screenName, firstName, lastName, email);
    userInformationForm.setStyleName("form");
    userInformationForm.setCaption("User Information");
    tokenDialog = new ServiceAccessTokenDialog();
    //Credentials
    //table with serviceId, key, secret for logged in userId
    //---mainLogin and webdav are special (username = email), others can be configured in AuthenticatorFactory
    //---support for adding/regenerating new tokens (support for random secrets)
    //---support for blocking?
    //---'show secrets' button
    credentialTable = new Table("Credentials");
    credentialTable.setSelectable(true);
    credentialTable.setMultiSelect(false);
    credentialTable.addContainerProperty("ServiceId", String.class, null);
    credentialTable.addContainerProperty("Key", String.class, null);
    credentialTable.addContainerProperty("Secret", String.class, null);
    credentialTable.addStyleName("myboldcaption");
    credentialTable.setSizeFull();

    Button addCredential = new Button();
    addCredential.setIcon(new ThemeResource(IconContainer.ADD));
    Button modifyCredential = new Button();
    modifyCredential.setIcon(new ThemeResource(IconContainer.EDIT));
    Button removeCredential = new Button();
    removeCredential.setIcon(new ThemeResource(IconContainer.DELETE));
    Button reloadCredentialTable = new Button();
    reloadCredentialTable.setIcon(new ThemeResource(IconContainer.REFRESH));
    reloadCredentialTable.addClickListener(((event) -> {
        reload();
    }));

    CheckBox showPasswords = new CheckBox("Show Secrets");
    showPasswords.addValueChangeListener((Property.ValueChangeEvent event) -> {
        showSecrets(showPasswords.getValue());
    });

    removeCredential.addClickListener((event) -> {
        Long selection = (Long) credentialTable.getValue();
        if (selection != null) {
            ConfirmationWindow7.showConfirmation("Delete Credential",
                    "If you delete the selected credential, you won't be able to access the associated service any longer.<br/> "
                            + "Do you wish to proceed?",
                    ConfirmationWindow7.OPTION_TYPE.YES_NO_OPTION, ConfirmationWindow7.MESSAGE_TYPE.WARNING,
                    (ConfirmationWindow7.RESULT pResult) -> {
                        switch (pResult) {
                        case YES:
                            removeCredential(selection);
                            break;
                        default:
                            //do nothing
                        }
                    });
        }

    });

    modifyCredential.addClickListener((event) -> {
        Long selection = (Long) credentialTable.getValue();
        if (selection != null) {
            updateCredential(selection);
        }
    });

    addCredential.addClickListener((event) -> {
        createCredential();
    });

    VerticalLayout buttonLayout = new VerticalLayout(addCredential, modifyCredential, removeCredential,
            reloadCredentialTable);

    buttonLayout.setComponentAlignment(modifyCredential, Alignment.TOP_LEFT);
    buttonLayout.setComponentAlignment(removeCredential, Alignment.TOP_LEFT);
    buttonLayout.setComponentAlignment(reloadCredentialTable, Alignment.TOP_LEFT);
    buttonLayout.setMargin(true);

    UIUtils7.GridLayoutBuilder builder = new UIUtils7.GridLayoutBuilder(2, 3);

    builder.fillRow(userInformationForm, 0, 0, 1);
    builder.addComponent(credentialTable, 0, 1).addComponent(buttonLayout, 1, 1);
    builder.fillRow(showPasswords, 0, 2, 1);
    mainLayout = builder.getLayout();

    mainLayout.setSpacing(true);
    mainLayout.setMargin(true);
    mainLayout.setRowExpandRatio(1, 1.0f);
    mainLayout.setColumnExpandRatio(0, .9f);
    mainLayout.setColumnExpandRatio(1, .1f);
    mainLayout.setSizeFull();
    reload();
}

From source file:edu.kit.dama.ui.admin.schedule.SchedulerBasePropertiesLayout.java

License:Apache License

/**
 * Default constructor./*from  ww  w .  j  ava2s .c  o  m*/
 */
public SchedulerBasePropertiesLayout() {
    super();
    LOGGER.debug("Building " + DEBUG_ID_PREFIX + " ...");

    setId(DEBUG_ID_PREFIX.substring(0, DEBUG_ID_PREFIX.length() - 1));

    setSizeFull();
    setMargin(true);
    setSpacing(true);

    setColumns(3);
    setRows(3);
    //first row
    addComponent(getIdField(), 0, 0);
    addComponent(getGroupField(), 1, 0);
    addComponent(getNameField(), 2, 0);

    //second row
    addComponent(getDescriptionArea(), 0, 1, 2, 1);
    Button addTriggerButton = new Button();
    addTriggerButton.setDescription("Add a new trigger.");
    addTriggerButton.setIcon(new ThemeResource(IconContainer.ADD));
    addTriggerButton.addClickListener((Button.ClickEvent event) -> {
        addTrigger();
    });

    Button removeTriggerButton = new Button();
    removeTriggerButton.setDescription("Remove the selected trigger.");
    removeTriggerButton.setIcon(new ThemeResource(IconContainer.DELETE));
    removeTriggerButton.addClickListener((Button.ClickEvent event) -> {
        removeTrigger();
    });

    Button refreshTriggerButton = new Button();
    refreshTriggerButton.setDescription("Refresh the list of triggers.");
    refreshTriggerButton.setIcon(new ThemeResource(IconContainer.REFRESH));
    refreshTriggerButton.addClickListener((Button.ClickEvent event) -> {
        reloadTriggers();
    });

    VerticalLayout buttonLayout = new VerticalLayout(addTriggerButton, refreshTriggerButton,
            removeTriggerButton);
    buttonLayout.setComponentAlignment(addTriggerButton, Alignment.TOP_RIGHT);
    buttonLayout.setComponentAlignment(removeTriggerButton, Alignment.TOP_RIGHT);
    buttonLayout.setMargin(true);

    GridLayout triggerLayout = new UIUtils7.GridLayoutBuilder(2, 2).addComponent(getTriggerTable(), 0, 0, 1, 2)
            .addComponent(buttonLayout, 1, 0, 1, 2).getLayout();
    triggerLayout.setSizeFull();
    triggerLayout.setMargin(false);
    triggerLayout.setColumnExpandRatio(0, .95f);
    triggerLayout.setColumnExpandRatio(1, .05f);
    triggerLayout.setRowExpandRatio(0, .9f);
    triggerLayout.setRowExpandRatio(1, .05f);
    triggerLayout.setRowExpandRatio(2, .05f);

    //third row
    addComponent(triggerLayout, 0, 2, 2, 2);
    addTriggerComponent = new AddTriggerComponent(this);

    setRowExpandRatio(1, .3f);
    setRowExpandRatio(2, .6f);
}

From source file:edu.kit.dama.ui.admin.workflow.DataWorkflowBasePropertiesLayout.java

License:Apache License

public DataWorkflowBasePropertiesLayout() {
    LOGGER.debug("Building " + DEBUG_ID_PREFIX + " ...");

    setId(DEBUG_ID_PREFIX.substring(0, DEBUG_ID_PREFIX.length() - 1));
    setSizeFull();/*from  w  w w. j a  v  a  2 s.  co  m*/
    setMargin(true);
    setSpacing(true);
    setCaption("TASK CONFIGURATION");

    setColumns(4);
    setRows(6);
    //first row
    addComponent(getNameField(), 0, 0);
    addComponent(getVersionField(), 1, 0);
    addComponent(getContactBox(), 2, 0);
    addComponent(getGroupBox(), 3, 0);
    //second row
    addComponent(getApplicationPackageUrlField(), 0, 1, 1, 1);
    addComponent(getApplicationArgumentsField(), 2, 1);
    //addComponent(getCheckBoxesLayout(), 3, 1, 3, 2);
    //add placeholder only
    addComponent(new VerticalLayout(), 3, 1, 3, 2);
    Label l = new Label("* Changing fields with a red border will update the version of the associated task.");
    l.addStyleName("red-text");
    addComponent(l, 0, 2, 2, 2);
    l.setHeight("12px");
    setComponentAlignment(l, Alignment.TOP_CENTER);

    //
    addComponent(getKeywordsField(), 0, 3, 2, 3);
    //
    addComponent(getDescriptionArea(), 0, 4, 2, 5);

    Button addPropertyButton = new Button();
    addPropertyButton.setIcon(new ThemeResource(IconContainer.ADD));
    addPropertyButton.addClickListener((Button.ClickEvent event) -> {
        addPropertyComponent.reset();
        addPropertyComponent.showWindow();
    });

    HorizontalLayout layout = new HorizontalLayout(getEnvironmentPropertiesSelect(), addPropertyButton);
    layout.setComponentAlignment(getEnvironmentPropertiesSelect(), Alignment.TOP_LEFT);
    layout.setComponentAlignment(addPropertyButton, Alignment.BOTTOM_RIGHT);
    layout.setSizeFull();
    layout.setExpandRatio(getEnvironmentPropertiesSelect(), .95f);
    layout.setExpandRatio(addPropertyButton, .05f);
    addComponent(layout, 3, 3, 3, 5);

    //add popup to layout
    addPropertyComponent = new AddEnvironmentPropertyComponent(this);

    //set dummy row height to 0
    setColumnExpandRatio(0, 0.2f);
    setColumnExpandRatio(1, 0.15f);
    setColumnExpandRatio(2, 0.2f);
    setColumnExpandRatio(3, 0.25f);
    setRowExpandRatio(5, 1f);

}