Example usage for com.vaadin.ui ComboBox ComboBox

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

Introduction

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

Prototype

protected ComboBox(DataCommunicator<T> dataCommunicator) 

Source Link

Document

Constructs and initializes an empty combo box.

Usage

From source file:nl.kpmg.lcm.ui.view.transfer.MonitorPanel.java

License:Apache License

private ComboBox initTaskStatusComboBox() throws UnsupportedOperationException {
    ComboBox statusComboBox = new ComboBox("Status");

    statusComboBox.addItem(ALL_KEY);// w w  w .j  av  a2s. c  o  m
    statusComboBox.setItemCaption(ALL_KEY, ALL_KEY);
    statusComboBox.addItem(TaskStatus.RUNNING);
    statusComboBox.setItemCaption(TaskStatus.RUNNING, TaskStatus.RUNNING.toString());
    statusComboBox.addItem(TaskStatus.FAILED);
    statusComboBox.setItemCaption(TaskStatus.FAILED, TaskStatus.FAILED.toString());
    statusComboBox.addItem(TaskStatus.SUCCESS);
    statusComboBox.setItemCaption(TaskStatus.SUCCESS, TaskStatus.SUCCESS.toString());
    statusComboBox.addItem(TaskStatus.PENDING);
    statusComboBox.setItemCaption(TaskStatus.PENDING, TaskStatus.PENDING.toString());
    statusComboBox.addItem(TaskStatus.SCHEDULED);
    statusComboBox.setItemCaption(TaskStatus.SCHEDULED, TaskStatus.SCHEDULED.toString());

    statusComboBox.addStyleName("margin-right-20");
    statusComboBox.addStyleName("width-search-field");
    statusComboBox.setRequired(true);
    statusComboBox.setInputPrompt("Please select one");

    return statusComboBox;
}

From source file:nl.kpmg.lcm.ui.view.transfer.SchedulePanel.java

License:Apache License

private ComboBox initRemoteLcmListComboBox() throws UnsupportedOperationException {
    ComboBox remoteLcmListComboBox = new ComboBox("Remote LCMs");
    RemoteLcmsRepresentation remoteLcms;
    try {/*  ww w. j a va  2  s  .  c o m*/
        remoteLcms = restClientService.getRemoteLcm();
        remoteLcmListComboBox.addItem("all");
        remoteLcmListComboBox.setItemCaption("all", "All");

        for (RemoteLcmRepresentation item : remoteLcms.getItems()) {
            RemoteLcm remoteLcm = item.getItem();
            String template = "%s://%s:%s";
            String url = String.format(template, remoteLcm.getProtocol(), remoteLcm.getDomain(),
                    remoteLcm.getPort().toString());

            remoteLcmUrlMap.put(remoteLcm.getId(), remoteLcm.getName() + " : " + url);
            remoteLcmListComboBox.addItem(remoteLcm.getId());
            remoteLcmListComboBox.setItemCaption(remoteLcm.getId(), remoteLcm.getName() + " : " + url);
            remoteLcmListComboBox.setTextInputAllowed(false);
        }
    } catch (ServerException ex) {
        LOGGER.error("Unable to load remote LCMs! Message:" + ex.getMessage());
    } catch (AuthenticationException | LcmBadRequestException ex) {
        LOGGER.error("Unable to reload remote LCMs." + ex.getMessage());
        Notification.show("Unable to reload the remote LCMs! Message: " + ex.getMessage());
    }

    remoteLcmListComboBox.addStyleName("margin-right-20");
    remoteLcmListComboBox.addStyleName("width-wide-search-field");
    remoteLcmListComboBox.setRequired(true);
    remoteLcmListComboBox.setInputPrompt("Please select one");

    return remoteLcmListComboBox;
}

From source file:org.abstractform.vaadin.VaadinFormToolkit.java

License:Apache License

protected AbstractComponent internalBuildField(Field field, Map<String, Object> extraObjects) {
    AbstractComponent ret = null;//w w w.  jav  a 2  s.c  o m
    if (field.getType().equals(Field.TYPE_BOOL)) {
        CheckBox cb = new CheckBox(field.getName());
        cb.setImmediate(true);
        ret = cb;
    } else if (field.getType().equals(Field.TYPE_DATETIME)) {
        DateField dt = new DateField(field.getName());
        dt.setResolution(DateField.RESOLUTION_DAY);
        dt.setDescription(field.getDescription());
        dt.setRequired(field.isRequired());
        dt.setImmediate(true);
        dt.setReadOnly(field.isReadOnly());
        ret = dt;
    } else if (field.getType().equals(Field.TYPE_TEXT) || field.getType().equals(Field.TYPE_NUMERIC)
            || field.getType().equals(Field.TYPE_PASSWORD)) {
        AbstractTextField textField;
        if (field.getType().equals(Field.TYPE_PASSWORD)) {
            textField = new PasswordField(field.getName());
        } else {
            textField = new TextField(field.getName());
        }
        //textField.setColumns(field.getDisplayWidth());
        if (field.getMaxLength() != 0) {
            textField.setMaxLength(field.getMaxLength());
        }
        textField.setDescription(field.getDescription());
        textField.setReadOnly(field.isReadOnly());
        textField.setNullRepresentation("".intern());
        textField.setNullSettingAllowed(true);
        textField.setRequired(field.isRequired());
        textField.setImmediate(true);
        textField.setWidth("100%");
        ret = textField;
    } else if (field.getType().equals(SelectorConstants.TYPE_SELECTOR)) {
        ComboBox comboBox = new ComboBox(field.getName());
        comboBox.setTextInputAllowed(false);
        comboBox.setNullSelectionAllowed(!field.isRequired());
        comboBox.setDescription(field.getDescription());
        comboBox.setReadOnly(field.isReadOnly());
        comboBox.setRequired(field.isRequired());
        comboBox.setImmediate(true);
        comboBox.setItemCaptionMode(ComboBox.ITEM_CAPTION_MODE_PROPERTY);
        comboBox.setItemCaptionPropertyId(VaadinSelectorContainer.PROPERTY_CAPTION);
        comboBox.setWidth("100%");
        ret = comboBox;
    } else if (field.getType().equals(TableConstants.TYPE_TABLE)) {
        ret = buildTableField(field, extraObjects);
    }
    return ret;
}

From source file:org.accelerators.activiti.admin.ui.GroupCreateForm.java

License:Open Source License

/**
 * // w ww . ja  v a 2  s.  co m
 * @param app
 */
public GroupCreateForm(AdminApp application) {

    // Set application reference
    this.app = application;

    // Enable buffering so that commit() must be called for the form.
    setWriteThrough(false);

    // Set the form to act immediately on user input.
    setImmediate(true);

    // Set form size
    setSizeFull();

    // Setup footer layout
    HorizontalLayout footer = new HorizontalLayout();
    footer.setSpacing(true);
    footer.setWidth("100%");
    footer.setVisible(true);

    // Add footer
    setFooter(footer);

    // Init buttons
    create = new Button(app.getMessage(Messages.Create), (ClickListener) this);
    close = new Button(app.getMessage(Messages.Close), (ClickListener) this);
    reset = new Button(app.getMessage(Messages.Reset), this, "discard");

    // Set button grid
    GridLayout grid = new GridLayout(3, 1);
    grid.addComponent(create, 0, 0);
    grid.addComponent(reset, 1, 0);
    grid.addComponent(close, 2, 0);
    grid.setSpacing(true);

    // Add grid to footer
    footer.addComponent(grid);

    // Right align buttons in footer
    footer.setComponentAlignment(grid, Alignment.BOTTOM_RIGHT);

    // Init group types
    types = new String[] { app.getMessage(Messages.Assignment), app.getMessage(Messages.Program),
            app.getMessage(Messages.Project), app.getMessage(Messages.Role), app.getMessage(Messages.Team),
            app.getMessage(Messages.Unit) };

    // Create combo box for group types
    groupTypes = new ComboBox("type");

    groupTypes.setFilteringMode(Filtering.FILTERINGMODE_STARTSWITH);
    for (int i = 0; i < types.length; i++) {
        groupTypes.addItem(types[i]);
    }

    // Propagate changes directly
    groupTypes.setImmediate(true);

    // Allow adding new group types
    groupTypes.setNewItemsAllowed(true);

    // Get available users
    members = new TwinColSelect(app.getMessage(Messages.Members), app.getAdminService().getUsers());

    // Set column headers
    members.setLeftColumnCaption(app.getMessage(Messages.AvailableUsers));
    members.setRightColumnCaption(app.getMessage(Messages.GroupMembers));

    // Propagate changes directly
    members.setImmediate(true);

    // Set max width
    members.setWidth("100%");

    // Field factory for over riding how fields are created
    setFormFieldFactory(new DefaultFieldFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public Field createField(Item item, Object propertyId, Component uiContext) {

            if (propertyId.equals("type")) {
                groupTypes.setWidth("100%");
                groupTypes.setRequired(false);
                groupTypes.setCaption(app.getMessage(Messages.Types));
                return groupTypes;
            }

            Field field = super.createField(item, propertyId, uiContext);

            if (propertyId.equals("id")) {
                TextField tf = (TextField) field;

                // Do not display "null" to the user when the field is empty
                tf.setNullRepresentation("");

                // Set as required field
                tf.setRequired(true);

                // Set error message
                tf.setRequiredError("Id is missing");

                // Set read only
                tf.setReadOnly(false);

            } else if (propertyId.equals("name")) {
                TextField tf = (TextField) field;

                // Do not display "null" to the user when the field is empty
                tf.setNullRepresentation("");

                // Set as required field
                tf.setRequired(true);

                // Set error message
                tf.setRequiredError(app.getMessage(Messages.GroupNameIsMissing));

            }

            field.setWidth("100%");
            return field;
        }
    });
}

From source file:org.accelerators.activiti.admin.ui.GroupEditForm.java

License:Open Source License

/**
 * /*from   w  ww .j  a v  a  2s  .c o m*/
 * @param app
 */
public GroupEditForm(AdminApp application) {

    // Set application reference
    this.app = application;

    // Enable buffering so that commit() must be called for the form.
    setWriteThrough(false);

    // Set the form to act immediately on user input.
    setImmediate(true);

    // Set form size
    setSizeFull();

    // Setup footer layout
    HorizontalLayout footer = new HorizontalLayout();
    footer.setSpacing(true);
    footer.setWidth("100%");
    footer.setVisible(true);

    // Add footer
    setFooter(footer);

    // Init buttons
    save = new Button(app.getMessage(Messages.Save), (ClickListener) this);
    close = new Button(app.getMessage(Messages.Close), (ClickListener) this);
    reset = new Button(app.getMessage(Messages.Reset), this, "discard");

    // Set button grid
    GridLayout grid = new GridLayout(3, 1);
    grid.addComponent(save, 0, 0);
    grid.addComponent(reset, 1, 0);
    grid.addComponent(close, 2, 0);
    grid.setSpacing(true);

    // Add grid to footer
    footer.addComponent(grid);

    // Right align buttons in footer
    footer.setComponentAlignment(grid, Alignment.BOTTOM_RIGHT);

    // Init group types
    types = new String[] { app.getMessage(Messages.Assignment), app.getMessage(Messages.Program),
            app.getMessage(Messages.Project), app.getMessage(Messages.Role), app.getMessage(Messages.Team),
            app.getMessage(Messages.Unit) };

    // Create combo box for group types
    groupTypes = new ComboBox("type");

    groupTypes.setFilteringMode(Filtering.FILTERINGMODE_STARTSWITH);
    for (int i = 0; i < types.length; i++) {
        groupTypes.addItem(types[i]);
    }

    // Propagate changes directly
    groupTypes.setImmediate(true);

    // Allow adding new group types
    groupTypes.setNewItemsAllowed(true);

    // Get available users
    members = new TwinColSelect(app.getMessage(Messages.Members), app.getAdminService().getUsers());

    // Set column headers
    members.setLeftColumnCaption(app.getMessage(Messages.AvailableUsers));
    members.setRightColumnCaption(app.getMessage(Messages.GroupMembers));

    // Propagate changes directly
    members.setImmediate(true);

    // Set max width
    members.setWidth("100%");

    // Field factory for over riding how fields are created
    setFormFieldFactory(new DefaultFieldFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public Field createField(Item item, Object propertyId, Component uiContext) {

            if (propertyId.equals("type")) {
                groupTypes.setWidth("100%");
                groupTypes.setRequired(false);
                groupTypes.setCaption(app.getMessage(Messages.Types));
                return groupTypes;
            }

            Field field = super.createField(item, propertyId, uiContext);

            if (propertyId.equals("id")) {
                TextField tf = (TextField) field;

                // Do not display "null" to the user when the field is empty
                tf.setNullRepresentation("");

                // Set as read-only. Changing the id will create a new
                // group.
                tf.setReadOnly(true);

                // Set as required field
                // tf.setRequired(true);

                // Set error message
                tf.setRequiredError("Id is missing");

            } else if (propertyId.equals("name")) {
                TextField tf = (TextField) field;

                // Do not display "null" to the user when the field is empty
                tf.setNullRepresentation("");

                // Set as required field
                tf.setRequired(true);

                // Set error message
                tf.setRequiredError(app.getMessage(Messages.GroupNameIsMissing));

            }

            field.setWidth("100%");
            return field;
        }
    });
}

From source file:org.activiti.explorer.ui.form.ComboAsignaturaFormPropertyRenderer.java

License:Apache License

@Override
public Field getPropertyField(FormProperty formProperty) {

    List<Asignatura> asignaturas = asignaturaService.findAll();
    ComboBox combo = new ComboBox(formProperty.getName());
    ids = new HashMap<>();
    for (Asignatura asig : asignaturas) {
        ids.put(asig.getName(), asig.getId());
        combo.addItem(asig.getName());//from   w w w.  j a v  a2  s .  co m
    }

    combo.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
    combo.setImmediate(true);

    return combo;
}

From source file:org.activiti.explorer.ui.form.ComboCarreraFormPropertyRenderer.java

License:Apache License

@Override
public Field getPropertyField(FormProperty formProperty) {

    List<Carreer> carreras = carreerService.findAll();
    ComboBox combo = new ComboBox(formProperty.getName());
    ids = new HashMap<>();
    for (Carreer carrera : carreras) {
        ids.put(carrera.getName(), carrera.getId());
        combo.addItem(carrera.getName());
    }/*w  ww.jav a 2s. c  o  m*/

    combo.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
    combo.setImmediate(true);

    return combo;
}

From source file:org.activiti.explorer.ui.form.ComboMateriaFormPropertyRenderer.java

License:Apache License

@Override
public Field getPropertyField(FormProperty formProperty) {

    List<Materia> materias = materiaService.findAll();
    ComboBox combo = new ComboBox(formProperty.getName());
    ids = new HashMap<>();
    for (Materia m : materias) {
        ids.put(m.getName(), m.getId());
        combo.addItem(m.getName());//from   w  w  w  .  j  a v a  2  s .  c om
    }

    combo.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
    combo.setImmediate(true);

    return combo;
}

From source file:org.activiti.explorer.ui.form.ComboSolicitudAsignaturaFormPropertyRenderer.java

License:Apache License

@Override
public Field getPropertyField(FormProperty formProperty) {

    List<SolicitudAsignatura> solicitudes = solicitudService.findall();
    ComboBox combo = new ComboBox(formProperty.getName());
    ids = new HashMap<>();
    for (SolicitudAsignatura solAs : solicitudes) {
        ids.put(solAs.getNombreAsignatura(), solAs.getId());
        combo.addItem(solAs.getNombreAsignatura());
    }/*from  w  w w  . j a v a  2 s  .c o m*/

    combo.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
    combo.setImmediate(true);

    return combo;
}

From source file:org.activiti.explorer.ui.form.EnumFormPropertyRenderer.java

License:Apache License

@SuppressWarnings("unchecked")
@Override/*from w  w w  .  jav a2s  .  co  m*/
public Field getPropertyField(FormProperty formProperty) {
    ComboBox comboBox = new ComboBox(getPropertyLabel(formProperty));
    comboBox.setRequired(formProperty.isRequired());
    comboBox.setRequiredError(getMessage(Messages.FORM_FIELD_REQUIRED, getPropertyLabel(formProperty)));
    comboBox.setEnabled(formProperty.isWritable());
    comboBox.setNullSelectionAllowed(false);

    Object firstItemId = null;
    Object itemToSelect = null;
    Map<String, String> values = (Map<String, String>) formProperty.getType().getInformation("values");
    if (values != null) {
        for (Entry<String, String> enumEntry : values.entrySet()) {
            // Add value and label (if any)
            comboBox.addItem(enumEntry.getKey());

            if (firstItemId == null) {
                firstItemId = enumEntry.getKey(); // select first element
            }

            String selectedValue = formProperty.getValue();
            if (selectedValue != null && selectedValue.equals(enumEntry.getKey())) {
                itemToSelect = enumEntry.getKey(); // select first element
            }

            if (enumEntry.getValue() != null) {
                comboBox.setItemCaption(enumEntry.getKey(), enumEntry.getValue());
            }
        }
    }

    // Select value or first element
    if (itemToSelect != null) {
        comboBox.select(itemToSelect);

    } else if (firstItemId != null) {
        comboBox.select(firstItemId);
    }

    return comboBox;
}