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.antonjohansson.managementcenter.core.web.welcome.WelcomeView.java

License:Apache License

private Component getExistingConnectionLayout() {
    ComboBox connection = new ComboBox("Existing connection");
    connection.addItem("SQL Server 01");
    connection.addItem("Elasticsearch Server 01");
    connection.setWidth("400");
    connection.setNullSelectionAllowed(false);
    connection.setTextInputAllowed(false);

    Button connect = new Button("Connect");
    connect.addStyleName(ValoTheme.BUTTON_PRIMARY);
    connect.setClickShortcut(KeyCode.ENTER);
    connect.setWidth("120");

    HorizontalLayout layout = new HorizontalLayout();
    layout.setSpacing(true);/*from  www  . j a  va  2 s.co  m*/
    layout.addComponents(connection, connect);
    layout.setComponentAlignment(connect, Alignment.BOTTOM_LEFT);
    return layout;
}

From source file:com.antonjohansson.managementcenter.core.web.welcome.WelcomeView.java

License:Apache License

private Component getNewConnectionLayout() {
    engine = new ComboBox("New connection");
    engine.setWidth("400");
    engine.setNullSelectionAllowed(false);
    engine.setTextInputAllowed(false);//w ww.ja v a2s  .  c  om

    create = new Button("Create");
    create.addStyleName(ValoTheme.BUTTON_PRIMARY);
    create.setClickShortcut(KeyCode.ENTER);
    create.setWidth("120");

    HorizontalLayout layout = new HorizontalLayout();
    layout.setSpacing(true);
    layout.addComponents(engine, create);
    layout.setComponentAlignment(create, Alignment.BOTTOM_LEFT);
    return layout;
}

From source file:com.application.modules.commercial.ClientListView.java

public void init() {

    //Recherche TextField
    rech = new ComboBox("Rechercher un Client :");
    this.addComponent(rech);
    this.setComponentAlignment(rech, Alignment.TOP_RIGHT);

    //Panels/*w  w w.j  av  a  2s  .co m*/
    HorizontalLayout panels = new HorizontalLayout();
    panels.setHeight("100%");
    panels.setWidth("100%");
    Panel panel_liste = new Panel("Liste des Clients");
    Panel panel_license = new Panel("Liste des licenses");
    panels.addComponent(panel_liste);
    panels.addComponent(panel_license);
    this.addComponent(panels);

    //Intervention Liste table
    Client_liste = new Table();
    Client_liste.setHeight("550px");
    License_liste = new Table();
    License_liste.setHeight("550px");

    Client_liste.setWidth("100%");
    License_liste.setWidth("100%");

    // selectable
    Client_liste.setSelectable(true);
    Client_liste.setMultiSelect(false);
    Client_liste.setImmediate(true);

    License_liste.setSelectable(true);
    License_liste.setMultiSelect(false);
    License_liste.setImmediate(true);

    // turn on column reordering and collapsing
    Client_liste.setColumnReorderingAllowed(true);
    Client_liste.setColumnCollapsingAllowed(true);
    License_liste.setColumnReorderingAllowed(true);
    License_liste.setColumnCollapsingAllowed(true);

    //Client Table
    Client_liste.addContainerProperty("Num", String.class, null);
    Client_liste.addContainerProperty("Nom client", String.class, null);
    Client_liste.addContainerProperty("Contact", String.class, null);
    Client_liste.addContainerProperty("Adresse", String.class, null);
    Client_liste.addContainerProperty("Tlephone", String.class, null);

    //License Table
    License_liste.addContainerProperty("Num", String.class, null);
    License_liste.addContainerProperty("Application", String.class, null);
    License_liste.addContainerProperty("Date Expiration", Date.class, null);

    panel_liste.addComponent(Client_liste);
    panel_license.addComponent(License_liste);

    rech.setImmediate(true);
    Property.ValueChangeListener listener = new Property.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            presenter.load_ClientListe();
        }
    };

    Client_liste.addListener(new ItemClickEvent.ItemClickListener() {
        @Override
        public void itemClick(ItemClickEvent itemClickEvent) {
            System.out.println(itemClickEvent.getItemId().toString());
            presenter.load_LicenseListe(itemClickEvent.getItemId());
        }
    });

    rech.addListener(listener);

    //Class Layout properties
    this.setWidth("100%");
    this.setMargin(true);
    this.setSpacing(true);

    presenter.load_ClientListe();
    presenter.list_client();

}

From source file:com.bellkenz.modules.PersonalInformation.java

public ComponentContainer personalInformation() {
    employeeInformationDAO = new EmployeeInformationDAO(getEmployeeId());
    employeePersonalInformation = new EmployeePersonalInformation();

    GridLayout glayout = new GridLayout(5, 9);
    glayout.setSpacing(true);/*from   w  ww  .j a  v  a 2 s. c  o m*/
    glayout.setMargin(true);

    final Panel imagePanel = new Panel();
    imagePanel.setStyleName("light");
    AbstractLayout panelLayout = (AbstractLayout) imagePanel.getContent();
    panelLayout.setMargin(false);
    imagePanel.setSizeFull();

    employeeImage = new Embedded(null, new ThemeResource("../myTheme/images/ronnie.jpg"));
    employeeImage.setImmediate(true);
    employeeImage.setWidth(90, Sizeable.UNITS_PIXELS);
    employeeImage.setHeight(90, Sizeable.UNITS_PIXELS);
    employeeImage.setStyleName("logo-img");
    imagePanel.addComponent(employeeImage);
    glayout.addComponent(employeeImage, 0, 0, 0, 1);
    glayout.setComponentAlignment(imagePanel, Alignment.MIDDLE_CENTER);

    firstname = createTextField("Firstname: ");
    glayout.addComponent(firstname, 1, 0, 2, 0);

    final TextField middlename = createTextField("Middlename: ");
    glayout.addComponent(middlename, 3, 0);

    final TextField lastname = createTextField("Lastname: ");
    glayout.addComponent(lastname, 4, 0);

    final TextField houseNo = createTextField("No: ");
    houseNo.setWidth("40px");
    glayout.addComponent(houseNo, 1, 1);

    final TextField street = createTextField("Street: ");
    street.setWidth("118");
    glayout.addComponent(street, 2, 1);

    final TextField city = createTextField("City: ");
    glayout.addComponent(city, 3, 1);

    final TextField zipCode = createTextField("Zip Code:");
    glayout.addComponent(zipCode, 4, 1);

    final TextField nickname = createTextField("Nickname: ");
    nickname.setWidth("90px");
    glayout.addComponent(nickname, 0, 2);

    final TextField permanentAddress = createTextField("Permanent/Provincial Address: ");
    permanentAddress.setWidth("533px");
    glayout.addComponent(permanentAddress, 1, 2, 4, 2);

    Button uploadPicture = new Button("Upload...");
    uploadPicture.setWidth("100%");
    uploadPicture.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (employeeId == null) {
                getWindow().showNotification("You did not select and Employee!",
                        Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            Window uploadImage = new UploadImage(imagePanel, employeeImage, employeeId);
            uploadImage.setWidth("450px");
            if (uploadImage.getParent() == null) {
                getWindow().addWindow(uploadImage);
            }
            uploadImage.setModal(true);
            uploadImage.center();
        }
    });
    glayout.addComponent(uploadPicture, 0, 3);

    final TextField landline = createTextField("Landline #: ");
    glayout.addComponent(landline, 1, 3, 2, 3);

    final TextField mobileNo = createTextField("Mobile #: ");
    glayout.addComponent(mobileNo, 3, 3);

    final TextField age = createTextField("Age: ");
    glayout.addComponent(age, 4, 3);

    final TextField emailAddress = createTextField("Email Address: ");
    glayout.addComponent(emailAddress, 1, 4, 2, 4);

    final PopupDateField dob = (PopupDateField) createDateField("Date of Birth: ");
    glayout.addComponent(dob, 3, 4);

    final TextField height = createTextField("Height: ");
    glayout.addComponent(height, 4, 4);

    final ComboBox civilStatus = new ComboBox("Civil Status: ");
    civilStatus.setWidth("100%");
    dropDownBoxList.populateCivilStatusList(civilStatus);
    glayout.addComponent(civilStatus, 1, 5, 2, 5);

    final ComboBox gender = new ComboBox("Gender: ");
    gender.setWidth("100%");
    dropDownBoxList.populateGenderList(gender);
    glayout.addComponent(gender, 3, 5);

    final TextField weight = createTextField("Weigth: ");
    glayout.addComponent(weight, 4, 5);

    final TextField driversLicenseNo = createTextField("Drivers License: ");
    glayout.addComponent(driversLicenseNo, 1, 6, 2, 6);

    final TextField restrictionCode = createTextField("Restriction Code: ");
    glayout.addComponent(restrictionCode, 3, 6);

    final TextField religion = createTextField("Religion: ");
    glayout.addComponent(religion, 4, 6);

    final ComboBox division = new ComboBox("Division: ");
    division.setWidth("100%");
    dropDownBoxList.populateBranchComboBox(division);
    glayout.addComponent(division, 1, 7, 2, 7);

    final ComboBox department = dropDownBoxList.populateDepartment(new ComboBox());
    department.setWidth("100%");
    division.addListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if (division.getValue() == null) {
            } else {
                divisionId = branchDAO.getBranchId(division.getValue().toString());
            }
        }

    });
    glayout.addComponent(department, 3, 7);

    final TextField position = createTextField("Position: ");
    glayout.addComponent(position, 4, 7);
    //glayout.setComponentAlignment(position, Alignment.BOTTOM_LEFT);

    Button transferButton = new Button("Transfer Employee");
    transferButton.setWidth("100%");
    transferButton.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (getEmployeeId() == null) {
                getWindow().showNotification("You did not select an Employee!",
                        Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            Window subWindow = transferEmployee(getEmployeeId(), division, department, position);
            if (subWindow.getParent() == null) {
                getWindow().addWindow(subWindow);
            }
            subWindow.setModal(true);
            subWindow.center();
        }
    });
    glayout.addComponent(transferButton, 1, 8, 2, 8);
    glayout.setComponentAlignment(transferButton, Alignment.BOTTOM_CENTER);

    if (employeeId != null) {
        epiList = employeeInformationDAO.employeePersonalInformation();
        for (EmployeePersonalInformation epi : epiList) {
            final byte[] image = epi.getImage();
            if (image != null) {
                StreamResource.StreamSource imageSource = new StreamResource.StreamSource() {

                    @Override
                    public InputStream getStream() {
                        return new ByteArrayInputStream(image);
                    }

                };

                StreamResource imageResource = new StreamResource(imageSource, epi.getFirstname() + ".jpg",
                        getApplication());
                imageResource.setCacheTime(0);
                employeeImage.setSource(imageResource);
            }
            firstname.setValue(epi.getFirstname());
            middlename.setValue(epi.getMiddlename());
            lastname.setValue(epi.getLastname());
            houseNo.setValue(epi.getHouseNumber());

            street.setValue(epi.getStreet());
            city.setValue(epi.getStreet());
            zipCode.setValue(epi.getZipCode());
            nickname.setValue(epi.getNickname());
            permanentAddress.setValue(epi.getPermanentAddress());
            landline.setValue(epi.getLandlineNumber());
            mobileNo.setValue(epi.getMobileNumber());
            age.setValue(epi.getAge());
            emailAddress.setValue(epi.getEmailAddress());

            if (epi.getDob() != null) {
                dob.setValue(conUtil.parsingDate(epi.getDob()));
            } else {
                dob.setValue(null);
            }

            height.setValue(epi.getHeight());

            if (epi.getCivilStatus() != null) {
                Object civilStatusId = civilStatus.addItem();
                civilStatus.setItemCaption(civilStatusId, epi.getCivilStatus());
                civilStatus.setValue(civilStatusId);
            }

            if (epi.getGender() != null) {
                Object genderId = gender.addItem();
                gender.setItemCaption(genderId, epi.getGender());
                gender.setValue(genderId);
            }

            weight.setValue(epi.getWeight());
            driversLicenseNo.setValue(epi.getDriversLicense());
            restrictionCode.setValue(epi.getRestrictionCode());
            religion.setValue(epi.getReligion());
            position.setValue(epi.getPosition());

            Object divisionObjectId = division.addItem();
            division.setItemCaption(divisionObjectId, epi.getDivision());
            division.setValue(divisionObjectId);

            Object departmentObjectId = department.addItem();
            department.setItemCaption(departmentObjectId, epi.getDepartment());
            department.setValue(departmentObjectId);
        }
    }

    firstname.addListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            employeePersonalInformation.setFirstname(event.getProperty().getValue().toString());
        }
    });
    firstname.setImmediate(true);
    setInformation(employeePersonalInformation);

    return glayout;
}

From source file:com.bellkenz.modules.PersonalInformation.java

public Window transferEmployee(final String employeeId, final ComboBox div, final ComboBox dept,
        final TextField post) {
    VerticalLayout vlayout = new VerticalLayout();
    vlayout.setMargin(true);//from  w w w.  ja  v  a 2s .  c om
    vlayout.setSpacing(true);

    final Window subWindow = new Window("Transfer Employee", vlayout);
    subWindow.setWidth("200px");

    final ComboBox division = new ComboBox("Division: ");
    division.setWidth("100%");
    dropDownBoxList.populateBranchComboBox(division);
    subWindow.addComponent(division);

    final ComboBox department = dropDownBoxList.populateDepartment(new ComboBox());
    department.setWidth("100%");
    division.addListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if (division.getValue() == null) {
            } else {
                divisionId = branchDAO.getBranchId(division.getValue().toString());
            }
        }

    });
    subWindow.addComponent(department);

    final TextField position = createTextField("Position: ");
    position.setWidth("100%");
    subWindow.addComponent(position);

    final PopupDateField entryDate = (PopupDateField) createDateField("Date of Entry: ");
    subWindow.addComponent(entryDate);

    Button updateButton = new Button("UPDATE");
    updateButton.setWidth("100%");
    updateButton.addListener(new Button.ClickListener() {

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

            if (department.getValue() == null) {
                getWindow().showNotification("Select Department!", Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            if (position.getValue() == null || position.getValue().toString().trim().isEmpty()) {
                getWindow().showNotification("Enter Position!", Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            if (entryDate.getValue() == null) {
                getWindow().showNotification("Select Entry Date!", Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            List<EmployeePositionHistory> ephList = new ArrayList<EmployeePositionHistory>();
            EmployeePositionHistory eph = new EmployeePositionHistory();
            eph.setBranch(division.getValue().toString());
            eph.setDepartment(department.getValue().toString());
            eph.setPosition(position.getValue().toString().trim().toLowerCase());
            eph.setEntryDate(conUtil.convertDateFormat(entryDate.getValue().toString()));
            ephList.add(eph);
            Integer deptId = departmentDAO.getDepartmentId(divisionId, department.getValue().toString());
            Boolean result = employeeInformationDAO.transferEmployee(ephList, deptId);
            if (result) {
                Object divObjectId = div.addItem();
                div.setItemCaption(divObjectId, division.getValue().toString());
                div.setValue(divObjectId);

                Object deptObjectId = dept.addItem();
                dept.setItemCaption(deptObjectId, department.getValue().toString());
                dept.setValue(deptObjectId);

                post.setValue(position.getValue().toString().trim().toLowerCase());

                (subWindow.getParent()).removeWindow(subWindow);
            } else {
                getWindow().showNotification("Cannot Transfer employee",
                        Window.Notification.TYPE_ERROR_MESSAGE);
            }
        }
    });
    subWindow.addComponent(updateButton);

    return subWindow;
}

From source file:com.cavisson.gui.dashboard.components.controls.ComboBoxes.java

License:Apache License

public ComboBoxes() {
    setMargin(true);/*from   w w  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(ValoThemeUI.generateContainer(200, false));
    combo.setNullSelectionAllowed(false);
    combo.select(combo.getItemIds().iterator().next());
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.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(ValoThemeUI.generateContainer(200, false));
    combo.setNullSelectionAllowed(false);
    combo.select(combo.getItemIds().iterator().next());
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.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(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.addStyleName("color1");
    row.addComponent(combo);

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

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

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

    combo = new ComboBox("Large");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.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(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.addStyleName("tiny");
    row.addComponent(combo);

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

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

private Component setFirstStep() {
    VerticalLayout firstStep = new VerticalLayout();
    firstStep.setMargin(true);/*from  ww  w . ja va  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);//w ww .java 2s  .  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.SignIn.java

private VerticalLayout setFirstStep() {
    VerticalLayout firstStep = new VerticalLayout();
    CssLayout header = new CssLayout();
    Label title = new Label("Benvenuto " + u.getNomeUtente() + "!");
    Label istructions = new Label("Crea il tuo personaggio");
    Label step = new Label("1/*");
    header.addComponents(title, istructions, step);
    HorizontalLayout body = new HorizontalLayout();
    FormLayout datiIniziali = new FormLayout();
    TextField nomePG = new TextField("Nome del Personaggio");
    TextField cognomePG = new TextField("Cognome del Personaggio");
    OptionGroup sessoPG = new OptionGroup("Sesso del Personaggio");
    sessoPG.addItems("Maschio", "Femmina");
    ComboBox razzaPG = new ComboBox("Razza");
    datiIniziali.addComponents(nomePG, cognomePG, sessoPG, razzaPG);
    HorizontalLayout descrizioneRazza = new HorizontalLayout();
    descrizioneRazza.setWidth(datiIniziali.getWidth(), datiIniziali.getWidthUnits());
    //        Dettagli di popolazione e comportamento ComboBox
    razzaPG.addItem("Essere umano");
    body.addComponents(datiIniziali, descrizioneRazza);
    CssLayout footer = new CssLayout();
    Button next = new Button("Avanti ->");
    next.addClickListener((Button.ClickEvent event) -> {
        u.setNomePG(nomePG.getValue());/*from  ww  w .ja  va 2 s .com*/
        u.setCognomePG(cognomePG.getValue());
        u.setSessoPG(sessoPG.getValue().toString());
        u.setRazzaPG(razzaPG.getValue().toString());
        this.setContent(setSecondStep());
    });
    footer.addComponents(next, createCancelButton());

    firstStep.addComponents(header, body, footer);
    return firstStep;
}

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

private Component setThirdStep() {
    VerticalLayout thirdStep = new VerticalLayout();
    CssLayout header = new CssLayout();
    Label title = new Label("Benvenuto " + u.getNomeUtente() + "!");
    Label istructions = new Label("Crea il tuo personaggio");
    Label step = new Label("3/*");
    header.addComponents(title, istructions, step);
    HorizontalLayout body = new HorizontalLayout();
    VerticalLayout carrieraPanel = new VerticalLayout();
    ComboBox carriera = new ComboBox("Scegli la tua carriera:");
    carriera.addItem("Guerriero");
    HorizontalLayout descrizioneCarriera = new HorizontalLayout();
    // Comportamento ComboBox
    carrieraPanel.addComponents(carriera, descrizioneCarriera);
    VerticalLayout orientamentoPanel = new VerticalLayout();
    ComboBox orientamento = new ComboBox("Scegli il tuo orientamento");
    orientamento.addItem("Buono Ordine");
    HorizontalLayout descrizioneOrientamento = new HorizontalLayout();
    // Comportamento ComboBox
    orientamentoPanel.addComponents(orientamento, descrizioneOrientamento);
    body.addComponents(carrieraPanel, orientamentoPanel);
    CssLayout footer = new CssLayout();
    Button next = new Button("Avanti ->");
    next.addClickListener((Button.ClickEvent event) -> {
        u.setCarrieraPG(carriera.getValue().toString());
        u.setOrientamentoPG(orientamento.getValue().toString());
        this.setContent(setFourthStep());
    });//  w  w w  . java  2  s  .  co m
    footer.addComponents(next, createCancelButton());
    thirdStep.addComponents(header, body, footer);
    return thirdStep;
}