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:de.uni_tuebingen.qbic.qbicmainportlet.ChangeSampleMetadataComponent.java

License:Open Source License

private void buildFormLayout() {
    final FieldGroup fieldGroup = new FieldGroup();
    final FormLayout form2 = new FormLayout();
    this.fieldGroup = new FieldGroup();
    this.form = new FormLayout();

    Map<String, PropertyBean> controlledVocabularies = getControlledVocabularies();
    Map<String, PropertyBean> properties = getProperties();
    List<Property> xmlProps = getXMLProperties();

    for (Property f : xmlProps) {
        properties.PropertyType type = f.getType();

        String label = f.getLabel();
        if (f.hasUnit())
            label += " in " + f.getUnit();
        TextField tf = new TextField(label);
        tf.setData(type);// save property type for later, when it is written back
        fieldGroup.bind(tf, label);//from   w w w  .j  av  a2  s  .c  o  m
        tf.setCaption(label);
        tf.setDescription("Q_PROPERTIES");
        tf.setValue((String) f.getValue());
        form2.addComponent(tf);
    }

    for (String key : properties.keySet()) {
        if (controlledVocabularies.keySet().contains(key)) {
            ComboBox select = new ComboBox(controlledVocabularies.get(key).getLabel());
            fieldGroup.bind(select, key);

            // Add items with given item IDs
            select.addItems(controlledVocabularies.get(key).getVocabularyValues());

            select.setDescription(controlledVocabularies.get(key).getCode());
            select.setValue(properties.get(key).getValue());

            form2.addComponent(select);

        } else {
            TextField tf = new TextField(key);
            fieldGroup.bind(tf, key);
            tf.setCaption(properties.get(key).getLabel());
            tf.setDescription(properties.get(key).getCode());
            tf.setValue((String) properties.get(key).getValue());
            form2.addComponent(tf);
        }
    }
    this.fieldGroup = fieldGroup;
    this.form = form2;
}

From source file:dhbw.clippinggorilla.userinterface.views.ArchiveView.java

public ArchiveView() {
    HorizontalLayout optionsLayout = new HorizontalLayout();
    optionsLayout.setWidth("100%");

    Grid<Clipping> gridClippings = new Grid<>();
    Set<Clipping> clippings = ClippingUtils.getUserClippings(UserUtils.getCurrent(),
            LocalDate.now(ZoneId.of("Europe/Berlin")));
    gridClippings.setItems(clippings);/*from ww  w  . ja  v  a2 s . co m*/

    InlineDateTimeField datePicker = new InlineDateTimeField();
    datePicker.setValue(LocalDateTime.now(ZoneId.of("Europe/Berlin")));
    datePicker.setLocale(Locale.GERMANY);
    datePicker.setResolution(DateTimeResolution.DAY);
    datePicker.addValueChangeListener(date -> {
        Set<Clipping> clippingsOfDate = ClippingUtils.getUserClippings(UserUtils.getCurrent(),
                date.getValue().toLocalDate());
        gridClippings.setItems(clippingsOfDate);
        gridClippings.getDataProvider().refreshAll();
    });

    DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM);
    formatter.withZone(ZoneId.of("Europe/Berlin"));
    Column columnTime = gridClippings.addColumn(c -> {
        return c.getDate().format(formatter);
    });
    Language.setCustom(Word.TIME, s -> columnTime.setCaption(s));
    Column columnAmountArticles = gridClippings.addColumn(c -> {
        long amountArticles = c.getArticles().values().stream().flatMap(l -> l.stream()).count();
        amountArticles += c.getArticlesFromGroup().values().stream().flatMap(l -> l.stream()).count();
        if (amountArticles != 1) {
            return amountArticles + " " + Language.get(Word.ARTICLES);
        } else {
            return amountArticles + " " + Language.get(Word.ARTICLE);
        }
    });
    Language.setCustom(Word.ARTICLES, s -> {
        columnAmountArticles.setCaption(s);
        gridClippings.getDataProvider().refreshAll();
    });

    gridClippings.setHeight("100%");
    gridClippings.setSelectionMode(Grid.SelectionMode.SINGLE);
    gridClippings.addSelectionListener(c -> {
        if (c.getFirstSelectedItem().isPresent()) {
            currentClipping = c.getFirstSelectedItem().get();
            showClippingBy(currentClipping, currentSort);
        }
    });

    optionsLayout.addComponents(datePicker, gridClippings);
    optionsLayout.setComponentAlignment(datePicker, Alignment.BOTTOM_CENTER);
    optionsLayout.setComponentAlignment(gridClippings, Alignment.BOTTOM_RIGHT);
    optionsLayout.setExpandRatio(gridClippings, 5);

    VerticalLayout sortLayout = new VerticalLayout();

    comboBoxSortOptions = new ComboBox<>(Language.get(Word.SORT_BY));
    Language.setCustom(Word.SORT_BY, s -> {
        comboBoxSortOptions.setCaption(s);
        comboBoxSortOptions.getDataProvider().refreshAll();
    });
    comboBoxSortOptions.setItems(EnumSet.allOf(ClippingView.SortOptions.class));
    comboBoxSortOptions.setItemCaptionGenerator(s -> s.getName());
    comboBoxSortOptions.setItemIconGenerator(s -> s.getIcon());
    comboBoxSortOptions.setValue(currentSort);
    comboBoxSortOptions.setTextInputAllowed(false);
    comboBoxSortOptions.setEmptySelectionAllowed(false);
    comboBoxSortOptions.addStyleName("comboboxsort");
    comboBoxSortOptions.addValueChangeListener(e -> {
        currentSort = e.getValue();
        showClippingBy(currentClipping, currentSort);
    });
    comboBoxSortOptions.setVisible(false);

    sortLayout.setMargin(false);
    sortLayout.setSpacing(false);
    sortLayout.addComponent(comboBoxSortOptions);

    clippingArticlesLayout = new VerticalLayout();
    clippingArticlesLayout.setSpacing(true);
    clippingArticlesLayout.setMargin(false);
    clippingArticlesLayout.setSizeFull();

    addComponents(optionsLayout, sortLayout, clippingArticlesLayout);
}

From source file:dhbw.clippinggorilla.userinterface.views.ClippingView.java

public ClippingView(Clipping clipping) {
    User user = UserUtils.getCurrent();/* w  w  w .  j ava2 s. co  m*/

    clippingArticlesLayout = new VerticalLayout();
    clippingArticlesLayout.setSpacing(true);
    clippingArticlesLayout.setMargin(false);
    clippingArticlesLayout.setSizeFull();

    HorizontalLayout clippingOptionsLayout = new HorizontalLayout();
    clippingOptionsLayout.setSpacing(true);
    clippingOptionsLayout.setMargin(false);
    clippingOptionsLayout.setWidth("100%");

    ComboBox<SortOptions> comboBoxSortOptions = new ComboBox<>(Language.get(Word.SORT_BY));
    Language.setCustom(Word.SORT_BY, s -> {
        comboBoxSortOptions.setCaption(s);
        comboBoxSortOptions.getDataProvider().refreshAll();
    });
    comboBoxSortOptions.setItems(EnumSet.allOf(SortOptions.class));
    comboBoxSortOptions.setItemCaptionGenerator(s -> s.getName());
    comboBoxSortOptions.setItemIconGenerator(s -> s.getIcon());
    comboBoxSortOptions.setValue(SortOptions.BYPROFILE);
    comboBoxSortOptions.setTextInputAllowed(false);
    comboBoxSortOptions.setEmptySelectionAllowed(false);
    comboBoxSortOptions.addStyleName("comboboxsort");
    comboBoxSortOptions.addValueChangeListener(e -> {
        switch (e.getValue()) {
        case BYDATE:
            createClippingViewByDate(clipping);
            break;
        case BYPROFILE:
            createClippingViewByProfile(clipping);
            break;
        case BYSOURCE:
            createClippingViewBySource(clipping);
            break;
        }
    });

    Button buttonRegenerateClipping = new Button(VaadinIcons.REFRESH);
    buttonRegenerateClipping.addStyleName(ValoTheme.BUTTON_PRIMARY);
    buttonRegenerateClipping.addClickListener(ce -> {
        user.setLastClipping(ClippingUtils.generateClipping(user, false));
        ClippingGorillaUI.getCurrent().setMainContent(ClippingView.getCurrent());
    });

    clippingOptionsLayout.addComponents(comboBoxSortOptions, buttonRegenerateClipping);
    clippingOptionsLayout.setExpandRatio(comboBoxSortOptions, 5);
    clippingOptionsLayout.setComponentAlignment(buttonRegenerateClipping, Alignment.BOTTOM_CENTER);

    addComponents(clippingOptionsLayout, clippingArticlesLayout);

    createClippingViewByProfile(clipping);
    if (clipping.getArticles().keySet().isEmpty() && clipping.getArticlesFromGroup().keySet().isEmpty()) {
        Label labelNoProfile = new Label();
        Language.setCustom(Word.NO_PROFILE_PRESENT, s -> labelNoProfile.setValue(s));
        labelNoProfile.addStyleName(ValoTheme.LABEL_H2);
        clippingArticlesLayout.addComponent(labelNoProfile);
    }
}

From source file:ed.cracken.pos.ui.products.ProductForm.java

public void initComponents() {
    setId("product-form");
    setStyleName("product-form-wrapper");
    addStyleName("product-form");
    VerticalLayout formLayout = new VerticalLayout();
    formLayout.setHeightUndefined();//from ww  w . j  a va  2 s .  c  om
    formLayout.setSpacing(true);
    formLayout.setStyleName("form-layout");
    formLayout.addComponent(productName = new TextField("Name"));
    HorizontalLayout priceAndStockLayout = new HorizontalLayout();
    priceAndStockLayout.addComponent(price = new TextField("Price"));
    priceAndStockLayout.addComponent(stockCount = new TextField("Stock"));
    formLayout.addComponent(priceAndStockLayout);
    formLayout.addComponent(availability = new ComboBox("Availability"));
    formLayout.addComponent(category = new CategoryField("Category"));
    CssLayout separator = new CssLayout();
    separator.setStyleName("expander");
    formLayout.addComponent(separator);
    formLayout.addComponent(save = new Button("Save") {
        {
            setStyleName("primary");
            setId("save");
        }
    });
    formLayout.addComponent(cancel = new Button("Cancel") {
        {
            setStyleName("cancel");
            setId("cancel");
        }
    });
    formLayout.addComponent(delete = new Button("Delete") {
        {
            setStyleName("danger");
            setId("delete");
        }
    });
    addComponent(formLayout);

}

From source file:edu.kit.dama.ui.admin.AbstractBasePropertiesLayout.java

License:Apache License

/**
 * Get the group combobox allowing to select by which group the element is
 * available.// w  w w. j  a va 2  s.  co  m
 *
 * @return The groupbox.
 */
public final ComboBox getGroupBox() {
    if (groupBox == null) {
        String id = "groupBox";
        LOGGER.debug("Building " + DEBUG_ID_PREFIX + id + " ...");

        groupBox = new ComboBox("ACCESSIBLE BY");
        groupBox.setId(DEBUG_ID_PREFIX + id);
        groupBox.setWidth("100%");
        groupBox.setImmediate(true);
        groupBox.setNullSelectionAllowed(false);
        groupBox.addStyleName(CSSTokenContainer.BOLD_CAPTION);
    }
    return groupBox;
}

From source file:edu.kit.dama.ui.admin.administration.user.MembershipRoleEditorWindow.java

License:Apache License

/**
 * Get the role selection combobox./*from w w  w.j av  a 2  s  .  c o m*/
 *
 * @return The ComboBox.
 */
private ComboBox getRoleComboBox() {
    if (roleComboBox == null) {
        String id = "roleComboBox";
        LOGGER.debug("Building " + DEBUG_ID_PREFIX + id + " ...");

        roleComboBox = new ComboBox("NEW ROLE");
        roleComboBox.setId(DEBUG_ID_PREFIX + id);
        roleComboBox.setWidth("100%");
        roleComboBox.setNullSelectionAllowed(false);
        try {
            Role maxRole = (Role) UserServiceLocal.getSingleton().getRoleRestriction(userId,
                    UIHelper.getSessionContext());
            for (Role role : Role.getValidRoles()) {
                if (role.moreThan(maxRole)) {
                    //do not continue
                    break;
                }
                roleComboBox.addItem(role);
            }
            //select max. role by default
            roleComboBox.select(maxRole);
        } catch (UnauthorizedAccessAttemptException | EntityNotFoundException ex) {
            //unable to determine max. role, just continue
        }
        roleComboBox.addStyleName(CSSTokenContainer.BOLD_CAPTION);

    }
    return roleComboBox;
}

From source file:edu.kit.dama.ui.admin.administration.user.UserDataAdministrationTab.java

License:Apache License

private ComboBox getFilterColumnBox() {
    if (columnBox == null) {
        String id = "columnBox";
        LOGGER.debug("Building " + DEBUG_ID_PREFIX + id + " ...");

        columnBox = new ComboBox("TABLE COLUMN");
        columnBox.setId(DEBUG_ID_PREFIX + id);
        columnBox.setRequired(true);//from w w w  . j a  v  a2s  .c  o  m
        columnBox.setWidth("150px");
        columnBox.setNullSelectionAllowed(false);
        columnBox.setDescription("Table column that shall be filtered");
        columnBox.addStyleName(CSSTokenContainer.BOLD_CAPTION);

        columnBox.addValueChangeListener((Property.ValueChangeEvent event) -> {
            //reset search field on change
            getFilterSearchField().setValue("");
        });

        reloadFilterColumnBox();
    }
    return columnBox;
}

From source file:edu.kit.dama.ui.admin.administration.user.UserDataForm.java

License:Apache License

private ComboBox getMaximumRoleBox() {
    if (maximumRoleBox == null) {
        String id = "maximumRoleBox";
        LOGGER.debug("Building " + DEBUG_ID_PREFIX + id + " ...");

        maximumRoleBox = new ComboBox("MAXIMUM ROLE");
        maximumRoleBox.setId(DEBUG_ID_PREFIX + id);
        maximumRoleBox.setWidth("100%");
        maximumRoleBox.setRequired(true);
        maximumRoleBox.setNullSelectionAllowed(false);
        maximumRoleBox.setReadOnly(true);
        maximumRoleBox.setDescription("Maximum role of the selected user.");

        for (Role role : Role.getValidRoles()) {
            maximumRoleBox.addItem(role);
        }/*from ww  w .  java 2 s  .c om*/

        maximumRoleBox.select(null);
        maximumRoleBox.addStyleName(CSSTokenContainer.BOLD_CAPTION);
    }
    return maximumRoleBox;
}

From source file:edu.kit.dama.ui.admin.administration.usergroup.UserGroupAdministrationTab.java

License:Apache License

private ComboBox getColumnBox() {
    if (columnBox == null) {
        String id = "columnBox";
        LOGGER.debug("Building " + DEBUG_ID_PREFIX + id + " ...");

        columnBox = new ComboBox("TABLE COLUMN");
        columnBox.setId(DEBUG_ID_PREFIX + id);
        columnBox.setRequired(true);/*www .  ja v a2 s  . c  o m*/
        columnBox.setWidth("150px");
        columnBox.setNullSelectionAllowed(false);
        columnBox.addStyleName(CSSTokenContainer.BOLD_CAPTION);
        columnBox.setDescription("Table column that shall be filtered");

        columnBox.addValueChangeListener((Property.ValueChangeEvent event) -> {
            getFilterSearchField().setValue("");
        });

        reloadColumnBox();
    }
    return columnBox;
}

From source file:edu.kit.dama.ui.admin.schedule.trigger.AddTriggerComponent.java

License:Apache License

/**
 * Build the main layout including the type selection combobox, the buttons
 * and the placeholder for the property configuration component.
 *//*from   w ww . jav a 2 s .  co m*/
private void buildMainLayout() {
    triggerEditorLayout = new VerticalLayout();
    triggerEditorLayout.setSizeFull();
    triggerEditorLayout.setMargin(false);
    triggerEditorLayout.setSpacing(true);
    triggerEditorLayout.setWidth("400px");

    triggerTypeSelectionBox = new ComboBox("TRIGGER TYPE");
    triggerTypeSelectionBox.setWidth("100%");
    triggerTypeSelectionBox.setNullSelectionAllowed(false);
    triggerTypeSelectionBox.addStyleName(CSSTokenContainer.BOLD_CAPTION);

    for (TRIGGER_TYPE type : TRIGGER_TYPE.values()) {
        triggerTypeSelectionBox.addItem(type.toString());
        triggerTypeSelectionBox.setItemCaption(type.toString(), type.getName());
    }

    triggerTypeSelectionBox.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            updateTriggerSelection(TRIGGER_TYPE.valueOf((String) triggerTypeSelectionBox.getValue()));
        }
    });
    final Button createButton = new Button("Create");
    final Button cancelButton = new Button("Cancel");

    Button.ClickListener listener = new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (cancelButton.equals(event.getButton())
                    || (createButton.equals(event.getButton()) && createTrigger())) {
                //hide window if cration was canceled or if createTrigger succeeded (and 'create' was pressed) 
                parent.hideAddTriggerWindow();
            } //otherwise, createTrigger failed 
        }
    };

    createButton.addClickListener(listener);
    cancelButton.addClickListener(listener);

    HorizontalLayout buttonLayout = new HorizontalLayout(cancelButton, createButton);
    buttonLayout.setSpacing(true);
    mainLayout = new VerticalLayout(triggerTypeSelectionBox, triggerEditorLayout, buttonLayout);
    mainLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT);
    mainLayout.setExpandRatio(triggerTypeSelectionBox, .1f);
    mainLayout.setExpandRatio(triggerEditorLayout, .9f);
    mainLayout.setExpandRatio(buttonLayout, .1f);
    mainLayout.setSpacing(true);
    triggerTypeSelectionBox.setValue(TRIGGER_TYPE.NOW_TRIGGER.toString());
}