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.etest.valo.ComboBoxes.java

License:Apache License

public ComboBoxes() {
    setMargin(true);/* ww w.j  a  v  a  2  s.  c o  m*/

    Label h1 = new Label("Combo Boxes");
    h1.addStyleName("h1");
    addComponent(h1);

    HorizontalLayout row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    ComboBox combo = new ComboBox("Normal");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setNullSelectionAllowed(false);
    combo.select(combo.getItemIds().iterator().next());
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.setItemIcon(combo.getItemIds().iterator().next(), new ThemeResource("../runo/icons/16/document.png"));
    row.addComponent(combo);

    CssLayout group = new CssLayout();
    group.setCaption("Grouped with a Button");
    group.addStyleName("v-component-group");
    row.addComponent(group);

    combo = new ComboBox();
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setNullSelectionAllowed(false);
    combo.select(combo.getItemIds().iterator().next());
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.setWidth("240px");
    group.addComponent(combo);
    Button today = new Button("Do It");
    group.addComponent(today);

    combo = new ComboBox("Explicit size");
    combo.setInputPrompt("You can type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setWidth("260px");
    combo.setHeight("60px");
    row.addComponent(combo);

    combo = new ComboBox("No text input allowed");
    combo.setInputPrompt("You can click here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setTextInputAllowed(false);
    combo.setNullSelectionAllowed(false);
    combo.select("Option One");
    row.addComponent(combo);

    combo = new ComboBox("Error");
    combo.setInputPrompt("You can type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setNullSelectionAllowed(false);
    combo.select("Option One");
    combo.setComponentError(new UserError("Fix it, now!"));
    row.addComponent(combo);

    combo = new ComboBox("Error, borderless");
    combo.setInputPrompt("You can type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setNullSelectionAllowed(false);
    combo.select("Option One");
    combo.setComponentError(new UserError("Fix it, now!"));
    combo.addStyleName("borderless");
    row.addComponent(combo);

    combo = new ComboBox("Disabled");
    combo.setInputPrompt("You can't type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setEnabled(false);
    row.addComponent(combo);

    combo = new ComboBox("Custom color");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.addStyleName("color1");
    row.addComponent(combo);

    combo = new ComboBox("Custom color");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.addStyleName("color2");
    row.addComponent(combo);

    combo = new ComboBox("Custom color");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.addStyleName("color3");
    row.addComponent(combo);

    combo = new ComboBox("Small");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.addStyleName("small");
    row.addComponent(combo);

    combo = new ComboBox("Large");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.addStyleName("large");
    row.addComponent(combo);

    combo = new ComboBox("Borderless");
    combo.setInputPrompt("You can type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.addStyleName("borderless");
    row.addComponent(combo);

    combo = new ComboBox("Tiny");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.addStyleName("tiny");
    row.addComponent(combo);

    combo = new ComboBox("Huge");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.addStyleName("huge");
    row.addComponent(combo);
}

From source file:com.etest.view.testbank.CellCaseWindow.java

Window modifyCaseWindow(CellCase cellCase) {
    VerticalLayout v = new VerticalLayout();
    v.setWidth("100%");
    v.setMargin(true);/*from w  w w  . j a  v  a2  s  . c  o  m*/
    v.setSpacing(true);

    Window sub = new Window("MODIFY");
    sub.setWidth("400px");
    sub.setModal(true);
    sub.center();

    ComboBox actionDone = new ComboBox("Action: ");
    actionDone.setWidth("70%");
    actionDone.addStyleName(ValoTheme.COMBOBOX_SMALL);
    actionDone.setNullSelectionAllowed(false);
    actionDone.addItem("resolved");
    actionDone.addItem("clarified");
    actionDone.addItem("modified");
    actionDone.setImmediate(true);
    v.addComponent(actionDone);

    TextArea remarks = new TextArea("Remarks: ");
    remarks.setWidth("100%");
    remarks.setRows(3);
    v.addComponent(remarks);

    Button modify = new Button("UPDATE");
    modify.setWidth("70%");
    modify.setIcon(FontAwesome.EDIT);
    modify.addStyleName(ValoTheme.BUTTON_PRIMARY);
    modify.addStyleName(ValoTheme.BUTTON_SMALL);
    modify.addClickListener((Button.ClickEvent event) -> {
        if (remarks.getValue() == null || remarks.getValue().trim().isEmpty()) {
            Notification.show("Add remarks!", Notification.Type.WARNING_MESSAGE);
            return;
        }

        if (actionDone.getValue() == null) {
            Notification.show("Add action!", Notification.Type.WARNING_MESSAGE);
            return;
        }

        cellCase.setActionDone(actionDone.getValue().toString());
        cellCase.setRemarks(remarks.getValue().trim());
        boolean result = ccs.modifyCellCase(cellCase);
        if (result) {
            Notification.show("Case has been Modified!", Notification.Type.TRAY_NOTIFICATION);
            sub.close();
            close();
        }
    });
    v.addComponent(modify);

    sub.setContent(v);
    sub.getContent().setHeightUndefined();

    return sub;
}

From source file:com.etest.view.testbank.cellitem.CellItemWindow.java

Window modifyCellItemWindow(CellItem ci) {
    VerticalLayout v = new VerticalLayout();
    v.setWidth("100%");
    v.setMargin(true);//from   w  ww  .j  a v  a  2  s.c  om
    v.setSpacing(true);

    Window sub = new Window("MODIFY");
    sub.setWidth("400px");
    sub.setModal(true);
    sub.center();

    ComboBox actionDone = new ComboBox("Action: ");
    actionDone.setWidth("70%");
    actionDone.addStyleName(ValoTheme.COMBOBOX_SMALL);
    actionDone.setNullSelectionAllowed(false);
    actionDone.addItem("resolved");
    actionDone.addItem("clarified");
    actionDone.addItem("modified");
    actionDone.setImmediate(true);
    v.addComponent(actionDone);

    TextArea remarks = new TextArea("Remarks: ");
    remarks.setWidth("100%");
    remarks.setRows(3);
    v.addComponent(remarks);

    Button modify = new Button("UPDATE");
    modify.setWidth("70%");
    modify.setIcon(FontAwesome.EDIT);
    modify.addStyleName(ValoTheme.BUTTON_PRIMARY);
    modify.addStyleName(ValoTheme.BUTTON_SMALL);
    modify.addClickListener((Button.ClickEvent event) -> {
        if (remarks.getValue() == null || remarks.getValue().trim().isEmpty()) {
            Notification.show("Add remarks!", Notification.Type.WARNING_MESSAGE);
            return;
        }

        if (actionDone.getValue() == null) {
            Notification.show("Add action!", Notification.Type.WARNING_MESSAGE);
            return;
        }

        ci.setRemarks(remarks.getValue().trim());
        ci.setActionDone(actionDone.getValue().toString());
        boolean result = cis.modifyCellItem(ci);
        if (result) {
            sub.close();
            close();
        }
    });
    v.addComponent(modify);

    sub.setContent(v);
    sub.getContent().setHeightUndefined();

    return sub;
}

From source file:com.etest.view.testbank.cellitem.CellItemWindow.java

Window modifyKeyWindow(int itemKeyId, int cellItemId, String keyValue, String optionValue,
        boolean isOptionKeyExist) {
    VerticalLayout v = new VerticalLayout();
    v.setWidth("100%");
    v.setMargin(true);/* w w  w.  ja  v  a  2 s  .c  om*/
    v.setSpacing(true);

    Window sub = new Window("MODIFY");
    sub.setWidth("400px");
    sub.setModal(true);
    sub.center();

    ComboBox actionDone = new ComboBox("Action: ");
    actionDone.setWidth("70%");
    actionDone.addStyleName(ValoTheme.COMBOBOX_SMALL);
    actionDone.setNullSelectionAllowed(false);
    actionDone.addItem("resolved");
    actionDone.addItem("clarified");
    actionDone.addItem("modified");
    actionDone.setImmediate(true);
    v.addComponent(actionDone);

    TextArea remarks = new TextArea("Remarks: ");
    remarks.setWidth("100%");
    remarks.setRows(3);
    v.addComponent(remarks);

    Button modify = new Button("UPDATE");
    modify.setWidth("70%");
    modify.setIcon(FontAwesome.EDIT);
    modify.addStyleName(ValoTheme.BUTTON_PRIMARY);
    modify.addStyleName(ValoTheme.BUTTON_SMALL);
    modify.addClickListener((Button.ClickEvent event) -> {
        if (remarks.getValue() == null || remarks.getValue().trim().isEmpty()) {
            Notification.show("Add remarks!", Notification.Type.WARNING_MESSAGE);
            return;
        }

        if (actionDone.getValue() == null) {
            Notification.show("Add action!", Notification.Type.WARNING_MESSAGE);
            return;
        }

        boolean result = k.modifyItemKey(itemKeyId, cellItemId, keyValue, optionValue, isOptionKeyExist,
                remarks.getValue().trim(), actionDone.getValue().toString());
        if (result) {
            Notification.show("Key SUCCESSFULLY modified", Notification.Type.TRAY_NOTIFICATION);
            sub.close();
        }
    });
    v.addComponent(modify);

    sub.setContent(v);
    sub.getContent().setHeightUndefined();

    return sub;
}

From source file:com.example.testzbox.vista.TabCarga.java

private void iniciarElementos() {

    //layout.setSpacing(true);
    layout.setWidth(200.0f, Unit.PERCENTAGE);
    //layout.setSizeFull();

    cmbArea = new ComboBox("Area");
    cmbArea.setWidth(30.0f, Unit.PERCENTAGE);
    cmbArea.setNullSelectionAllowed(false);
    cmbArea.setTextInputAllowed(false);// ww  w. j a v a2  s.c  o  m
    cmbArea.setInputPrompt("Seleccione");
    cmbArea.addItem("adjustment");
    //        cmbArea.addItem("theft");
    //        cmbArea.addItem("siu");
    //        cmbArea.addItem("glasses");
    //        cmbArea.addItem("payments");
    //        cmbArea.addItem("valuation");
    //                
    cmbOperacion = new ComboBox("Operacin");
    cmbOperacion.setWidth(30.0f, Unit.PERCENTAGE);
    cmbOperacion.setNullSelectionAllowed(false);
    cmbOperacion.setTextInputAllowed(false);
    cmbOperacion.setInputPrompt("Seleccione");
    cmbOperacion.addItem("Asegurado");
    cmbOperacion.addItem("Tercero");

    txtNombreDoc = new TextField("Nombre Documento");
    txtNombreDoc.setWidth(30.0f, Unit.PERCENTAGE);

    //SINIESTRO
    txtNumSiniestro = new TextField("Nmero Siniestro");
    txtNumSiniestro.setWidth(30.0f, Unit.PERCENTAGE);
    txtNumPoliza = new TextField("Nmero de Pliza");
    txtNumPoliza.setWidth(30.0f, Unit.PERCENTAGE);
    txtNombAsegurado = new TextField("Nombre Asegurado");
    txtNombAsegurado.setWidth(30.0f, Unit.PERCENTAGE);
    dateFechaDocumento = new DateField("Fecha Creacin");
    dateFechaDocumento.setWidth(30.0f, Unit.PERCENTAGE);
    txtIdUsuarioCmp = new TextField("Id Usuario");
    txtIdUsuarioCmp.setWidth(30.0f, Unit.PERCENTAGE);

    //TIPO DOCUMENTAL
    cmbTipoDoc = new ComboBox("Tipo Documental");
    cmbTipoDoc.setWidth(30.0f, Unit.PERCENTAGE);
    cmbTipoDoc.setNullSelectionAllowed(false);
    cmbTipoDoc.setTextInputAllowed(false);
    cmbTipoDoc.setInputPrompt("Seleccione");
    cmbTipoDoc.addItem("averiguacionPrevia");
    cmbTipoDoc.addItem("declaracionUniversalAccidente");
    cmbTipoDoc.addItem("declaracionUniversalAccidenteSIPAC");
    cmbTipoDoc.addItem("demanda");
    cmbTipoDoc.addItem("poderNotarial");
    cmbTipoDoc.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            dateFechaExpedicion.setVisible(true);
            txtFolioActa.setVisible(true);
            cmbTipoEvento.setVisible(true);
        }
    });

    dateFechaExpedicion = new DateField("Fecha Expedicin");
    dateFechaExpedicion.setWidth(30.0f, Unit.PERCENTAGE);
    dateFechaExpedicion.setVisible(false);
    txtFolioActa = new TextField("Folio Acta");
    txtFolioActa.setWidth(30.0f, Unit.PERCENTAGE);
    txtFolioActa.setVisible(false);
    cmbTipoEvento = new ComboBox("Tipo Evento");
    cmbTipoEvento.setWidth(30.0f, Unit.PERCENTAGE);
    cmbTipoEvento.setVisible(false);
    cmbTipoEvento.setNullSelectionAllowed(false);
    cmbTipoEvento.setTextInputAllowed(false);
    cmbTipoEvento.setInputPrompt("Seleccione");
    cmbTipoEvento.addItem("Averiguacin Previa");
    cmbTipoEvento.addItem("DUA");
    cmbTipoEvento.addItem("DUA SIPAC");
    cmbTipoEvento.addItem("DUA Cristaleras");
    cmbTipoEvento.addItem("Demanda");
    cmbTipoEvento.addItem("Poder Notarial");

    lblPathArchivo = new Label();
    lblPathArchivo.setVisible(false);
    lblExtensionArchivo = new Label();
    lblExtensionArchivo.setVisible(false);

    //  form.setSpacing(true);
    form.addComponents(cmbArea, cmbOperacion, txtNombreDoc, txtNumSiniestro, txtNumPoliza, txtNombAsegurado,
            dateFechaDocumento, txtIdUsuarioCmp, cmbTipoDoc, dateFechaExpedicion, txtFolioActa, cmbTipoEvento);

    uploader = uploadContents();
    btnEnviar = new Button("Enviar");
    btnEnviar.addStyleName(ValoTheme.BUTTON_PRIMARY);
    btnEnviar.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            //Path pathFile = Paths.get("C:\\Documento Prueba.pdf");
            Path pathFile = Paths.get(lblPathArchivo.getCaption());

            DocumentoVO documentoVO = new DocumentoVO();

            documentoVO.setNombreDocumento(txtNombreDoc.getValue() + "." + lblExtensionArchivo.getCaption());
            documentoVO.setSubTipoDocumental(cmbTipoDoc.getValue().toString());
            documentoVO.setInputStream(pathFile.toFile());

            Map<String, String> metadatos = new HashMap<>();
            metadatos.put("folioActa", txtFolioActa.getValue());
            metadatos.put("tipoEvento", cmbTipoEvento.getValue().toString());
            metadatos.put("fechaExpedicion", convertDate(dateFechaExpedicion));
            metadatos.put("numeroSiniestro", txtNumSiniestro.getValue());
            metadatos.put("numeroPoliza", txtNumPoliza.getValue());
            metadatos.put("nombreAsegurado", txtNombAsegurado.getValue());
            metadatos.put("fechaCreacionDocumento", convertDate(dateFechaDocumento));
            metadatos.put("idUsuarioCmp", txtIdUsuarioCmp.getValue());
            metadatos.put("area", cmbArea.getValue().toString());
            metadatos.put("operacion", cmbOperacion.getValue().toString());

            documentoVO.setMetadatos(metadatos);

            cargarDocumento(documentoVO);

        }

    });

    footer.setSpacing(true);
    footer.setWidth(38.0f, Unit.PERCENTAGE);
    footer.addComponents(uploader, btnEnviar);
    footer.setComponentAlignment(btnEnviar, Alignment.BOTTOM_RIGHT);

    layout.addComponents(form, lblPathArchivo, footer);

    setCaption("Carga");
    setMargin(true);
    //setSpacing(true);
    addComponents(layout, panel);

}

From source file:com.example.testzbox.vista.TabChecklist.java

private void initElements() {

    txtNumSiniestro = new TextField("Nmero Siniestro");
    txtNumSiniestro.setWidth(30.0f, Sizeable.Unit.PERCENTAGE);

    cmbChecklist = new ComboBox("Checklist");
    cmbChecklist.setWidth(30.0f, Sizeable.Unit.PERCENTAGE);
    cmbChecklist.setNullSelectionAllowed(false);
    cmbChecklist.setTextInputAllowed(false);
    cmbChecklist.setInputPrompt("Seleccione");
    cmbChecklist.addItem("CHKLST_AJT_ASG_001");
    cmbChecklist.addItem("CHKLST_AJT_TRC_001");
    cmbChecklist.addItem("CHKLST_PAG_PT_006");
    cmbChecklist.addItem("CHKLST_PAG_PD_001");

    form.addComponents(txtNumSiniestro, cmbChecklist);

    btnVerificar = new Button("Verificar");
    btnVerificar.addStyleName(ValoTheme.BUTTON_PRIMARY);
    btnVerificar.addClickListener(new Button.ClickListener() {
        @Override/*w  ww  .  ja  va2 s . c  o  m*/
        public void buttonClick(Button.ClickEvent event) {

            CheckListVO checkListVO = new CheckListVO();

            checkListVO.setIdCheckList(cmbChecklist.getValue().toString());

            Map<String, String> parametros = new HashMap<>();
            parametros.put("numeroSiniestro", txtNumSiniestro.getValue());

            checkListVO.setParametros(parametros);

            verificarChecklist(checkListVO);

        }

    });

    footer.setSpacing(true);
    footer.setWidth(38.0f, Unit.PERCENTAGE);
    footer.addComponents(btnVerificar);
    footer.setComponentAlignment(btnVerificar, Alignment.BOTTOM_RIGHT);

    panel1.setVisible(false);

    setCaption("Checklist");
    setSpacing(true);
    setMargin(true);
    addComponents(form, footer, panel1);

}

From source file:com.gnts.gcat.rpt.SyncLogger.java

License:Open Source License

private void buildview() {
    logger.info(// w  w  w  .ja  va  2s  . com
            "Company ID : " + companyid + " | User Name : " + username + " > " + "Painting Email logger UI");
    // Client text box
    btnAdd.setVisible(false);
    btnAuditRecords.setVisible(false);
    btnEdit.setCaption("View");
    btnEdit.setStyleName("view");

    tfemailId = new TextField("Email Id");
    tfemailId.setReadOnly(false);
    // RAte Changing text box
    tflicError = new TextField("License Error");
    tflicError.setReadOnly(false);
    // product combo box
    tflogMsg = new TextField("Log Message");
    tflogMsg.setReadOnly(false);

    cbsearLogType = new ComboBox("Log Type");
    cbsearLogType.addItem("SYNC");
    cbsearLogType.addItem("ERR");
    cbsearLogType.addItem("EMAIL");

    // productcombo box for search
    cbSearStatus = new GERPComboBox("Sync Status");
    cbSearStatus.addItem("Success");
    cbSearStatus.addItem("Failed");

    cbstatus = new GERPComboBox("Sync Status");
    cbstatus.addItem("Success");
    cbstatus.addItem("Failed");
    cbstatus.setReadOnly(false);

    cblogType = new GERPComboBox("Log Type");
    cblogType.addItem("SYNC");
    cblogType.addItem("ERR");
    cblogType.addItem("EMAIL");

    cblogType.setReadOnly(false);
    // client TExt for Search

    cbcode = new GERPComboBox("Device Code");
    cbcode.setItemCaptionPropertyId("deviceCode");
    loaddevice();

    cbSerDev = new GERPComboBox("Device Code");
    cbSerDev.setItemCaptionPropertyId("deviceCode");
    loaddevice();

    cbemailStatus = new GERPComboBox("Email Status");
    cbemailStatus.addItem("Delivered");
    cbemailStatus.addItem("Failed");
    cbemailStatus.setReadOnly(false);
    // Change start date
    dflogDate = new GERPPopupDateField("Log Date");
    dflogDate.setInputPrompt("Select Date");
    dflogDate.setReadOnly(false);
    // build search layout
    hlSearchLayout = new GERPAddEditHLayout();
    assembleSearchLayout();
    hlSrchContainer.addComponent(GERPPanelGenerator.createPanel(hlSearchLayout));
    //assembleSearchLayout();
    resetFields();
    loadSrchRslt();
}

From source file:com.hivesys.dashboard.view.preferences.PreferencesView.java

License:Apache License

public PreferencesView() {

    user = (User) VaadinSession.getCurrent().getAttribute(User.class.getName());

    setSpacing(true);/*w  ww  .j a v  a 2 s  .  com*/
    setMargin(true);

    Label title = new Label("Forms");
    title.addStyleName("h1");
    addComponent(title);

    final FormLayout form = new FormLayout();
    form.setMargin(false);
    form.setWidth("800px");
    form.addStyleName("light");
    addComponent(form);

    Label section = new Label("Personal Info");
    section.addStyleName("h2");
    section.addStyleName("colored");
    form.addComponent(section);

    firstNameField = new TextField("First Name");
    firstNameField.setWidth("50%");
    form.addComponent(firstNameField);

    lastNameField = new TextField("Last Name");
    lastNameField.setWidth("50%");
    form.addComponent(lastNameField);

    titleField = new ComboBox("Title");
    titleField.setInputPrompt("Please specify");
    titleField.addItem("Mr.");
    titleField.addItem("Mrs.");
    titleField.addItem("Ms.");
    titleField.setNewItemsAllowed(true);
    form.addComponent(titleField);

    usernameField = new TextField("Username");
    usernameField.setRequired(true);
    form.addComponent(usernameField);

    sexField = new OptionGroup("Sex");
    sexField.addItem(Boolean.FALSE);
    sexField.setItemCaption(Boolean.FALSE, "Female");
    sexField.addItem(Boolean.TRUE);
    sexField.setItemCaption(Boolean.TRUE, "Male");
    sexField.addStyleName("horizontal");
    form.addComponent(sexField);

    section = new Label("Contact Info");
    section.addStyleName("h3");
    section.addStyleName("colored");
    form.addComponent(section);

    emailField = new TextField("Email");
    emailField.setWidth("50%");
    emailField.setRequired(true);
    form.addComponent(emailField);

    locationField = new TextField("Location");
    locationField.setWidth("50%");
    locationField.setNullRepresentation("");
    form.addComponent(locationField);

    phoneField = new TextField("Phone");
    phoneField.setWidth("50%");
    phoneField.setNullRepresentation("");
    form.addComponent(phoneField);

    section = new Label("Additional Info");
    section.addStyleName("h4");
    section.addStyleName("colored");
    form.addComponent(section);

    websiteField = new TextField("Website");
    websiteField.setInputPrompt("http://");
    websiteField.setWidth("100%");
    form.addComponent(websiteField);

    bioField = new RichTextArea("Bio");
    bioField.setWidth("100%");
    bioField.setValue(
            "<div><p><span>Integer legentibus erat a ante historiarum dapibus.</span> <span>Vivamus sagittis lacus vel augue laoreet rutrum faucibus.</span> <span>A communi observantia non est recedendum.</span> <span>Morbi fringilla convallis sapien, id pulvinar odio volutpat.</span> <span>Ab illo tempore, ab est sed immemorabili.</span> <span>Quam temere in vitiis, legem sancimus haerentia.</span></p><p><span>Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh.</span> <span>Quam diu etiam furor iste tuus nos eludet?</span> <span>Cum sociis natoque penatibus et magnis dis parturient.</span> <span>Quam diu etiam furor iste tuus nos eludet?</span> <span>Tityre, tu patulae recubans sub tegmine fagi  dolor.</span></p><p><span>Curabitur blandit tempus ardua ridiculus sed magna.</span> <span>Phasellus laoreet lorem vel dolor tempus vehicula.</span> <span>Etiam habebis sem dicantur magna mollis euismod.</span> <span>Hi omnes lingua, institutis, legibus inter se differunt.</span></p></div>");
    form.addComponent(bioField);

    Button edit = new Button("Edit", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            boolean readOnly = form.isReadOnly();
            if (readOnly) {
                bioField.setReadOnly(false);
                form.setReadOnly(false);
                form.removeStyleName("light");
                event.getButton().setCaption("Save");
                event.getButton().addStyleName("primary");
            } else {
                bioField.setReadOnly(true);
                form.setReadOnly(true);
                form.addStyleName("light");
                event.getButton().setCaption("Edit");
                event.getButton().removeStyleName("primary");
            }
        }
    });

    HorizontalLayout footer = new HorizontalLayout();
    footer.setMargin(new MarginInfo(true, false, true, false));
    footer.setSpacing(true);
    footer.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    form.addComponent(footer);
    footer.addComponent(edit);

    Label lastModified = new Label("Last modified by you a minute ago");
    lastModified.addStyleName("light");
    footer.addComponent(lastModified);

    fieldGroup = new BeanFieldGroup<>(User.class);
    fieldGroup.bindMemberFields(this);
    fieldGroup.setItemDataSource(user);

    form.setReadOnly(true);
    bioField.setReadOnly(true);

}

From source file:com.jain.addon.web.bean.factory.AbstractFieldFactory.java

License:Apache License

protected Field<?> createEnumField(Class<?> type, JNIProperty property) {
    final ComboBox combo = new ComboBox(getCaption(property));
    combo.setInputPrompt(getCaption(property));
    combo.setDescription(getDescription(property));

    Object[] values = type.getEnumConstants();
    for (Object object : values) {
        combo.addItem(object);/*from ww  w.ja  va 2 s  .c o  m*/
        if (object instanceof JNINamed) {
            combo.setItemCaption(object, ((JNINamed) object).getDisplayName());
        }
    }
    return combo;
}

From source file:com.jain.addon.web.bean.factory.AbstractFieldFactory.java

License:Apache License

protected Field<?> createRestrictionField(JNIPropertyConstraint propertyConstraint) {
    final ComboBox combo = new ComboBox(getCaption(propertyConstraint.getProperty()));
    combo.setInputPrompt(getCaption(propertyConstraint.getProperty()));
    combo.setDescription(getDescription(propertyConstraint.getProperty()));

    Collection<?> values = EnumerationHandler.getValue(propertyConstraint);
    for (Object object : values) {
        combo.addItem(object);//from   w  w  w  .j  a  v  a2s  .c o  m
        if (object instanceof JNINamed) {
            combo.setItemCaption(object, ((JNINamed) object).getDisplayName());
        }
    }

    if (propertyConstraint.getTypes() != null) {
        if (propertyConstraint.getTypes().contains(JConstraintType.REQUIRED)) {
            combo.setNullSelectionAllowed(false);
        }
    }

    updateFieldProperties(propertyConstraint, combo);

    return combo;
}