Example usage for com.vaadin.ui Layout addComponent

List of usage examples for com.vaadin.ui Layout addComponent

Introduction

In this page you can find the example usage for com.vaadin.ui Layout addComponent.

Prototype

public void addComponent(Component c);

Source Link

Document

Adds the component into this container.

Usage

From source file:com.purebred.core.view.EntityForm.java

License:Open Source License

@PostConstruct
@Override/* w  w  w.j  a v a  2s .c  o  m*/
public void postConstruct() {
    super.postConstruct();

    addStyleName("p-entity-form");

    List<ToManyRelationship> toManyRelationships = getViewableToManyRelationships();
    if (toManyRelationships.size() > 0) {
        toManyRelationshipTabs = new TabSheet();
        toManyRelationshipTabs.setSizeUndefined();
        for (ToManyRelationship toManyRelationship : toManyRelationships) {
            toManyRelationshipTabs.addTab(toManyRelationship);
            labelDepot.putFieldLabel(getEntityType().getName(),
                    toManyRelationship.getResults().getChildPropertyId(), "Relationship",
                    toManyRelationship.getResults().getEntityCaption());
        }

        Layout layout = new HorizontalLayout();
        layout.setSizeUndefined();
        Label label = new Label("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", Label.CONTENT_XHTML);
        layout.addComponent(label);
        layout.addComponent(toManyRelationshipTabs);
        addComponent(layout);
    }
}

From source file:com.skysql.manager.ui.NodeForm.java

License:Open Source License

/**
 * Instantiates a new node form./*from w  w w .j  a v  a  2 s.co m*/
 *
 * @param node the node
 * @param description the description
 */
NodeForm(final NodeInfo node, String description) {
    this.node = node;

    setMargin(new MarginInfo(true, true, false, true));
    setSpacing(false);

    isGalera = node.getSystemType().equals(SystemTypes.Type.galera.name());

    HorizontalLayout formDescription = new HorizontalLayout();
    formDescription.setSpacing(true);

    Embedded info = new Embedded(null, new ThemeResource("img/info.png"));
    info.addStyleName("infoButton");
    String infoText = "<table border=0 cellspacing=3 cellpadding=0 summary=\"\">\n"
            + "     <tr bgcolor=\"#ccccff\">" + "         <th align=left>Field"
            + "         <th align=left>Description" + "     <tr>" + "         <td><code>Name</code>"
            + "         <td>Name of the Node" + "     <tr bgcolor=\"#eeeeff\">"
            + "         <td><code>Hostname</code>"
            + "         <td>In some systems, a hostname that identifies the node" + "     <tr>"
            + "         <td><code>Instance ID</code>"
            + "         <td>The instance ID field is for information only and is not used within the Manager"
            + "     <tr bgcolor=\"#eeeeff\">" + "         <td><code>Public IP</code>"
            + "         <td>In some systems, the public IP address of the node" + "     <tr>"
            + "         <td><code>Private IP</code>"
            + "         <td>The IP address that accesses the node internally to the manager";

    if (!isGalera) {
        infoText += "     <tr bgcolor=\"#eeeeff\">" + "         <td><code>Database Username</code>"
                + "         <td>Node system override for database user name" + "     <tr>"
                + "         <td><code>Database Password</code>"
                + "         <td>Node system override for database password" + "     <tr bgcolor=\"#eeeeff\">"
                + "         <td><code>Replication Username</code>"
                + "         <td>Node system override for replication user name" + "     <tr>"
                + "         <td><code>Replication Password</code>"
                + "         <td>Node system override for replication password";

    }
    infoText += " </table>" + " </blockquote>";
    info.setDescription(infoText);

    formDescription.addComponent(info);
    Label labelDescription = new Label(description);
    formDescription.addComponent(labelDescription);
    formDescription.setComponentAlignment(labelDescription, Alignment.MIDDLE_LEFT);
    addComponent(formDescription);

    addComponent(form);
    form.setImmediate(false);
    form.setFooter(null);
    form.setDescription(null);

    String value;
    if ((value = node.getName()) != null) {
        name.setValue(value);
    }
    form.addField("name", name);
    name.focus();
    name.setImmediate(true);
    name.addValidator(new NodeNameValidator(node.getName()));

    if ((value = node.getHostname()) != null) {
        hostname.setValue(value);
    }
    form.addField("hostname", hostname);

    if ((value = node.getInstanceID()) != null) {
        instanceID.setValue(value);
    }
    form.addField("instanceID", instanceID);

    if ((value = node.getPublicIP()) != null) {
        publicIP.setValue(value);
    }
    form.addField("publicIP", publicIP);

    if ((value = node.getPrivateIP()) != null) {
        privateIP.setValue(value);
    }
    form.addField("privateIP", privateIP);
    privateIP.setRequired(true);
    privateIP.setRequiredError("Private IP is a required field");

    if (!isGalera) {
        if ((value = node.getDBUsername()) != null) {
            dbUsername.setValue(value);
        }
        form.addField("dbusername", dbUsername);
        dbUsername.setRequired(true);
        dbUsername.setImmediate(false);
        dbUsername.setRequiredError("Database Username is a required field");
        dbUsername.addValidator(new UserNotRootValidator(dbUsername.getCaption()));

        if ((value = node.getDBPassword()) != null) {
            dbPassword.setValue(value);
        }
        form.addField("dbpassword", dbPassword);
        dbPassword.setRequired(true);
        dbPassword.setImmediate(false);
        dbPassword.setRequiredError("Database Password is a required field");

        if ((value = node.getDBPassword()) != null) {
            dbPassword2.setValue(value);
        }
        form.addField("dbpassword2", dbPassword2);
        dbPassword2.setRequired(true);
        dbPassword2.setImmediate(true);
        dbPassword2.setRequiredError("Confirm Password is a required field");
        dbPassword2.addValidator(new Password2Validator(dbPassword));

        if ((value = node.getRepUsername()) != null) {
            repUsername.setValue(value);
        }
        form.addField("repusername", repUsername);
        repUsername.setRequired(true);
        repUsername.setImmediate(false);
        repUsername.setRequiredError("Replication Username is a required field");
        repUsername.addValidator(new UserNotRootValidator(repUsername.getCaption()));

        if ((value = node.getRepPassword()) != null) {
            repPassword.setValue(value);
        }
        form.addField("reppassword", repPassword);
        repPassword.setRequired(true);
        repPassword.setImmediate(false);
        repPassword.setRequiredError("Replication Password is a required field");

        if ((value = node.getRepPassword()) != null) {
            repPassword2.setValue(value);
        }
        form.addField("reppassword2", repPassword2);
        repPassword2.setRequired(true);
        repPassword2.setImmediate(true);
        repPassword2.setRequiredError("Confirm Password is a required field");
        repPassword2.addValidator(new Password2Validator(repPassword));
    }

    if (node.getID() == null) {
        Layout layout = form.getLayout();

        {
            Label spacer = new Label();
            spacer.setWidth("40px");
            layout.addComponent(spacer);
        }

        HorizontalLayout optionLayout = new HorizontalLayout();
        optionLayout.addStyleName("formInfoLayout");
        optionLayout.setSpacing(true);
        optionLayout.setSizeUndefined();
        layout.addComponent(optionLayout);

        Label padding = new Label("\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0");
        optionLayout.addComponent(padding);

        Embedded info2 = new Embedded(null, new ThemeResource("img/info.png"));
        info2.addStyleName("infoButton");
        info2.setDescription(connectionInfo);
        optionLayout.addComponent(info2);

        final Validator validator = new Password2Validator(connectPassword);

        final OptionGroup connectOption = new OptionGroup("Connection options");
        connectOption.setSizeUndefined();
        connectOption.addItem(false);
        connectOption.setItemCaption(false, "Node is not available, user will run connect later");
        connectOption.addItem(true);
        connectOption.setItemCaption(true, "Node is available now, connect automatically");
        connectOption.setImmediate(true);
        connectOption.addValueChangeListener(new Property.ValueChangeListener() {
            private static final long serialVersionUID = 0x4C656F6E6172646FL;

            @Override
            public void valueChange(ValueChangeEvent event) {
                runConnect = (Boolean) event.getProperty().getValue();
                passwordOption.setVisible(runConnect);
                connectPassword.setRequired(runConnect && usePassword);
                connectPassword2.setRequired(runConnect && usePassword);
                connectKey.setRequired(runConnect && !usePassword);
                if (!runConnect) {
                    connectPassword.setVisible(false);
                    connectPassword2.setVisible(false);
                    connectPassword2.removeValidator(validator);
                    connectKey.setVisible(false);
                } else {
                    if (usePassword) {
                        connectPassword.setVisible(true);
                        connectPassword2.setVisible(true);
                        connectPassword2.addValidator(validator);
                    } else {
                        connectKey.setVisible(true);
                    }
                }
                form.setComponentError(null);
                form.setValidationVisible(false);
            }
        });
        optionLayout.addComponent(connectOption);
        optionLayout.setComponentAlignment(connectOption, Alignment.MIDDLE_LEFT);
        connectOption.select(true);

        passwordOption.addItem(true);
        passwordOption.setItemCaption(true, "Authenticate with root user");
        passwordOption.addItem(false);
        passwordOption.setItemCaption(false, "Authenticate with SSH Key");
        passwordOption.setImmediate(true);
        passwordOption.addValueChangeListener(new Property.ValueChangeListener() {
            private static final long serialVersionUID = 0x4C656F6E6172646FL;

            @Override
            public void valueChange(ValueChangeEvent event) {
                usePassword = (Boolean) event.getProperty().getValue();
                if (usePassword) {
                    connectPassword2.addValidator(validator);
                } else {
                    connectPassword2.removeValidator(validator);
                }
                connectPassword.setVisible(usePassword);
                connectPassword.setRequired(usePassword);
                connectPassword2.setVisible(usePassword);
                connectPassword2.setRequired(usePassword);
                connectKey.setVisible(!usePassword);
                connectKey.setRequired(!usePassword);
                form.setComponentError(null);
                form.setValidationVisible(false);
            }
        });
        layout.addComponent(passwordOption);
        passwordOption.select(false);

        form.addField("connectPassword", connectPassword);
        connectPassword.setImmediate(false);
        connectPassword.setRequiredError("Root Password is a required field");

        form.addField("connectPassword2", connectPassword2);
        connectPassword2.setImmediate(true);
        connectPassword2.setRequiredError("Confirm Password is a required field");

        form.addField("connectKey", connectKey);
        connectKey.setStyleName("sshkey");
        connectKey.setColumns(41);
        connectKey.setRequiredError("SSH Key is a required field");
    }

}

From source file:com.wcs.wcslib.vaadin.widget.recaptcha.demo.ConfigComponent.java

License:Apache License

private Layout createThemeconfLayout() {
    Layout themeLayout = new FormLayout();
    themeSelect = new NativeSelect("theme", Arrays.asList("red", "white", "blackglass", "clean", "custom"));
    themeSelect.setImmediate(true);/*from www .ja v a  2s  .c  o  m*/
    themeSelect.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            customHtmlArea.setEnabled(isCustomTheme());
            customThemeWidgetField.setEnabled(isCustomTheme());
        }
    });
    themeLayout.addComponent(themeSelect);
    customHtmlArea = new TextArea("custom HTML", CUSTOM_HTML_SAMPLE);
    customHtmlArea.setEnabled(false);
    customHtmlArea.setRows(15);
    customHtmlArea.setColumns(40);
    themeLayout.addComponent(customHtmlArea);
    customThemeWidgetField = new TextField("custom_theme_widget", CUSTOM_THEME_WIDGET);
    customThemeWidgetField.setEnabled(false);
    themeLayout.addComponent(customThemeWidgetField);
    return themeLayout;
}

From source file:de.unioninvestment.eai.portal.portlet.crud.mvp.views.DefaultFormView.java

License:Apache License

private Field<Boolean> createCheckBox(FormField field, int columns) {
    CheckBoxFormField checkBoxFormField = (CheckBoxFormField) field;

    Layout checkboxLayout = null;
    if (columns == 1) {
        checkboxLayout = new HorizontalLayout();
        checkboxLayout.setCaption(field.getTitle());
    } else {/*  w ww . j  av a2 s.com*/
        checkboxLayout = new VerticalLayout();
        Label checkBoxLabel = new Label(field.getTitle());
        checkboxLayout.addComponent(checkBoxLabel);
    }

    CheckBox checkBoxField = new CheckBox();
    checkboxLayout.addComponent(checkBoxField);

    checkBoxField.setConverter(checkBoxFormField.getConverter());
    checkBoxField.setPropertyDataSource(checkBoxFormField.getProperty());
    checkBoxField.setImmediate(true);
    checkBoxField.addStyleName(field.getName());

    // addField(field.getName(), checkBoxField);
    fieldLayout.addComponent(checkboxLayout);

    return checkBoxField;
}

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

private void refreshProfiles(Group g, Layout layoutProfiles) {
    layoutProfiles.removeAllComponents();
    GroupUtils.getAllInterestProfiles(g, UserUtils.getCurrent()).forEach((p, enabled) -> {
        HorizontalLayout layoutProfile = new HorizontalLayout();
        layoutProfile.setWidth("100%");

        CheckBox checkBoxEnabled = new CheckBox();
        checkBoxEnabled.setValue(enabled);
        checkBoxEnabled.addValueChangeListener(v -> {
            GroupInterestProfileUtils.changeEnabled(p, UserUtils.getCurrent(), v.getValue());
            refreshAll(g);// w w  w  .  j a  va 2s  .  c  o m
        });

        long subscribers = p.getEnabledUsers().values().stream().filter(v -> v).count();
        Label labelProfileInfo = new Label();
        Language.setCustom(Word.SUBSCRIBERS, s -> {
            String info = p.getName() + " (" + subscribers + " ";
            info += subscribers == 1 ? Language.get(Word.SUBSCRIBER) + ")"
                    : Language.get(Word.SUBSCRIBERS) + ")";
            labelProfileInfo.setValue(info);
        });

        boolean isAdmin = g.getUsers().getOrDefault(UserUtils.getCurrent(), false);

        Button buttonOpen = new Button(VaadinIcons.EXTERNAL_LINK);
        buttonOpen.addClickListener(ce -> {
            UI.getCurrent().addWindow(GroupProfileWindow.show(p, isAdmin, () -> {
            }));
        });

        if (isAdmin) {
            Button buttonRemove = new Button(VaadinIcons.MINUS);
            buttonRemove.addStyleName(ValoTheme.BUTTON_DANGER);
            buttonRemove.addClickListener(ce -> {
                ConfirmationDialog.show(
                        Language.get(Word.REALLY_DELETE_PROFILE).replace("[PROFILE]", p.getName()), () -> {
                            GroupInterestProfileUtils.delete(p);
                            refreshAll(g);
                        });
            });

            layoutProfile.addComponents(checkBoxEnabled, labelProfileInfo, buttonOpen, buttonRemove);
        } else {
            layoutProfile.addComponents(checkBoxEnabled, labelProfileInfo, buttonOpen);
        }

        layoutProfile.setExpandRatio(labelProfileInfo, 5);
        layoutProfile.setComponentAlignment(checkBoxEnabled, Alignment.MIDDLE_CENTER);
        layoutProfile.setComponentAlignment(labelProfileInfo, Alignment.MIDDLE_LEFT);

        layoutProfiles.addComponent(layoutProfile);
    });
}

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

public void refreshMembers(Group g, Layout layoutMembers) {
    layoutMembers.removeAllComponents();
    Map<User, Boolean> allMembers = GroupUtils.getAllMembers(g);
    boolean isAdmin = GroupUtils.isAdmin(g, UserUtils.getCurrent());
    if (!isAdmin) {
        if (allMembers.size() < 2) {
            buttonLeave.setVisible(false);
        } else {/*from   w  w  w  .  ja  v a2s .com*/
            buttonLeave.setVisible(true);
        }
    } else {
        if (allMembers.entrySet().stream().map(e -> e.getValue()).filter(b -> b == true).count() > 1) {
            buttonLeave.setVisible(true);
        } else {
            buttonLeave.setVisible(false);
        }
    }
    allMembers.forEach((u, admin) -> {
        HorizontalLayout layoutMember = new HorizontalLayout();
        layoutMember.setWidth("100%");

        VaadinIcons iconRole = admin ? VaadinIcons.KEY : VaadinIcons.USER;
        Label labelMemberName = new Label(iconRole.getHtml() + " " + u.getUsername(), ContentMode.HTML);
        //labelMemberName.setWidth("50%");

        layoutMember.addComponents(labelMemberName);
        layoutMember.setComponentAlignment(labelMemberName, Alignment.MIDDLE_LEFT);
        layoutMember.setExpandRatio(labelMemberName, 5);
        if (isAdmin) {
            if (g.getUsers().size() > 1) {
                Button buttonChangeRole = new Button(admin ? VaadinIcons.ARROW_DOWN : VaadinIcons.ARROW_UP);
                buttonChangeRole.addClickListener(ce -> {
                    if (g.getUsers().get(u)) {//Downgrade
                        long amountAdmins = g.getUsers().entrySet().stream().filter(e -> e.getValue()).count();
                        if (amountAdmins > 1) {
                            if (UserUtils.getCurrent() == u) {
                                ConfirmationDialog.show(Language.get(Word.REALLY_DEADMIN_YOURSELF), () -> {
                                    GroupUtils.makeNormalMember(g, u);
                                    refreshAll(g);
                                });
                            } else {
                                GroupUtils.makeNormalMember(g, u);
                                refreshAll(g);
                            }
                        } else {
                            VaadinUtils.errorNotification(Language.get(Word.NOT_ENOUGH_ADMINS_IN_GROUP));
                            buttonLeave.setVisible(false);
                        }
                    } else {//Upgrade
                        GroupUtils.makeAdmin(g, u);
                        refreshAll(g);
                    }
                });
                layoutMember.addComponent(buttonChangeRole);

                if (g.getUsers().values().stream().filter(v -> v).count() > 1 || !GroupUtils.isAdmin(g, u)) {
                    Button buttonRemoveUser = new Button(VaadinIcons.MINUS);
                    buttonRemoveUser.addStyleName(ValoTheme.BUTTON_DANGER);
                    buttonRemoveUser.addClickListener(ce -> {
                        ConfirmationDialog.show(
                                Language.get(Word.REALLY_REMOVE_USER_FROM_GROUP)
                                        .replace("[USER]", u.getUsername()).replace("[GROUP]", g.getName()),
                                () -> {
                                    GroupUtils.removeUser(g, u);
                                    refreshAll(g);
                                });
                    });
                    layoutMember.addComponents(buttonRemoveUser);
                }
            }
        }
        layoutMembers.addComponent(layoutMember);
    });
}

From source file:fr.amapj.view.engine.tools.BaseUiTools.java

License:Open Source License

static public Label addStdLabel(Layout layout, String content, String styleName) {
    Label tf = new Label(content);
    tf.addStyleName(styleName);//  w w w .  jav  a 2  s. c o  m
    layout.addComponent(tf);
    return tf;
}

From source file:fr.amapj.view.engine.tools.BaseUiTools.java

License:Open Source License

static public Label addHtmlLabel(Layout layout, String content, String styleName) {
    Label tf = new Label(content, ContentMode.HTML);
    tf.addStyleName(styleName);//from www  .  ja v  a  2s . co  m
    layout.addComponent(tf);
    return tf;
}

From source file:fr.amapj.view.engine.tools.BaseUiTools.java

License:Open Source License

/**
 * Cre un Panel avec un VerticalLayout  l'intrieur 
 * /*from   w ww. ja v  a  2  s. com*/
 * @param layout
 * @param styleName
 * @return
 */
static public VerticalLayout addPanel(Layout layout, String styleName) {
    Panel p0 = new Panel();
    p0.setWidth("100%");
    p0.addStyleName(styleName);

    VerticalLayout vl1 = new VerticalLayout();
    vl1.setMargin(true);
    p0.setContent(vl1);
    layout.addComponent(p0);

    return vl1;
}

From source file:fr.amapj.view.engine.tools.BaseUiTools.java

License:Open Source License

/**
 * Permet de crer un bandeau, c'est  dire avec un texte avec un fond, et ceci sur toute la longueur 
 * // ww  w .  ja  v a2s  .  c om
 */
static public Label addBandeau(Layout layout, String content, String styleName) {
    Label l = new Label(content);
    l.setWidth("100%");

    Panel p1 = new Panel();
    p1.setContent(l);
    p1.addStyleName("bandeau-" + styleName);

    layout.addComponent(p1);

    return l;
}