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:com.ocs.dynamo.ui.composite.form.UploadForm.java

License:Apache License

@Override
protected void doBuildLayout(Layout main) {
    FormLayout form = new FormLayout();
    form.setMargin(true);//w w w .  ja v a  2s.c om
    if (ScreenMode.VERTICAL.equals(screenMode)) {
        form.setStyleName(DynamoConstants.CSS_CLASS_HALFSCREEN);
    }

    main.addComponent(form);

    // add custom components
    doBuildForm(form);

    // add file upload field
    UploadReceiver receiver = new UploadReceiver();

    Upload upload = new Upload(message("ocs.uploadform.title"), receiver);

    upload.addSucceededListener(receiver);
    form.addComponent(upload);

    if (showCancelButton) {
        Button cancelButton = new Button(message("ocs.cancel"));
        cancelButton.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                cancel();
            }
        });
        main.addComponent(cancelButton);
    }
}

From source file:com.oodrive.nuage.webui.component.DeviceItemComponent.java

License:Apache License

/**
 * Create the component to take a snapshot.
 * /*from ww  w .  j a va2  s  . c o m*/
 * @return the component
 */
@SuppressWarnings("serial")
private final AbstractComponent createTakeSnap() {

    final VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);
    layout.setMargin(true);

    final FormLayout takeSnapLayout = new FormLayout();
    takeSnapLayout.setMargin(true);
    takeSnapLayout.setImmediate(true);
    takeSnapLayout.setWidth(null);
    layout.addComponent(takeSnapLayout);
    layout.setComponentAlignment(takeSnapLayout, Alignment.MIDDLE_CENTER);

    // Enter name
    final TextField vvrName = new TextField("Name", "");
    takeSnapLayout.addComponent(vvrName);

    // take button
    final Button take = new Button("Take snapshot");
    layout.addComponent(take);
    layout.setComponentAlignment(take, Alignment.MIDDLE_CENTER);

    take.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            try {
                model.takeDeviceSnapshot(vvrName.getValue());
                Notification.show("New snapshot created", Notification.Type.TRAY_NOTIFICATION);
            } catch (final Exception e) {
                final ErrorWindow err = new ErrorWindow("Snapshot not taken: " + e.getMessage());
                err.add(model);
            }
        }
    });
    return layout;
}

From source file:com.oodrive.nuage.webui.component.DeviceItemComponent.java

License:Apache License

/**
 * Create attributes component.//from  w ww  . j  a va2s . c  om
 * 
 * @return the component
 */
private final AbstractComponent createAttributes() {

    final VerticalLayout layout = new VerticalLayout();

    final FormLayout deviceAttributesLayout = new FormLayout();
    deviceAttributesLayout.setMargin(true);
    deviceAttributesLayout.setWidth(null);
    deviceAttributesLayout.setImmediate(true);
    layout.addComponent(deviceAttributesLayout);
    layout.setComponentAlignment(deviceAttributesLayout, Alignment.MIDDLE_CENTER);

    // Enter NAME
    WebUiUtils.createFieldString(new StringAttributeOperation() {
        @Override
        public void setStringValue(final String value) {
            model.setDeviceName(value);
        }

        @Override
        public String getStringValue() {
            return model.getDeviceName();
        }
    }, "Name", deviceAttributesLayout, model);

    // Enter DESCRIPTION
    WebUiUtils.createFieldString(new StringAttributeOperation() {
        @Override
        public void setStringValue(final String value) {
            model.setDeviceDescription(value);
        }

        @Override
        public String getStringValue() {
            return model.getDeviceDescription();
        }
    }, "Description", deviceAttributesLayout, model);

    // Enter UUID (not editable)
    final TextField deviceUUID = new TextField("UUID", model.getItemUuid().toString());
    deviceUUID.setReadOnly(true);
    deviceUUID.setWidth("300px");
    deviceAttributesLayout.addComponent(deviceUUID);

    // Enter active
    final TextField deviceActive = new TextField("Active");
    if (model.isDeviceActive()) {
        deviceActive.setValue("yes");
    } else {
        deviceActive.setValue("no");
    }
    deviceActive.setReadOnly(true);
    deviceActive.setSizeFull();
    deviceAttributesLayout.addComponent(deviceActive);

    // Enter read only
    final TextField deviceReadOnly = new TextField("Read Only");
    if (model.isDeviceReadOnly()) {
        deviceReadOnly.setValue("yes");
    } else {
        deviceReadOnly.setValue("no");
    }
    deviceReadOnly.setReadOnly(true);
    deviceReadOnly.setSizeFull();
    deviceAttributesLayout.addComponent(deviceReadOnly);

    // Enter size
    WebUiUtils.createFieldLong(new LongAttributeOperation() {
        @Override
        public void setLongValue(final long value) {
            model.setDeviceSize(value);
        }

        @Override
        public long getLongValue() {
            return model.getDeviceSize();
        }

    }, "Size", deviceAttributesLayout, model);

    // Enter IQN
    WebUiUtils.createFieldString(new StringAttributeOperation() {
        @Override
        public void setStringValue(final String value) {
            model.setDeviceIqn(value);
        }

        @Override
        public String getStringValue() {
            return model.getDeviceIqn();
        }
    }, "IQN", deviceAttributesLayout, model);

    // Enter Alias
    WebUiUtils.createFieldString(new StringAttributeOperation() {
        @Override
        public void setStringValue(final String value) {
            model.setDeviceIscsiAlias(value);
        }

        @Override
        public String getStringValue() {
            return model.getDeviceIscsiAlias();
        }
    }, "iSCSI Alias", deviceAttributesLayout, model);

    // Enter iscsi block size
    WebUiUtils.createFieldInteger(new IntegerAttributeOperation() {
        @Override
        public void setIntegerValue(final int value) {
            model.setDeviceIscsiBlockSize(value);
        }

        @Override
        public int getIntegerValue() {
            return model.getDeviceIscsiBlockSize();
        }

    }, "iSCSI Block Size", deviceAttributesLayout, model, true);
    return layout;
}

From source file:com.oodrive.nuage.webui.component.SnapshotItemComponent.java

License:Apache License

/**
 * Create the component to create a device.
 * /*from   ww w.  j a  va  2 s .com*/
 * @return the component
 */
@SuppressWarnings("serial")
private final AbstractComponent createDevice() {

    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);

    final FormLayout createDeviceLayout = new FormLayout();
    createDeviceLayout.setMargin(true);
    createDeviceLayout.setWidth(null);
    createDeviceLayout.setImmediate(true);
    layout.addComponent(createDeviceLayout);
    layout.setComponentAlignment(createDeviceLayout, Alignment.MIDDLE_CENTER);

    // Enter name
    final TextField deviceName = new TextField("Name", "");
    createDeviceLayout.addComponent(deviceName);

    // Enter size
    final TextField deviceSize = new TextField("Size", "");
    createDeviceLayout.addComponent(deviceSize);

    // Create button
    final Button create = new Button("Create device");
    layout.addComponent(create);
    layout.setComponentAlignment(create, Alignment.MIDDLE_CENTER);

    create.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            try {
                model.createDevice(deviceName.getValue(), Long.valueOf(deviceSize.getValue()));
                Notification.show("New device created", Notification.Type.TRAY_NOTIFICATION);
            } catch (final NumberFormatException e) {
                final ErrorWindow err = new ErrorWindow("Size must be a valid number");
                err.add(model);
            } catch (final Exception e) {
                final ErrorWindow err = new ErrorWindow("Device not created: " + e.getMessage());
                err.add(model);
            }
        }
    });
    return layout;
}

From source file:com.oodrive.nuage.webui.component.SnapshotItemComponent.java

License:Apache License

/**
 * Create the component for the snapshot attributes
 * //w  w  w  .  j a  va 2  s.  c  o m
 * @return the component
 */
private final AbstractComponent createAttributes() {

    final VerticalLayout layout = new VerticalLayout();

    final FormLayout snapshotAttributesLayout = new FormLayout();
    snapshotAttributesLayout.setMargin(true);
    snapshotAttributesLayout.setWidth(null);
    snapshotAttributesLayout.setImmediate(true);
    layout.addComponent(snapshotAttributesLayout);
    layout.setComponentAlignment(snapshotAttributesLayout, Alignment.MIDDLE_CENTER);

    // Enter NAME
    WebUiUtils.createFieldString(new StringAttributeOperation() {
        @Override
        public void setStringValue(final String value) {
            model.setSnapshotName(value);
        }

        @Override
        public String getStringValue() {
            return model.getSnapshotName();
        }
    }, "Name", snapshotAttributesLayout, model);

    // Enter DESCRIPTION
    WebUiUtils.createFieldString(new StringAttributeOperation() {
        @Override
        public void setStringValue(final String value) {
            model.setSnapshotDescription(value);
        }

        @Override
        public String getStringValue() {
            return model.getSnapshotDescription();
        }
    }, "Description", snapshotAttributesLayout, model);

    // Enter UUID (not editable)
    final TextField snapUUID = new TextField("UUID", model.getItemUuid().toString());
    snapUUID.setReadOnly(true);
    snapUUID.setWidth("300px");
    snapshotAttributesLayout.addComponent(snapUUID);

    return layout;
}

From source file:com.oodrive.nuage.webui.component.window.VvrAttributesWindow.java

License:Apache License

@SuppressWarnings("serial")
@Override/*from  w  ww .  j a v a 2 s  . co  m*/
public final Window init(final AbstractItemModel model) {

    // Cast model in vvrModel
    final VvrModel vvrModel = (VvrModel) model;
    // Add new window
    final Window vvrAttributesWindow = new Window("VVR Attributes");
    vvrAttributesWindow.center();
    vvrAttributesWindow.setWidth("400px");
    vvrAttributesWindow.setResizable(false);

    final VerticalLayout layout = new VerticalLayout();
    vvrAttributesWindow.setContent(layout);
    layout.setMargin(true);

    final FormLayout vvrAttributesLayout = new FormLayout();
    layout.addComponent(vvrAttributesLayout);
    vvrAttributesLayout.setMargin(true);

    // Enter NAME
    String value = vvrModel.getVvrName();
    if (value == null) {
        value = "";
    }
    final TextField name = new TextField("Name", value);
    name.setSizeFull();
    vvrAttributesLayout.addComponent(name);

    // Enter description
    value = vvrModel.getVvrDescription();
    if (value == null) {
        value = "";
    }
    final TextField desc = new TextField("Description", value);
    desc.setSizeFull();
    vvrAttributesLayout.addComponent(desc);

    // Enter name
    final TextField vvrUUID = new TextField("UUID");
    vvrUUID.setValue(vvrUuid.toString());
    vvrUUID.setReadOnly(true);
    vvrUUID.setSizeFull();
    vvrAttributesLayout.addComponent(vvrUUID);

    // OK button
    final HorizontalLayout hzlayout = new HorizontalLayout();
    layout.addComponent(hzlayout);
    hzlayout.setSizeFull();

    final Button okButton = new Button("OK");
    hzlayout.addComponent(okButton);
    hzlayout.setComponentAlignment(okButton, Alignment.MIDDLE_CENTER);

    okButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            WaitingComponent.executeBackground(vvrModel, new Background() {
                @Override
                public void processing() {
                    vvrModel.setVvrName(name.getValue());
                    vvrModel.setVvrDescription(desc.getValue());
                }

                @Override
                public void postProcessing() {
                }
            });
            vvrAttributesWindow.close();
        }
    });

    // Cancel button
    final Button cancelButton = new Button("Cancel");
    hzlayout.addComponent(cancelButton);
    hzlayout.setComponentAlignment(cancelButton, Alignment.MIDDLE_CENTER);

    cancelButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            // Just close the window
            vvrAttributesWindow.close();
        }
    });
    return vvrAttributesWindow;
}

From source file:com.oodrive.nuage.webui.component.window.VvrCreateWindow.java

License:Apache License

@SuppressWarnings("serial")
@Override/*from  w w  w . java  2s . c  o m*/
public final Window init(final AbstractItemModel model) {

    // Add new window
    vvrCreateWindow.center();
    final FormLayout vvrCreateLayout = new FormLayout();
    vvrCreateLayout.setMargin(true);
    vvrCreateWindow.setContent(vvrCreateLayout);
    vvrCreateWindow.setResizable(false);
    vvrCreateWindow.setClosable(false);

    // Enter name
    final TextField vvrName = new TextField("Name");
    vvrName.setValue("");
    vvrCreateLayout.addComponent(vvrName);

    // Enter decription
    final TextField vvrDescription = new TextField("Description");
    vvrDescription.setValue("");
    vvrCreateLayout.addComponent(vvrDescription);

    // Button create
    final Button vvrCreateButton = new Button("Create");
    vvrCreateLayout.addComponent(vvrCreateButton);
    vvrCreateButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            try {
                ((VvrManagerModel) model).createVvr(vvrName.getValue(), vvrDescription.getValue());
                Notification.show("New VVR created", Notification.Type.TRAY_NOTIFICATION);
                postProcessing.execute();
            } catch (final Exception e) {
                final ErrorWindow err = new ErrorWindow("VVR not created: " + e.getMessage());
                err.add(model);
            }
        }
    });
    return vvrCreateWindow;
}

From source file:com.oodrive.nuage.webui.WebUiUtils.java

License:Apache License

/**
 * Create a new String text field with a given setter/getter.
 * //  w  ww  .j  a va 2s  . com
 * @param operation
 *            the operation to get/set the value contains in the text field.
 * @param fieldName
 *            the name of the field
 * @param rootLayout
 *            the layout to add the text field
 * @param model
 *            the model used to get/set the value
 */
@SuppressWarnings({ "serial" })
public static final void createFieldString(final StringAttributeOperation operation, final String fieldName,
        final FormLayout rootLayout, final AbstractItemModel model) {

    String value = operation.getStringValue();
    // Display empty string if value is null
    if (value == null) {
        value = "";
    }
    final TextField field = new TextField(fieldName, value);
    field.setWidth("250px");
    field.setImmediate(true);
    rootLayout.addComponent(field);

    field.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent event) {
            final String newValue = String.valueOf(event.getProperty().getValue());
            final String oldValue = operation.getStringValue();
            if (!newValue.equals(oldValue)) {
                // Set value in background (could be a long operation)
                WaitingComponent.executeBackground(model, new Background() {
                    @Override
                    public void processing() {
                        operation.setStringValue(newValue);
                    }

                    @Override
                    public void postProcessing() {
                        Notification.show(fieldName + " changed", newValue,
                                Notification.Type.TRAY_NOTIFICATION);
                    }
                });

            }
        }
    });
}

From source file:com.oodrive.nuage.webui.WebUiUtils.java

License:Apache License

/**
 * Create a new long text field with a given setter/getter.
 * /*  w  w w . j  a  va  2s.co  m*/
 * @param operation
 *            the operation to get/set the value contains in the text field.
 * @param fieldName
 *            the name of the field
 * @param rootLayout
 *            the layout to add the text field
 * @param model
 *            the model used to get/set the value
 */
@SuppressWarnings({ "serial" })
public static final void createFieldLong(final LongAttributeOperation operation, final String fieldName,
        final FormLayout rootLayout, final AbstractItemModel model) {

    final TextField field = new TextField(fieldName, Long.toString(operation.getLongValue()));
    field.setWidth("250px");
    field.setImmediate(true);
    rootLayout.addComponent(field);

    field.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent event) {
            final String newValue = String.valueOf(event.getProperty().getValue());
            final String oldValue = Long.toString(operation.getLongValue());
            if (!oldValue.equals(newValue)) {
                try {
                    // Cast here to check format
                    final long longNewValue = Long.valueOf(newValue);

                    // Set value in background (could be a long operation)
                    WaitingComponent.executeBackground(model, new Background() {
                        @Override
                        public void processing() {
                            operation.setLongValue(longNewValue);
                        }

                        @Override
                        public void postProcessing() {
                            // Get the new real value set in the model (can be different)
                            final String newValue = Long.toString(operation.getLongValue());
                            Notification.show(fieldName + " changed", newValue,
                                    Notification.Type.TRAY_NOTIFICATION);
                            // Reset the field with the new value
                            field.setValue(newValue);
                        }
                    });
                } catch (final NumberFormatException e) {
                    final ErrorWindow err = new ErrorWindow("You must enter a valid number");
                    err.add(model);
                    // Reset the last value
                    field.setValue(oldValue);
                }
            }
        }
    });
}

From source file:com.oodrive.nuage.webui.WebUiUtils.java

License:Apache License

/**
 * Create a new integer text field with a given setter/getter.
 * //from ww  w.ja  v a2 s  .c o  m
 * @param operation
 *            the operation to get/set the value contains in the text field.
 * @param fieldName
 *            the name of the field
 * @param rootLayout
 *            the layout to add the text field
 * @param model
 *            the model used to get/set the value
 */
@SuppressWarnings({ "serial" })
public static final void createFieldInteger(final IntegerAttributeOperation operation, final String fieldName,
        final FormLayout rootLayout, final AbstractItemModel model, final boolean emptyAllowed) {

    final TextField field = new TextField(fieldName, Integer.toString(operation.getIntegerValue()));
    field.setWidth("250px");
    field.setImmediate(true);
    rootLayout.addComponent(field);

    field.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent event) {
            final String newValue = String.valueOf(event.getProperty().getValue());
            final String oldValue = Integer.toString(operation.getIntegerValue());
            if (!oldValue.equals(newValue)) {
                try {
                    final int intNewValue;

                    if (emptyAllowed && "".equals(newValue)) {
                        // Empty equals 0
                        intNewValue = 0;
                    } else {
                        // Cast here to check format
                        intNewValue = Integer.valueOf(newValue);
                    }

                    // Set value in background (could be a long operation)
                    WaitingComponent.executeBackground(model, new Background() {
                        @Override
                        public void processing() {
                            operation.setIntegerValue(intNewValue);
                        }

                        @Override
                        public void postProcessing() {
                            // Get the new real value set in the model (can be different)
                            final String newValue = Integer.toString(operation.getIntegerValue());
                            Notification.show(fieldName + " changed", newValue,
                                    Notification.Type.TRAY_NOTIFICATION);
                            // Reset the field with the new value
                            field.setValue(newValue);
                        }
                    });
                } catch (final NumberFormatException e) {
                    final ErrorWindow err = new ErrorWindow("You must enter a valid number");
                    err.add(model);
                    // Reset the last value
                    field.setValue(oldValue);
                }
            }
        }
    });
}