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:com.jain.addon.web.bean.factory.generator.select.RestrictionFieldGenerator.java

License:Apache License

public Field<?> createField(Class<?> type, JNIPropertyConstraint restriction) {
    final ComboBox field = new ComboBox(getCaption(restriction.getProperty()));
    field.setInputPrompt(getCaption(restriction.getProperty()));
    field.setDescription(getDescription(restriction.getProperty()));
    field.setFilteringMode(FilteringMode.STARTSWITH);

    Collection<?> values = extractValues(type, restriction);
    for (Object object : values) {
        field.addItem(object);//from  w w w  .j  ava 2  s  . c o m
        if (object instanceof JNINamed) {
            field.setItemCaption(object, ((JNINamed) object).getDisplayName());
        }
    }
    updateField(restriction, field);
    return field;
}

From source file:com.klwork.explorer.project.MyCalendarView.java

License:Apache License

private ComboBox createStyleNameComboBox() {
    ComboBox s = new ComboBox("");
    s.addContainerProperty("c", String.class, "");
    s.setItemCaptionPropertyId("c");
    Item i = s.addItem("color1");
    i.getItemProperty("c").setValue("");
    i = s.addItem("color2");
    i.getItemProperty("c").setValue("?");
    i = s.addItem("color3");
    i.getItemProperty("c").setValue("");
    i = s.addItem("color4");
    i.getItemProperty("c").setValue("");
    return s;/*  ww w.j  a  v a 2 s .  c o  m*/
}

From source file:com.klwork.explorer.project.MyCalendarView.java

License:Apache License

private ComboBox createTimeZoneSelect() {
    ComboBox s = new ComboBox("");
    s.addContainerProperty("caption", String.class, "");
    s.setItemCaptionPropertyId("caption");
    s.setFilteringMode(FilteringMode.CONTAINS);

    Item i = s.addItem(DEFAULT_ITEMID);/*from  w w  w .j  a  v  a  2 s.co  m*/
    i.getItemProperty("caption").setValue("Default (" + TimeZone.getDefault().getID() + ")");
    for (String id : TimeZone.getAvailableIDs()) {
        if (!s.containsId(id)) {
            i = s.addItem(id);
            i.getItemProperty("caption").setValue(id);
        }
    }

    if (testBench) {
        s.select("America/New_York");
    } else {
        s.select(DEFAULT_ITEMID);
    }
    s.setImmediate(true);
    s.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {

            updateCalendarTimeZone(event.getProperty().getValue());
        }
    });

    return s;
}

From source file:com.klwork.explorer.project.MyCalendarView.java

License:Apache License

private ComboBox createCalendarFormatSelect() {
    ComboBox s = new ComboBox("?");
    s.addContainerProperty("caption", String.class, "");
    s.setItemCaptionPropertyId("caption");

    Item i = s.addItem(DEFAULT_ITEMID);/* www.j  a  v  a  2 s  .  co  m*/
    i.getItemProperty("caption").setValue("");
    i = s.addItem(TimeFormat.Format12H);
    i.getItemProperty("caption").setValue("12H");
    i = s.addItem(TimeFormat.Format24H);
    i.getItemProperty("caption").setValue("24H");

    s.select(DEFAULT_ITEMID);
    s.setImmediate(true);
    s.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            updateCalendarFormat(event.getProperty().getValue());
        }
    });

    return s;
}

From source file:com.klwork.explorer.project.MyCalendarView.java

License:Apache License

private ComboBox createLocaleSelect() {
    ComboBox s = new ComboBox("/");
    s.addContainerProperty("caption", String.class, "");
    s.setItemCaptionPropertyId("caption");
    s.setFilteringMode(FilteringMode.CONTAINS);

    for (Locale l : Locale.getAvailableLocales()) {
        if (!s.containsId(l)) {
            Item i = s.addItem(l);//from w  ww  . j a  v  a  2 s .  co m
            i.getItemProperty("caption").setValue(getLocaleItemCaption(l));
        }
    }

    s.select(getLocale());
    s.setImmediate(true);
    s.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            updateCalendarLocale((Locale) event.getProperty().getValue());
        }
    });

    return s;
}

From source file:com.klwork.explorer.ui.business.project.MyCalendarView.java

License:Apache License

private ComboBox createCalendarFormatSelect() {
    ComboBox s = new ComboBox("?");
    s.addContainerProperty("caption", String.class, "");
    s.setItemCaptionPropertyId("caption");

    Item i = s.addItem(DEFAULT_ITEMID);/*w w w  .ja  va2s.  c  o  m*/
    i.getItemProperty("caption").setValue("");
    i = s.addItem(TimeFormat.Format12H);
    i.getItemProperty("caption").setValue("12H");
    i = s.addItem(TimeFormat.Format24H);
    i.getItemProperty("caption").setValue("24H");

    s.select(DEFAULT_ITEMID);
    s.setImmediate(true);
    s.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            updateCalendarFormat(event.getProperty().getValue());
        }
    });

    return s;
}

From source file:com.klwork.explorer.ui.form.EnumFormPropertyRenderer.java

License:Apache License

@SuppressWarnings("unchecked")
@Override//from   w  w  w  .j a  v a 2  s. 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;
    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
            }

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

    // Select first element
    if (firstItemId != null) {
        comboBox.select(firstItemId);
    }

    return comboBox;
}

From source file:com.ocs.dynamo.functional.ui.MultiDomainEditLayout.java

License:Apache License

public void build() {

    mainLayout = new DefaultVerticalLayout(true, true);

    // form that contains the combo box
    FormLayout form = new FormLayout();
    form.setMargin(true);/*from w  w  w .  j  av a 2  s .c om*/
    form.setStyleName(DynamoConstants.CSS_CLASS_HALFSCREEN);
    mainLayout.addComponent(form);

    // combo box for selecting domain
    domainCombo = new ComboBox(message("ocs.select.domain"));
    for (Class<? extends Domain> clazz : getDomainClasses()) {
        domainCombo.addItem(clazz);
        domainCombo.setItemCaption(clazz, getEntityModelFactory().getModel(clazz).getDisplayName());
    }
    domainCombo.setNullSelectionAllowed(false);
    domainCombo.setSizeFull();

    // respond to a change by displaying the correct domain
    domainCombo.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 8441066091930807231L;

        @Override
        @SuppressWarnings("unchecked")
        public void valueChange(ValueChangeEvent event) {
            selectDomain((Class<? extends Domain>) event.getProperty().getValue());
        }
    });

    form.addComponent(domainCombo);

    selectedDomainLayout = new DefaultVerticalLayout();
    mainLayout.addComponent(selectedDomainLayout);

    // select the first domain (if there is any)
    if (!getDomainClasses().isEmpty()) {
        domainCombo.setValue(getDomainClasses().get(0));
    }
    setCompositionRoot(mainLayout);
}

From source file:com.openhris.employee.EmployeeSummaryUI.java

public EmployeeSummaryUI(int branchId) {
    this.branchId = branchId;

    setSizeFull();/*from w w w  .  j  a va 2  s.  c  om*/
    setSpacing(true);
    setMargin(new MarginInfo(true, true, false, false));

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

    final ComboBox employeeStatus = new ComboBox("Status: ");
    employeeStatus.setWidth("150px");
    employeeStatus.setNullSelectionAllowed(false);
    employeeStatus.addItem("employed");
    employeeStatus.addItem("resigned");
    h.addComponent(employeeStatus);

    Button generateBtn = new Button("GENERATE EMPLOYEE SUMMARY");
    generateBtn.setWidth("250px");
    generateBtn.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (employeeStatus.getValue() == null) {
                getWindow().showNotification("Employee Status!", Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            tradeId = cs.getTradeIdByBranchId(getBranchId());
            corporateId = cs.getCorporateIdByTradeId(tradeId);

            summary.setContainerDataSource(
                    new EmployeeSummaryDataContainer(corporateId, employeeStatus.getValue().toString()));
        }
    });
    h.addComponent(generateBtn);
    h.setComponentAlignment(generateBtn, Alignment.BOTTOM_LEFT);

    Button exportTableToExcel = new Button("EXPORT TO EXCEL");
    exportTableToExcel.setWidth("250px");
    exportTableToExcel.addListener(new Button.ClickListener() {

        private static final long serialVersionUID = -73954695086117200L;
        private ExcelExport excelExport;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            excelExport = new ExcelExport(summary, "EMPLOYEE SUMMARY");
            excelExport.excludeCollapsedColumns();
            excelExport.setReportTitle(cs.getCorporateById(corporateId).toUpperCase() + " Employee Summary");
            excelExport.setExportFileName(cs.getCorporateById(corporateId).replace(",", " ").toUpperCase()
                    + "-Employee-Summary-" + ".xls");
            excelExport.export();
        }
    });
    h.addComponent(exportTableToExcel);
    h.setComponentAlignment(exportTableToExcel, Alignment.BOTTOM_LEFT);
    h.setExpandRatio(exportTableToExcel, 3);

    addComponent(h);
    addComponent(summary);
    setExpandRatio(summary, 2);
}

From source file:com.piccritic.website.PostQuickView.java

public PostQuickView() {
    setSizeFull();//from   ww  w .  j  a v  a2  s.com
    setHeightUndefined();
    tagSearch.addComponent(chooser);
    tagSearch.addComponent(searchTags);
    addComponent(tagSearch);
    gl.setSizeFull();
    gl.setHeightUndefined();

    //add sorting options combo box
    List<String> sortOptions = new ArrayList<>();
    sortOptions.add("Title");
    sortOptions.add("Upload Date");
    sortOptions.add("License");

    select = new ComboBox("Select sorting option");
    select.addItems(sortOptions);

    ValueChangeListener listener = new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            String option = (String) event.getProperty().getValue();
            option = option.replaceAll(" ", "");
            UI.getCurrent().getPage().setLocation("#!home/" + option);
            UI.getCurrent().getPage().reload();
        }
    };

    select.addValueChangeListener(listener);

    addComponent(select);

    addComponent(gl);

}