Example usage for com.vaadin.ui HorizontalLayout setWidth

List of usage examples for com.vaadin.ui HorizontalLayout setWidth

Introduction

In this page you can find the example usage for com.vaadin.ui HorizontalLayout setWidth.

Prototype

@Override
    public void setWidth(float width, Unit unit) 

Source Link

Usage

From source file:fr.univlorraine.mondossierweb.views.windows.HelpBasicWindow.java

License:Apache License

/**
 * Cre une fentre de confirmation/*from w  ww .  ja v a 2  s . co m*/
 * @param message
 * @param titre
 */
public HelpBasicWindow(String message, String titre, boolean displayLienContact) {
    /* Style */
    setWidth(900, Unit.PIXELS);
    setModal(true);
    setResizable(false);
    setClosable(false);

    /* Layout */
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(false);
    setContent(layout);

    /* Titre */
    setCaption(titre);

    // Lien de contact
    if (displayLienContact) {
        String mailContact = configController.getAssistanceContactMail();
        if (StringUtils.hasText(mailContact)) {
            Button contactBtn = new Button(
                    applicationContext.getMessage(NAME + ".btnContact", null, getLocale()),
                    FontAwesome.ENVELOPE);
            contactBtn.addStyleName(ValoTheme.BUTTON_LINK);
            BrowserWindowOpener contactBwo = new BrowserWindowOpener("mailto:" + mailContact);
            contactBwo.extend(contactBtn);
            layout.addComponent(contactBtn);
            layout.setComponentAlignment(contactBtn, Alignment.TOP_RIGHT);
        }
    }

    /* Texte */
    Label textLabel = new Label(message, ContentMode.HTML);
    layout.addComponent(textLabel);

    /* Boutons */
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setWidth(100, Unit.PERCENTAGE);
    buttonsLayout.setSpacing(true);
    layout.addComponent(buttonsLayout);

    btnFermer.setCaption(applicationContext.getMessage("helpWindow.btnFermer", null, getLocale()));
    btnFermer.setIcon(FontAwesome.TIMES);
    btnFermer.addClickListener(e -> close());
    buttonsLayout.addComponent(btnFermer);
    buttonsLayout.setComponentAlignment(btnFermer, Alignment.MIDDLE_RIGHT);

    /* Centre la fentre */
    center();
}

From source file:fr.univlorraine.mondossierweb.views.windows.HelpMobileWindow.java

License:Apache License

/**
 * Cre une fentre de confirmation// w  w w.  jav a  2 s.  co  m
 * @param message
 * @param titre
 */
public HelpMobileWindow(String message, String titre, boolean displayCheckBox) {
    // Style 
    setWidth("90%");
    setModal(true);
    setResizable(false);
    setClosable(false);

    // Layout 
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    setContent(layout);

    // Titre 
    if (titre == null) {
        titre = applicationContext.getMessage("helpWindow.defaultTitle", null, getLocale());
    }
    setCaption(titre);

    // Texte 
    Label textLabel = new Label(message, ContentMode.HTML);
    layout.addComponent(textLabel);

    // Boutons
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setWidth(100, Unit.PERCENTAGE);
    buttonsLayout.setSpacing(true);
    layout.addComponent(buttonsLayout);

    if (displayCheckBox) {
        // Checkbox "ne plus afficher ce message"
        checkBox.setCaption(
                applicationContext.getMessage("helpWindow.checkBox.mobile.message", null, getLocale()));
        buttonsLayout.addComponent(checkBox);
        buttonsLayout.setComponentAlignment(checkBox, Alignment.MIDDLE_RIGHT);
    }
    // Bouton "Fermer"
    btnFermer.setIcon(FontAwesome.CHECK);
    btnFermer.setStyleName(ValoTheme.BUTTON_PRIMARY);
    btnFermer.addStyleName("v-popover-button");
    btnFermer.addClickListener(e -> close());
    buttonsLayout.addComponent(btnFermer);
    buttonsLayout.setComponentAlignment(btnFermer, Alignment.MIDDLE_RIGHT);
    if (displayCheckBox) {
        buttonsLayout.setExpandRatio(checkBox, 1);
    }

    // Centre la fentre 
    center();
}

From source file:fr.univlorraine.mondossierweb.views.windows.HelpWindow.java

License:Apache License

/**
 * Cre une fentre de confirmation//w ww .  j  a  v  a  2 s . co m
 * @param message
 * @param titre
 */
public HelpWindow(String message, String titre, boolean displayCheckBox) {
    /* Style */
    setWidth(900, Unit.PIXELS);
    setModal(true);
    setResizable(false);
    setClosable(false);

    /* Layout */
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    setContent(layout);

    /* Titre */
    if (titre == null) {
        titre = applicationContext.getMessage("helpWindow.defaultTitle", null, getLocale());
    }
    setCaption(titre);

    /* Texte */
    Label textLabel = new Label(message, ContentMode.HTML);
    layout.addComponent(textLabel);

    /* Boutons */
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setWidth(100, Unit.PERCENTAGE);
    buttonsLayout.setSpacing(true);
    layout.addComponent(buttonsLayout);

    if (displayCheckBox) {
        checkBox.setCaption(applicationContext.getMessage("helpWindow.checkBox.message", null, getLocale()));
        buttonsLayout.addComponent(checkBox);
        buttonsLayout.setComponentAlignment(checkBox, Alignment.MIDDLE_RIGHT);
    }

    btnFermer.setCaption(applicationContext.getMessage("helpWindow.btnFermer", null, getLocale()));
    btnFermer.setIcon(FontAwesome.TIMES);
    btnFermer.addClickListener(e -> close());
    buttonsLayout.addComponent(btnFermer);
    buttonsLayout.setComponentAlignment(btnFermer, Alignment.MIDDLE_RIGHT);
    if (displayCheckBox) {
        buttonsLayout.setExpandRatio(checkBox, 1);
    }

    /* Centre la fentre */
    center();
}

From source file:fr.univlorraine.mondossierweb.views.windows.InputWindow.java

License:Apache License

/**
 * Cre une fentre de saisie/* w w w. j a  v a2  s. c o m*/
 * @param message
 * @param titre
 */
public InputWindow(String message, String titre) {
    /* Style */
    setWidth(400, Unit.PIXELS);
    setModal(true);
    setResizable(false);
    setClosable(false);

    /* Layout */
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    setContent(layout);

    /* Titre */
    if (titre == null) {
        titre = applicationContext.getMessage("inputWindow.defaultTitle", null, getLocale());
    }
    setCaption(titre);

    /* Texte */
    if (message == null) {
        message = applicationContext.getMessage("inputWindow.defaultMessage", null, getLocale());
    }
    Label textLabel = new Label(message);
    layout.addComponent(textLabel);

    /* Champ de saisie */
    inputTextField.setWidth(100, Unit.PERCENTAGE);
    inputTextField.addShortcutListener(new ShortcutListener(null, ShortcutAction.KeyCode.ENTER, null) {
        private static final long serialVersionUID = 6231790311427334925L;

        @Override
        public void handleAction(Object sender, Object target) {
            btnOk.click();
        }
    });
    layout.addComponent(inputTextField);

    /* Boutons */
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setWidth(100, Unit.PERCENTAGE);
    buttonsLayout.setSpacing(true);
    layout.addComponent(buttonsLayout);

    btnCancel.setCaption(applicationContext.getMessage("inputWindow.btnCancel", null, getLocale()));
    btnCancel.addClickListener(e -> close());
    buttonsLayout.addComponent(btnCancel);
    buttonsLayout.setComponentAlignment(btnCancel, Alignment.MIDDLE_LEFT);

    btnOk.setCaption(applicationContext.getMessage("inputWindow.btnOk", null, getLocale()));
    btnOk.addStyleName(ValoTheme.BUTTON_PRIMARY);
    btnOk.addClickListener(e -> {
        btnOkListeners.forEach(l -> l.btnOkClick(inputTextField.getValue()));
        close();
    });
    buttonsLayout.addComponent(btnOk);
    buttonsLayout.setComponentAlignment(btnOk, Alignment.MIDDLE_RIGHT);

    /* Centre la fentre */
    center();
    /* Place le focus sur le champ de saisie */
    inputTextField.focus();
}

From source file:fr.univlorraine.mondossierweb.views.windows.ModificationAdressesWindow.java

License:Apache License

/**
 * Cre une fentre de confirmation/*w  w  w . j  a  va  2s .com*/
 * @param message
 * @param titre
 */
public ModificationAdressesWindow(Etudiant etudiant) {
    /* Style */
    //setWidth(900, Unit.PIXELS);
    setModal(true);
    setResizable(false);
    setClosable(false);

    /* Layout */
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    setContent(layout);

    /* Titre */
    setCaption(applicationContext.getMessage(NAME + ".title", null, getLocale()));

    /* Layout pour afficher les erreurs */
    VerticalLayout erreursLayout = new VerticalLayout();
    layout.addComponent(erreursLayout);
    erreursLayout.setVisible(false);

    HorizontalLayout panelslayout = new HorizontalLayout();
    panelslayout.setMargin(true);
    panelslayout.setSpacing(true);
    layout.addComponent(panelslayout);

    /* Panel adresse annuelle */
    Panel adressesAnnuellePanel = new Panel(
            applicationContext.getMessage(NAME + ".panel.adresseannuelle.title", null, getLocale()) + " "
                    + MainUI.getCurrent().getEtudiant().getAdresseAnnuelle().getAnnee());

    FormLayout formAdresseAnnuelleLayout = new FormLayout();
    formAdresseAnnuelleLayout.setSpacing(true);
    formAdresseAnnuelleLayout.setMargin(true);

    //TypeHebergement
    String captionHebergement = applicationContext.getMessage(NAME + ".typehebergement", null, getLocale());
    TypeHebergementDTO[] hebergements = adresseController.getTypesHebergement();
    lhebergement = new NativeSelect();
    lhebergement.setCaption(captionHebergement);
    lhebergement.setNullSelectionAllowed(false);
    lhebergement.setRequired(true);
    lhebergement.setWidth("326px");
    for (TypeHebergementDTO h : hebergements) {
        lhebergement.addItem(h.getCodTypeHebergement());
        lhebergement.setItemCaption(h.getCodTypeHebergement(), h.getLibWebTypeHebergement());
    }
    lhebergement.setValue(etudiant.getAdresseAnnuelle().getType());
    lhebergement.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            String selectedValue = (String) event.getProperty().getValue();

            //Si un hbergement autre que la Domicile parental a t choisi
            if (!selectedValue.equals(COD_HEBERG_DOMICILE_PARENTAL)) {
                activeFormulaireAdresseAnnuelle();

            } else {
                desactiveFormulaireAdresseAnnuelle();
            }
        }
    });

    formAdresseAnnuelleLayout.addComponent(lhebergement);

    //labelChoixHebergement
    labelChoixHebergement = new Label(
            applicationContext.getMessage(NAME + ".labelhebergement", null, getLocale()));
    formAdresseAnnuelleLayout.addComponent(labelChoixHebergement);

    //AdresseAnnuelle1
    fieldAnnu1 = new TextField(applicationContext.getMessage(NAME + ".annu1", null, getLocale()));
    fieldAnnu1.setValue(etudiant.getAdresseAnnuelle().getAdresse1());
    fieldAnnu1.setNullRepresentation("");
    fieldAnnu1.setWidth("326px");
    fieldAnnu1.setMaxLength(32);
    fieldAnnu1.setRequired(true);
    formAdresseAnnuelleLayout.addComponent(fieldAnnu1);

    //AdresseAnnuelle2
    fieldAnnu2 = new TextField(applicationContext.getMessage(NAME + ".annu2", null, getLocale()));
    fieldAnnu2.setValue(etudiant.getAdresseAnnuelle().getAdresse2());
    fieldAnnu2.setNullRepresentation("");
    fieldAnnu2.setWidth("326px");
    fieldAnnu2.setMaxLength(32);
    formAdresseAnnuelleLayout.addComponent(fieldAnnu2);

    //AdresseAnnuelle3
    fieldAnnu3 = new TextField(applicationContext.getMessage(NAME + ".annu3", null, getLocale()));
    fieldAnnu3.setValue(etudiant.getAdresseAnnuelle().getAdresse3());
    fieldAnnu3.setNullRepresentation("");
    fieldAnnu3.setWidth("326px");
    fieldAnnu3.setMaxLength(32);
    formAdresseAnnuelleLayout.addComponent(fieldAnnu3);

    //Liste des Pays
    String captionPays = applicationContext.getMessage(NAME + ".pays1", null, getLocale());
    PaysDTO[] pays = adresseController.getPays();
    lpays1 = new NativeSelect();
    lpays1.setCaption(captionPays);
    lpays1.setNullSelectionAllowed(false);
    lpays1.setRequired(true);
    lpays1.setWidth("326px");
    for (PaysDTO p : pays) {
        lpays1.addItem(p.getCodePay());
        lpays1.setItemCaption(p.getCodePay(), p.getLibPay());
    }
    lpays1.setValue(etudiant.getAdresseAnnuelle().getCodPays());
    lpays1.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            String selectedValue = (String) event.getProperty().getValue();

            //Si un pays autre que France a t choisi
            if (!selectedValue.equals(COD_PAY_FRANCE)) {
                activerChampPourAdresseAnnuelleEtranger();
            } else {
                activerChampPourAdresseAnnuelleEnFrance();
            }
        }
    });
    formAdresseAnnuelleLayout.addComponent(lpays1);

    //Ville pour adresse  l'tranger
    fieldVilleEtranger1 = new TextField(
            applicationContext.getMessage(NAME + ".villeetranger1", null, getLocale()));
    fieldVilleEtranger1.setValue(etudiant.getAdresseAnnuelle().getAdresseetranger());
    fieldVilleEtranger1.setNullRepresentation("");
    fieldVilleEtranger1.setWidth("326px");
    fieldVilleEtranger1.setMaxLength(5);
    fieldVilleEtranger1.setRequired(true);
    formAdresseAnnuelleLayout.addComponent(fieldVilleEtranger1);

    //codePostal1 pour adresses en france
    fieldCodePostal1 = new TextField(applicationContext.getMessage(NAME + ".codepostal1", null, getLocale()));
    fieldCodePostal1.setValue(etudiant.getAdresseAnnuelle().getCodePostal());
    fieldCodePostal1.setNullRepresentation("");
    fieldCodePostal1.setWidth("326px");
    fieldCodePostal1.setMaxLength(5);
    fieldCodePostal1.setRequired(true);
    //fieldCodePostal1.setTextChangeEventMode(TextChangeEventMode.EAGER);
    fieldCodePostal1.addTextChangeListener(new TextChangeListener() {
        @Override
        public void textChange(TextChangeEvent event) {
            updateListeVillesAnnuelle(event.getText());
        }
    });

    formAdresseAnnuelleLayout.addComponent(fieldCodePostal1);

    //Ville pour adresse en france
    List<CommuneDTO> villes1 = adresseController.getVilles(etudiant.getAdresseAnnuelle().getCodePostal());
    lville1 = new NativeSelect();
    lville1.setCaption(applicationContext.getMessage(NAME + ".ville1", null, getLocale()));
    lville1.setNullSelectionAllowed(false);
    lville1.setRequired(true);
    lville1.setWidth("326px");
    for (CommuneDTO v : villes1) {
        lville1.addItem(v.getLibCommune());
        lville1.setItemCaption(v.getLibCommune(), v.getLibCommune());
    }
    codePostalVillesAnnu = etudiant.getAdresseAnnuelle().getCodePostal();
    lville1.setValue(etudiant.getAdresseAnnuelle().getVille());
    lville1.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            updateCodePostalVilleAnnuelle();
        }
    });
    formAdresseAnnuelleLayout.addComponent(lville1);

    //activation des champs utiles en fonction de l'adresse de l'tudiant avant la modification
    if (etudiant.getAdresseAnnuelle().getCodPays().equals(COD_PAY_FRANCE)) {
        activerChampPourAdresseAnnuelleEnFrance();
    } else {
        activerChampPourAdresseAnnuelleEtranger();
    }

    //Tlphone1
    fieldTelephone1 = new TextField(applicationContext.getMessage(NAME + ".tel1", null, getLocale()));
    fieldTelephone1.setValue(etudiant.getAdresseAnnuelle().getNumerotel());
    fieldTelephone1.setNullRepresentation("");
    fieldTelephone1.setWidth("326px");
    fieldTelephone1.setMaxLength(15);
    fieldTelephone1.setRequired(false);
    formAdresseAnnuelleLayout.addComponent(fieldTelephone1);

    //ajout du panel adresse Annuelle
    adressesAnnuellePanel.setContent(formAdresseAnnuelleLayout);
    panelslayout.addComponent(adressesAnnuellePanel);

    //Si un hbergement autre que la Domicile parental a t choisi
    if (!etudiant.getAdresseAnnuelle().getType().equals(COD_HEBERG_DOMICILE_PARENTAL)) {
        activeFormulaireAdresseAnnuelle();
    } else {
        desactiveFormulaireAdresseAnnuelle();
    }

    /* Panel adresse fixe */
    Panel adressesFixePanel = new Panel(
            applicationContext.getMessage(NAME + ".panel.adressefixe.title", null, getLocale()));

    FormLayout formAdresseFixeLayout = new FormLayout();
    formAdresseFixeLayout.setSpacing(true);
    formAdresseFixeLayout.setMargin(true);

    //AdresseFixe1
    fieldFixe1 = new TextField(applicationContext.getMessage(NAME + ".fixe1", null, getLocale()));
    fieldFixe1.setValue(etudiant.getAdresseFixe().getAdresse1());
    fieldFixe1.setNullRepresentation("");
    fieldFixe1.setWidth("326px");
    fieldFixe1.setMaxLength(32);
    fieldFixe1.setRequired(true);
    formAdresseFixeLayout.addComponent(fieldFixe1);

    //AdresseFixe2
    fieldFixe2 = new TextField(applicationContext.getMessage(NAME + ".fixe2", null, getLocale()));
    fieldFixe2.setValue(etudiant.getAdresseFixe().getAdresse2());
    fieldFixe2.setNullRepresentation("");
    fieldFixe2.setWidth("326px");
    fieldFixe2.setMaxLength(32);
    formAdresseFixeLayout.addComponent(fieldFixe2);

    //AdresseFixe3
    fieldFixe3 = new TextField(applicationContext.getMessage(NAME + ".fixe3", null, getLocale()));
    fieldFixe3.setValue(etudiant.getAdresseFixe().getAdresse3());
    fieldFixe3.setNullRepresentation("");
    fieldFixe3.setWidth("326px");
    fieldFixe3.setMaxLength(32);
    formAdresseFixeLayout.addComponent(fieldFixe3);

    //Liste des Pays
    lpays2 = new NativeSelect();
    lpays2.setCaption(captionPays);
    lpays2.setNullSelectionAllowed(false);
    lpays2.setRequired(true);
    lpays2.setWidth("326px");
    for (PaysDTO p : pays) {
        lpays2.addItem(p.getCodePay());
        lpays2.setItemCaption(p.getCodePay(), p.getLibPay());
    }
    lpays2.setValue(etudiant.getAdresseFixe().getCodPays());
    lpays2.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            String selectedValue = (String) event.getProperty().getValue();

            //Si un pays autre que France a t choisi
            if (!selectedValue.equals(COD_PAY_FRANCE)) {
                activerChampPourAdresseFixeEtranger();
            } else {
                activerChampPourAdresseFixeEnFrance();
            }
        }
    });
    formAdresseFixeLayout.addComponent(lpays2);

    //Ville pour adresse  l'tranger
    fieldVilleEtranger2 = new TextField(
            applicationContext.getMessage(NAME + ".villeetranger2", null, getLocale()));
    fieldVilleEtranger2.setValue(etudiant.getAdresseFixe().getAdresseetranger());
    fieldVilleEtranger2.setNullRepresentation("");
    fieldVilleEtranger2.setWidth("326px");
    fieldVilleEtranger2.setMaxLength(5);
    fieldVilleEtranger2.setRequired(true);
    formAdresseFixeLayout.addComponent(fieldVilleEtranger2);

    //codePostal2 pour adresses en france
    fieldCodePostal2 = new TextField(applicationContext.getMessage(NAME + ".codepostal2", null, getLocale()));
    fieldCodePostal2.setValue(etudiant.getAdresseFixe().getCodePostal());
    fieldCodePostal2.setNullRepresentation("");
    fieldCodePostal2.setWidth("326px");
    fieldCodePostal2.setMaxLength(5);
    fieldCodePostal2.setRequired(true);
    //fieldCodePostal1.setTextChangeEventMode(TextChangeEventMode.EAGER);
    fieldCodePostal2.addTextChangeListener(new TextChangeListener() {
        @Override
        public void textChange(TextChangeEvent event) {
            updateListeVillesFixe(event.getText());
        }
    });

    formAdresseFixeLayout.addComponent(fieldCodePostal2);

    //Ville pour adresse en france
    List<CommuneDTO> villes2 = adresseController.getVilles(etudiant.getAdresseFixe().getCodePostal());
    lville2 = new NativeSelect();
    lville2.setCaption(applicationContext.getMessage(NAME + ".ville2", null, getLocale()));
    lville2.setNullSelectionAllowed(false);
    lville2.setRequired(true);
    lville2.setWidth("326px");
    for (CommuneDTO v : villes2) {
        lville2.addItem(v.getLibCommune());
        lville2.setItemCaption(v.getLibCommune(), v.getLibCommune());
    }
    codePostalVillesFixe = etudiant.getAdresseFixe().getCodePostal();
    lville2.setValue(etudiant.getAdresseFixe().getVille());
    lville2.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            updateCodePostalVilleFixe();
        }
    });
    formAdresseFixeLayout.addComponent(lville2);

    //activation des champs utiles en fonction de l'adresse de l'tudiant avant la modification
    if (etudiant.getAdresseFixe().getCodPays().equals(COD_PAY_FRANCE)) {
        activerChampPourAdresseFixeEnFrance();
    } else {
        activerChampPourAdresseFixeEtranger();
    }

    //Tlphone2
    fieldTelephone2 = new TextField(applicationContext.getMessage(NAME + ".tel2", null, getLocale()));
    fieldTelephone2.setValue(etudiant.getAdresseFixe().getNumerotel());
    fieldTelephone2.setNullRepresentation("");
    fieldTelephone2.setWidth("326px");
    fieldTelephone2.setMaxLength(15);
    fieldTelephone2.setRequired(false);
    formAdresseFixeLayout.addComponent(fieldTelephone2);

    //ajout du panel adresse fixe
    adressesFixePanel.setContent(formAdresseFixeLayout);
    panelslayout.addComponent(adressesFixePanel);

    /* Boutons */
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setWidth(100, Unit.PERCENTAGE);
    buttonsLayout.setSpacing(true);

    btnValider.setCaption(applicationContext.getMessage(NAME + ".btnValider", null, getLocale()));
    btnValider.setIcon(FontAwesome.CHECK);
    btnValider.addStyleName(ValoTheme.BUTTON_PRIMARY);
    btnValider.addClickListener(e -> {

        Adresse adresseAnnuelle = new Adresse();
        adresseAnnuelle.setType(lhebergement.getValue().toString());
        adresseAnnuelle.setAdresse1(fieldAnnu1.getValue());
        adresseAnnuelle.setAdresse2(fieldAnnu2.getValue());
        adresseAnnuelle.setAdresse3(fieldAnnu3.getValue());
        adresseAnnuelle.setCodPays(lpays1.getValue().toString());
        adresseAnnuelle.setCodePostal(fieldCodePostal1.getValue());
        adresseAnnuelle.setVille((lville1.getValue() == null) ? null : lville1.getValue().toString());
        adresseAnnuelle.setAdresseetranger(fieldVilleEtranger1.getValue());
        adresseAnnuelle.setNumerotel(fieldTelephone1.getValue());

        Adresse adresseFixe = new Adresse();
        adresseFixe.setAdresse1(fieldFixe1.getValue());
        adresseFixe.setAdresse2(fieldFixe2.getValue());
        adresseFixe.setAdresse3(fieldFixe3.getValue());
        adresseFixe.setCodPays(lpays2.getValue().toString());
        adresseFixe.setCodePostal(fieldCodePostal2.getValue());
        adresseFixe.setVille((lville2.getValue() == null) ? null : lville2.getValue().toString());
        adresseFixe.setAdresseetranger(fieldVilleEtranger2.getValue());
        adresseFixe.setNumerotel(fieldTelephone2.getValue());

        erreursLayout.removeAllComponents();
        List<String> retour = adresseController.majAdresses(adresseAnnuelle, adresseFixe);
        if (retour != null && retour.size() == 1 && retour.get(0).equals("OK")) {
            //ajout maj vue adresse
            etudiantController.recupererAdresses();
            close();
        } else {
            //affichage erreurs
            if (retour != null && retour.size() > 0) {
                String errorMsg = "";
                for (String erreur : retour) {
                    if (!errorMsg.equals(""))
                        errorMsg = errorMsg + "<br />";
                    errorMsg = errorMsg + erreur;
                }
                Label labelErreur = new Label(errorMsg);
                labelErreur.setContentMode(ContentMode.HTML);
                labelErreur.setStyleName(ValoTheme.LABEL_FAILURE);
                erreursLayout.addComponent(labelErreur);
            }
            erreursLayout.setVisible(true);
        }

    });
    buttonsLayout.addComponent(btnValider);
    buttonsLayout.setComponentAlignment(btnValider, Alignment.MIDDLE_CENTER);

    btnAnnuler.setCaption(
            applicationContext.getMessage("modificationAdressesWindow.btnAnnuler", null, getLocale()));
    btnAnnuler.setIcon(FontAwesome.TIMES);
    btnAnnuler.addStyleName(ValoTheme.BUTTON_DANGER);
    btnAnnuler.addClickListener(e -> close());
    buttonsLayout.addComponent(btnAnnuler);
    buttonsLayout.setComponentAlignment(btnAnnuler, Alignment.MIDDLE_CENTER);

    layout.addComponent(buttonsLayout);

    /* Centre la fentre */
    center();
}

From source file:fr.univlorraine.mondossierweb.views.windows.PreferencesApplicationWindow.java

License:Apache License

/**
 * Cre une fentre d'dition des preferences applicative
 * @param prfrence  diter/* w  ww. ja va 2 s  . c  o  m*/
 */
public PreferencesApplicationWindow(PreferencesApplication prefApp) {
    /* Style */
    setModal(true);
    setResizable(false);
    setClosable(false);
    setWidth("50%");

    /* Layout */
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setWidth("100%");
    setContent(layout);

    /* Titre */
    setCaption(applicationContext.getMessage(NAME + ".title", null, getLocale()));

    /* Formulaire */
    fieldGroup = new BeanFieldGroup<>(PreferencesApplication.class);
    fieldGroup.setItemDataSource(prefApp);

    fieldGroup.setFieldFactory(new FieldGroupFieldFactory() {
        private static final long serialVersionUID = 1L;

        @Override
        @SuppressWarnings("rawtypes")
        public <T extends Field> T createField(Class<?> dataType, Class<T> fieldType) {
            if (fieldType == NativeSelect.class) {
                final NativeSelect field = new NativeSelect();
                field.addItem("true");
                field.addItem("false");
                field.setNullSelectionAllowed(false);
                field.setImmediate(true);
                //field.setValue(centre.getTemSrv());
                field.addValueChangeListener(new ValueChangeListener() {
                    @Override
                    public void valueChange(ValueChangeEvent event) {
                        field.setValue(event.getProperty().getValue());
                    }
                });
                return fieldType.cast(field);
            } else {
                final TextField field = new TextField();
                field.setImmediate(true);
                field.addTextChangeListener(new FieldEvents.TextChangeListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void textChange(TextChangeEvent event) {
                        if (!field.isReadOnly()) {
                            field.setValue(event.getText());
                        }
                    }
                });
                return fieldType.cast(field);
            }

        }
    });

    FormLayout formLayout = new FormLayout();
    formLayout.setSpacing(true);
    formLayout.setSizeUndefined();
    formLayout.setWidth("100%");
    for (String fieldName : CONF_APP_FIELDS_ORDER) {
        String caption = applicationContext.getMessage(NAME + ".confAppTable." + fieldName, null, getLocale());
        //Si on est sur un parametre booleen
        if (fieldName.equals("valeur") && estUneValeurBooleenne(prefApp.getValeur())) {
            //On forme le nativeSelect
            Field<?> field = fieldGroup.buildAndBind(caption, fieldName, NativeSelect.class);
            formLayout.addComponent(field);
        } else {
            Field<?> field = fieldGroup.buildAndBind(caption, fieldName);
            if (field instanceof AbstractTextField) {
                ((AbstractTextField) field).setNullRepresentation("");
                field.setWidth("100%");
            }
            formLayout.addComponent(field);
        }
    }

    fieldGroup.getField("prefId").setReadOnly(prefApp.getPrefId() != null);
    fieldGroup.getField("prefDesc").setReadOnly(prefApp.getPrefDesc() != null);

    layout.addComponent(formLayout);

    /* Ajoute les boutons */
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setWidth(100, Unit.PERCENTAGE);
    buttonsLayout.setSpacing(true);
    buttonsLayout.setMargin(true);
    layout.addComponent(buttonsLayout);

    btnAnnuler = new Button(applicationContext.getMessage(NAME + ".btnAnnuler", null, getLocale()),
            FontAwesome.TIMES);
    btnAnnuler.addClickListener(e -> close());
    buttonsLayout.addComponent(btnAnnuler);
    buttonsLayout.setComponentAlignment(btnAnnuler, Alignment.MIDDLE_LEFT);

    btnEnregistrer = new Button(applicationContext.getMessage(NAME + ".btnSave", null, getLocale()),
            FontAwesome.SAVE);
    btnEnregistrer.addStyleName(ValoTheme.BUTTON_PRIMARY);
    btnEnregistrer.addClickListener(e -> {
        try {
            /* Valide la saisie */
            fieldGroup.commit();
            /* Enregistre la conf saisie */
            configController.saveAppParameter(prefApp);
            /* Ferme la fentre */
            close();
        } catch (CommitException ce) {
        }
    });
    buttonsLayout.addComponent(btnEnregistrer);
    buttonsLayout.setComponentAlignment(btnEnregistrer, Alignment.MIDDLE_RIGHT);

    /* Centre la fentre */
    center();
}