Example usage for com.vaadin.ui GridLayout setMargin

List of usage examples for com.vaadin.ui GridLayout setMargin

Introduction

In this page you can find the example usage for com.vaadin.ui GridLayout setMargin.

Prototype

@Override
    public void setMargin(MarginInfo marginInfo) 

Source Link

Usage

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

public GroupProfileWindow(GroupInterestProfile p, Runnable onClose, boolean isAdmin) {
    VerticalLayout profileSettingsLayout = new VerticalLayout();
    GridLayout windowContent;
    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();/*ww w . j a v a2  s.  c  om*/
            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  ww .ja  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;
}

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

private void addRow(GroupInterestProfile profile, boolean included, String value, boolean isAdmin) {
    GridLayout tagLayout = new GridLayout(2, 1);
    tagLayout.setWidth("100%");

    Label labelTagName = new Label(value, ContentMode.HTML);
    labelTagName.setWidth("100%");
    labelTagName.addStyleName(ValoTheme.LABEL_H3);
    labelTagName.addStyleName(ValoTheme.LABEL_NO_MARGIN);
    tagLayout.addComponent(labelTagName);
    tagLayout.setComponentAlignment(labelTagName, Alignment.MIDDLE_LEFT);

    if (isAdmin) {
        Button buttonDeleteTag = new Button(VaadinIcons.TRASH);
        buttonDeleteTag.addStyleName(ValoTheme.BUTTON_DANGER);
        buttonDeleteTag.addClickListener(ev -> {
            profile.getTags().remove(value);
            if (included) {
                includedTagsLayouts.get(profile).removeComponent(tagLayout);
            } else {
                excludedTagsLayouts.get(profile).removeComponent(tagLayout);
            }//from w  w  w .  j a va 2  s  .  com
        });
        tagLayout.addComponent(buttonDeleteTag);
        tagLayout.setComponentAlignment(buttonDeleteTag, Alignment.MIDDLE_RIGHT);
    }

    tagLayout.setWidth("100%");
    tagLayout.setColumnExpandRatio(0, 5);
    tagLayout.setSpacing(true);
    tagLayout.setMargin(false);

    if (included) {
        if (isAdmin) {
            includedTagsLayouts.get(profile).addComponent(tagLayout, 2);
        } else {
            includedTagsLayouts.get(profile).addComponent(tagLayout, 1);
        }
    } else {
        if (isAdmin) {
            excludedTagsLayouts.get(profile).addComponent(tagLayout, 2);
        } else {
            excludedTagsLayouts.get(profile).addComponent(tagLayout, 1);
        }
    }
}

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

/**
 * Value is optional/*from w w w . j  a va 2  s.  c  o  m*/
 *
 * @param action
 * @param content
 * @param value
 * @return
 */
private Component getRow(Layout parent, Runnable onDelete, String action, String content, String value) {
    Panel panelRow = new Panel();
    GridLayout layoutRow = new GridLayout(2, 1);

    Label labelInfo = new Label("", ContentMode.HTML);
    String stringInfo = action.toUpperCase() + "<br>";
    if (value != null) {
        stringInfo += content + " = " + value;
    } else {
        stringInfo += content + " ";
    }
    labelInfo.setValue(stringInfo);

    Button buttonDelete = new Button(VaadinIcons.TRASH);
    buttonDelete.addStyleName(ValoTheme.BUTTON_DANGER);
    buttonDelete.addClickListener(ce -> {
        onDelete.run();
        parent.removeComponent(panelRow);
    });

    layoutRow.addComponents(labelInfo, buttonDelete);
    layoutRow.setComponentAlignment(buttonDelete, Alignment.MIDDLE_RIGHT);
    layoutRow.setComponentAlignment(labelInfo, Alignment.MIDDLE_LEFT);
    layoutRow.setWidth("100%");
    layoutRow.setMargin(true);
    layoutRow.addStyleName("crawler");
    panelRow.setContent(layoutRow);
    panelRow.setWidth("100%");
    return panelRow;
}

From source file:edu.kit.dama.ui.admin.MainControlPanel.java

License:Apache License

/**
 * Build the main layout./*ww w.j  av a  2 s .c om*/
 */
private void buildMainLayout() {
    infoCell = createCell("img/128x128/information2.png", Alignment.TOP_RIGHT, 0,
            "<p>Show/edit your profile and personel settings.</p>", "help-right");
    profileCell = createCell("img/128x128/preferences.png", Alignment.TOP_LEFT, 1,
            "<p>Get information on how you use this KIT Data Manager instance.</p>", "help-left");
    administrationCell = createCell("img/128x128/gears_preferences.png", Alignment.BOTTOM_RIGHT, 2,
            "<p>Logout.</p>", "help-right");
    logoutCell = createCell("img/128x128/exit.png", Alignment.BOTTOM_LEFT, 3,
            "<p>Show KIT Data Manager settings.<br/>This view is only available for administrators and group manager</p>.",
            "help-left");

    GridLayout actionCellLayout = new UIUtils7.GridLayoutBuilder(2, 2)
            .addComponent(infoCell, Alignment.BOTTOM_RIGHT, 0, 0, 1, 1)
            .addComponent(profileCell, Alignment.BOTTOM_LEFT, 1, 0, 1, 1)
            .addComponent(administrationCell, Alignment.TOP_RIGHT, 0, 1, 1, 1)
            .addComponent(logoutCell, Alignment.TOP_LEFT, 1, 1, 1, 1).getLayout();
    actionCellLayout.setSpacing(true);
    actionCellLayout.setMargin(true);
    actionCellLayout.setSizeFull();

    actionCellLayout.addLayoutClickListener(new LayoutEvents.LayoutClickListener() {

        @Override
        public void layoutClick(LayoutEvents.LayoutClickEvent event) {
            if (event.getClickedComponent() instanceof Image) {
                // Check if childComponent is disabled
                if (!event.getChildComponent().isEnabled()) {
                    return;
                }
                Image img = (Image) event.getClickedComponent();
                if ("image0".equals(img.getId())) {
                    parent.updateView(AdminUIMainView.VIEW.INFORMATION);
                } else if ("image1".equals(img.getId())) {
                    parent.updateView(AdminUIMainView.VIEW.PROFILE);
                } else if ("image2".equals(img.getId())) {
                    parent.updateView(AdminUIMainView.VIEW.SETTINGS);
                } else if ("image3".equals(img.getId())) {
                    parent.logout();
                }
            }
        }
    });

    mainLayout = new VerticalLayout(actionCellLayout);
    mainLayout.setSizeFull();
}

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

License:Apache License

/**
 * Default constructor./*from  ww  w.j ava2  s . c  om*/
 */
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.schedule.trigger.AtTriggerConfigurationPanel.java

License:Apache License

@Override
public AbstractLayout getLayout() {
    GridLayout layout = new UIUtils7.GridLayoutBuilder(2, 5).addComponent(getGroupField(), 0, 0)
            .addComponent(getNameField(), 1, 0).addComponent(getPrioritySlider(), 0, 1, 2, 1)
            .addComponent(getAtDateField(), 0, 2, 2, 1).addComponent(getDescriptionField(), 0, 3, 2, 2)
            .getLayout();/*from w  w  w  .j a  v  a 2 s . com*/
    layout.setMargin(false);
    layout.setSpacing(true);
    layout.setSizeFull();
    return layout;
}

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

License:Apache License

@Override
public AbstractLayout getLayout() {
    GridLayout layout = new UIUtils7.GridLayoutBuilder(2, 6).addComponent(getGroupField(), 0, 0)
            .addComponent(getNameField(), 1, 0).addComponent(getPrioritySlider(), 0, 1, 2, 1)
            .addComponent(getStartDateField(), 0, 2, 1, 1).addComponent(getEndDateField(), 1, 2, 1, 1)
            .addComponent(getExpressionLayout(), 0, 3, 2, 1).addComponent(getDescriptionField(), 0, 4, 2, 2)
            .getLayout();//from   w w w  .j  a  v a  2s .c  o m
    layout.setMargin(false);
    layout.setSpacing(true);
    layout.setSizeFull();
    return layout;
}

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

License:Apache License

@Override
public AbstractLayout getLayout() {
    GridLayout layout = new UIUtils7.GridLayoutBuilder(2, 6).addComponent(getGroupField(), 0, 0)
            .addComponent(getNameField(), 1, 0).addComponent(getPrioritySlider(), 0, 1, 2, 1)
            .addComponent(getStartDateField(), 0, 2, 1, 1).addComponent(getEndDateField(), 1, 2, 1, 1)
            .addComponent(getPeriodField(), 0, 3, 1, 1).addComponent(getTimesField(), 1, 3, 1, 1)
            .addComponent(getDescriptionField(), 0, 4, 2, 2).getLayout();
    layout.setMargin(false);
    layout.setSpacing(true);//  w  ww.  jav a2 s .c om
    layout.setSizeFull();
    return layout;
}

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

License:Apache License

@Override
public AbstractLayout getLayout() {
    GridLayout layout = new UIUtils7.GridLayoutBuilder(2, 5).addComponent(getGroupField(), 0, 0)
            .addComponent(getNameField(), 1, 0).addComponent(getPrioritySlider(), 0, 1, 2, 1)
            .addComponent(new Label("No configuration needed."), Alignment.MIDDLE_CENTER, 0, 2, 2, 1)
            .addComponent(getDescriptionField(), 0, 3, 2, 2).getLayout();
    layout.setMargin(false);
    layout.setSpacing(true);/* w w w  .  ja v  a 2s.  c  o  m*/
    layout.setSizeFull();
    return layout;
}