Example usage for com.vaadin.ui ComboBox addValueChangeListener

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

Introduction

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

Prototype

@Override
    public Registration addValueChangeListener(HasValue.ValueChangeListener<T> listener) 

Source Link

Usage

From source file:cirad.cgh.vcf2fasta.view.Vcf2fastaForm.java

License:Open Source License

private void initComponents() {
    removeAllComponents();/*from   ww w.j  a va 2  s.  c  o m*/

    fieldGroup = new BeanFieldGroup<Vcf2fastaInputBean>(Vcf2fastaInputBean.class);
    vcf2fastaInputBean = new Vcf2fastaInputBean(config);
    fieldGroup.setItemDataSource(vcf2fastaInputBean);

    FormLayout layout = new FormLayout();
    layout.setResponsive(true);
    layout.setMargin(true);
    layout.setWidth("100%");
    //layout.addStyleName("light");
    layout.setImmediate(true);
    addComponent(layout);

    Label section1;
    final ComboBox analysis_combo;
    final ComboBox accession_combo;
    Label section2;
    ComboBox contig_combo;
    TextField interval;
    Label section3;
    Component buttonLayout;
    Component progressLayout;

    section1 = new Label("Input");
    section1.addStyleName("h3 colored");
    layout.addComponent(section1);
    analysis_combo = getComboBox(ANALYSIS_CAPTION, ANALYSIS, getAnalysesList(), false);
    layout.addComponent(analysis_combo);
    accession_combo = getComboBox(ACCESSION_CAPTION, ACCESSION,
            getAccessionsList("Cassava 6.1 WGS Bredeson 61 accessions"), false);
    layout.addComponent(accession_combo);

    analysis_combo.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            accession_combo.setContainerDataSource(getAccessionsList((String) analysis_combo.getValue()));
            accession_combo.select(accession_combo.getContainerDataSource().getItemIds().iterator().next());
        }
    });

    section2 = new Label("Parameters");
    section2.addStyleName("h3 colored");
    layout.addComponent(section2);
    contig_combo = getComboBox(CONTIG_CAPTION, CONTIG, getContigsList(), true);
    layout.addComponent(contig_combo);
    interval = getTextField(INTERVAL_CAPTION, INTERVAL, vcf2fastaUI.getConfig().getString("defaultInterval"),
            20);
    layout.addComponent(interval);

    section3 = new Label("Result");
    section3.addStyleName("h3 colored");
    layout.addComponent(section3);
    resultLayout = new VerticalLayout();
    resultLayout.setSizeFull();
    resultLayout.setMargin(true);
    resultLayout.setSpacing(true);
    resultLayout.addStyleName("light");
    layout.addComponent(resultLayout);

    layout.addComponent(new Label(""));

    buttonLayout = getSubmitLayout();
    layout.addComponent(buttonLayout);
    progressLayout = getProgressLayout();
    layout.addComponent(progressLayout);

    initCommitHandler();
}

From source file:com.cerebro.gorgone.landingpage.SignInWindow.java

private Component setFirstStep() {
    VerticalLayout firstStep = new VerticalLayout();
    firstStep.setMargin(true);/*from w ww  .jav  a  2  s  .c o m*/
    // Body
    HorizontalLayout body = new HorizontalLayout();
    FormLayout datiIniziali = new FormLayout();
    TextField nomePG = new TextField("Nome del Personaggio");
    nomePG.setRequired(true);
    TextField cognomePG = new TextField("Cognome del Personaggio");
    cognomePG.setRequired(true);
    OptionGroup sessoPG = new OptionGroup("Sesso del Personaggio");
    sessoPG.setRequired(true);
    sessoPG.addItems("Maschio", "Femmina");
    ComboBox razzaPG = new ComboBox("Razza");
    razzaPG.setRequired(true);
    Slider age = new Slider("Et");
    age.setImmediate(true);
    age.setWidth("200px");
    age.setVisible(false);
    HorizontalLayout ageDescription = new HorizontalLayout();
    ageDescription.setHeight("250px");
    Label ageText = new Label("Valore dell'et: ");
    Label ageValue = new Label(age.getValue().toString());
    Label periodoVita = new Label("");
    ageDescription.addComponents(ageText, ageValue, periodoVita);
    age.addValueChangeListener((Property.ValueChangeEvent event) -> {
        System.out.println("Valore: " + age.getValue().toString());
        ageValue.setValue(age.getValue().toString());
        Double value = (100 * (age.getValue()) / (age.getMax()));
        if (value < 14) {
            periodoVita.setValue("Bambino");
        } else if (value > 14 && value < 24) {
            periodoVita.setValue("Adolescenza");
        } else if (value > 24 && value < 73) {
            periodoVita.setValue("Et adulta");
        } else if (value > 73) {
            periodoVita.setValue("Et anziana");
        }
    });
    ageDescription.addComponents(ageText, ageValue, periodoVita);
    ageDescription.setVisible(false);
    datiIniziali.addComponents(nomePG, cognomePG, sessoPG, razzaPG, age, ageDescription);
    Panel descrizioneRazza = new Panel();
    CssLayout descrizioneRazzaContent = new CssLayout();
    descrizioneRazza.setWidth("400px");
    descrizioneRazza.setHeight("500px");
    descrizioneRazza.setContent(descrizioneRazzaContent);
    //  Dettagli di popolazione e comportamento ComboBox
    TableQuery tq_races = new TableQuery(DatabaseTables.RACES_TABLE, connPool);
    tq_races.setVersionColumn(DatabaseTables.RACES_VERSION);
    SQLContainer container_races = null;
    try {
        container_races = new SQLContainer(tq_races);
    } catch (Exception ex) {
        logger.error(ex.getMessage());
    }
    razzaPG.setContainerDataSource(container_races);
    razzaPG.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY);
    razzaPG.setItemCaptionPropertyId(DatabaseTables.RACES_NAME);
    razzaPG.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if (razzaPG.getValue() != null) {
                logger.info("Razza selezionata: " + razzaPG.getValue());
                age.setVisible(true);
                ageDescription.setVisible(true);
                descrizioneRazzaContent.removeAllComponents();
                Item item = razzaPG.getContainerDataSource().getItem(razzaPG.getValue());
                race = (String) item.getItemProperty(DatabaseTables.RACES_NAME).getValue();
                Label nameRace = new Label(race);
                FileResource imageSrc = new FileResource(
                        new File(MyUI.basePath + item.getItemProperty(DatabaseTables.RACES_IMAGE).getValue()));
                Image imageRace = new Image(null, imageSrc);
                imageRace.setWidth("200px");
                Label descriptionRace = new Label(
                        (String) item.getItemProperty(DatabaseTables.RACES_DESCRIPTION).getValue(),
                        ContentMode.HTML);
                min_age = (int) item.getItemProperty(DatabaseTables.RACES_MIN_AGE).getValue();
                max_age = (int) item.getItemProperty(DatabaseTables.RACES_MAX_AGE).getValue();
                age.setMin(min_age);
                age.setMax(max_age);
                strenght = (int) item.getItemProperty(DatabaseTables.RACES_STRENGHT).getValue();
                resistance = (int) item.getItemProperty(DatabaseTables.RACES_RESISTANCE).getValue();
                agility = (int) item.getItemProperty(DatabaseTables.RACES_AGILITY).getValue();
                intelligence = (int) item.getItemProperty(DatabaseTables.RACES_INTELLIGENCE).getValue();
                wisdom = (int) item.getItemProperty(DatabaseTables.RACES_WISDOM).getValue();
                charm = (int) item.getItemProperty(DatabaseTables.RACES_CHARM).getValue();
                Label min_ageL = new Label("Et minima: " + min_age);
                Label max_ageL = new Label("Et masima " + max_age);
                //                Panel levels = new Panel();
                //                VerticalLayout levelsContent = new VerticalLayout();
                //                levels.setContent(levelsContent);
                //                Label strenghtL = new Label("Forza: " + strenght);
                //                levelsContent.addComponents(strenghtL);

                String levelTable = "<table><tr><td>Forza</td><td>Resistenza</td><td>Agilit</td><td>Intelligenza</td>"
                        + "<td>Saggezza</td><td>Carisma</td></tr><tr>" + "<td>" + strenght + "</td>" + "<td>"
                        + resistance + "</td>" + "<td>" + agility + "</td>" + "<td>" + intelligence + "</td>"
                        + "<td>" + wisdom + "</td>" + "<td>" + charm + "</td>" + "</tr></table>";
                Label levels = new Label(levelTable, ContentMode.HTML);

                descrizioneRazzaContent.addComponents(nameRace, imageRace, descriptionRace, min_ageL, max_ageL,
                        levels);
            }
        }
    });

    body.addComponents(datiIniziali, descrizioneRazza);
    CssLayout footer = new CssLayout();
    Button next = new Button("Avanti ->");
    next.addClickListener((Button.ClickEvent event) -> {
        user.setNomePG(nomePG.getValue());
        user.setCognomePG(cognomePG.getValue());
        user.setSessoPG(sessoPG.getValue().toString());
        user.setRazzaPG(race);
        user.setEtaPG(age.getValue().toString());
        user.setForzaPG(strenght);
        user.setResistenzaPG(resistance);
        user.setAgilitaPG(agility);
        user.setIntelligenzaPG(intelligence);
        user.setSaggezzaPG(wisdom);
        user.setCarismaPG(charm);
        this.setContent(setSecondStep());
    });
    footer.addComponents(next, createCancelButton());
    firstStep.addComponents(setHeader("2/4"), body, footer);
    return firstStep;
}

From source file:com.cerebro.gorgone.landingpage.SignInWindow.java

private Component setSecondStep() {
    VerticalLayout secondStep = new VerticalLayout();
    HorizontalLayout body = new HorizontalLayout();
    Panel sx = new Panel();
    VerticalLayout sxContent = new VerticalLayout();
    sx.setContent(sxContent);/*from   ww  w . ja  v a 2  s. c o m*/
    Label welcome = null;
    if (user.getSessoPG().equals("Maschio")) {
        welcome = new Label("Benvenuto: " + user.getNomePG() + "!");
    } else if (user.getSessoPG().equals("Femmina")) {
        welcome = new Label("Benvenuta: " + user.getNomePG() + "!");
    }
    ComboBox carrieraPG = new ComboBox("Scegli la tua carriera:");
    carrieraPG.isRequired();
    Panel careerDescription = new Panel();
    CssLayout careerDescrContent = new CssLayout();
    careerDescription.setContent(careerDescrContent);
    sxContent.addComponents(welcome, carrieraPG, careerDescription);

    //  Dettagli di popolazione e comportamento ComboBox
    TableQuery tq_career = new TableQuery(DatabaseTables.CAREER_TABLE, connPool);
    tq_career.setVersionColumn(DatabaseTables.CAREER_VERSION);
    SQLContainer container_career = null;
    try {
        container_career = new SQLContainer(tq_career);
    } catch (Exception ex) {
        logger.error(ex.getMessage());
    }
    carrieraPG.setContainerDataSource(container_career);
    carrieraPG.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY);
    carrieraPG.setItemCaptionPropertyId(DatabaseTables.CAREER_NAME);
    carrieraPG.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if (carrieraPG.getValue() != null) {
                logger.info("Carriera: " + carrieraPG.getValue().toString());
                careerDescrContent.removeAllComponents();
                Item item = (Item) carrieraPG.getContainerDataSource().getItem(carrieraPG.getValue());
                career = (String) item.getItemProperty(DatabaseTables.CAREER_NAME).getValue();
                Label careerName = new Label(career);
                FileResource imageSrc = new FileResource(
                        new File(MyUI.basePath + item.getItemProperty(DatabaseTables.CAREER_IMAGE).getValue()));
                Image imageCareer = new Image(null, imageSrc);
                imageCareer.setWidth("200px");
                Label careerDescription = new Label(item.getItemProperty(DatabaseTables.CAREER_DESCRIPTION),
                        ContentMode.HTML);
                strenght_car = (int) item.getItemProperty(DatabaseTables.CAREER_STRENGTH).getValue();
                resistance_car = (int) item.getItemProperty(DatabaseTables.CAREER_RESISTANCE).getValue();
                agility_car = (int) item.getItemProperty(DatabaseTables.CAREER_AGILITY).getValue();
                intelligence_car = (int) item.getItemProperty(DatabaseTables.CAREER_INTELLIGENCE).getValue();
                wisdom_car = (int) item.getItemProperty(DatabaseTables.CAREER_WISDOM).getValue();
                charm_car = (int) item.getItemProperty(DatabaseTables.CAREER_CHARM).getValue();
                String modsTable = "<table><tr><td>Forza</td><td>Resistenza</td><td>Agilit</td><td>Intelligenza</td>"
                        + "<td>Saggezza</td><td>Carisma</td></tr><tr>" + "<td>" + strenght_car + "</td>"
                        + "<td>" + resistance_car + "</td>" + "<td>" + agility_car + "</td>" + "<td>"
                        + intelligence_car + "</td>" + "<td>" + wisdom_car + "</td>" + "<td>" + charm_car
                        + "</td>" + "</tr></table>";
                Label mods = new Label(modsTable, ContentMode.HTML);
                careerDescrContent.addComponents(careerName, imageCareer, careerDescription, mods);
            }

        }

    });

    Panel dx = new Panel();
    VerticalLayout dxContent = new VerticalLayout();
    dx.setContent(dxContent);
    ComboBox orientamentoPG = new ComboBox("Scegli il tuo orientamento:");
    orientamentoPG.isRequired();
    Panel orientamentoDescription = new Panel();
    CssLayout orientamentoDescrContent = new CssLayout();
    orientamentoDescription.setContent(orientamentoDescrContent);
    dxContent.addComponents(orientamentoPG, orientamentoDescription);
    //  Dettagli di popolazione e comportamento ComboBox
    TableQuery tq_orientamento = new TableQuery(DatabaseTables.MORALCODE_TABLE, connPool);
    tq_orientamento.setVersionColumn(DatabaseTables.MORALCODE_VERSION);
    SQLContainer container_orientamento = null;
    try {
        container_orientamento = new SQLContainer(tq_orientamento);
    } catch (Exception ex) {
        logger.error(ex.getMessage());
    }
    orientamentoPG.setContainerDataSource(container_orientamento);
    orientamentoPG.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY);
    orientamentoPG.setItemCaptionPropertyId(DatabaseTables.MORALCODE_TENDENCY);
    orientamentoPG.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if (orientamentoPG.getValue() != null) {
                logger.info("Orientamento: " + orientamentoPG.getValue().toString());
                orientamentoDescrContent.removeAllComponents();
                Item item = (Item) orientamentoPG.getContainerDataSource().getItem(orientamentoPG.getValue());
                moralCode = (String) item.getItemProperty(DatabaseTables.MORALCODE_TENDENCY).getValue();
                Label orientamentoName = new Label(moralCode);
                FileResource imageSrc = new FileResource(new File(
                        MyUI.basePath + item.getItemProperty(DatabaseTables.MORALCODE_IMAGE).getValue()));
                Image imageTendency = new Image(null, imageSrc);
                imageTendency.setWidth("200px");
                Label orientamentoDescription = new Label(
                        item.getItemProperty(DatabaseTables.MORALCODE_DESCRIPTION), ContentMode.HTML);

                orientamentoDescrContent.addComponents(orientamentoName, imageTendency,
                        orientamentoDescription);
            }

        }

    });

    body.addComponents(sx, dx);
    CssLayout footer = new CssLayout();
    Button next = new Button("Avanti ->");
    next.addClickListener((Button.ClickEvent event) -> {
        user.setCarrieraPG(career);
        // Gestire modificatori
        user.setForzaPG(user.getForzaPG() + strenght_car);
        user.setResistenzaPG(user.getResistenzaPG() + resistance_car);
        user.setAgilitaPG(user.getAgilitaPG() + agility_car);
        user.setIntelligenzaPG(user.getIntelligenzaPG() + intelligence_car);
        user.setSaggezzaPG(user.getSaggezzaPG() + wisdom_car);
        user.setCarismaPG(user.getCarismaPG() + charm_car);
        user.setOrientamentoPG(moralCode);
        this.setContent(setThirdStep());
    });
    footer.addComponents(next, createCancelButton());
    secondStep.addComponents(setHeader("3/4"), body, footer);
    return secondStep;
}

From source file:com.cerebro.provevaadin.Mappa.java

public Mappa(User user) {

    Label ultimoLuogo = new Label(user.getUltimoLuogoPG());
    ComboBox elencoLuoghi = new ComboBox();
    elencoLuoghi.addItems("Luogo A", "Luogo B");
    elencoLuoghi.addValueChangeListener((Property.ValueChangeEvent event) -> {
        System.out.println("Cambio luogo, vai a: " + elencoLuoghi.getValue().toString());
        user.setUltimoLuogo(elencoLuoghi.getValue().toString());

    });// www  .  j  a  v  a 2 s.c om

    addComponents(ultimoLuogo, elencoLuoghi);

}

From source file:com.esofthead.mycollab.module.project.view.assignments.GanttChartViewImpl.java

License:Open Source License

private void constructUI() {
    MHorizontalLayout header = new MHorizontalLayout().withMargin(new MarginInfo(false, false, true, false))
            .withStyleName("hdr-view").withWidth("100%");
    header.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    Label headerText = new Label(FontAwesome.BAR_CHART_O.getHtml() + " Gantt chart", ContentMode.HTML);
    headerText.setStyleName(ValoTheme.LABEL_H2);
    headerText.addStyleName(ValoTheme.LABEL_NO_MARGIN);
    CssLayout headerWrapper = new CssLayout();
    headerWrapper.addComponent(headerText);

    MHorizontalLayout resWrapper = new MHorizontalLayout();
    Label resLbl = new Label("Resolution: ");
    final ComboBox resValue = new ValueComboBox(false, "Day", "Week");
    resValue.addValueChangeListener(new Property.ValueChangeListener() {
        @Override/*from  w  w w .ja va2  s .co m*/
        public void valueChange(Property.ValueChangeEvent event) {
            String val = (String) resValue.getValue();
            if ("Day".equals(val)) {
                gantt.setResolution(Resolution.Day);
            } else if ("Week".equals(val)) {
                gantt.setResolution(Resolution.Week);
            }
        }
    });
    resWrapper.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    resWrapper.with(resLbl, resValue);

    header.with(headerWrapper, resWrapper).withAlign(headerWrapper, Alignment.MIDDLE_LEFT)
            .expand(headerWrapper);

    mainLayout = new MHorizontalLayout().withSpacing(false);
    mainLayout.addStyleName("gantt_container");
    mainLayout.setSizeFull();
    this.with(header, mainLayout);
}

From source file:com.esofthead.mycollab.module.project.view.task.TaskDashboardViewImpl.java

License:Open Source License

public TaskDashboardViewImpl() {
    this.withMargin(new MarginInfo(false, true, true, true));
    taskSearchPanel = new TaskSearchPanel();

    MHorizontalLayout groupWrapLayout = new MHorizontalLayout();
    groupWrapLayout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);

    groupWrapLayout.addComponent(new Label("Sort"));
    final ComboBox sortCombo = new ValueComboBox(false,
            AppContext.getMessage(GenericI18Enum.OPT_SORT_DESCENDING),
            AppContext.getMessage(GenericI18Enum.OPT_SORT_ASCENDING));
    sortCombo.addValueChangeListener(new Property.ValueChangeListener() {
        @Override/*from  w  ww . ja v  a 2 s.c  om*/
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            String sortValue = (String) sortCombo.getValue();
            if (AppContext.getMessage(GenericI18Enum.OPT_SORT_ASCENDING).equals(sortValue)) {
                sortDirection = SearchCriteria.ASC;
            } else {
                sortDirection = SearchCriteria.DESC;
            }
            queryAndDisplayTasks();
        }
    });
    sortDirection = SearchCriteria.DESC;
    groupWrapLayout.addComponent(sortCombo);

    groupWrapLayout.addComponent(new Label("Group by"));
    final ComboBox groupCombo = new ValueComboBox(false, GROUP_DUE_DATE, GROUP_START_DATE, GROUP_CREATED_DATE,
            PLAIN_LIST, GROUP_USER);
    groupCombo.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            groupByState = (String) groupCombo.getValue();
            queryAndDisplayTasks();
        }
    });
    groupByState = GROUP_DUE_DATE;
    groupWrapLayout.addComponent(groupCombo);

    taskSearchPanel.addHeaderRight(groupWrapLayout);

    Button printBtn = new Button("", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            UI.getCurrent().addWindow(new TaskCustomizeReportOutputWindow(new LazyValueInjector() {
                @Override
                protected Object doEval() {
                    return baseCriteria;
                }
            }));
        }
    });
    printBtn.setIcon(FontAwesome.PRINT);
    printBtn.addStyleName(UIConstants.BUTTON_OPTION);
    printBtn.setDescription(AppContext.getMessage(GenericI18Enum.ACTION_EXPORT));
    groupWrapLayout.addComponent(printBtn);

    Button newTaskBtn = new Button(AppContext.getMessage(TaskI18nEnum.NEW), new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            if (CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS)) {
                SimpleTask newTask = new SimpleTask();
                newTask.setProjectid(CurrentProjectVariables.getProjectId());
                newTask.setSaccountid(AppContext.getAccountId());
                newTask.setLogby(AppContext.getUsername());
                UI.getCurrent().addWindow(new TaskAddWindow(newTask));
            }
        }
    });
    newTaskBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS));
    newTaskBtn.setIcon(FontAwesome.PLUS);
    newTaskBtn.setStyleName(UIConstants.BUTTON_ACTION);
    groupWrapLayout.addComponent(newTaskBtn);

    Button advanceDisplayBtn = new Button("List");
    advanceDisplayBtn.setWidth("100px");
    advanceDisplayBtn.setIcon(FontAwesome.SITEMAP);
    advanceDisplayBtn.setDescription("Advance View");

    Button kanbanBtn = new Button("Kanban", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            displayKanbanView();
        }
    });
    kanbanBtn.setWidth("100px");
    kanbanBtn.setDescription("Kanban View");
    kanbanBtn.setIcon(FontAwesome.TH);

    ToggleButtonGroup viewButtons = new ToggleButtonGroup();
    viewButtons.addButton(advanceDisplayBtn);
    viewButtons.addButton(kanbanBtn);
    viewButtons.withDefaultButton(advanceDisplayBtn);
    groupWrapLayout.addComponent(viewButtons);

    MHorizontalLayout mainLayout = new MHorizontalLayout().withFullHeight().withFullWidth();
    wrapBody = new MVerticalLayout().withMargin(new MarginInfo(false, true, true, false));
    rightColumn = new MVerticalLayout().withWidth("370px")
            .withMargin(new MarginInfo(true, false, false, false));
    mainLayout.with(wrapBody, rightColumn).expand(wrapBody);
    this.with(taskSearchPanel, mainLayout);
}

From source file:com.example.vaadindemo.AddItemPanel.java

public HorizontalLayout draw(BeanItemContainer<ShoppingList> container) {
    final HorizontalLayout x = new HorizontalLayout();
    x.setId("addItemPanel");
    Button persistNewItemButton = new Button("Dodaj");
    final Item item = new Item();
    BeanItem<Item> personBean = new BeanItem<Item>(item);

    final FormLayout formLayout = new FormLayout();

    final FieldGroup form = new FieldGroup(); //new name: form

    form.setItemDataSource(personBean);/* ww w . j  av  a  2  s.  c  o  m*/
    form.setBuffered(true);

    Field imieField = form.buildAndBind("Name", "firstName");
    imieField.setRequired(true);
    imieField.addValidator(new StringLengthValidator("bad length", 2, 5, false));
    formLayout.addComponent(imieField);

    //Container
    final BeanItemContainer<Item> beanContainer = new BeanItemContainer<Item>(Item.class);
    //beanContainer.addBean(new Item();
    //beanContainer.addBean(new Item("Bolek"));
    //beanContainer.addBean(new Person("Lolek", 1933));

    // Put some example data in it
    container.addItem(new ShoppingList("Mercury", null, null));
    //container.addItem(new Planet(2, "Venus"));
    //container.addItem(new Planet(3, "Earth"));
    //container.addItem(new Planet(4, "Mars"));

    // Create a selection component bound to the container
    final ComboBox select = new ComboBox("Planets", container);

    // Set the caption mode to read the caption directly
    // from the 'name' property of the bean
    select.setItemCaptionMode(ItemCaptionMode.PROPERTY);
    select.setItemCaptionPropertyId("name");
    select.setImmediate(true);
    final Label ldd = new Label();

    x.addComponent(select);
    x.addComponent(formLayout);
    x.addComponent(persistNewItemButton);
    x.addComponent(ldd);
    persistNewItemButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Label l = new Label("jsdcbsc");
            x.addComponent(l);
            //ldd.setValue(select.getItem(item.firstName).toString());
        }
    });

    select.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {

            ldd.setValue(select.getItemCaption(event.getProperty().getValue()));
        }
    });
    return x;
}

From source file:com.github.carljmosca.MainLayout.java

private void init() {
    setSizeFull();//from  w  w w  . j av a 2 s. com
    addStyleName("menylayout");
    Responsive.makeResponsive(this);
    ComboBox<Person> cmbPerson = new ComboBox<>();
    cmbPerson.setItems(personProcessor.findAll());
    cmbPerson.setItemCaptionGenerator(c -> c.getTitle() + " " + c.getFirstName() + " " + c.getLastName());
    cmbPerson.addValueChangeListener((HasValue.ValueChangeEvent<Person> event) -> {
        binder.setBean(cmbPerson.getValue());
    });
    title = new ComboBox("Title", Arrays.asList(titles));
    firstName = new TextField("First");
    middleName = new TextField("Middle");
    lastName = new TextField("Last");
    Button btnNew = new Button("New");
    btnNew.addClickListener((Button.ClickEvent event) -> {
        person = new Person();
        binder.setBean(person);
    });
    Button btnSave = new Button("Save");
    btnSave.addClickListener((Button.ClickEvent event) -> {
        personProcessor.addPerson(person);
        cmbPerson.setItems(personProcessor.findAll());
    });
    personLayout.setWidth(null);
    personLayout.setSpacing(true);
    personLayout.addStyleName("menu");
    personLayout.addComponent(title);
    personLayout.addComponent(firstName);
    personLayout.addComponent(middleName);
    personLayout.addComponent(lastName);
    personLayout.addComponent(btnNew);
    addComponent(btnSave);
    addComponent(cmbPerson);
    addComponent(personLayout);
    //addComponent(buttonLayout);
    doBinding();
}

From source file:com.github.daytron.containersdatasource.BeanSampleCombo.java

License:Open Source License

public BeanSampleCombo() {
    Person person1 = new Person(1L, "John", "DOE", new Date(70, 0, 1));
    Person person2 = new Person(2L, "Jane", "doe", new Date(70, 0, 1));
    Person person3 = new Person(3L, "jules", "winnf", new Date(48, 11, 21));
    Person person4 = new Person(4L, "vincent", "Vega", new Date(54, 1, 17));

    container = new BeanItemContainer<>(Person.class);

    container.addAll(Arrays.asList(person1, person2, person3, person4));

    ComboBox comboBox = new ComboBox("List Of Persons", container);
    comboBox.setImmediate(true);/*  w  w  w  .j a v  a  2s  .  c  o  m*/
    comboBox.setNullSelectionAllowed(true);
    comboBox.setItemCaptionPropertyId("fullname");

    comboBox.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            AbstractSelect combo = (AbstractSelect) event.getProperty();

            Person selected = (Person) combo.getValue();

            if (selected == null) {
                Notification.show("Null selected");
            } else {
                Notification.show(selected.getId() + ": " + selected.getFullname(),
                        Notification.Type.HUMANIZED_MESSAGE);
            }
        }
    });

    addComponent(comboBox);

}

From source file:com.github.mjvesa.herd.wordset.VaadinWordSet.java

License:Apache License

@Override
public Word[] getWords() {
    return new Word[] {

            new BaseWord("new-button", "", Word.POSTPONED) {

                private static final long serialVersionUID = -2492817908731559368L;

                @Override// www.ja  v  a2s  . com
                public void execute(final Interpreter interpreter) {

                    Button b = new Button("", new Button.ClickListener() {
                        private static final long serialVersionUID = -4622489800920283752L;

                        @Override
                        public void buttonClick(ClickEvent event) {
                            Button b = event.getButton();
                            Word command = (Word) b.getData();
                            if (command != null) {
                                interpreter.execute(command);
                            }
                        }
                    });
                    interpreter.pushData(b);
                }
            },

            new BaseWord("set-click-listener", "", Word.POSTPONED) {

                private static final long serialVersionUID = 5749856686458297558L;

                @Override
                public void execute(Interpreter interpreter) {
                    Object o = interpreter.popData();
                    Button b = (Button) interpreter.popData();
                    b.setData(o);
                    interpreter.pushData(b);
                }
            },

            new BaseWord("new-hl", "", Word.POSTPONED) {

                private static final long serialVersionUID = 8813556668649386248L;

                @Override
                public void execute(Interpreter interpreter) {
                    HorizontalLayout hl = new HorizontalLayout();
                    hl.setSpacing(true);
                    interpreter.pushData(hl);
                }
            },

            new BaseWord("new-vl", "", Word.POSTPONED) {

                private static final long serialVersionUID = -1848213448504804229L;

                @Override
                public void execute(Interpreter interpreter) {
                    VerticalLayout vl = new VerticalLayout();
                    vl.setSpacing(true);
                    interpreter.pushData(vl);
                }
            },

            new BaseWord("new-gl", "( x y - gl )", Word.POSTPONED) {

                private static final long serialVersionUID = 4079634885691605257L;

                @Override
                public void execute(Interpreter interpreter) {
                    Integer height = (Integer) interpreter.popData();
                    Integer width = (Integer) interpreter.popData();
                    interpreter.pushData(new GridLayout(width, height));
                }
            },

            new BaseWord("gl-new-line", "", Word.POSTPONED) {

                private static final long serialVersionUID = 975877390052961807L;

                @Override
                public void execute(Interpreter interpreter) {
                    ((GridLayout) interpreter.peekData()).newLine();
                }
            },

            new BaseWord("new-window", "", Word.POSTPONED) {

                private static final long serialVersionUID = -6887364362728545090L;

                @Override
                public void execute(Interpreter interpreter) {
                    Window w = new Window();
                    VerticalLayout vl = new VerticalLayout();
                    vl.setSpacing(true);
                    w.setContent(vl);
                    interpreter.pushData(w);
                    interpreter.pushData(vl);
                }
            },

            new BaseWord("main-panel", "", Word.POSTPONED) {

                private static final long serialVersionUID = -8622281600566696475L;

                @Override
                public void execute(Interpreter interpreter) {
                    interpreter.pushData(interpreter.getMainPanel());
                }
            },

            new BaseWord("add-window", "", Word.POSTPONED) {

                private static final long serialVersionUID = 7106029415576813922L;

                @Override
                public void execute(Interpreter interpreter) {
                    Window w = (Window) interpreter.popData();
                    interpreter.getView().getUI().addWindow(w);
                }
            },

            new BaseWord("add-component", "", Word.POSTPONED) {

                private static final long serialVersionUID = 5640824046985354091L;

                @Override
                public void execute(Interpreter interpreter) {
                    Component comp = (Component) interpreter.popData();
                    ComponentContainer cc = (ComponentContainer) interpreter.popData();
                    cc.addComponent(comp);
                    interpreter.pushData(cc);
                }
            },

            new BaseWord("set-caption", "", Word.POSTPONED) {

                private static final long serialVersionUID = 5497598050469462487L;

                @Override
                public void execute(Interpreter interpreter) {
                    String s = (String) interpreter.popData();
                    Component c = (Component) interpreter.popData();
                    c.setCaption(s);
                    interpreter.pushData(c);
                }
            },

            new BaseWord("set-value", "", Word.POSTPONED) {

                private static final long serialVersionUID = -1769743552659215058L;

                @Override
                public void execute(Interpreter interpreter) {
                    Object o = interpreter.popData();
                    Property p = (Property) interpreter.popData();
                    p.setValue(o);
                    interpreter.pushData(p);
                }
            },

            new BaseWord("get-value", "", Word.POSTPONED) {

                private static final long serialVersionUID = 8445550546521886374L;

                @Override
                public void execute(Interpreter interpreter) {
                    Field f = (Field) interpreter.popData();
                    interpreter.pushData(f);
                    interpreter.pushData(f.getValue());

                }
            },

            new BaseWord("set-size-full", "", Word.POSTPONED) {

                private static final long serialVersionUID = -1206491811133054467L;

                @Override
                public void execute(Interpreter interpreter) {
                    Component comp = (Component) interpreter.popData();
                    comp.setSizeFull();
                    interpreter.pushData(comp);
                }
            },

            new BaseWord("set-size-undefined", "", Word.POSTPONED) {

                private static final long serialVersionUID = -3450618729379622987L;

                @Override
                public void execute(Interpreter interpreter) {
                    Component comp = (Component) interpreter.popData();
                    comp.setSizeUndefined();
                    interpreter.pushData(comp);
                }
            },

            new BaseWord("set-height", "", Word.POSTPONED) {

                private static final long serialVersionUID = -8426734568403715950L;

                @Override
                public void execute(Interpreter interpreter) {
                    String str = (String) interpreter.popData();
                    Component comp = (Component) interpreter.popData();
                    comp.setHeight(str);
                    interpreter.pushData(comp);
                }
            },

            new BaseWord("set-width", "", Word.POSTPONED) {

                private static final long serialVersionUID = -4558264143049463814L;

                @Override
                public void execute(Interpreter interpreter) {
                    String str = (String) interpreter.popData();
                    Component comp = (Component) interpreter.popData();
                    comp.setWidth(str);
                    interpreter.pushData(comp);
                }
            },

            new BaseWord("clear-container", "", Word.POSTPONED) {

                private static final long serialVersionUID = 1070175466682034329L;

                @Override
                public void execute(Interpreter interpreter) {
                    ComponentContainer cc = (ComponentContainer) interpreter.popData();
                    cc.removeAllComponents();
                }
            },

            new BaseWord("new-check-box", "", Word.POSTPONED) {

                private static final long serialVersionUID = 4018632924389912599L;

                @Override
                public void execute(Interpreter interpreter) {
                    interpreter.pushData(new CheckBox());
                }
            },

            new BaseWord("new-date-field", "", Word.POSTPONED) {

                private static final long serialVersionUID = 6313296566085274642L;

                @Override
                public void execute(final Interpreter interpreter) {
                    interpreter.pushData(new DateField());
                    final String dfCommand = (String) interpreter.popData();
                    DateField df = new DateField();
                    df.setImmediate(true);
                    df.addValueChangeListener(new ValueChangeListener() {
                        /**
                        * 
                        */
                        private static final long serialVersionUID = 1472139878970514093L;

                        public void valueChange(ValueChangeEvent event) {
                            interpreter.pushData(event.getProperty().getValue());
                            interpreter.interpret(dfCommand);
                        }

                    });
                    interpreter.pushData(df);
                }
            },

            new BaseWord("new-label", "", Word.POSTPONED) {

                private static final long serialVersionUID = -2825285195439247251L;

                @Override
                public void execute(Interpreter interpreter) {
                    interpreter.pushData(new Label());
                }
            },

            new BaseWord("new-text-field", "", Word.POSTPONED) {

                private static final long serialVersionUID = -1064489458253275380L;

                @Override
                public void execute(final Interpreter interpreter) {
                    final String tfCommand = interpreter.getNextNonNopWord();
                    TextField tf = new TextField();
                    tf.setCaption((String) interpreter.popData());
                    tf.setValue("");
                    tf.setImmediate(true);
                    tf.addValueChangeListener(new ValueChangeListener() {
                        private static final long serialVersionUID = 4325104922208051065L;

                        public void valueChange(ValueChangeEvent event) {
                            interpreter.pushData(event.getProperty().getValue());
                            interpreter.interpret(tfCommand);
                        }
                    });
                    interpreter.pushData(tf);
                }
            },

            new BaseWord("new-table", "", Word.POSTPONED) {

                private static final long serialVersionUID = -5052653341575232035L;

                @Override
                public void execute(final Interpreter interpreter) {
                    final String tableCommand = interpreter.getParser().getNextWord();
                    Table table = new Table();
                    table.setCaption((String) interpreter.popData());
                    table.setImmediate(true);
                    table.setSelectable(true);
                    table.addItemClickListener(new ItemClickListener() {

                        /**
                        *
                        */
                        private static final long serialVersionUID = 3585546076571010729L;

                        public void itemClick(ItemClickEvent event) {

                            interpreter.pushData(event.getItem());
                            interpreter.execute(interpreter.getDictionary().get(tableCommand));
                        }
                    });
                    interpreter.pushData(table);
                }
            },

            new BaseWord("new-combo-box", "", Word.POSTPONED) {

                private static final long serialVersionUID = 3881577354424928897L;

                @Override
                public void execute(final Interpreter interpreter) {
                    final String newItemCommand = interpreter.getParser().getNextWord();
                    final String itemSelectedCommand = interpreter.getParser().getNextWord();
                    final ComboBox cb = new ComboBox();
                    String str = (String) interpreter.popData();
                    cb.setNullSelectionAllowed(false);
                    cb.setCaption(str);
                    cb.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ITEM);
                    cb.setNewItemsAllowed(true);
                    cb.setNewItemHandler(new NewItemHandler() {

                        /**
                        *
                        */
                        private static final long serialVersionUID = 3340658590351611289L;

                        public void addNewItem(String newItemCaption) {
                            cb.setImmediate(false);
                            interpreter.pushData(newItemCaption);
                            interpreter.interpret(newItemCommand);
                            cb.setImmediate(true);
                        }
                    });

                    cb.addValueChangeListener(new ValueChangeListener() {

                        /**
                        *
                        */
                        private static final long serialVersionUID = 2706579869793251379L;

                        public void valueChange(ValueChangeEvent event) {
                            interpreter.pushData(
                                    cb.getContainerDataSource().getItem(event.getProperty().getValue()));
                            interpreter.interpret(itemSelectedCommand);
                        }
                    });
                    cb.setImmediate(true);
                    interpreter.pushData(cb);
                }
            },

            new BaseWord("new-select", "", Word.POSTPONED) {

                private static final long serialVersionUID = -6142351970812196488L;

                @Override
                public void execute(final Interpreter interpreter) {
                    final String selCommand = interpreter.getParser().getNextWord();
                    final ComboBox sel = new ComboBox();
                    sel.setCaption((String) interpreter.popData());
                    sel.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ITEM);
                    sel.setNullSelectionAllowed(false);
                    sel.setImmediate(true);
                    sel.addValueChangeListener(new ValueChangeListener() {
                        /**
                        *
                        */
                        private static final long serialVersionUID = -7705548618092166199L;

                        public void valueChange(ValueChangeEvent event) {
                            Item item = sel.getContainerDataSource().getItem(event.getProperty().getValue());
                            interpreter.pushData(item);
                            interpreter.interpret(selCommand);
                        }
                    });
                    interpreter.pushData(sel);
                }
            },

            new BaseWord("new-list-select", "", Word.POSTPONED) {
                private static final long serialVersionUID = 8686093227035249035L;

                @Override
                public void execute(final Interpreter interpreter) {
                    final String lselCommand = interpreter.getParser().getNextWord();
                    final ListSelect lsel = new ListSelect();
                    lsel.setCaption((String) interpreter.popData());
                    lsel.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ITEM);
                    lsel.setNullSelectionAllowed(false);
                    lsel.setImmediate(true);
                    lsel.addValueChangeListener(new ValueChangeListener() {
                        private static final long serialVersionUID = -5523488417834167806L;

                        public void valueChange(ValueChangeEvent event) {
                            Item item = lsel.getContainerDataSource().getItem(event.getProperty().getValue());
                            interpreter.pushData(item);
                            interpreter.interpret(lselCommand);
                        }
                    });
                    interpreter.pushData(lsel);
                }
            },

            new BaseWord("set-container-data-source", "", Word.POSTPONED) {
                private static final long serialVersionUID = 8644721936358613031L;

                @Override
                public void execute(Interpreter interpreter) {
                    Container cont = (Container) interpreter.popData();
                    AbstractSelect as = (AbstractSelect) interpreter.popData();
                    as.setContainerDataSource(cont);
                    interpreter.pushData(as);
                }
            },

            new BaseWord("set-column-headers", "", Word.POSTPONED) {
                private static final long serialVersionUID = -7296881714369214846L;

                @Override
                public void execute(Interpreter interpreter) {
                    Table table = (Table) interpreter.popData();
                    table.setColumnHeaders((String[]) getArrayFromList(interpreter, new String[0]));
                }
            },

            new BaseWord("set-visible-columns", "", Word.POSTPONED) {
                private static final long serialVersionUID = 5674765074478598320L;

                @Override
                public void execute(Interpreter interpreter) {
                    Table table = (Table) interpreter.popData();
                    table.setVisibleColumns((String[]) getArrayFromList(interpreter, new String[0]));
                }
            }

    };
}