Example usage for com.vaadin.ui FormLayout addComponent

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

Introduction

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

Prototype

@Override
public void addComponent(Component c) 

Source Link

Document

Add a component into this container.

Usage

From source file:org.ripla.web.internal.views.RiplaLogin.java

License:Open Source License

private void createForm(final VerticalLayout inLayout, final IAppConfiguration inConfiguration) {
    final IMessages lMessages = Activator.getMessages();

    final FormLayout lLayout = new FormLayout();
    lLayout.setStyleName("ripla-login-form"); //$NON-NLS-1$
    lLayout.setWidth(400, Unit.PIXELS);/*from  ww  w. ja v a  2  s  . c o m*/
    inLayout.addComponent(lLayout);
    inLayout.setComponentAlignment(lLayout, Alignment.TOP_CENTER);

    lLayout.addComponent(LabelHelper.createLabel(inConfiguration.getWelcome(), "ripla-welcome"));

    userid = new TextField(String.format("%s:", lMessages.getMessage("login.field.user"))); //$NON-NLS-1$ //$NON-NLS-2$
    lLayout.addComponent(userid);
    userid.focus();

    password = new PasswordField(String.format("%s:", lMessages.getMessage("login.field.pass"))); //$NON-NLS-1$ //$NON-NLS-2$
    lLayout.addComponent(password);

    loginButton = new Button(lMessages.getMessage("login.button")); //$NON-NLS-1$
    lLayout.addComponent(loginButton);

    loginItem = createLoginItem();
    final FieldGroup lBinding = new FieldGroup(loginItem);
    lBinding.bindMemberFields(this);
    lBinding.setBuffered(false);
}

From source file:org.rubicone.poc.vpush.uil.sending.SendingUI.java

License:Apache License

private FormLayout createPushMessageSendingForm() {
    FormLayout pushMessageSendingForm = new FormLayout();

    Panel pushMessageSendingPanel = new Panel("push message sending form");
    pushMessageSendingPanel.setContent(pushMessageSendingForm);

    TextField inputField = new TextField("text to send");
    inputField.setValueChangeMode(ValueChangeMode.EAGER);
    pushMessageSendingForm.addComponent(inputField);

    Button sendButton = new Button("send", VaadinIcons.LOCATION_ARROW);
    sendButton.setDisableOnClick(true);/*from   w w  w  . j a  va2  s. c o m*/
    sendButton.setEnabled(false);
    sendButton.addClickListener(event -> {
        this.broadcaster.broadcast(inputField.getValue());
        this.sentMessages.addComponent(new Label(new Date() + ": " + inputField.getValue()));
        inputField.setValue("");
    });

    inputField.addValueChangeListener(event -> {
        sendButton.setEnabled(!event.getValue().isEmpty());
    });

    pushMessageSendingForm.addComponent(sendButton);

    return pushMessageSendingForm;
}

From source file:org.sensorhub.ui.GenericConfigForm.java

License:Mozilla Public License

@Override
public void build(String title, MyBeanItem<? extends Object> beanItem) {
    List<Field<?>> labels = new ArrayList<Field<?>>();
    List<Field<?>> textBoxes = new ArrayList<Field<?>>();
    List<Field<?>> listBoxes = new ArrayList<Field<?>>();
    List<Field<?>> numberBoxes = new ArrayList<Field<?>>();
    List<Field<?>> checkBoxes = new ArrayList<Field<?>>();
    List<Component> otherWidgets = new ArrayList<Component>();

    // prepare header and form layout
    setSpacing(true);//from  www  . j a v a 2s.  c  o  m

    // add main form widgets
    FormLayout form = new FormLayout();
    form.setWidth(100.0f, Unit.PERCENTAGE);
    form.setMargin(false);

    if (title != null) {
        Label sectionLabel = new Label(title);
        sectionLabel.addStyleName(STYLE_H3);
        sectionLabel.addStyleName(STYLE_COLORED);
        form.addComponent(sectionLabel);
    }

    // add widget for each visible attribute
    if (beanItem != null) {
        fieldGroup = new FieldGroup(beanItem);
        for (Object propId : fieldGroup.getUnboundPropertyIds()) {
            Property<?> prop = fieldGroup.getItemDataSource().getItemProperty(propId);

            // sub objects with multiplicity > 1
            if (prop instanceof ContainerProperty) {
                Class<?> eltType = ((ContainerProperty) prop).getValue().getBeanType();

                // use simple table for string lists
                if (eltType == String.class) {
                    Component list = buildSimpleTable((String) propId, (ContainerProperty) prop);
                    fieldGroup.bind((Field<?>) list, propId);
                    listBoxes.add((Field<?>) list);
                }

                // else use tab sheet
                else if (!((ContainerProperty) prop).getValue().getItemIds().isEmpty()) {
                    Component subform = buildTabs((String) propId, (ContainerProperty) prop, fieldGroup);
                    otherWidgets.add(subform);
                }
            }

            // sub object
            else if (prop instanceof ComplexProperty) {
                Component subform = buildSubForm((String) propId, (ComplexProperty) prop);
                otherWidgets.add(subform);
            }

            // scalar field
            else {
                Field<?> field = null;

                try {
                    String label = null;
                    if (prop instanceof FieldProperty)
                        label = ((FieldProperty) prop).getLabel();
                    if (label == null)
                        label = DisplayUtils.getPrettyName((String) propId);

                    String desc = null;
                    if (prop instanceof FieldProperty)
                        desc = ((FieldProperty) prop).getDescription();

                    field = buildAndBindField(label, (String) propId, prop);
                    ((AbstractField<?>) field).setDescription(desc);
                } catch (Exception e) {
                    System.err.println("No UI generator for field " + propId);
                    continue;
                }

                // add to one of the widget lists so we can order by widget type
                Class<?> propType = prop.getType();
                if (propType.equals(String.class)) {
                    if (field instanceof Label)
                        labels.add(field);
                    else
                        textBoxes.add(field);
                } else if (Enum.class.isAssignableFrom(propType))
                    numberBoxes.add(field);
                else if (Number.class.isAssignableFrom(propType))
                    numberBoxes.add(field);
                else if (field instanceof CheckBox)
                    checkBoxes.add(field);
                else
                    otherWidgets.add(field);
            }
        }
    }

    // main form
    for (Field<?> w : labels)
        form.addComponent(w);
    for (Field<?> w : textBoxes)
        form.addComponent(w);
    for (Field<?> w : listBoxes)
        form.addComponent(w);
    for (Field<?> w : numberBoxes)
        form.addComponent(w);
    for (Field<?> w : checkBoxes)
        form.addComponent(w);
    addComponent(form);

    // sub forms
    for (Component w : otherWidgets)
        addComponent(w);
}

From source file:org.sensorhub.ui.GenericConfigFormBuilder.java

License:Mozilla Public License

@SuppressWarnings("serial")
@Override/*from w  w  w.  j a v  a  2 s.c  o  m*/
public FormLayout buildForm(final FieldGroup fieldGroup) {
    reset();
    FormLayout form = new FormLayout();

    // add widget for each visible attribute
    for (Object propId : fieldGroup.getUnboundPropertyIds()) {
        Property<?> prop = fieldGroup.getItemDataSource().getItemProperty(propId);

        if (prop instanceof ContainerProperty) {
            String label = ((ContainerProperty) prop).getLabel();
            if (label == null)
                label = getPrettyName((String) propId);

            /*Table table = new Table();
            table.setCaption(label);
            table.setSizeFull();
            table.setPageLength(5);
            table.setHeight(50, Unit.POINTS);
            table.setSelectable(true);
            table.setEditable(true);
            table.setColumnReorderingAllowed(false);
            table.setContainerDataSource(((ContainerProperty)prop).getValue());
            table.setBuffered(true);
            table.setStyleName(Runo.TABLE_SMALL);
            otherWidgets.add(table);*/

            if (!((ContainerProperty) prop).getValue().getItemIds().isEmpty()) {
                Object firstItemId = ((ContainerProperty) prop).getValue().getItemIds().iterator().next();
                FieldGroup newFieldGroup = new FieldGroup(
                        ((ContainerProperty) prop).getValue().getItem(firstItemId));
                FormLayout subform = new GenericConfigFormBuilder().buildForm(newFieldGroup);
                subform.setCaption(label);
                otherWidgets.add(subform);
            }
        } else {
            Field<?> field = null;

            try {
                String label = null;
                if (prop instanceof FieldProperty)
                    label = ((FieldProperty) prop).getLabel();
                if (label == null)
                    label = getPrettyName((String) propId);
                field = fieldGroup.buildAndBind(label, propId);
            } catch (Exception e) {
                System.err.println("No UI generator for field " + propId);
                continue;
            }

            //Property<?> prop = field.getPropertyDataSource();            
            customizeField((String) propId, prop, field);

            if (field instanceof Label)
                labels.add(field);
            else if (field instanceof TextField)
                textBoxes.add(field);
            else if (field instanceof CheckBox)
                checkBoxes.add(field);
            else
                otherWidgets.add(field);
        }
    }

    // add all widgets
    for (Field<?> w : labels)
        form.addComponent(w);
    for (Field<?> w : textBoxes)
        form.addComponent(w);
    for (Field<?> w : checkBoxes)
        form.addComponent(w);
    for (Component w : otherWidgets)
        form.addComponent(w);

    // add save button
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setWidth(100.0f, Unit.PERCENTAGE);
    //buttonsLayout.setSizeFull();
    buttonsLayout.setMargin(true);
    buttonsLayout.setSpacing(true);
    form.addComponent(buttonsLayout);

    Button saveButton = new Button("Save");
    saveButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            try {
                fieldGroup.commit();
            } catch (CommitException e) {
                e.printStackTrace();
            }
        }
    });
    buttonsLayout.addComponent(saveButton);
    //buttonsLayout.setComponentAlignment(saveButton, Alignment.MIDDLE_CENTER);

    // add cancel button
    Button cancelButton = new Button("Cancel");
    cancelButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            fieldGroup.discard();
        }
    });
    buttonsLayout.addComponent(cancelButton);
    //buttonsLayout.setComponentAlignment(cancelButton, Alignment.MIDDLE_CENTER);

    return form;
}

From source file:org.sensorhub.ui.SWECommonFormBuilder.java

License:Mozilla Public License

public Panel buildForm(DataComponent dataComponent) {
    FormLayout layout = new FormLayout();

    for (int i = 0; i < dataComponent.getComponentCount(); i++) {
        DataComponent c = dataComponent.getComponent(i);
        Component w = buildWidget(c);
        if (w != null)
            layout.addComponent(w);
    }//from w w  w .j a va  2  s.c o  m

    Panel panel = new Panel();
    panel.setContent(layout);
    return panel;
}

From source file:org.sensorhub.ui.SWECommonFormBuilder.java

License:Mozilla Public License

protected Component buildWidget(DataComponent dataComponent) {
    if (dataComponent instanceof DataRecord) {
        DataRecord dataRecord = (DataRecord) dataComponent;
        FormLayout layout = new FormLayout();

        for (int i = 0; i < dataRecord.getComponentCount(); i++) {
            DataComponent c = dataRecord.getComponent(i);
            Component w = buildWidget(c);
            if (w != null)
                layout.addComponent(w);
        }//  ww w.ja va2s.  co m

        Panel panel = new Panel();
        panel.setCaption(getPrettyName(dataComponent));
        panel.setContent(layout);
        return panel;
    }

    else if (dataComponent instanceof DataArray) {
        DataArray dataArray = (DataArray) dataComponent;
        VerticalLayout layout = new VerticalLayout();
        layout.addComponent(new Label(getPrettyName(dataArray)));
        layout.addComponent(buildWidget(dataArray.getElementType()));
        return layout;
    }

    else if (dataComponent instanceof DataChoice) {

    }

    else if (dataComponent instanceof Quantity) {
        Label c = new Label();
        c.setCaption(getPrettyName(dataComponent));
        c.setDescription(dataComponent.getDescription());
        return c;
    }

    return null;
}

From source file:org.vaadin.spring.samples.security.shared.LoginUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    getPage().setTitle("Vaadin Shared Security Demo Login");

    FormLayout loginForm = new FormLayout();
    loginForm.setSizeUndefined();//ww w .j a v a2  s  .  co  m

    userName = new TextField("Username");
    passwordField = new PasswordField("Password");
    rememberMe = new CheckBox("Remember me");
    login = new Button("Login");
    loginForm.addComponent(userName);
    loginForm.addComponent(passwordField);
    loginForm.addComponent(rememberMe);
    loginForm.addComponent(login);
    login.addStyleName(ValoTheme.BUTTON_PRIMARY);
    login.setDisableOnClick(true);
    login.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    login.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            login();
        }
    });

    VerticalLayout loginLayout = new VerticalLayout();
    loginLayout.setSpacing(true);
    loginLayout.setSizeUndefined();

    if (request.getParameter("logout") != null) {
        loggedOutLabel = new Label("You have been logged out!");
        loggedOutLabel.addStyleName(ValoTheme.LABEL_SUCCESS);
        loggedOutLabel.setSizeUndefined();
        loginLayout.addComponent(loggedOutLabel);
        loginLayout.setComponentAlignment(loggedOutLabel, Alignment.BOTTOM_CENTER);
    }

    loginLayout.addComponent(loginFailedLabel = new Label());
    loginLayout.setComponentAlignment(loginFailedLabel, Alignment.BOTTOM_CENTER);
    loginFailedLabel.setSizeUndefined();
    loginFailedLabel.addStyleName(ValoTheme.LABEL_FAILURE);
    loginFailedLabel.setVisible(false);

    loginLayout.addComponent(loginForm);
    loginLayout.setComponentAlignment(loginForm, Alignment.TOP_CENTER);

    VerticalLayout rootLayout = new VerticalLayout(loginLayout);
    rootLayout.setSizeFull();
    rootLayout.setComponentAlignment(loginLayout, Alignment.MIDDLE_CENTER);
    setContent(rootLayout);
    setSizeFull();
}

From source file:pl.exsio.frameset.vaadin.account.window.view.AccountWindowView.java

License:Open Source License

private FormLayout createForm() {
    this.form = new Form();
    this.form.setFormFieldFactory(new FramesetFieldFactory(UserImpl.class));
    this.form.setItemDataSource(this.item,
            Arrays.asList(FIELD_USERNAME, FIELD_FIRST_NAME, FIELD_lAST_NAME, FIELD_PHONE_NO));
    this.form.setBuffered(true);
    this.form.getField(FIELD_USERNAME)
            .addValidator(new EmailValidator(t("core.management.users.invalid_username")));
    Field passwordField = this.createPasswordField();
    this.form.addField(FIELD_PASSWORD, passwordField);
    Field passwordFieldRepeated = this.createPasswordRepeatedField();
    this.form.addField(FIELD_PASSWORD_REPEATED, passwordFieldRepeated);
    FormLayout formLayout = new FormLayout();
    formLayout.addComponent(this.form);
    formLayout.setMargin(true);//  www.  ja v  a2 s  .  c  om
    HorizontalLayout controls = this.createFormControls();
    formLayout.addComponent(controls);
    return formLayout;
}

From source file:pl.exsio.frameset.vaadin.module.management.roles.RolesDataTable.java

License:Open Source License

@Override
protected Layout decorateForm(TabbedForm form, EntityItem<? extends Role> item, int mode) {

    form.init(this.getTabsConfig());
    form.getLayout().setWidth("400px");
    FormLayout formLayout = new FormLayout();
    FramesetFieldFactory<? extends Role> ff = new FramesetFieldFactory<>(this.securityEntities.getRoleClass(),
            this.getClass());
    ff.setMultiSelectType(this.securityEntities.getRoleClass(), OptionGroup.class);
    form.setFormFieldFactory(ff);/*from ww w . ja  v a  2 s.c om*/
    form.setItemDataSource(item, Arrays.asList(new String[] { "name", "label", "childRoles" }));
    item.getEntity().setOldName(item.getEntity().getName());
    form.setBuffered(true);
    formLayout.addComponent(form);
    return formLayout;
}

From source file:pl.exsio.frameset.vaadin.ui.support.component.data.form.SecurityPermissionsForm.java

License:Open Source License

private void handleRoleSelectionChange(ComboBox roleSelect, final FormLayout permissionsLayout,
        final JPAContainer<? extends Role> roles, final Map<String, Permission> permissionsMap) {
    roleSelect.addValueChangeListener(new Property.ValueChangeListener() {

        private Map<CheckBox, Permission> permissionCbsMap;

        @Override//from w  w  w. j  av  a 2 s.co m
        public void valueChange(Property.ValueChangeEvent event) {
            if (event.getProperty().getValue() != null) {
                this.createRolePermissionsForm(event);
            }
        }

        private void createRolePermissionsForm(Property.ValueChangeEvent event) throws NumberFormatException {
            this.permissionCbsMap = new HashMap<>();
            permissionsLayout.removeAllComponents();

            Long itemId = Long.parseLong(event.getProperty().getValue().toString());
            Role selectedRole = roles.getItem(itemId).getEntity();
            final GrantedAuthoritySid sid = new GrantedAuthoritySid(selectedRole.getName());

            for (String permissionName : permissionsMap.keySet()) {
                CheckBox permissionCb = this.createPermissionCheckbox(permissionName, sid);
                permissionsLayout.addComponent(permissionCb);
            }

            Button savePermissions = this.createSaveButton(sid);
            permissionsLayout.addComponent(savePermissions);
        }

        private CheckBox createPermissionCheckbox(String permissionName, final GrantedAuthoritySid sid) {
            CheckBox permissionCb = new CheckBox(permissionName,
                    acl.isGranted(subject, permissionsMap.get(permissionName), sid));
            this.permissionCbsMap.put(permissionCb, permissionsMap.get(permissionName));
            return permissionCb;
        }

        private Button createSaveButton(final GrantedAuthoritySid sid) {
            Button savePermissions = new Button(t("core.save"), FontAwesome.FLOPPY_O);
            savePermissions.addClickListener(new Button.ClickListener() {

                @Override
                public void buttonClick(Button.ClickEvent event) {
                    for (CheckBox permissionCb : permissionCbsMap.keySet()) {
                        if (permissionCb.getValue()) {
                            acl.grant(subject, permissionCbsMap.get(permissionCb), sid);
                        } else {
                            acl.revoke(subject, permissionCbsMap.get(permissionCb), sid);
                        }
                    }
                    Notification.show(t("core.security.management.permision.update.success"));
                }
            });
            return savePermissions;
        }
    });
}