Example usage for com.vaadin.ui FormLayout FormLayout

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

Introduction

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

Prototype

public FormLayout() 

Source Link

Usage

From source file:org.ow2.sirocco.cloudmanager.KeyPairImportDialog.java

License:Open Source License

public KeyPairImportDialog(final DialogCallback callback) {
    super("Import Key Pair");
    this.callback = callback;
    this.center();
    this.setClosable(false);
    this.setModal(true);
    this.setResizable(false);

    VerticalLayout content = new VerticalLayout();
    content.setSizeFull();/*  www .j  av  a2 s  .  com*/
    content.setMargin(true);
    content.setSpacing(true);
    content.setWidth("500px");
    content.setHeight("250px");

    FormLayout form = new FormLayout();
    form.setWidth("100%");
    form.setMargin(true);
    form.setSpacing(true);

    this.nameField = new TextField("Name");
    this.nameField.setWidth("50%");
    this.nameField.setRequired(true);
    this.nameField.setRequiredError("Please enter a name for your key pair");
    form.addComponent(this.nameField);

    this.publicKeyField = new TextArea("Public Key");
    this.publicKeyField.setWidth("100%");
    this.publicKeyField.setRequired(true);
    this.publicKeyField.setRequiredError("Please enter a name for your key pair");
    form.addComponent(this.publicKeyField);

    content.addComponent(form);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    this.okButton = new Button("Ok", this);
    this.cancelButton = new Button("Cancel", this);
    this.cancelButton.focus();
    buttonLayout.addComponent(this.okButton);
    buttonLayout.addComponent(this.cancelButton);
    content.addComponent(buttonLayout);
    content.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT);

    this.setContent(content);

}

From source file:org.ow2.sirocco.cloudmanager.SecurityGroupRuleCreationDialog.java

License:Open Source License

public SecurityGroupRuleCreationDialog(final List<SecGroupChoice> choices, final DialogCallback callback) {
    super("Add Rule");
    this.callback = callback;
    this.center();
    this.setClosable(false);
    this.setModal(true);
    this.setResizable(false);

    FormLayout content = new FormLayout();
    content.setMargin(true);//  ww  w .ja v a2s.c  o  m
    content.setWidth("500px");
    content.setHeight("350px");

    this.protocolBox = new ComboBox("IP Protocol");
    this.protocolBox.setRequired(true);
    this.protocolBox.setTextInputAllowed(false);
    this.protocolBox.setNullSelectionAllowed(false);
    this.protocolBox.setImmediate(true);
    this.protocolBox.addItem("TCP");
    this.protocolBox.addItem("UDP");
    this.protocolBox.addItem("ICMP");
    this.protocolBox.setValue("TCP");
    content.addComponent(this.protocolBox);

    this.portField = new TextField("Port range");
    this.portField.setRequired(true);
    this.portField.setWidth("80%");
    this.portField.setRequired(true);
    this.portField.setRequiredError("Please provide a port range");
    this.portField.setImmediate(true);
    content.addComponent(this.portField);

    this.sourceChoice = new OptionGroup("Source");
    this.sourceChoice.addItem("CIDR");
    this.sourceChoice.addItem("Security Group");
    this.sourceChoice.setValue("CIDR");
    this.sourceChoice.setImmediate(true);
    this.sourceChoice.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(final ValueChangeEvent event) {
            boolean sourceIsCidr = SecurityGroupRuleCreationDialog.this.sourceChoice.getValue().equals("CIDR");
            SecurityGroupRuleCreationDialog.this.sourceIpRangeField.setEnabled(sourceIsCidr);
            SecurityGroupRuleCreationDialog.this.sourceSecGroupBox.setEnabled(!sourceIsCidr);
        }
    });
    content.addComponent(this.sourceChoice);

    this.sourceIpRangeField = new TextField("CIDR");
    this.sourceIpRangeField.setRequired(true);
    this.sourceIpRangeField.setWidth("80%");
    this.sourceIpRangeField.setRequired(true);
    this.sourceIpRangeField.setRequiredError("Please provide a CIDR");
    this.sourceIpRangeField.setImmediate(true);
    this.sourceIpRangeField.setValue("0.0.0.0/0");
    content.addComponent(this.sourceIpRangeField);

    this.sourceSecGroupBox = new ComboBox("Security Group");
    this.sourceSecGroupBox.setRequired(true);
    this.sourceSecGroupBox.setTextInputAllowed(false);
    this.sourceSecGroupBox.setNullSelectionAllowed(false);
    this.sourceSecGroupBox.setInputPrompt("select machine");
    this.sourceSecGroupBox.setImmediate(true);
    for (SecGroupChoice choice : choices) {
        this.sourceSecGroupBox.addItem(choice.id);
        this.sourceSecGroupBox.setItemCaption(choice.id, choice.name);
    }
    this.sourceSecGroupBox.setValue(choices.get(0).id);
    this.sourceSecGroupBox.setEnabled(false);
    content.addComponent(this.sourceSecGroupBox);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSizeFull();
    buttonLayout.setSpacing(true);

    this.errorLabel = new Label("                                       ");
    this.errorLabel.setStyleName("errorMsg");
    this.errorLabel.setWidth("100%");
    buttonLayout.addComponent(this.errorLabel);
    buttonLayout.setExpandRatio(this.errorLabel, 1.0f);

    this.okButton = new Button("Ok", this);
    this.cancelButton = new Button("Cancel", this);
    this.cancelButton.focus();
    buttonLayout.addComponent(this.okButton);
    buttonLayout.addComponent(this.cancelButton);
    content.addComponent(buttonLayout);
    // content.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT);

    this.setContent(content);

}

From source file:org.ow2.sirocco.cloudmanager.util.InputDialog.java

License:Open Source License

private InputDialog(final String title, final String name, final String initialValue, final boolean isPassword,
        final DialogCallback callback) {
    super(title);
    this.callback = callback;
    this.center();
    this.setClosable(false);
    this.setModal(true);
    this.setResizable(false);

    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setSpacing(true);//  w  w w.  j  ava2 s.  c o  m
    verticalLayout.setMargin(true);

    FormLayout content = new FormLayout();
    content.setMargin(true);
    content.setWidth("400px");
    content.setHeight("100px");

    this.textField = isPassword ? new PasswordField(name) : new TextField(name);
    this.textField.setRequired(true);
    this.textField.setWidth("100%");
    this.textField.setRequired(true);
    this.textField.setRequiredError("Please provide a " + name);
    this.textField.setImmediate(true);
    if (initialValue != null) {
        this.textField.setValue(initialValue);
    }
    content.addComponent(this.textField);

    verticalLayout.addComponent(content);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth("100%");
    Label spacer = new Label("");
    buttonLayout.addComponent(spacer);
    spacer.setWidth("100%");
    buttonLayout.setExpandRatio(spacer, 1f);
    this.okButton = new Button("Ok", this);
    this.okButton.setClickShortcut(KeyCode.ENTER, null);
    this.cancelButton = new Button("Cancel", this);
    this.cancelButton.setClickShortcut(KeyCode.ESCAPE, null);
    this.cancelButton.focus();
    buttonLayout.addComponent(this.okButton);
    buttonLayout.addComponent(this.cancelButton);
    content.addComponent(buttonLayout);
    // content.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT);

    verticalLayout.addComponent(buttonLayout);

    this.setContent(verticalLayout);
}

From source file:org.ow2.sirocco.cloudmanager.VolumeAttachDialog.java

License:Open Source License

public VolumeAttachDialog(final List<MachineChoice> choices, final DialogCallback callback) {
    super("Attach Volume");
    this.callback = callback;
    this.center();
    this.setClosable(false);
    this.setModal(true);
    this.setResizable(false);

    FormLayout content = new FormLayout();
    content.setMargin(true);//from w  w w  . java  2s  . c  om
    content.setWidth("400px");
    content.setHeight("150px");

    this.machineBox = new ComboBox("Machine");
    this.machineBox.setRequired(true);
    this.machineBox.setTextInputAllowed(false);
    this.machineBox.setNullSelectionAllowed(false);
    this.machineBox.setInputPrompt("select machine");
    this.machineBox.setImmediate(true);
    content.addComponent(this.machineBox);

    this.deviceField = new TextField("Device location");
    this.deviceField.setRequired(true);
    this.deviceField.setWidth("80%");
    this.deviceField.setRequired(true);
    this.deviceField.setRequiredError("Please provide a device location");
    this.deviceField.setImmediate(true);
    content.addComponent(this.deviceField);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    this.okButton = new Button("Ok", this);
    this.cancelButton = new Button("Cancel", this);
    this.cancelButton.focus();
    buttonLayout.addComponent(this.okButton);
    buttonLayout.addComponent(this.cancelButton);
    content.addComponent(buttonLayout);
    content.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT);

    this.setContent(content);

    for (MachineChoice choice : choices) {
        this.machineBox.addItem(choice.id);
        this.machineBox.setItemCaption(choice.id, choice.name);
    }

}

From source file:org.ozkar.vaadinBootstrapp.login.LoginPage.java

public LoginPage() {

    final VerticalLayout root = new VerticalLayout();
    final FormLayout loginForm = new FormLayout();

    txtUsername.setRequired(true);//from  ww w .  j av  a 2s  . co  m
    txtPassword.setRequired(true);
    btnOk.setClickShortcut(KeyCode.ENTER);

    root.addComponent(loginForm);
    root.setComponentAlignment(loginForm, Alignment.MIDDLE_CENTER);
    root.setSizeFull();

    loginForm.addComponent(txtUsername);
    loginForm.addComponent(txtPassword);
    loginForm.addComponent(btnOk);

    loginForm.setSpacing(true);
    loginForm.setMargin(new MarginInfo(true, true, true, false));
    loginForm.setCaption(":::LOGIN:::");
    loginForm.setSizeUndefined();

    this.setSizeFull();
    this.setCompositionRoot(root);

    /* Event Handling */
    btnOk.addClickListener((Button.ClickEvent event) -> {

        User user = User.getUser(txtUsername.getValue());

        if (AuthUtils.validUser(user, txtPassword.getValue())) {
            Notification.show("Bienvenido...");
            AuthUtils.logIn(getUI(), user);
            getUI().getNavigator().navigateTo(HomePage.URL);
        } else {
            Notification.show("Usuario o Contrasea Incorrecto.");
        }
    });

}

From source file:org.qa82.analyzer.ui.PreferencesDialog.java

License:Open Source License

public PreferencesDialog() {
    super("Preferences"); // Set window caption

    center();//from   ww w . j  a  v a2  s  .co  m
    setClosable(true);
    setModal(true);
    ;
    setResizable(false);

    FormLayout layout = new FormLayout();

    // Form for editing the bean
    final BeanFieldGroup<UserData> binder = new BeanFieldGroup<UserData>(UserData.class);

    UserData userData = ((AnalyzerUI) UI.getCurrent()).getUserData();
    binder.setItemDataSource(userData);
    layout.addComponent(binder.buildAndBind("Repository", "repository"));

    // Buffer the form content
    binder.setBuffered(true);
    layout.addComponent(new Button("Save", new ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            try {
                binder.commit();
                close();
            } catch (CommitException e) {
            }
        }
    }));

    setContent(layout);
}

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);/* w  w  w . jav a  2s .co 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 ww  w. ja  v  a  2s.co 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   ww w  .j av  a 2  s  .com*/

    // 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//www  . java2s . co  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;
}