Example usage for com.vaadin.ui VerticalLayout setSpacing

List of usage examples for com.vaadin.ui VerticalLayout setSpacing

Introduction

In this page you can find the example usage for com.vaadin.ui VerticalLayout setSpacing.

Prototype

@Override
    public void setSpacing(boolean spacing) 

Source Link

Usage

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

public void createClippingViewByProfile(Clipping clipping) {
    clippingArticlesLayout.removeAllComponents();
    if (clipping.getArticles().keySet().isEmpty() && clipping.getArticlesFromGroup().keySet().isEmpty()) {
        Label labelNoProfile = new Label();
        Language.setCustom(Word.NO_PROFILE_PRESENT, s -> labelNoProfile.setValue(s));
        labelNoProfile.addStyleName(ValoTheme.LABEL_H2);
        clippingArticlesLayout.addComponent(labelNoProfile);
    } else {//from   ww  w. j  ava2 s  .c o  m
        clipping.getArticles().entrySet().stream().forEach(p -> {
            VerticalLayout layoutProfile = new VerticalLayout();
            layoutProfile.setSpacing(true);
            layoutProfile.setMargin(true);
            layoutProfile.addStyleName("tags");
            layoutProfile.setWidth("100%");
            if (p.getValue().isEmpty()) {
                Label labelNoArticles = new Label();
                Language.setCustom(Word.NO_ARTICLES_PRESENT, s -> labelNoArticles.setValue(s));
                labelNoArticles.addStyleName(ValoTheme.LABEL_H3);
                layoutProfile.addComponent(labelNoArticles);
            } else {
                p.getValue().forEach(a -> layoutProfile.addComponent(createClippingRow(a)));
            }
            Panel panelProfile = new Panel(p.getKey().getName(), layoutProfile);
            clippingArticlesLayout.addComponent(panelProfile);
        });
        clipping.getArticlesFromGroup().entrySet().stream().forEach(p -> {
            VerticalLayout layoutProfile = new VerticalLayout();
            layoutProfile.setSpacing(true);
            layoutProfile.setMargin(true);
            layoutProfile.addStyleName("tags");
            layoutProfile.setWidth("100%");
            if (p.getValue().isEmpty()) {
                Label labelNoArticles = new Label();
                Language.setCustom(Word.NO_ARTICLES_PRESENT, s -> labelNoArticles.setValue(s));
                labelNoArticles.addStyleName(ValoTheme.LABEL_H3);
                layoutProfile.addComponent(labelNoArticles);
            } else {
                p.getValue().forEach(a -> layoutProfile.addComponent(createClippingRow(a)));
            }
            Panel panelProfile = new Panel(Language.get(Word.GROUP) + " " + p.getKey().getGroup().getName()
                    + ": " + p.getKey().getName(), layoutProfile);
            Language.setCustom(Word.GROUP, s -> panelProfile
                    .setCaption(s + " " + p.getKey().getGroup().getName() + ": " + p.getKey().getName()));
            clippingArticlesLayout.addComponent(panelProfile);
        });
    }
}

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

public Component createClippingRow(Article a) {
    Image imageNewsImage = new Image();
    String url = a.getUrlToImage();
    if (url == null || url.isEmpty()) {
        url = a.getSourceAsSource().getLogo().toExternalForm();
    }/*from   w  w  w . j  ava 2 s.  c  o m*/
    imageNewsImage.setSource(new ExternalResource(url));
    imageNewsImage.addStyleName("articleimage");

    VerticalLayout layoutNewsImage = new VerticalLayout(imageNewsImage);
    layoutNewsImage.setMargin(false);
    layoutNewsImage.setSpacing(false);
    layoutNewsImage.setWidth("200px");
    layoutNewsImage.setHeight("150px");
    layoutNewsImage.setComponentAlignment(imageNewsImage, Alignment.MIDDLE_CENTER);

    Label labelHeadLine = new Label(a.getTitle(), ContentMode.HTML);
    labelHeadLine.addStyleName(ValoTheme.LABEL_H2);
    labelHeadLine.addStyleName(ValoTheme.LABEL_NO_MARGIN);
    labelHeadLine.setWidth("100%");

    Label labelDescription = new Label(a.getDescription(), ContentMode.HTML);
    labelDescription.setWidth("100%");

    Image imageSource = new Image();
    Source s = a.getSourceAsSource();
    URL logo;
    if (s != null) {
        logo = s.getLogo();
    } else {
        Log.error("Source is null: " + a.getSource());
        return new Label("INTERNAL ERROR");
    }
    if (logo != null) {
        imageSource.setSource(new ExternalResource(logo));
    } else {
        Log.error("Sourcelogo is null: " + s.getName());
    }
    imageSource.setHeight("30px");
    Label labelSource = new Label(a.getSourceAsSource().getName());
    labelSource.addStyleName(ValoTheme.LABEL_SMALL);

    LocalDateTime time = a.getPublishedAtAsLocalDateTime();
    DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG);
    formatter.withZone(ZoneId.of("Europe/Berlin"));
    Label labelDate = new Label(time.format(formatter));
    labelDate.addStyleName(ValoTheme.LABEL_SMALL);

    Label labelAuthor = new Label();
    labelAuthor.addStyleName(ValoTheme.LABEL_SMALL);
    labelAuthor.setWidth("100%");
    if (a.getAuthor() != null && !a.getAuthor().isEmpty()) {
        labelAuthor.setValue(a.getAuthor());
    }

    Button openWebsite = new Button(VaadinIcons.EXTERNAL_LINK);
    openWebsite.addClickListener(e -> UI.getCurrent().getPage().open(a.getUrl(), "_blank", false));

    HorizontalLayout layoutArticleOptions = new HorizontalLayout();
    layoutArticleOptions.setWidth("100%");
    layoutArticleOptions.addComponents(imageSource, labelSource, labelDate, labelAuthor, openWebsite);
    layoutArticleOptions.setComponentAlignment(imageSource, Alignment.MIDDLE_CENTER);
    layoutArticleOptions.setComponentAlignment(labelSource, Alignment.MIDDLE_CENTER);
    layoutArticleOptions.setComponentAlignment(labelDate, Alignment.MIDDLE_CENTER);
    layoutArticleOptions.setComponentAlignment(labelAuthor, Alignment.MIDDLE_LEFT);
    layoutArticleOptions.setComponentAlignment(openWebsite, Alignment.MIDDLE_CENTER);
    layoutArticleOptions.setExpandRatio(labelAuthor, 5);

    VerticalLayout layoutNewsText = new VerticalLayout(labelHeadLine, labelDescription, layoutArticleOptions);
    layoutNewsText.setMargin(false);
    layoutNewsText.setWidth("100%");

    HorizontalLayout layoutClipping = new HorizontalLayout();
    layoutClipping.setWidth("100%");
    layoutClipping.setMargin(true);
    layoutClipping.addComponents(layoutNewsImage, layoutNewsText);
    layoutClipping.setComponentAlignment(layoutNewsImage, Alignment.MIDDLE_CENTER);
    layoutClipping.setExpandRatio(layoutNewsText, 5);
    layoutClipping.addStyleName(ValoTheme.LAYOUT_CARD);
    layoutClipping.addStyleName("tags");
    return layoutClipping;
}

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

public void createClippingViewByProfile(Clipping clipping) {
    clippingArticlesLayout.removeAllComponents();
    clipping.getArticles().entrySet().stream().forEach(p -> {
        VerticalLayout layoutProfile = new VerticalLayout();
        layoutProfile.setSpacing(true);
        layoutProfile.setMargin(true);//from   w  ww . j a  va 2  s.  c om
        layoutProfile.addStyleName("tags");
        layoutProfile.setWidth("100%");
        if (p.getValue().isEmpty()) {
            Label labelNoArticles = new Label();
            Language.setCustom(Word.NO_ARTICLES_PRESENT, s -> labelNoArticles.setValue(s));
            labelNoArticles.addStyleName(ValoTheme.LABEL_H3);
            layoutProfile.addComponent(labelNoArticles);
        } else {
            p.getValue().forEach(a -> layoutProfile.addComponent(createClippingRow(a)));
        }
        Panel panelProfile = new Panel(p.getKey().getName(), layoutProfile);
        clippingArticlesLayout.addComponent(panelProfile);
    });
    clipping.getArticlesFromGroup().entrySet().stream().forEach(p -> {
        VerticalLayout layoutProfile = new VerticalLayout();
        layoutProfile.setSpacing(true);
        layoutProfile.setMargin(true);
        layoutProfile.addStyleName("tags");
        layoutProfile.setWidth("100%");
        if (p.getValue().isEmpty()) {
            Label labelNoArticles = new Label();
            Language.setCustom(Word.NO_ARTICLES_PRESENT, s -> labelNoArticles.setValue(s));
            labelNoArticles.addStyleName(ValoTheme.LABEL_H3);
            layoutProfile.addComponent(labelNoArticles);
        } else {
            p.getValue().forEach(a -> layoutProfile.addComponent(createClippingRow(a)));
        }
        Panel panelProfile = new Panel(
                Language.get(Word.GROUP) + " " + p.getKey().getGroup().getName() + ": " + p.getKey().getName(),
                layoutProfile);
        Language.setCustom(Word.GROUP, s -> panelProfile
                .setCaption(s + " " + p.getKey().getGroup().getName() + ": " + p.getKey().getName()));
        clippingArticlesLayout.addComponent(panelProfile);
    });
}

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

public Component createClippingRow(Article a) {
    Image imageNewsImage = new Image();
    String url = a.getUrlToImage();
    if (url == null || url.isEmpty()) {
        url = a.getSourceAsSource().getLogo().toExternalForm();
    }/*from  w  w  w  .j  a  v  a 2s.co m*/
    imageNewsImage.setSource(new ExternalResource(url));
    imageNewsImage.addStyleName("articleimage");

    VerticalLayout layoutNewsImage = new VerticalLayout(imageNewsImage);
    layoutNewsImage.setMargin(false);
    layoutNewsImage.setSpacing(false);
    layoutNewsImage.setWidth("200px");
    layoutNewsImage.setHeight("150px");
    layoutNewsImage.setComponentAlignment(imageNewsImage, Alignment.MIDDLE_CENTER);

    Label labelHeadLine = new Label(a.getTitle(), ContentMode.HTML);
    labelHeadLine.addStyleName(ValoTheme.LABEL_H2);
    labelHeadLine.addStyleName(ValoTheme.LABEL_NO_MARGIN);
    labelHeadLine.setWidth("100%");

    Label labelDescription = new Label(a.getDescription(), ContentMode.HTML);
    labelDescription.setWidth("100%");

    Image imageSource = new Image();
    Source s = a.getSourceAsSource();
    URL logo = null;
    if (s != null) {
        logo = s.getLogo();
    } else {
        Log.error("Source is null: " + a.getSource());
        return new Label("INTERNAL ERROR");
    }
    if (logo != null) {
        imageSource.setSource(new ExternalResource(logo));
    } else {
        Log.error("Sourcelogo is null: " + s.getName());
    }
    imageSource.setHeight("30px");
    Label labelSource = new Label(a.getSourceAsSource().getName());
    labelSource.addStyleName(ValoTheme.LABEL_SMALL);

    LocalDateTime time = a.getPublishedAtAsLocalDateTime();
    DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG);
    formatter.withZone(ZoneId.of("Europe/Berlin"));
    Label labelDate = new Label(time.format(formatter));
    labelDate.addStyleName(ValoTheme.LABEL_SMALL);

    Label labelAuthor = new Label();
    labelAuthor.addStyleName(ValoTheme.LABEL_SMALL);
    labelAuthor.setWidth("100%");
    if (a.getAuthor() != null && !a.getAuthor().isEmpty()) {
        labelAuthor.setValue(a.getAuthor());
    }

    Button openWebsite = new Button(VaadinIcons.EXTERNAL_LINK);
    openWebsite.addClickListener(e -> UI.getCurrent().getPage().open(a.getUrl(), "_blank", false));

    HorizontalLayout layoutArticleOptions = new HorizontalLayout();
    layoutArticleOptions.setWidth("100%");
    layoutArticleOptions.addComponents(imageSource, labelSource, labelDate, labelAuthor, openWebsite);
    layoutArticleOptions.setComponentAlignment(imageSource, Alignment.MIDDLE_CENTER);
    layoutArticleOptions.setComponentAlignment(labelSource, Alignment.MIDDLE_CENTER);
    layoutArticleOptions.setComponentAlignment(labelDate, Alignment.MIDDLE_CENTER);
    layoutArticleOptions.setComponentAlignment(labelAuthor, Alignment.MIDDLE_LEFT);
    layoutArticleOptions.setComponentAlignment(openWebsite, Alignment.MIDDLE_CENTER);
    layoutArticleOptions.setExpandRatio(labelAuthor, 5);

    VerticalLayout layoutNewsText = new VerticalLayout(labelHeadLine, labelDescription, layoutArticleOptions);
    layoutNewsText.setMargin(false);
    layoutNewsText.setWidth("100%");

    HorizontalLayout layoutClipping = new HorizontalLayout();
    layoutClipping.setWidth("100%");
    layoutClipping.setMargin(true);
    layoutClipping.addComponents(layoutNewsImage, layoutNewsText);
    layoutClipping.setComponentAlignment(layoutNewsImage, Alignment.MIDDLE_CENTER);
    layoutClipping.setExpandRatio(layoutNewsText, 5);
    layoutClipping.addStyleName(ValoTheme.LAYOUT_CARD);
    layoutClipping.addStyleName("tags");
    return layoutClipping;
}

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

public VerticalLayout createTab(Group g) {
    User u = UserUtils.getCurrent();//w w  w  . j av  a  2s  . c o  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.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);/*from  w  w w . j a  v  a2 s.c  o 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 ww  .  j  a v a2 s  .com
                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.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);
    root.setMargin(false);/*from  w w  w .  j a  va  2s. c  om*/
    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);

}

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.j a  v a 2s  . co  m*/
    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.GroupProfileWindow.java

public Component getSources(GroupInterestProfile profile, boolean isAdmin) {
    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()));
                sourceSelected.setEnabled(isAdmin);
                checkBoxes.add(sourceSelected);

                Image sourceLogo = new Image();
                sourceLogo.addStyleName("logosmall");
                sourceLogo.setSource(new ExternalResource(source.getLogo()));
                if (isAdmin) {
                    sourceLogo.addClickListener(c -> {
                        sourceSelected.setValue(!sourceSelected.getValue());
                        profile.getSources().replace(source, sourceSelected.getValue());
                    });//from  w  w  w.  j  a v  a  2s .  c om
                }
                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()));
    });
    checkBoxSelectAll.setEnabled(isAdmin);

    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;
}