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:de.uni_tuebingen.qbic.qbicmainportlet.SearchBarView.java

License:Open Source License

public void initUI() {
    mainlayout = new Panel();
    mainlayout.addStyleName(ValoTheme.PANEL_BORDERLESS);

    // static information for the user
    // Label info = new Label();
    // info.setValue(infotext);
    // info.setStyleName(ValoTheme.LABEL_LIGHT);
    // info.setStyleName(ValoTheme.LABEL_H4);
    // mainlayout.addComponent(info);

    // Search bar
    // *----------- search text field .... search button-----------*
    HorizontalLayout searchbar = new HorizontalLayout();
    searchbar.setSpacing(true);//ww w .  j  a  v  a2s. c o  m
    final TextField searchfield = new TextField();
    searchfield.setHeight("44px");
    searchfield.setImmediate(true);

    searchfield.setInputPrompt("search for sample");
    // TODO would be nice to have a autofill or something similar
    searchbar.addComponent(searchfield);
    Button searchOk = new Button("GoTo");
    searchOk.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    searchOk.setIcon(FontAwesome.SEARCH);
    searchOk.addClickListener(new ClickListener() {
        private static final long serialVersionUID = -2409450448301908214L;

        @Override
        public void buttonClick(ClickEvent event) {
            // TODO how to deal with entities
            Pattern pattern = Pattern.compile("Q[A-Z0-9]{4}[0-9]{3}[A-Z0-9]{2}");
            Pattern pattern2 = Pattern.compile("Q[A-Z0-9]{4}ENTITY-[0-9]+");

            LOGGER.info("searching for sample: " + (String) searchfield.getValue());

            if (searchfield.getValue() == null || searchfield.getValue().toString().equals("")) {
                Notification.show("Please provide a Barcode before clicking GoTo.", Type.WARNING_MESSAGE);
            }

            else {
                String entity = (String) searchfield.getValue().toString();

                Matcher matcher = pattern.matcher(entity);
                Matcher matcher2 = pattern2.matcher(entity);

                Boolean patternFound1 = matcher.find();
                Boolean patternFound2 = matcher2.find();

                if (patternFound1) {
                    try {
                        Sample foundSample = datahandler.getOpenBisClient()
                                .getSampleByIdentifier(matcher.group(0).toString());
                        String identifier = foundSample.getIdentifier();

                        State state = (State) UI.getCurrent().getSession().getAttribute("state");
                        ArrayList<String> message = new ArrayList<String>();
                        message.add("clicked");
                        message.add(identifier);
                        message.add("sample");
                        state.notifyObservers(message);
                    } catch (Exception e) {
                        Notification.show("No Sample found for given barcode.", Type.WARNING_MESSAGE);
                    }
                }

                else if (patternFound2) {
                    try {
                        Sample foundSample = datahandler.getOpenBisClient()
                                .getSampleByIdentifier(matcher2.group(0).toString());
                        String identifier = foundSample.getIdentifier();

                        State state = (State) UI.getCurrent().getSession().getAttribute("state");
                        ArrayList<String> message = new ArrayList<String>();
                        message.add("clicked");
                        message.add(identifier);
                        message.add("sample");
                        state.notifyObservers(message);
                    } catch (Exception e) {
                        Notification.show("No Sample found for given barcode.", Type.WARNING_MESSAGE);
                    }
                } else {
                    Notification.show("Please provide a valid Sample Barcode.", Type.WARNING_MESSAGE);
                }
            }
        }
    });

    // setClickShortcut() would add global shortcut, instead we
    // 'scope' the shortcut to the panel:
    mainlayout.addAction(new com.vaadin.ui.Button.ClickShortcut(searchOk, KeyCode.ENTER));
    // searchfield.addItems(this.getSearchResults("Q"));
    searchfield.setDescription(infotext);
    searchfield.addValidator(new NullValidator("Field must not be empty", false));
    searchfield.setValidationVisible(false);

    searchbar.addComponent(searchOk);
    // searchbar.setMargin(new MarginInfo(true, false, true, false));
    mainlayout.setContent(searchbar);
    // mainlayout.setComponentAlignment(searchbar, Alignment.MIDDLE_RIGHT);
    // mainlayout.setWidth(100, Unit.PERCENTAGE);
    setCompositionRoot(mainlayout);
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.SearchEngineView.java

License:Open Source License

public void initUI() {

    mainlayout = new Panel();
    mainlayout.addStyleName(ValoTheme.PANEL_BORDERLESS);

    // Search bar
    // *----------- search text field .... search button-----------*
    VerticalLayout searchbar = new VerticalLayout();
    searchbar.setWidth(100, Unit.PERCENTAGE);
    setResponsive(true);//w w w  .  ja  v a  2  s .  co  m
    searchbar.setResponsive(true);
    // searchbar.setWidth();

    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setResponsive(true);
    buttonLayout.setWidth(75, Unit.PERCENTAGE);

    // searchbar.setSpacing(true);
    final TextField searchfield = new TextField();
    searchfield.setHeight("44px");
    searchfield.setImmediate(true);
    searchfield.setResponsive(true);
    searchfield.setWidth(75, Unit.PERCENTAGE);

    buttonLayout.setSpacing(true);

    searchfield.setInputPrompt("search DB");
    // searchfield.setCaption("QSearch");
    // searchfield.setWidth(25.0f, Unit.EM);
    // searchfield.setWidth(60, Unit.PERCENTAGE);

    // TODO would be nice to have a autofill or something similar
    // searchFieldLayout.addComponent(searchfield);
    searchbar.addComponent(searchfield);
    searchbar.setComponentAlignment(searchfield, Alignment.MIDDLE_RIGHT);

    final NativeSelect navsel = new NativeSelect();
    navsel.addItem("Whole DB");
    navsel.addItem("Projects Only");
    navsel.addItem("Experiments Only");
    navsel.addItem("Samples Only");
    navsel.setValue("Whole DB");
    navsel.setHeight("20px");
    navsel.setNullSelectionAllowed(false);
    navsel.setResponsive(true);
    navsel.setWidth(100, Unit.PERCENTAGE);

    navsel.addValueChangeListener(new Property.ValueChangeListener() {

        /**
         * 
         */
        private static final long serialVersionUID = -6896454887050432147L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            // TODO Auto-generated method stub
            Notification.show((String) navsel.getValue());

            switch ((String) navsel.getValue()) {
            case "Whole DB":
                datahandler.setShowOptions(Arrays.asList("Projects", "Experiments", "Samples"));
                break;
            case "Projects Only":
                datahandler.setShowOptions(Arrays.asList("Projects"));
                break;
            case "Experiments Only":
                datahandler.setShowOptions(Arrays.asList("Experiments"));
                break;
            case "Samples Only":
                datahandler.setShowOptions(Arrays.asList("Samples"));
                break;
            default:
                datahandler.setShowOptions(Arrays.asList("Projects", "Experiments", "Samples"));
                break;
            }

        }
    });

    searchbar.addComponent(buttonLayout);
    searchbar.setComponentAlignment(buttonLayout, Alignment.MIDDLE_RIGHT);
    Button searchOk = new Button("");
    searchOk.setStyleName(ValoTheme.BUTTON_TINY);
    // searchOk.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    searchOk.setIcon(FontAwesome.SEARCH);
    searchOk.setSizeUndefined();
    // searchOk.setWidth(15.0f, Unit.EM);
    searchOk.setResponsive(true);
    searchOk.setHeight("20px");

    searchOk.addClickListener(new ClickListener() {
        private static final long serialVersionUID = -2409450448301908214L;

        @Override
        public void buttonClick(ClickEvent event) {
            String queryString = (String) searchfield.getValue().toString();

            LOGGER.debug("the query was " + queryString);

            if (searchfield.getValue() == null || searchfield.getValue().toString().equals("")
                    || searchfield.getValue().toString().trim().length() == 0) {
                Notification.show("Query field was empty!", Type.WARNING_MESSAGE);
            } else {

                try {
                    /**
                     * Sample foundSample = datahandler.getOpenBisClient() .getSampleByIdentifier(
                     * matcher.group(0).toString());
                     */

                    datahandler.setSampleResults(querySamples(queryString));
                    datahandler.setExpResults(queryExperiments(queryString));
                    datahandler.setProjResults(queryProjects(queryString));
                    datahandler.setLastQueryString(queryString);

                    State state = (State) UI.getCurrent().getSession().getAttribute("state");
                    ArrayList<String> message = new ArrayList<String>();
                    message.add("clicked");
                    message.add("view" + queryString);
                    message.add("searchresults");
                    state.notifyObservers(message);

                } catch (Exception e) {
                    LOGGER.error("after query: ", e);
                    Notification.show("No Sample found for given barcode.", Type.WARNING_MESSAGE);
                }
            }

        }

    });

    // setClickShortcut() would add global shortcut, instead we
    // 'scope' the shortcut to the panel:
    mainlayout.addAction(new com.vaadin.ui.Button.ClickShortcut(searchOk, KeyCode.ENTER));
    // searchfield.addItems(this.getSearchResults("Q"));
    searchfield.setDescription(infotext);
    searchfield.addValidator(new NullValidator("Field must not be empty", false));
    searchfield.setValidationVisible(false);

    buttonLayout.addComponent(navsel);
    // buttonLayout.addComponent(new Label(""));
    buttonLayout.addComponent(searchOk);

    // searchFieldLayout.setComponentAlignment(searchOk, Alignment.TOP_RIGHT);
    // buttonLayout.setExpandRatio(searchOk, 1);
    // buttonLayout.setExpandRatio(navsel, 1);

    // searchFieldLayout.setSpacing(true);
    buttonLayout.setComponentAlignment(searchOk, Alignment.BOTTOM_RIGHT);
    // buttonLayout.setComponentAlignment(navsel, Alignment.BOTTOM_LEFT);

    buttonLayout.setExpandRatio(searchOk, 1);
    buttonLayout.setExpandRatio(navsel, 2);

    // searchbar.setMargin(new MarginInfo(true, false, true, false));
    mainlayout.setContent(searchbar);
    // mainlayout.setComponentAlignment(searchbar, Alignment.MIDDLE_RIGHT);
    // mainlayout.setWidth(100, Unit.PERCENTAGE);
    setCompositionRoot(mainlayout);
}

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);/*w  w w .j av  a2  s . com*/
    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);//ww  w  .  j a  v  a2s. co 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 GroupView() {
    User user = UserUtils.getCurrent();/*from  w  ww.  j a v  a  2s  . c  om*/
    Set<Group> groups = UserUtils.getAllGroups(user);

    CssLayout newGroupGroup = new CssLayout();
    newGroupGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);

    TextField textFieldNewGroupName = new TextField();
    Language.setCustom(Word.GROUP_NAME, s -> textFieldNewGroupName.setPlaceholder(s));
    textFieldNewGroupName.setWidth("260px");
    textFieldNewGroupName.setMaxLength(255);
    newGroupGroup.addComponent(textFieldNewGroupName);

    Button buttonNewGroup = new Button();
    buttonNewGroup.setIcon(VaadinIcons.PLUS);
    buttonNewGroup.addStyleName(ValoTheme.BUTTON_PRIMARY);
    buttonNewGroup.addClickListener(e -> {
        TabSheet.Tab newTab = accordion.addTab(createTab(createEmptyGroup(textFieldNewGroupName.getValue())),
                textFieldNewGroupName.getValue());
        accordion.setSelectedTab(newTab);
        accordion.setWidth("100%");
        textFieldNewGroupName.clear();
    });
    newGroupGroup.addComponent(buttonNewGroup);
    textFieldNewGroupName
            .addFocusListener(f -> buttonNewGroup.setClickShortcut(ShortcutAction.KeyCode.ENTER, null));
    textFieldNewGroupName.addBlurListener(f -> buttonNewGroup.removeClickShortcut());

    groups.forEach(g -> {
        accordion.addTab(createTab(g), g.getName());
    });
    addComponents(newGroupGroup, accordion);
    //SESSIONS.put(user, this);
}

From source file:dhbw.clippinggorilla.userinterface.views.GroupView.java

public VerticalLayout createTab(Group g) {
    User u = UserUtils.getCurrent();//from w  w  w  .  j  ava2 s  .  com
    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 Component getProfiles(Group g) {
    VerticalLayout layoutRootProfiles = new VerticalLayout();
    layoutRootProfiles.setMargin(false);
    layoutRootProfiles.setWidth("100%");
    Panel panelProfiles = new Panel(Language.get(Word.PROFILES));
    Language.setCustom(Word.PROFILES, s -> panelProfiles.setCaption(s));
    panelProfiles.setWidth("100%");
    panelProfiles.setHeight("200px");

    VerticalLayout layoutProfiles = new VerticalLayout();
    mapLayoutProfiles.put(g, layoutProfiles);
    layoutProfiles.setWidth("100%");

    refreshProfiles(g, layoutProfiles);//from ww  w . ja va  2 s  . c o m

    panelProfiles.setContent(layoutProfiles);
    layoutRootProfiles.addComponent(panelProfiles);

    if (GroupUtils.isAdmin(g, UserUtils.getCurrent())) {
        CssLayout addProfileGroup = new CssLayout();
        addProfileGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
        addProfileGroup.setWidth("100%");

        TextField textFieldAddProfile = new TextField();
        Language.setCustom(Word.PROFILE_NAME, s -> textFieldAddProfile.setPlaceholder(s));
        textFieldAddProfile.setMaxLength(255);
        textFieldAddProfile.setWidth("35%");
        addProfileGroup.addComponent(textFieldAddProfile);

        Button buttonAddProfile = new Button();
        buttonAddProfile.setIcon(VaadinIcons.PLUS);
        buttonAddProfile.addStyleName(ValoTheme.BUTTON_PRIMARY);
        buttonAddProfile.setWidth("15%");
        buttonAddProfile.addClickListener(e -> {
            try {
                String name = textFieldAddProfile.getValue();
                textFieldAddProfile.clear();
                Runnable onClose = () -> refreshAll(g);
                UI.getCurrent().addWindow(GroupProfileWindow.create(g, name, true, onClose));
            } catch (UserNotFoundException ex) {
                VaadinUtils.errorNotification(Language.get(Word.USER_NOT_FOUND));
            }
        });
        addProfileGroup.addComponent(buttonAddProfile);

        layoutRootProfiles.addComponent(addProfileGroup);
    }
    return layoutRootProfiles;
}

From source file:dhbw.clippinggorilla.userinterface.views.GroupView.java

private Component getMembers(Group g) {
    VerticalLayout layoutRootMembers = new VerticalLayout();
    layoutRootMembers.setMargin(false);/*from  w w  w  .ja  va  2 s .  c  om*/
    layoutRootMembers.setWidth("100%");
    Panel panelMembers = new Panel(Language.get(Word.MEMBERS));
    Language.setCustom(Word.MEMBERS, s -> panelMembers.setCaption(s));
    panelMembers.setWidth("100%");
    panelMembers.setHeight("200px");

    VerticalLayout layoutMembers = new VerticalLayout();
    mapLayoutMembers.put(g, layoutMembers);
    layoutMembers.setWidth("100%");

    refreshMembers(g, layoutMembers);

    panelMembers.setContent(layoutMembers);
    layoutRootMembers.addComponent(panelMembers);

    if (GroupUtils.isAdmin(g, UserUtils.getCurrent())) {
        CssLayout addUserGroup = new CssLayout();
        addUserGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
        addUserGroup.setWidth("100%");

        TextField textFieldaddUser = new TextField();
        Language.setCustom(Word.USERNAME, s -> textFieldaddUser.setPlaceholder(s));
        textFieldaddUser.setMaxLength(255);
        textFieldaddUser.setWidth("70%");
        addUserGroup.addComponent(textFieldaddUser);

        Button buttonAddUser = new Button();
        buttonAddUser.setIcon(VaadinIcons.PLUS);
        buttonAddUser.addStyleName(ValoTheme.BUTTON_PRIMARY);
        buttonAddUser.setWidth("30%");
        buttonAddUser.addClickListener(e -> {
            try {
                User u = UserUtils.getUser(textFieldaddUser.getValue());
                textFieldaddUser.clear();
                GroupUtils.addUser(g, u);
                refreshAll(g);
            } catch (UserNotFoundException ex) {
                VaadinUtils.errorNotification(Language.get(Word.USER_NOT_FOUND));
            }
        });
        addUserGroup.addComponent(buttonAddUser);

        layoutRootMembers.addComponent(addUserGroup);
    }

    return layoutRootMembers;
}

From source file:dhbw.clippinggorilla.userinterface.views.InterestProfileView.java

public InterestProfileView() {
    User user = UserUtils.getCurrent();/*from  ww w. j  a  va2 s.co  m*/
    Set<InterestProfile> profiles = UserUtils.getAllInterestProfiles(user);

    CssLayout newProfileGroup = new CssLayout();
    newProfileGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);

    TextField textFieldNewProfileName = new TextField();
    Language.setCustom(Word.PROFILE_NAME, s -> textFieldNewProfileName.setPlaceholder(s));
    textFieldNewProfileName.setWidth("260px");
    textFieldNewProfileName.setMaxLength(255);
    newProfileGroup.addComponent(textFieldNewProfileName);

    Button buttonNewProfile = new Button();
    buttonNewProfile.setIcon(VaadinIcons.PLUS);
    buttonNewProfile.addStyleName(ValoTheme.BUTTON_PRIMARY);
    buttonNewProfile.addClickListener(e -> {
        Tab newTab = accordion.addTab(createTab(createEmptyProfile(textFieldNewProfileName.getValue())),
                textFieldNewProfileName.getValue());
        accordion.setSelectedTab(newTab);
        accordion.setWidth("100%");
        textFieldNewProfileName.clear();
    });
    newProfileGroup.addComponent(buttonNewProfile);
    textFieldNewProfileName
            .addFocusListener(f -> buttonNewProfile.setClickShortcut(ShortcutAction.KeyCode.ENTER, null));
    textFieldNewProfileName.addBlurListener(f -> buttonNewProfile.removeClickShortcut());

    profiles.forEach((InterestProfile profile) -> {
        accordion.addTab(createTab(profile), profile.getName());
    });
    addComponents(newProfileGroup, accordion);
    SESSIONS.put(user, this);
}

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);/*w w w .jav a2  s. com*/
    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;
}