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

public ComboBox(String caption, Collection<T> options) 

Source Link

Document

Constructs a combo box with a static in-memory data provider with the given options.

Usage

From source file:org.processbase.ui.bpm.admin.ActivityWindow.java

License:Open Source License

public void addField(DataFieldDefinition dfd, Object value) {
    Field field = null;/*from   w  ww  .j  av  a  2 s  . c  o  m*/
    if (dfd.isEnumeration()) {
        field = new ComboBox(dfd.getName(), dfd.getEnumerationValues());
        ((ComboBox) field).setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS);
        ((ComboBox) field).setMultiSelect(false);
        if (value instanceof java.lang.String) {
            field.setValue(value);
        } else {
            field.setValue(dfd.getInitialValue());
        }
    } else {
        if (dfd.getDataTypeClassName().equals("java.lang.Long")) {
            field = new TextField(dfd.getLabel());
            if (value != null) {
                field.setValue(new Long(value.toString()));
            }
            //                    field.addValidator(new DoubleValidator("   "));
        } else if (dfd.getDataTypeClassName().equals("java.lang.Double")) {
            field = new TextField(dfd.getLabel());
            if (value != null) {
                field.setValue(new Double(value.toString()));
            }
            //                    field.addValidator(new DoubleValidator("   "));
        } else if (dfd.getDataTypeClassName().equals("java.util.Date")) {
            field = new PopupDateField(dfd.getLabel());
            if (value != null && value instanceof java.util.Date) {
                field.setValue(value);
            } else {
                field.setValue(new java.util.Date());
            }
            ((PopupDateField) field).setResolution(PopupDateField.RESOLUTION_DAY);
        } else if (dfd.getDataTypeClassName().equals("java.lang.String")) {
            field = new TextField(dfd.getLabel());
            field.setValue(value != null ? value.toString() : "");
        } else if (dfd.getDataTypeClassName().equals("java.lang.Boolean")) {
            field = new CheckBox(dfd.getLabel());
            field.setValue(value != null ? value : Boolean.FALSE);
        } else {
            field = new TextField(dfd.getLabel());
            field.setValue(value != null ? value.toString() : "");
        }
    }
    field.setDescription(dfd.getDescription() != null ? dfd.getDescription() : "");

    Item woItem = variablesTable.addItem(dfd);
    woItem.getItemProperty("name").setValue(dfd.getName());
    woItem.getItemProperty("label").setValue(dfd.getLabel());
    woItem.getItemProperty("type").setValue(dfd.getDataTypeClassName());
    woItem.getItemProperty("value").setValue(field);
}

From source file:org.processbase.ui.bpm.generator.GeneratedWindow.java

License:Open Source License

private ComboBox getComboBox(Widget widget, Collection options) {
    ComboBox component = new ComboBox(widget.getLabel(), options);
    component.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS);
    return component;
}

From source file:org.ripla.web.demo.config.views.SkinConfigurationView.java

License:Open Source License

/**
 * @param inSkinSelectController//  w w  w .jav  a  2s  .  c  o m
 */
public SkinConfigurationView(final SkinSelectController inController) {
    super();

    final IMessages lMessages = Activator.getMessages();
    final VerticalLayout lLayout = new VerticalLayout();
    setCompositionRoot(lLayout);
    lLayout.setStyleName("demo-view"); //$NON-NLS-1$
    lLayout.addComponent(new Label(String.format(RiplaViewHelper.TMPL_TITLE, "demo-pagetitle", //$NON-NLS-1$
            lMessages.getMessage("config.skin.page.title")), ContentMode.HTML)); //$NON-NLS-1$

    skinSelect = new ComboBox(null, SkinConfigRegistry.INSTANCE.getSkins());
    skinSelect.setNullSelectionAllowed(false);
    skinSelect.setNewItemsAllowed(false);
    skinSelect.setWidth(230, Unit.PIXELS);
    skinSelect.focus();
    lLayout.addComponent(skinSelect);

    final Button lSave = new Button(lMessages.getMessage("config.view.button.save")); //$NON-NLS-1$
    lSave.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final Button.ClickEvent inEvent) {
            inController.save((SkinBean) skinSelect.getValue());
        }
    });
    lSave.setClickShortcut(KeyCode.ENTER);
    lLayout.addComponent(lSave);
}

From source file:org.ripla.web.demo.widgets.views.SelectionWidgetsView.java

License:Open Source License

public SelectionWidgetsView(final CountryContainer inCountries) {
    super();//from  w  w w .  j  av a2 s.  c om

    final IMessages lMessages = Activator.getMessages();
    final VerticalLayout lLayout = initLayout(lMessages, "widgets.title.page.select"); //$NON-NLS-1$

    final HorizontalLayout lColumns = new HorizontalLayout();
    lColumns.setSpacing(true);
    lLayout.addComponent(lColumns);

    final VerticalLayout lCol1 = new VerticalLayout();
    lCol1.setSizeUndefined();
    lColumns.addComponent(lCol1);
    final VerticalLayout lCol2 = new VerticalLayout();
    lCol2.setSizeUndefined();
    lColumns.addComponent(lCol2);
    final VerticalLayout lCol3 = new VerticalLayout();
    lCol3.setSizeUndefined();
    lColumns.addComponent(lCol3);
    lColumns.setExpandRatio(lCol3, 1);

    lCol1.addComponent(getSubtitle(lMessages.getMessage("widgets.selection.subtitle.list"))); //$NON-NLS-1$
    final ListSelect lList1 = new ListSelect(null, inCountries);
    lList1.setItemCaptionMode(ItemCaptionMode.ID);
    lList1.setRows(10);
    lList1.setMultiSelect(true);
    lList1.setNullSelectionAllowed(false);
    lList1.select(inCountries.getIdByIndex(0));
    lList1.setImmediate(true);
    lList1.addValueChangeListener(new Listener());
    lCol1.addComponent(lList1);

    lCol1.addComponent(getSubtitle(lMessages.getMessage("widgets.selection.subtitle.combox"))); //$NON-NLS-1$
    final ComboBox lCombo = new ComboBox(null, inCountries);
    lCombo.setInputPrompt(lMessages.getMessage("widgets.selection.combox.prompt")); //$NON-NLS-1$
    lCombo.setNullSelectionAllowed(false);
    lCombo.setFilteringMode(FilteringMode.STARTSWITH);
    lCombo.setImmediate(true);
    lCombo.addValueChangeListener(new Listener());
    lCol1.addComponent(lCombo);

    lCol2.addComponent(getSubtitle(lMessages.getMessage("widgets.selection.subtitle.options.single"))); //$NON-NLS-1$
    List<String> lCountries = getRandomSubset(inCountries, OPTION_SIZE, System.currentTimeMillis());
    final OptionGroup lOptions1 = new OptionGroup(null, lCountries);
    lOptions1.setNullSelectionAllowed(false);
    lOptions1.select(lCountries.get(0));
    lOptions1.setImmediate(true);
    lOptions1.addValueChangeListener(new Listener());
    lCol2.addComponent(lOptions1);

    lCol2.addComponent(getSubtitle(lMessages.getMessage("widgets.selection.subtitle.options.multiple"))); //$NON-NLS-1$
    lCountries = getRandomSubset(inCountries, OPTION_SIZE, System.currentTimeMillis() + 2000);
    final OptionGroup lOptions2 = new OptionGroup(null, lCountries);
    lOptions2.setNullSelectionAllowed(false);
    lOptions2.setMultiSelect(true);
    lOptions2.select(lCountries.get(0));
    lOptions2.setImmediate(true);
    lOptions2.addValueChangeListener(new Listener());
    lCol2.addComponent(lOptions2);

    lCol3.addComponent(getSubtitle(lMessages.getMessage("widgets.selection.subtitle.twin"))); //$NON-NLS-1$
    final TwinColSelect lCountrySelect = new TwinColSelect();
    lCountrySelect.setContainerDataSource(inCountries);
    lCountrySelect.setRows(OPTION_SIZE);
    lCountrySelect.setNullSelectionAllowed(true);
    lCountrySelect.setMultiSelect(true);
    lCountrySelect.setWidth(400, Unit.PIXELS);
    lCol3.addComponent(lCountrySelect);
}

From source file:org.ripla.web.util.GenericSelect.java

License:Open Source License

/**
 * Creates a <code>Selection</code> widget with the provided options.
 * /*from  w w  w . ja  va 2  s  .co  m*/
 * @param inProperty
 *            {@link Property&lt;String>}
 * @param inOptions
 *            {@link Collection}
 * @param inWidth
 *            int
 * @param inAllowNull
 *            boolean
 * @param inProcessor
 *            {@link IProcessor} for post processing, may be
 *            <code>null</code>
 * @return {@link ComboBox}
 */
@SuppressWarnings("serial")
public static ComboBox getSelection(final Property<String> inProperty, final Collection<String> inOptions,
        final int inWidth, final boolean inAllowNull, final IProcessor inProcessor) {
    final ComboBox outSelect = new ComboBox(null, inOptions);
    outSelect.select(inProperty.getValue());
    outSelect.setStyleName("ripla-select"); //$NON-NLS-1$
    outSelect.setWidth(inWidth, Unit.PIXELS);
    outSelect.setNullSelectionAllowed(inAllowNull);
    outSelect.setImmediate(true);
    outSelect.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent inEvent) {
            final String lItemID = (String) inEvent.getProperty().getValue();
            inProperty.setValue(lItemID);
            if (inProcessor != null) {
                inProcessor.process(lItemID);
            }
        }
    });
    return outSelect;
}

From source file:org.vaadin.spinkit.demo.DemoUI.java

License:Apache License

private Component spinnerSizesContainer() {
    int types = SpinnerSize.values().length;
    GridLayout spinners = new GridLayout(4, (types / 4 + types % 4));
    spinners.setSizeFull();//ww  w .  j a  va 2s  .  c o  m
    spinners.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    spinners.setSpacing(true);

    ComboBox selector = new ComboBox("Select spinner type", Arrays.asList(SpinnerType.values()));
    selector.setNullSelectionAllowed(false);
    selector.setPageLength(0);
    selector.setValue(SpinnerType.ROTATING_PLANE);
    selector.addValueChangeListener(e -> {
        for (Component c : spinners) {
            if (c instanceof Spinner) {
                ((Spinner) c).setType((SpinnerType) selector.getValue());
            }
        }
    });

    StringToEnumConverter converter = new StringToEnumConverter();
    for (SpinnerSize size : SpinnerSize.values()) {
        Spinner spinner = new Spinner(SpinnerType.ROTATING_PLANE);
        spinner.setSize(size);
        spinner.setCaption(converter.convertToPresentation(size, String.class, getLocale()));
        spinners.addComponent(spinner);
    }

    VerticalLayout l = new VerticalLayout();
    l.setDefaultComponentAlignment(Alignment.TOP_CENTER);
    l.setSizeFull();
    l.setMargin(false);
    l.setSpacing(true);
    l.addComponents(selector, spinners);
    l.setExpandRatio(spinners, 1);
    return l;
}

From source file:pl.exsio.ca.module.config.groups.AssignmentsDataTable.java

License:Open Source License

private ComboBox getPreacherField(EntityItem<? extends OverseerAssignment> item) {
    JPAContainer<? extends Preacher> groups = JPAContainerFactory.make(this.caEntities.getPreacherClass(),
            this.preacherEntityProvider.getEntityManager());
    groups.setEntityProvider(this.preacherEntityProvider);
    ComboBox group = new ComboBox(t("preacher"), groups);
    group.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY);
    group.setItemCaptionPropertyId("caption");
    group.setPropertyDataSource(item.getItemProperty("preacher"));
    group.setConverter(new SingleSelectConverter(group));
    group.addValidator(new NullValidator(t("invalid_preacher"), false));
    return group;
}

From source file:pl.exsio.ca.module.config.preachers.AssignmentsDataTable.java

License:Open Source License

private ComboBox getFroupField(EntityItem<? extends PreacherAssignment> item) {
    JPAContainer<? extends ServiceGroup> groups = JPAContainerFactory
            .make(this.caEntities.getServiceGroupClass(), this.serviceGroupEntityProvider.getEntityManager());
    groups.setEntityProvider(this.serviceGroupEntityProvider);
    ComboBox group = new ComboBox(t("group"), groups);
    group.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY);
    group.setItemCaptionPropertyId("caption");
    group.setPropertyDataSource(item.getItemProperty("group"));
    group.setConverter(new SingleSelectConverter(group));
    group.addValidator(new NullValidator(t("invalid_group"), false));
    return group;
}

From source file:pl.exsio.ca.module.terrain.evidence.AssignmentsDataTable.java

License:Open Source License

private ComboBox getGroupField(EntityItem<? extends TerrainAssignment> item) throws UnsupportedFilterException {
    JPAContainer<? extends ServiceGroup> groups = JPAContainerFactory
            .make(this.caEntities.getServiceGroupClass(), this.serviceGroupEntityProvider.getEntityManager());
    groups.setEntityProvider(this.serviceGroupEntityProvider);
    groups.addContainerFilter(eq("archival", false));
    ComboBox group = new ComboBox(t("group"), groups);
    group.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY);
    group.setItemCaptionPropertyId("caption");
    group.setPropertyDataSource(item.getItemProperty("group"));
    group.setConverter(new SingleSelectConverter(group));
    group.addValidator(new NullValidator(t("invalid_group"), false));
    return group;
}

From source file:pl.exsio.ca.module.terrain.evidence.NotificationsDataTable.java

License:Open Source License

private ComboBox getOverrideGroupField(EntityItem<? extends TerrainNotification> item) {
    JPAContainer<? extends ServiceGroup> groups = JPAContainerFactory.make(
            this.caEntities.getServiceGroupClass(),
            this.caEntityProviders.getServiceGroupEntityProvider().getEntityManager());
    groups.setEntityProvider(this.caEntityProviders.getServiceGroupEntityProvider());
    ComboBox overrideGroup = new ComboBox(t("override_group"), groups);
    overrideGroup.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY);
    overrideGroup.setItemCaptionPropertyId("caption");
    overrideGroup.setPropertyDataSource(item.getItemProperty("overrideGroup"));
    overrideGroup.setConverter(new SingleSelectConverter(overrideGroup));
    return overrideGroup;
}