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.opennms.netmgt.bsm.vaadin.adminpage.BusinessServiceEdgeEditWindow.java

License:Open Source License

/**
 * Constructor/*w  w  w  .j  a va  2  s.co  m*/
 *
 * @param businessService        the Business Service DTO instance to be configured
 * @param businessServiceManager the Business Service Manager
 */
@SuppressWarnings("unchecked")
public BusinessServiceEdgeEditWindow(final BusinessService businessService,
        final BusinessServiceManager businessServiceManager, final Edge edge) {
    super("Business Service Edge Edit");

    /**
     * Basic window setup
     */
    setModal(true);
    setClosable(false);
    setResizable(false);
    setWidth(650, Unit.PIXELS);
    setHeight(325, Unit.PIXELS);

    /**
     * Creating the root layout...
     */
    final VerticalLayout rootLayout = new VerticalLayout();
    rootLayout.setSpacing(true);
    rootLayout.setMargin(false);

    /**
     * ...and the nested layout
     */
    final FormLayout formLayout = new FormLayout();
    formLayout.setSpacing(true);
    formLayout.setMargin(true);

    /**
     * type selector box
     */
    m_typeSelect = new NativeSelect("Type");
    m_typeSelect.setId("edgeTypeSelector");
    m_typeSelect.setMultiSelect(false);
    m_typeSelect.setNewItemsAllowed(false);
    m_typeSelect.setNullSelectionAllowed(false);
    m_typeSelect.setRequired(true);
    m_typeSelect.addItem(EdgeType.CHILD_SERVICE);
    m_typeSelect.setItemCaption(EdgeType.CHILD_SERVICE, "Child Service");
    m_typeSelect.addItem(EdgeType.IP_SERVICE);
    m_typeSelect.setItemCaption(EdgeType.IP_SERVICE, "IP Service");
    m_typeSelect.addItem(EdgeType.REDUCTION_KEY);
    m_typeSelect.setItemCaption(EdgeType.REDUCTION_KEY, "Reduction Key");
    m_typeSelect.setWidth(100.0f, Unit.PERCENTAGE);
    formLayout.addComponent(m_typeSelect);

    // List of child services
    m_childServiceComponent = new ComboBox("Child Service");
    m_childServiceComponent.setId("childServiceList");
    m_childServiceComponent.setInputPrompt("No child service selected");
    m_childServiceComponent.setNewItemsAllowed(false);
    m_childServiceComponent.setNullSelectionAllowed(false);
    m_childServiceComponent.setWidth(100.0f, Unit.PERCENTAGE);
    m_childServiceComponent.setVisible(false);
    m_childServiceComponent.setImmediate(true);
    m_childServiceComponent.setValidationVisible(true);
    m_childServiceComponent.setFilteringMode(FilteringMode.CONTAINS);
    m_childServiceComponent.addItems(businessServiceManager.getFeasibleChildServices(businessService).stream()
            .sorted(Ordering.natural().onResultOf(s -> BusinessServiceEditWindow.describeBusinessService(s)))
            .collect(Collectors.toList()));
    m_childServiceComponent.getItemIds().forEach(item -> m_childServiceComponent.setItemCaption(item,
            BusinessServiceEditWindow.describeBusinessService((BusinessService) item)));
    formLayout.addComponent(m_childServiceComponent);

    // List of IP services
    m_ipServiceComponent = new ComboBox("IP Service");
    m_ipServiceComponent.setId("ipServiceList");
    m_ipServiceComponent.setInputPrompt("No IP service selected");
    m_ipServiceComponent.setNewItemsAllowed(false);
    m_ipServiceComponent.setNullSelectionAllowed(false);
    m_ipServiceComponent.setWidth(100.0f, Unit.PERCENTAGE);
    m_ipServiceComponent.setVisible(false);
    m_ipServiceComponent.setImmediate(true);
    m_ipServiceComponent.setValidationVisible(true);
    m_ipServiceComponent.setFilteringMode(FilteringMode.CONTAINS);
    m_ipServiceComponent.addItems(businessServiceManager.getAllIpServices().stream()
            .sorted(Ordering.natural().onResultOf(s -> BusinessServiceEditWindow.describeIpService(s)))
            .collect(Collectors.toList()));
    m_ipServiceComponent.getItemIds().forEach(item -> m_ipServiceComponent.setItemCaption(item,
            BusinessServiceEditWindow.describeIpService((IpService) item)));
    formLayout.addComponent(m_ipServiceComponent);

    /**
     * reduction key input field
     */
    m_reductionKeyComponent = new TextField("Reduction Key");
    m_reductionKeyComponent.setId("reductionKeyField");
    m_reductionKeyComponent.setWidth(100.0f, Unit.PERCENTAGE);
    m_reductionKeyComponent.setVisible(false);
    m_reductionKeyComponent.setImmediate(true);
    m_reductionKeyComponent.setValidationVisible(true);
    formLayout.addComponent(m_reductionKeyComponent);

    /**
     * the friendly name
     */

    m_friendlyNameField = new TextField("Friendly Name");
    m_friendlyNameField.setId("friendlyNameField");
    m_friendlyNameField.setWidth(100.0f, Unit.PERCENTAGE);
    m_friendlyNameField.setVisible(false);
    m_friendlyNameField.setImmediate(true);
    m_friendlyNameField.setValidationVisible(true);
    m_friendlyNameField.setNullSettingAllowed(true);
    m_friendlyNameField.setNullRepresentation("");
    m_friendlyNameField.setMaxLength(FRIENDLY_NAME_MAXLENGTH);
    formLayout.addComponent(m_friendlyNameField);

    /**
     * show and hide components
     */
    m_typeSelect.addValueChangeListener(event -> {
        m_childServiceComponent.setVisible(m_typeSelect.getValue() == EdgeType.CHILD_SERVICE);
        m_childServiceComponent.setRequired(m_typeSelect.getValue() == EdgeType.CHILD_SERVICE);
        m_ipServiceComponent.setVisible(m_typeSelect.getValue() == EdgeType.IP_SERVICE);
        m_ipServiceComponent.setRequired(m_typeSelect.getValue() == EdgeType.IP_SERVICE);
        m_reductionKeyComponent.setVisible(m_typeSelect.getValue() == EdgeType.REDUCTION_KEY);
        m_reductionKeyComponent.setRequired(m_typeSelect.getValue() == EdgeType.REDUCTION_KEY);
        m_friendlyNameField.setVisible(m_typeSelect.getValue() == EdgeType.REDUCTION_KEY
                || m_typeSelect.getValue() == EdgeType.IP_SERVICE);
    });

    /**
     * map function field
     */
    m_mapFunctionSelect = new NativeSelect("Map Function", ImmutableList.builder().add(Decrease.class)
            .add(Identity.class).add(Ignore.class).add(Increase.class).add(SetTo.class).build());
    m_mapFunctionSelect.setId("mapFunctionSelector");
    m_mapFunctionSelect.setNullSelectionAllowed(false);
    m_mapFunctionSelect.setMultiSelect(false);
    m_mapFunctionSelect.setNewItemsAllowed(false);
    m_mapFunctionSelect.setRequired(true);
    m_mapFunctionSelect.setWidth(100.0f, Unit.PERCENTAGE);

    /**
     * setting the captions for items
     */
    m_mapFunctionSelect.getItemIds()
            .forEach(itemId -> m_mapFunctionSelect.setItemCaption(itemId, ((Class<?>) itemId).getSimpleName()));

    formLayout.addComponent(m_mapFunctionSelect);

    /**
     * severity selection field
     */
    m_mapFunctionSeveritySelect = new NativeSelect("Severity");
    m_mapFunctionSeveritySelect.setMultiSelect(false);
    m_mapFunctionSeveritySelect.setNewItemsAllowed(false);
    m_mapFunctionSeveritySelect.setNullSelectionAllowed(false);
    m_mapFunctionSeveritySelect.setRequired(false);
    m_mapFunctionSeveritySelect.addItem(Status.CRITICAL);
    m_mapFunctionSeveritySelect.setItemCaption(Status.CRITICAL, "Critical");
    m_mapFunctionSeveritySelect.addItem(Status.MAJOR);
    m_mapFunctionSeveritySelect.setItemCaption(Status.MAJOR, "Major");
    m_mapFunctionSeveritySelect.addItem(Status.MINOR);
    m_mapFunctionSeveritySelect.setItemCaption(Status.MINOR, "Minor");
    m_mapFunctionSeveritySelect.addItem(Status.WARNING);
    m_mapFunctionSeveritySelect.setItemCaption(Status.WARNING, "Warning");
    m_mapFunctionSeveritySelect.addItem(Status.NORMAL);
    m_mapFunctionSeveritySelect.setItemCaption(Status.NORMAL, "Normal");
    m_mapFunctionSeveritySelect.addItem(Status.INDETERMINATE);
    m_mapFunctionSeveritySelect.setItemCaption(Status.INDETERMINATE, "Indeterminate");
    m_mapFunctionSeveritySelect.setWidth(100.0f, Unit.PERCENTAGE);
    m_mapFunctionSeveritySelect.setEnabled(false);
    m_mapFunctionSeveritySelect.setImmediate(true);
    m_mapFunctionSeveritySelect.setValidationVisible(true);
    formLayout.addComponent(m_mapFunctionSeveritySelect);

    /**
     * hide or show additional severity input field
     */
    m_mapFunctionSelect.addValueChangeListener(event -> {
        m_mapFunctionSeveritySelect.setEnabled(SetTo.class.equals(m_mapFunctionSelect.getValue()));
        m_mapFunctionSeveritySelect.setRequired(SetTo.class.equals(m_mapFunctionSelect.getValue()));
    });

    /**
     * the weight input field
     */
    m_weightField = new TextField("Weight");
    m_weightField.setId("weightField");
    m_weightField.setRequired(true);
    m_weightField.setWidth(100.0f, Unit.PERCENTAGE);
    m_weightField.addValidator(value -> {
        try {
            int intValue = Integer.parseInt((String) value);
            if (intValue <= 0) {
                throw new Validator.InvalidValueException("Weight must be > 0");
            }
        } catch (final NumberFormatException e) {
            throw new Validator.InvalidValueException("Weight must be a number");
        }
    });
    m_weightField.setImmediate(true);
    m_weightField.setValidationVisible(true);
    formLayout.addComponent(m_weightField);

    /**
     * setting the defaults
     */
    m_typeSelect.setValue(EdgeType.CHILD_SERVICE);
    m_mapFunctionSelect.setValue(Identity.class);
    m_mapFunctionSeveritySelect.setValue(Status.INDETERMINATE);
    m_weightField.setValue(Integer.toString(Edge.DEFAULT_WEIGHT));

    /**
     * add the button layout...
     */
    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.setMargin(true);

    /**
     * ...and the save button
     */
    final Button saveButton = new Button(edge == null ? "Add Edge" : "Update Edge");
    saveButton.setId("saveEdgeButton");
    saveButton.addClickListener(UIHelper.getCurrent(TransactionAwareUI.class)
            .wrapInTransactionProxy((Button.ClickListener) event -> {
                if (!m_weightField.isValid())
                    return;
                if (!m_ipServiceComponent.isValid())
                    return;
                if (!m_childServiceComponent.isValid())
                    return;
                if (!m_reductionKeyComponent.isValid())
                    return;

                final MapFunction mapFunction = getMapFunction();
                final int weight = Integer.parseInt(m_weightField.getValue());

                /**
                 * in the case edge is not null, remove the old object...
                 */
                if (edge != null) {
                    businessService.removeEdge(edge);
                }

                /**
                 * ...and add the new edge
                 */
                switch ((EdgeType) m_typeSelect.getValue()) {
                case CHILD_SERVICE:
                    businessService.addChildEdge((BusinessService) m_childServiceComponent.getValue(),
                            mapFunction, weight);
                    break;
                case IP_SERVICE:
                    businessService.addIpServiceEdge((IpService) m_ipServiceComponent.getValue(), mapFunction,
                            weight, m_friendlyNameField.getValue());
                    break;
                case REDUCTION_KEY:
                    businessService.addReductionKeyEdge(m_reductionKeyComponent.getValue(), mapFunction, weight,
                            m_friendlyNameField.getValue());
                    break;
                }

                close();
            }));
    buttonLayout.addComponent(saveButton);

    /**
     * ...and a cancel button
     */
    final Button cancelButton = new Button("Cancel");
    cancelButton.setId("cancelEdgeButton");
    cancelButton.addClickListener((Button.ClickListener) event -> close());
    buttonLayout.addComponent(cancelButton);

    /**
     * when edge is not null, fill the components with values
     */
    if (edge != null) {
        edge.accept(new EdgeVisitor<Void>() {
            @Override
            public Void visit(IpServiceEdge edge) {
                m_typeSelect.setValue(EdgeType.IP_SERVICE);

                for (IpService ipService : (Collection<IpService>) m_ipServiceComponent.getItemIds()) {
                    if (ipService.getId() == edge.getIpService().getId()) {
                        m_ipServiceComponent.setValue(ipService);
                        break;
                    }
                }
                m_friendlyNameField.setValue(edge.getFriendlyName());
                m_ipServiceComponent.setEnabled(false);
                return null;
            }

            @Override
            public Void visit(ReductionKeyEdge edge) {
                m_typeSelect.setValue(EdgeType.REDUCTION_KEY);
                m_reductionKeyComponent.setValue(edge.getReductionKey());
                m_friendlyNameField.setValue(edge.getFriendlyName());
                m_reductionKeyComponent.setEnabled(false);
                return null;
            }

            @Override
            public Void visit(ChildEdge edge) {
                m_typeSelect.setValue(EdgeType.CHILD_SERVICE);
                m_childServiceComponent.setValue(edge.getChild());
                m_childServiceComponent.setEnabled(false);
                return null;
            }
        });

        m_typeSelect.setEnabled(false);
        m_mapFunctionSelect.setValue(edge.getMapFunction().getClass());

        edge.getMapFunction().accept(new MapFunctionVisitor<Void>() {
            @Override
            public Void visit(Decrease decrease) {
                m_mapFunctionSeveritySelect.setValue(Status.INDETERMINATE);
                return null;
            }

            @Override
            public Void visit(Identity identity) {
                m_mapFunctionSeveritySelect.setValue(Status.INDETERMINATE);
                return null;
            }

            @Override
            public Void visit(Ignore ignore) {
                m_mapFunctionSeveritySelect.setValue(Status.INDETERMINATE);
                return null;
            }

            @Override
            public Void visit(Increase increase) {
                m_mapFunctionSeveritySelect.setValue(Status.INDETERMINATE);
                return null;
            }

            @Override
            public Void visit(SetTo setTo) {
                m_mapFunctionSeveritySelect.setValue(((SetTo) edge.getMapFunction()).getStatus());
                return null;
            }
        });

        m_weightField.setValue(String.valueOf(edge.getWeight()));
    }

    /**
     * now set the root layout
     */
    rootLayout.addComponent(formLayout);
    rootLayout.addComponent(buttonLayout);
    rootLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT);
    setContent(rootLayout);
}

From source file:org.opennms.netmgt.vaadin.core.KeyValueInputDialogWindow.java

License:Open Source License

/**
 * Constructor responsible for creating new instances of this class
 *
 * @param caption   the window's title//from ww w.j  a v  a  2 s. c  o  m
 * @param keyName   the title of the key input field
 * @param valueName the title of the value input field
 */
public KeyValueInputDialogWindow(String caption, String keyName, String valueName) {
    super(caption);

    /**
     * set window properties
     */
    setModal(true);
    setClosable(false);
    setResizable(false);

    /**
     * create the main layout
     */
    VerticalLayout verticalLayout = new VerticalLayout();

    /**
     * add the key input field
     */
    m_keyInputField = new TextField(keyName);

    m_keyInputField.setValue("");
    m_keyInputField.setId("keyField");
    m_keyInputField.selectAll();
    m_keyInputField.setImmediate(true);
    m_keyInputField.focus();

    /**
     * add the value input field
     */
    m_valueInputField = new TextField(valueName);

    m_valueInputField.setValue("");
    m_valueInputField.setId("valueField");
    m_valueInputField.selectAll();
    m_valueInputField.setImmediate(true);

    /**
     * create nested FormLayout instance
     */
    FormLayout formLayout = new FormLayout();
    formLayout.setSizeUndefined();
    formLayout.setMargin(true);
    formLayout.addComponent(m_keyInputField);
    formLayout.addComponent(m_valueInputField);

    /**
     * add the buttons in a horizontal layout
     */
    HorizontalLayout horizontalLayout = new HorizontalLayout();

    horizontalLayout.setMargin(true);
    horizontalLayout.setSpacing(true);
    horizontalLayout.setWidth("100%");

    /**
     * create cancel button
     */
    m_cancelButton = new Button("Cancel");
    m_cancelButton.setId("cancelBtn");
    m_cancelButton.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
    m_cancelButton.addClickListener(this);

    horizontalLayout.addComponent(m_cancelButton);
    horizontalLayout.setExpandRatio(m_cancelButton, 1);
    horizontalLayout.setComponentAlignment(m_cancelButton, Alignment.TOP_RIGHT);

    /**
     * create ok button
     */
    m_okButton = new Button("OK");
    m_okButton.setId("okBtn");
    m_okButton.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
    m_okButton.addClickListener(this);

    horizontalLayout.addComponent(m_okButton);
    formLayout.addComponent(horizontalLayout);
    verticalLayout.addComponent(formLayout);

    addFocusListener(new FieldEvents.FocusListener() {
        @Override
        public void focus(FieldEvents.FocusEvent event) {
            if (m_focusKey) {
                m_keyInputField.focus();
            } else {
                m_valueInputField.focus();
            }
        }
    });

    /**
     * the close listener
     */
    addCloseListener(this);

    /**
     * set the content
     */
    setContent(verticalLayout);
}

From source file:org.opennms.netmgt.vaadin.core.StringInputDialogWindow.java

License:Open Source License

/**
 * Constructor responsible for creating new instances of this class
 *
 * @param caption   the window's title/*from ww w  .j a  v a  2 s .co  m*/
 * @param fieldName the title of the input field
 */
public StringInputDialogWindow(String caption, String fieldName) {
    super(caption);

    /**
     * set window properties
     */
    setModal(true);
    setClosable(false);
    setResizable(false);

    /**
     * create the main layout
     */
    VerticalLayout verticalLayout = new VerticalLayout();

    /**
     * add the input field
     */
    m_inputField = new TextField(fieldName);

    m_inputField.setValue("");
    m_inputField.focus();
    m_inputField.selectAll();
    m_inputField.setImmediate(true);

    /**
     * create nested FormLayout instance
     */
    FormLayout formLayout = new FormLayout();
    formLayout.setSizeUndefined();
    formLayout.setMargin(true);
    formLayout.addComponent(m_inputField);

    /**
     * add the buttons in a horizontal layout
     */
    HorizontalLayout horizontalLayout = new HorizontalLayout();

    horizontalLayout.setMargin(true);
    horizontalLayout.setSpacing(true);
    horizontalLayout.setWidth("100%");

    /**
     * create cancel button
     */
    m_cancelButton = new Button("Cancel");
    m_cancelButton.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
    m_cancelButton.addClickListener(this);

    horizontalLayout.addComponent(m_cancelButton);
    horizontalLayout.setExpandRatio(m_cancelButton, 1);
    horizontalLayout.setComponentAlignment(m_cancelButton, Alignment.TOP_RIGHT);

    /**
     * create ok button
     */
    m_okButton = new Button("OK");
    m_okButton.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
    m_okButton.addClickListener(this);

    horizontalLayout.addComponent(m_okButton);
    formLayout.addComponent(horizontalLayout);
    verticalLayout.addComponent(formLayout);

    /**
     * the close listener
     */
    addCloseListener(this);

    /**
     * set the content
     */
    setContent(verticalLayout);
}

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

License:Open Source License

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

    FormLayout content = new FormLayout();
    content.setMargin(true);/*  www  .  jav  a2  s . c  o m*/
    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);

    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.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();// w  w w  .  j a  v a  2  s  .co  m
    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);//from   ww  w .j  av a  2 s. 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);/*from   w w w  . java  2  s .  c om*/
    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);//w ww .ja va2 s.c  o m
    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  w w w .java 2  s  .  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  .ja v a 2  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);
}