Example usage for com.vaadin.ui FormLayout setSpacing

List of usage examples for com.vaadin.ui FormLayout setSpacing

Introduction

In this page you can find the example usage for com.vaadin.ui FormLayout setSpacing.

Prototype

@Override
    public void setSpacing(boolean spacing) 

Source Link

Usage

From source file:fr.univlorraine.mondossierweb.views.ListeInscritsView.java

License:Apache License

public void initListe() {
    //On vrifie le droit d'accder  la vue
    if (UI.getCurrent() instanceof MainUI && userController.isEnseignant()) {
        // initialisation de la vue
        removeAllComponents();/* w ww  .  j  a v a2 s  .  co m*/
        listeEtapes = null;
        listeGroupes = null;

        // Style 
        setMargin(true);
        setSpacing(true);
        setSizeFull();

        // Rcupration de l'objet de la SE dont on doit afficher les inscrits
        code = MainUI.getCurrent().getCodeObjListInscrits();
        typeFavori = MainUI.getCurrent().getTypeObjListInscrits();
        libelleObj = "";
        if (typeIsVet() && MainUI.getCurrent().getEtapeListeInscrits() != null) {
            libelleObj = MainUI.getCurrent().getEtapeListeInscrits().getLibelle();
        }
        if (typeIsElp() && MainUI.getCurrent().getElpListeInscrits() != null) {
            libelleObj = MainUI.getCurrent().getElpListeInscrits().getLibelle();
        }

        // Si l'objet est renseign
        if (code != null && typeFavori != null) {

            //Panel contenant les filtres d'affichage et le bouton de mise en favori
            HorizontalLayout panelLayout = new HorizontalLayout();
            panelLayout.setSizeFull();
            panelLayout.addStyleName("small-font-element");

            // Layout contenant les filtres
            FormLayout formInscritLayout = new FormLayout();
            formInscritLayout.setStyleName(ValoTheme.FORMLAYOUT_LIGHT);
            formInscritLayout.setSpacing(true);
            formInscritLayout.setMargin(true);

            panelFormInscrits = new Panel(code + " " + libelleObj);

            //Affichage d'une liste droulante contenant la liste des annes
            List<String> lannees = MainUI.getCurrent().getListeAnneeInscrits();
            if (lannees != null && lannees.size() > 0) {
                listeAnnees = new ComboBox(applicationContext.getMessage(NAME + ".annee", null, getLocale()));
                listeAnnees.setPageLength(5);
                listeAnnees.setTextInputAllowed(false);
                listeAnnees.setNullSelectionAllowed(false);
                listeAnnees.setWidth("150px");
                for (String annee : lannees) {
                    listeAnnees.addItem(annee);
                    int anneenplusun = Integer.parseInt(annee) + 1;
                    listeAnnees.setItemCaption(annee, annee + "/" + anneenplusun);
                }
                listeAnnees.setValue(MainUI.getCurrent().getAnneeInscrits());

                //Gestion de l'vnement sur le changement d'anne
                listeAnnees.addValueChangeListener(new ValueChangeListener() {
                    @Override
                    public void valueChange(ValueChangeEvent event) {
                        String selectedValue = (String) event.getProperty().getValue();

                        //faire le changement
                        Map<String, String> parameterMap = new HashMap<>();
                        parameterMap.put("code", code);
                        parameterMap.put("type", typeFavori);

                        //rcupration de la nouvelle liste
                        if (typeIsVet()) {
                            listeInscritsController.recupererLaListeDesInscrits(parameterMap, selectedValue,
                                    MainUI.getCurrent());
                        }
                        if (typeIsElp()) {
                            listeInscritsController.recupererLaListeDesInscritsELP(parameterMap, selectedValue,
                                    MainUI.getCurrent());
                        }

                        //update de l'affichage
                        initListe();
                    }
                });
                formInscritLayout.addComponent(listeAnnees);

            }

            //Si on affiche la liste des inscrits  un ELP
            //on doit affiche l'tape d'appartenance et ventuellement les groupes
            //Affichage d'une liste droulante contenant la liste des annes
            if (typeIsElp()) {
                List<VersionEtape> letapes = MainUI.getCurrent().getListeEtapesInscrits();
                if (letapes != null && letapes.size() > 0) {
                    listeEtapes = new ComboBox(
                            applicationContext.getMessage(NAME + ".etapes", null, getLocale()));
                    listeEtapes.setPageLength(5);
                    listeEtapes.setNullSelectionAllowed(false);
                    listeEtapes.setTextInputAllowed(false);
                    listeEtapes.setRequired(false);
                    listeEtapes.setWidth("400px");
                    listeEtapes.addItem(TOUTES_LES_ETAPES_LABEL);
                    listeEtapes.setItemCaption(TOUTES_LES_ETAPES_LABEL, TOUTES_LES_ETAPES_LABEL);
                    for (VersionEtape etape : letapes) {
                        String idEtape = etape.getId().getCod_etp() + "/" + etape.getId().getCod_vrs_vet();
                        listeEtapes.addItem(idEtape);
                        listeEtapes.setItemCaption(idEtape, "[" + idEtape + "] " + etape.getLib_web_vet());
                    }

                    if (MainUI.getCurrent().getEtapeInscrits() != null) {
                        listeEtapes.setValue(MainUI.getCurrent().getEtapeInscrits());
                    } else {

                        listeEtapes.setValue(TOUTES_LES_ETAPES_LABEL);
                    }

                    //Gestion de l'vnement sur le changement d'tape
                    listeEtapes.addValueChangeListener(new ValueChangeListener() {
                        @Override
                        public void valueChange(ValueChangeEvent event) {
                            String vetSelectionnee = (String) event.getProperty().getValue();
                            if (vetSelectionnee.equals(TOUTES_LES_ETAPES_LABEL)) {
                                vetSelectionnee = null;
                            }
                            MainUI.getCurrent().setEtapeInscrits(vetSelectionnee);

                            //faire le changement
                            String groupeSelectionne = ((listeGroupes != null
                                    && listeGroupes.getValue() != null) ? (String) listeGroupes.getValue()
                                            : null);
                            if (groupeSelectionne != null && groupeSelectionne.equals(TOUS_LES_GROUPES_LABEL)) {
                                groupeSelectionne = null;
                            }
                            filtrerInscrits(vetSelectionnee, groupeSelectionne);

                        }
                    });
                    formInscritLayout.addComponent(listeEtapes);

                }

                List<ElpDeCollection> lgroupes = MainUI.getCurrent().getListeGroupesInscrits();
                if (lgroupes != null && lgroupes.size() > 0) {
                    listeGroupes = new ComboBox();
                    listeGroupes.setPageLength(5);
                    listeGroupes.setNullSelectionAllowed(false);
                    listeGroupes.setTextInputAllowed(false);
                    listeGroupes.setRequired(false);
                    listeGroupes.setStyleName(ValoTheme.COMBOBOX_BORDERLESS);
                    listeGroupes.setWidth("348px");
                    listeGroupes.addItem(TOUS_LES_GROUPES_LABEL);
                    listeGroupes.setItemCaption(TOUS_LES_GROUPES_LABEL, TOUS_LES_GROUPES_LABEL);
                    for (ElpDeCollection edc : lgroupes) {
                        for (CollectionDeGroupes cdg : edc.getListeCollection()) {
                            for (Groupe groupe : cdg.getListeGroupes()) {
                                listeGroupes.addItem(groupe.getCleGroupe());
                                listeGroupes.setItemCaption(groupe.getCleGroupe(), groupe.getLibGroupe());

                            }
                        }
                    }
                    if (MainUI.getCurrent().getGroupeInscrits() != null) {
                        listeGroupes.setValue(MainUI.getCurrent().getGroupeInscrits());
                    } else {
                        listeGroupes.setValue(TOUS_LES_GROUPES_LABEL);
                    }

                    //Gestion de l'vnement sur le changement de groupe
                    listeGroupes.addValueChangeListener(new ValueChangeListener() {
                        @Override
                        public void valueChange(ValueChangeEvent event) {
                            String grpSelectionnee = (String) event.getProperty().getValue();
                            if (grpSelectionnee.equals(TOUS_LES_GROUPES_LABEL)) {
                                grpSelectionnee = null;
                            }
                            MainUI.getCurrent().setGroupeInscrits(grpSelectionnee);

                            //faire le changement
                            String etapeSelectionnee = ((listeEtapes != null && listeEtapes.getValue() != null)
                                    ? (String) listeEtapes.getValue()
                                    : null);
                            if (etapeSelectionnee != null
                                    && etapeSelectionnee.equals(TOUTES_LES_ETAPES_LABEL)) {
                                etapeSelectionnee = null;
                            }
                            filtrerInscrits(etapeSelectionnee, grpSelectionnee);

                        }
                    });

                    HorizontalLayout gpLayout = new HorizontalLayout();
                    gpLayout.setCaption(applicationContext.getMessage(NAME + ".groupes", null, getLocale()));
                    gpLayout.setMargin(false);
                    gpLayout.setSpacing(false);
                    gpLayout.addComponent(listeGroupes);
                    Button btnDetailGpe = new Button();
                    btnDetailGpe.setWidth("52px");
                    btnDetailGpe.setHeight("32px");
                    btnDetailGpe.setStyleName(ValoTheme.BUTTON_PRIMARY);
                    btnDetailGpe.setIcon(FontAwesome.SEARCH);
                    btnDetailGpe.setDescription(
                            applicationContext.getMessage(NAME + ".detail.groupes", null, getLocale()));
                    btnDetailGpe.addClickListener(e -> {
                        String vet = null;
                        if (listeEtapes != null && listeEtapes.getValue() != null
                                && !listeEtapes.getValue().equals(TOUTES_LES_ETAPES_LABEL)) {
                            vet = listeEtapes.getItemCaption(listeEtapes.getValue());
                        }
                        DetailGroupesWindow dgw = new DetailGroupesWindow(lgroupes,
                                panelFormInscrits.getCaption(), vet, (String) listeAnnees.getValue());
                        UI.getCurrent().addWindow(dgw);
                    });
                    gpLayout.addComponent(btnDetailGpe);

                    formInscritLayout.addComponent(gpLayout);

                }
            }
            panelLayout.addComponent(formInscritLayout);
            panelLayout.setComponentAlignment(formInscritLayout, Alignment.MIDDLE_LEFT);

            //Cration du favori pour l'objet concern pas la liste des inscrits
            List<Favoris> lfav = favorisController.getFavoris();
            FavorisPK favpk = new FavorisPK();
            favpk.setLogin(userController.getCurrentUserName());
            favpk.setIdfav(code);
            favpk.setTypfav(typeFavori);
            Favoris favori = new Favoris();
            favori.setId(favpk);
            //Cration du bouton pour ajouter l'objet aux favoris
            favoriLayout = new VerticalLayout();
            favoriLayout.setSizeFull();
            favoriLayout.setMargin(true);
            favoriLayout.setSpacing(true);
            btnAjoutFavori = new Button(
                    applicationContext.getMessage(NAME + ".btn.ajoutFavori", null, getLocale()));
            btnAjoutFavori.setIcon(FontAwesome.STAR_O);
            btnAjoutFavori.addStyleName(ValoTheme.BUTTON_PRIMARY);
            btnAjoutFavori.setDescription(
                    applicationContext.getMessage(NAME + ".btn.ajoutFavori", null, getLocale()));
            btnAjoutFavori.addClickListener(e -> {

                //creation du favori en base sur le clic du bouton
                favorisController.saveFavori(favori);

                //On cache le bouton de mise en favori
                btnAjoutFavori.setVisible(false);

                //Affichage d'un message de confirmation
                Notification.show(
                        applicationContext.getMessage(NAME + ".message.favoriAjoute", null, getLocale()),
                        Type.TRAY_NOTIFICATION);
            });

            //Ajout du bouton  l'interface
            favoriLayout.addComponent(btnAjoutFavori);
            favoriLayout.setComponentAlignment(btnAjoutFavori, Alignment.TOP_RIGHT);
            if (typeIsElp()) {
                btnMasquerFiltre = new Button(
                        applicationContext.getMessage(NAME + ".btn.btnMasquerFiltre", null, getLocale()));
                btnMasquerFiltre.setIcon(FontAwesome.CHEVRON_CIRCLE_UP);
                btnMasquerFiltre.addStyleName(ValoTheme.BUTTON_FRIENDLY);
                btnMasquerFiltre.setDescription(
                        applicationContext.getMessage(NAME + ".btn.btnMasquerFiltre", null, getLocale()));
                btnMasquerFiltre.addClickListener(e -> {
                    panelFormInscrits.setContent(null);
                    if (btnDisplayFiltres != null) {
                        btnDisplayFiltres.setVisible(true);
                    }
                });
                favoriLayout.addComponent(btnMasquerFiltre);
                favoriLayout.setComponentAlignment(btnMasquerFiltre, Alignment.BOTTOM_RIGHT);
            }
            panelLayout.addComponent(favoriLayout);
            panelLayout.setComponentAlignment(favoriLayout, Alignment.TOP_RIGHT);

            //Si l'objet est dj en favori
            if (lfav != null && lfav.contains(favori)) {

                //On affiche pas le bouton de mise en favori
                btnAjoutFavori.setVisible(false);
            }

            panelFormInscrits.setContent(panelLayout);
            addComponent(panelFormInscrits);

            //Rcupration de la liste des inscrits
            linscrits = MainUI.getCurrent().getListeInscrits();

            refreshListeCodind(new BeanItemContainer<>(Inscrit.class, linscrits));

            //Test si la liste contient des tudiants
            if (linscrits != null && linscrits.size() > 0 && listecodind != null && listecodind.size() > 0) {
                infoLayout = new VerticalLayout();
                infoLayout.setSizeFull();

                //Layout avec le nb d'inscrit, le bouton trombinoscope et le bouton d'export
                HorizontalLayout resumeLayout = new HorizontalLayout();
                resumeLayout.setWidth("100%");
                resumeLayout.setHeight("50px");

                //Label affichant le nb d'inscrits
                infoNbInscrit = new Label(
                        applicationContext.getMessage(NAME + ".message.nbinscrit", null, getLocale()) + " : "
                                + linscrits.size());

                leftResumeLayout = new HorizontalLayout();
                leftResumeLayout.addComponent(infoNbInscrit);
                leftResumeLayout.setComponentAlignment(infoNbInscrit, Alignment.MIDDLE_LEFT);

                Button infoDescriptionButton = new Button();
                infoDescriptionButton.setStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
                infoDescriptionButton.setIcon(FontAwesome.INFO_CIRCLE);
                infoDescriptionButton.setDescription(applicationContext
                        .getMessage(NAME + ".message.info.predescription", null, getLocale()));
                infoDescriptionButton.addClickListener(e -> {
                    String message = "";
                    if (typeIsVet()) {
                        message = applicationContext.getMessage(NAME + ".message.info.vetdescription", null,
                                getLocale());
                    }
                    if (typeIsElp()) {
                        message = applicationContext.getMessage(NAME + ".message.info.elpdescription", null,
                                getLocale());
                    }

                    HelpBasicWindow hbw = new HelpBasicWindow(message,
                            applicationContext.getMessage("helpWindow.defaultTitle", null, getLocale()));
                    UI.getCurrent().addWindow(hbw);
                });
                leftResumeLayout.addComponent(infoDescriptionButton);
                leftResumeLayout.setComponentAlignment(infoDescriptionButton, Alignment.MIDDLE_LEFT);

                //Bouton export trombinoscope
                btnExportTrombi = new Button();
                btnExportTrombi.setIcon(FontAwesome.FILE_PDF_O);
                btnExportTrombi.setStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
                btnExportTrombi.addStyleName("button-icon");
                btnExportTrombi.addStyleName("red-button-icon");
                btnExportTrombi.setDescription(
                        applicationContext.getMessage(NAME + ".pdf.trombinoscope.link", null, getLocale()));

                //methode qui permet de generer l'export  la demande
                //Cration du nom du fichier
                String nomFichier = applicationContext.getMessage("pdf.trombinoscope.title", null,
                        Locale.getDefault()) + "_" + panelFormInscrits.getCaption() + ".pdf";
                nomFichier = nomFichier.replaceAll(" ", "_");
                StreamResource resource = new StreamResource(new StreamResource.StreamSource() {
                    @Override
                    public InputStream getStream() {

                        //recuperation de l'anne slectionne et du libell de l'ELP
                        String annee = (String) listeAnnees.getValue();
                        String libObj = panelFormInscrits.getCaption();

                        //cration du trombi en pdf
                        return listeInscritsController.getPdfStream(linscrits, listecodind, libObj, annee);
                    }
                }, nomFichier);
                resource.setMIMEType("application/force-download;charset=UTF-8");
                resource.setCacheTime(0);

                //On ajoute le FD sur le bouton d'export
                if (PropertyUtils.isPushEnabled()) {
                    new MyFileDownloader(resource).extend(btnExportTrombi);
                } else {
                    FileDownloader fdpdf = new FileDownloader(resource);
                    fdpdf.setOverrideContentType(false);
                    fdpdf.extend(btnExportTrombi);
                }

                leftResumeLayout.addComponent(btnExportTrombi);
                leftResumeLayout.setComponentAlignment(btnExportTrombi, Alignment.MIDDLE_LEFT);
                //if(!afficherTrombinoscope){

                //On cache le bouton d'export pdf
                btnExportTrombi.setVisible(false);
                //}

                //Bouton export liste excel
                btnExportExcel = new Button();
                btnExportExcel.setIcon(FontAwesome.FILE_EXCEL_O);
                btnExportExcel.setStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
                btnExportExcel.addStyleName("button-icon");
                btnExportExcel
                        .setDescription(applicationContext.getMessage(NAME + ".excel.link", null, getLocale()));
                String nomFichierXls = applicationContext.getMessage("excel.listeinscrits.title", null,
                        Locale.getDefault()) + "_" + panelFormInscrits.getCaption() + ".xls";
                nomFichierXls = nomFichierXls.replaceAll(" ", "_");

                StreamResource resourceXls = new StreamResource(new StreamResource.StreamSource() {

                    @Override
                    public InputStream getStream() {

                        //recuperation de l'anne slectionne et du libell de l'ELP
                        String annee = (String) listeAnnees.getValue();
                        String libObj = panelFormInscrits.getCaption();

                        //cration du trombi en pdf
                        return listeInscritsController.getXlsStream(linscrits, listecodind, listeGroupes,
                                libObj, annee, typeFavori);
                    }
                }, nomFichierXls);
                resourceXls.setMIMEType("application/force-download;charset=UTF-8");
                resourceXls.setCacheTime(0);
                //On ajoute le FD sur le bouton d'export
                if (PropertyUtils.isPushEnabled()) {
                    new MyFileDownloader(resourceXls).extend(btnExportExcel);
                } else {
                    FileDownloader fd = new FileDownloader(resourceXls);
                    fd.setOverrideContentType(false);
                    fd.extend(btnExportExcel);
                }

                //if(!afficherTrombinoscope){
                //On change le bouton d'export pdf par le bouton export excel
                leftResumeLayout.replaceComponent(btnExportTrombi, btnExportExcel);
                //}

                resumeLayout.addComponent(leftResumeLayout);

                //Middle layout avec les bouton de collapse des colonnes
                middleResumeLayout = new HorizontalLayout();
                middleResumeLayout.setSizeFull();
                middleResumeLayout.addStyleName("small-font-element");
                middleResumeLayout.setSpacing(true);

                if (!typeIsVet()) {
                    collapseEtp = new CheckBox(
                            applicationContext.getMessage(NAME + ".collapseEtp.title", null, getLocale()));
                    collapseEtp.setValue(true);
                    collapseEtp.addValueChangeListener(e -> {
                        inscritstable.setColumnCollapsed("etape", !collapseEtp.getValue());
                    });
                    collapseEtp.setDescription(applicationContext.getMessage(NAME + ".collapseEtp.description",
                            null, getLocale()));
                    middleResumeLayout.addComponent(collapseEtp);
                    middleResumeLayout.setComponentAlignment(collapseEtp, Alignment.MIDDLE_CENTER);
                }
                collapseResultatsS1 = new CheckBox(
                        applicationContext.getMessage(NAME + ".collapseResultatsS1.title", null, getLocale()));
                collapseResultatsS1.setValue(false);
                collapseResultatsS1.addValueChangeListener(e -> {
                    inscritstable.setColumnCollapsed("notes1", !collapseResultatsS1.getValue());
                });
                collapseResultatsS1.setDescription(applicationContext
                        .getMessage(NAME + ".collapseResultatsS1.description", null, getLocale()));
                middleResumeLayout.addComponent(collapseResultatsS1);
                middleResumeLayout.setComponentAlignment(collapseResultatsS1, Alignment.MIDDLE_CENTER);

                collapseResultatsS2 = new CheckBox(
                        applicationContext.getMessage(NAME + ".collapseResultatsS2.title", null, getLocale()));
                collapseResultatsS2.setValue(false);
                collapseResultatsS2.addValueChangeListener(e -> {
                    inscritstable.setColumnCollapsed("notes2", !collapseResultatsS2.getValue());
                });
                collapseResultatsS2.setDescription(applicationContext
                        .getMessage(NAME + ".collapseResultatsS2.description", null, getLocale()));
                middleResumeLayout.addComponent(collapseResultatsS2);
                middleResumeLayout.setComponentAlignment(collapseResultatsS2, Alignment.MIDDLE_CENTER);

                resumeLayout.addComponent(middleResumeLayout);

                HorizontalLayout buttonResumeLayout = new HorizontalLayout();
                buttonResumeLayout.setSizeFull();
                buttonResumeLayout.setSpacing(true);
                //Bouton pour afficher les filtres
                btnDisplayFiltres = new Button();
                btnDisplayFiltres.setWidth("52px");
                btnDisplayFiltres.setHeight("32px");
                btnDisplayFiltres.setStyleName(ValoTheme.BUTTON_FRIENDLY);
                btnDisplayFiltres.setIcon(FontAwesome.FILTER);
                btnDisplayFiltres.setDescription(
                        applicationContext.getMessage(NAME + ".btn.displayFilters", null, getLocale()));
                btnDisplayFiltres.addClickListener(e -> {
                    panelFormInscrits.setContent(panelLayout);
                    btnDisplayFiltres.setVisible(false);
                });
                buttonResumeLayout.addComponent(btnDisplayFiltres);
                buttonResumeLayout.setComponentAlignment(btnDisplayFiltres, Alignment.MIDDLE_RIGHT);
                buttonResumeLayout.setExpandRatio(btnDisplayFiltres, 1);
                btnDisplayFiltres.setVisible(false);

                //Bouton trombinoscope
                btnTrombi = new Button(
                        applicationContext.getMessage(NAME + ".message.trombinoscope", null, getLocale()));
                if (listeInscritsController.isPhotoProviderOperationnel()) {
                    btnTrombi.setIcon(FontAwesome.GROUP);
                    buttonResumeLayout.addComponent(btnTrombi);

                    //Gestion du clic sur le bouton trombinoscope
                    btnTrombi.addClickListener(e -> {

                        //Si on doit afficher une fentre de loading pendant l'excution
                        if (PropertyUtils.isPushEnabled() && PropertyUtils.isShowLoadingIndicator()) {
                            //affichage de la pop-up de loading
                            MainUI.getCurrent().startBusyIndicator();

                            //Execution de la mthode en parallle dans un thread
                            executorService.execute(new Runnable() {
                                public void run() {
                                    MainUI.getCurrent().access(new Runnable() {
                                        @Override
                                        public void run() {
                                            executeDisplayTrombinoscope();
                                            //close de la pop-up de loading
                                            MainUI.getCurrent().stopBusyIndicator();
                                        }
                                    });
                                }
                            });

                        } else {
                            //On ne doit pas afficher de fentre de loading, on excute directement la mthode
                            executeDisplayTrombinoscope();
                        }

                    });
                    buttonResumeLayout.setComponentAlignment(btnTrombi, Alignment.MIDDLE_RIGHT);
                }

                //Bouton de retour  l'affichage de la liste
                btnRetourListe = new Button(
                        applicationContext.getMessage(NAME + ".message.retourliste", null, getLocale()));
                btnRetourListe.setIcon(FontAwesome.BARS);
                buttonResumeLayout.addComponent(btnRetourListe);
                //if(!afficherTrombinoscope){
                btnRetourListe.setVisible(false);
                //}

                //Gestion du clic sur le bouton de  retour  l'affichage de la liste
                btnRetourListe.addClickListener(e -> {
                    afficherTrombinoscope = false;
                    btnExportTrombi.setVisible(false);
                    leftResumeLayout.replaceComponent(btnExportTrombi, btnExportExcel);
                    btnTrombi.setVisible(true);
                    btnRetourListe.setVisible(false);
                    dataLayout.removeAllComponents();
                    dataLayout.addComponent(inscritstable);
                    middleResumeLayout.setVisible(true);

                });
                buttonResumeLayout.setComponentAlignment(btnRetourListe, Alignment.MIDDLE_RIGHT);

                resumeLayout.addComponent(buttonResumeLayout);

                infoLayout.addComponent(resumeLayout);

                //Layout qui contient la liste des inscrits et le trombinoscope
                dataLayout = new VerticalLayout();
                dataLayout.setSizeFull();

                //Table contenant la liste des inscrits
                inscritstable = new Table(null, new BeanItemContainer<>(Inscrit.class, linscrits));

                inscritstable.addStyleName("table-without-column-selector");
                inscritstable.setSizeFull();
                inscritstable.setVisibleColumns(new String[0]);

                String[] fields = INS_FIELDS_ELP;
                if (typeIsVet()) {
                    fields = INS_FIELDS_VET;
                }
                for (String fieldName : fields) {
                    inscritstable.setColumnHeader(fieldName,
                            applicationContext.getMessage(NAME + ".table." + fieldName, null, getLocale()));
                }

                inscritstable.addGeneratedColumn("cod_etu", new CodEtuColumnGenerator());
                inscritstable.setColumnHeader("cod_etu",
                        applicationContext.getMessage(NAME + ".table.cod_etu", null, getLocale()));
                inscritstable.addGeneratedColumn("email", new MailColumnGenerator());
                inscritstable.setColumnHeader("email",
                        applicationContext.getMessage(NAME + ".table.email", null, getLocale()));
                inscritstable.addGeneratedColumn("notes1", new Session1ColumnGenerator());
                inscritstable.setColumnHeader("notes1",
                        applicationContext.getMessage(NAME + ".table.notes1", null, getLocale()));
                inscritstable.addGeneratedColumn("notes2", new Session2ColumnGenerator());
                inscritstable.setColumnHeader("notes2",
                        applicationContext.getMessage(NAME + ".table.notes2", null, getLocale()));

                //Si on est sur un ELP
                if (typeIsElp()) {
                    //on affiche l'tape de rattachement
                    inscritstable.addGeneratedColumn("etape", new EtapeColumnGenerator());
                    inscritstable.setColumnHeader("etape",
                            applicationContext.getMessage(NAME + ".table.etape", null, getLocale()));
                }

                String[] fields_to_display = INS_FIELDS_TO_DISPLAY_ELP;
                if (typeIsVet()) {
                    fields_to_display = INS_FIELDS_TO_DISPLAY_VET;
                }

                inscritstable.setVisibleColumns((Object[]) fields_to_display);

                inscritstable.setColumnCollapsingAllowed(true);
                inscritstable.setColumnReorderingAllowed(false);

                //On masque les colonnes de notes par dfaut
                inscritstable.setColumnCollapsed("notes1", true);
                inscritstable.setColumnCollapsed("notes2", true);

                inscritstable.setSelectable(false);
                inscritstable.setImmediate(true);
                inscritstable.addStyleName("scrollabletable");
                //Si on n'a pas dj demand  afficher le trombinoscope
                //if(!afficherTrombinoscope){
                //la layout contient la table
                dataLayout.addComponent(inscritstable);
                //}

                //Layout contenant le gridLayout correspondant au trombinoscope
                verticalLayoutForTrombi = new VerticalLayout();
                verticalLayoutForTrombi.setSizeFull();
                verticalLayoutForTrombi.addStyleName("v-scrollablepanel");

                //Cration du trombinoscope
                displayTrombinoscope();

                verticalLayoutForTrombi.addComponent(trombiLayout);
                verticalLayoutForTrombi.setSizeFull();
                verticalLayoutForTrombi.setHeight(null);

                //Si on a demand  afficher le trombinoscope
                /*if(afficherTrombinoscope){
                   //Le layout contient le trombi  afficher
                   dataLayout.addComponent(verticalLayoutForTrombi);
                }*/
                infoLayout.addComponent(dataLayout);
                infoLayout.setExpandRatio(dataLayout, 1);
                addComponent(infoLayout);
                setExpandRatio(infoLayout, 1);

                //Si on a demand  afficher le trombinoscope
                if (afficherTrombinoscope) {
                    //On execute la procdure d'affichage du trombinoscope
                    executeDisplayTrombinoscope();
                }
            } else {
                Label infoAucuninscrit = new Label(
                        applicationContext.getMessage(NAME + ".message.aucuninscrit", null, getLocale()));
                addComponent(infoAucuninscrit);
                setComponentAlignment(infoAucuninscrit, Alignment.TOP_CENTER);
                setExpandRatio(infoAucuninscrit, 1);
            }

        }
    }
}

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

License:Apache License

/**
 * Cre une fentre de confirmation// www . j a v a 2 s .c o m
 * @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/*from  w ww  .  j  a  v  a  2s.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();
}

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

License:Apache License

/**
 * Cre une fentre d'dition du swap utilisateur
 * @param swap utilisateur  diter//  ww w  . ja  va  2s.  c  o m
 */
public SwapUtilisateurWindow(UtilisateurSwap swap, boolean ajout) {
    /* 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 */
    if (ajout) {
        setCaption(applicationContext.getMessage(NAME + ".title.ajout", null, getLocale()));
    } else {
        setCaption(applicationContext.getMessage(NAME + ".title", null, getLocale()));
    }

    /* Formulaire */
    fieldGroup = new BeanFieldGroup<>(UtilisateurSwap.class);
    fieldGroup.setItemDataSource(swap);
    FormLayout formLayout = new FormLayout();
    formLayout.setSpacing(true);
    formLayout.setSizeUndefined();
    formLayout.setWidth("100%");
    for (String fieldName : CONF_APP_FIELDS_ORDER) {
        String caption = applicationContext.getMessage(NAME + ".swapUserTable." + fieldName, null, getLocale());
        Field<?> field = fieldGroup.buildAndBind(caption, fieldName);
        if (field instanceof AbstractTextField) {
            ((AbstractTextField) field).setNullRepresentation("");
            field.setWidth("100%");
        }
        if (field instanceof DateField) {
            ((DateField) field).setResolution(DateField.RESOLUTION_MIN);
        }
        formLayout.addComponent(field);
    }

    //fieldGroup.getField("loginCible").setReadOnly(swap.getLoginCible() != null);
    fieldGroup.getField("loginSource").setReadOnly(swap.getLoginSource() != 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();
            boolean commitok = true;
            if (ajout) {
                //On regarde si le login source n'est pas dj dans la table
                String loginSource = (String) fieldGroup.getField("loginSource").getValue();
                if (configController.getSwapUtilisateur(loginSource) != null) {
                    commitok = false;
                    //afficher message d'erreur
                    Notification.show(applicationContext.getMessage(NAME + ".error.loginexistant", null,
                            UI.getCurrent().getLocale()), Notification.Type.ERROR_MESSAGE);
                }
            }
            if (commitok) {
                /* Enregistre le swap saisie */
                configController.saveSwap(swap);

                /* Ferme la fentre */
                close();
            }
        } catch (CommitException ce) {
        }
    });
    buttonsLayout.addComponent(btnEnregistrer);
    buttonsLayout.setComponentAlignment(btnEnregistrer, Alignment.MIDDLE_RIGHT);

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

From source file:info.magnolia.messages.app.MessagesViewImpl.java

License:Open Source License

@Inject
public MessagesViewImpl(SimpleTranslator i18n) {

    this.i18n = i18n;

    // create form and data item
    final Message message = new Message(); // message POJO
    BeanItem<Message> messageItem = new BeanItem<Message>(message);

    final FieldGroup form = new FieldGroup();
    form.setItemDataSource(messageItem);

    Field<String> subjectField = createSubjectTextField();
    Field<String> messageBodyField = createMessageBodyTextField();
    Field<?> typeField = createTypeSelectionField();
    Field<?> scopeField = createScopeSelectionField();
    userOrGroupIdField = createUserOrGroupIdTextField();

    // disable user/group field if not necessary
    scopeField.addValueChangeListener(new ValueChangeListener() {

        @Override/*from  w  ww .j  ava  2 s  .  co  m*/
        public void valueChange(ValueChangeEvent event) {
            updateUserOrGroupField((String) event.getProperty().getValue());
        }
    });

    form.bind(subjectField, "title");
    form.bind(messageBodyField, "content");
    form.bind(typeField, "type");
    form.bind(scopeField, "scope");
    form.bind(userOrGroupIdField, "user");
    // FieldGroup overrides fields' own enabled property with its own.
    updateUserOrGroupField(message.getScope());

    FormLayout layout = new FormLayout();
    layout.addComponent(subjectField);
    layout.addComponent(messageBodyField);
    layout.addComponent(typeField);
    layout.addComponent(scopeField);
    layout.addComponent(userOrGroupIdField);

    layout.setSpacing(true);
    layout.setMargin(false);
    layout.setWidth("100%");

    // send button
    NativeButton sendButton = new NativeButton(i18n.translate("messages-app.app.button.sendMessage"),
            new Button.ClickListener() {

                @Override
                public void buttonClick(Button.ClickEvent event) {
                    try {
                        form.commit();
                        String subject = message.getTitle();
                        String content = message.getContent();
                        MessageType type = message.getType();
                        String scope = message.getScope();

                        if (MESSAGE_SCOPE_LOCAL.equals(scope)) {
                            listener.handleLocalMessage(type, subject, content);
                        } else if (MESSAGE_SCOPE_GLOBAL.equals(scope)) {
                            listener.handleGlobalMessage(type, subject, content);
                        } else if (MESSAGE_SCOPE_GROUP.equals(scope)) {
                            // message is bound to FieldGroup - hence the group name is to be retrieved from the user field of the message
                            final String groupName = message.getUser();
                            listener.handleGroupMessage(groupName, type, subject, content);
                        } else {
                            // User...
                            final String userName = message.getUser();
                            listener.handleUserMessage(userName, type, subject, content);
                        }
                    } catch (CommitException e) {

                    }
                }
            });
    sendButton.addStyleName("btn-dialog");
    sendButton.addStyleName("commit");

    // reset button
    NativeButton resetButton = new NativeButton(i18n.translate("messages-app.app.button.reset"),
            new Button.ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {
                    message.reset();
                    form.discard();
                }
            });
    resetButton.addStyleName("btn-dialog");
    resetButton.addStyleName("cancel");

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.addStyleName("buttons");
    buttons.setSpacing(true);
    buttons.addComponent(sendButton);
    buttons.addComponent(resetButton);
    layout.addComponent(buttons);

    // intro text
    Label intro = new Label(i18n.translate("messages-app.app.label.intro"), ContentMode.HTML);
    intro.addStyleName("intro");

    CssLayout container = new CssLayout();
    container.setSizeFull();
    container.addStyleName("small-app-panel");
    container.addComponent(layout);

    CssLayout root = new CssLayout();
    root.setSizeFull();
    root.setWidth("900px");
    root.setStyleName("small-app");
    root.addComponent(intro);
    root.addComponent(container);

    component = root;
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.LoginDialog.java

License:Apache License

public void init() {
    //Layout/*from w  ww .jav  a  2 s  .c om*/
    FormLayout layout = new FormLayout();
    setContent(layout);
    HorizontalLayout hlayout = new HorizontalLayout();
    hlayout.addComponent(loginButton);
    hlayout.addComponent(cancelButton);
    layout.addComponent(name);
    layout.addComponent(password);
    name.focus();
    name.setWidth(100, Unit.PERCENTAGE);
    StringLengthValidator nameVal = new StringLengthValidator(Lookup.getDefault()
            .lookup(InternationalizationProvider.class).translate("password.length.message"));
    nameVal.setMinLength(5);
    name.addValidator(nameVal);
    name.setImmediate(true);
    StringLengthValidator passVal = new StringLengthValidator(
            Lookup.getDefault().lookup(InternationalizationProvider.class).translate("password.empty.message"));
    passVal.setMinLength(3);
    password.addValidator(passVal);
    password.setImmediate(true);
    password.setWidth(100, Unit.PERCENTAGE);
    layout.addComponent(hlayout);
    layout.setComponentAlignment(name, Alignment.TOP_LEFT);
    layout.setComponentAlignment(password, Alignment.MIDDLE_LEFT);
    layout.setComponentAlignment(hlayout, Alignment.BOTTOM_LEFT);
    layout.setSpacing(true);
    layout.setMargin(true);

    // Keyboard navigation - enter key is a shortcut to login
    addActionHandler(new Handler() {
        @Override
        public Action[] getActions(Object target, Object sender) {
            return new Action[] { enterKey };
        }

        @Override
        public void handleAction(Action action, Object sender, Object target) {
            tryToLogIn();
        }
    });
}

From source file:org.apache.tamaya.ui.views.login.LoginBox.java

License:Apache License

private void addForm() {
    FormLayout loginForm = new FormLayout();
    MessageProvider mp = ServiceContextManager.getServiceContext().getService(MessageProvider.class);
    username = new TextField(mp.getMessage("default.label.username"));
    password = new PasswordField(mp.getMessage("default.label.password"));
    loginForm.addComponents(username, password);
    addComponent(loginForm);/*from  w  w w  . j a v a 2  s .co  m*/
    loginForm.setSpacing(true);
    for (Component component : loginForm) {
        component.setWidth("100%");
    }
    username.focus();
}

From source file:org.apache.usergrid.chop.webapp.view.chart.layout.ChartLayout.java

License:Apache License

private FormLayout addFormLayout() {

    FormLayout formLayout = new FormLayout();
    formLayout.setWidth("250px");
    formLayout.setHeight("250px");
    formLayout.addStyleName("outlined");
    formLayout.setSpacing(true);

    addComponent(formLayout, "left: 10px; top: 10px;");

    return formLayout;
}

From source file:org.apache.usergrid.chop.webapp.view.user.UserLayout.java

License:Apache License

private FormLayout addFormLayout(int x, int y) {

    FormLayout formLayout = new FormLayout();
    formLayout.setWidth(String.format("%spx", x));
    formLayout.setHeight(String.format("%spx", y));
    formLayout.addStyleName("outlined");
    formLayout.setSpacing(true);

    addComponent(formLayout, "left: 350px; top: 50px;");

    return formLayout;
}

From source file:org.jumpmind.metl.ui.views.admin.GeneralSettingsPanel.java

License:Open Source License

public GeneralSettingsPanel(final ApplicationContext context, TabbedPanel tabbedPanel) {
    this.context = context;
    this.tabbedPanel = tabbedPanel;

    final GlobalSetting systemTextSetting = getGlobalSetting(GlobalSetting.SYSTEM_TEXT, "");

    FormLayout form = new FormLayout();
    form.setSpacing(true);

    ImmediateUpdateTextField systemTextField = new ImmediateUpdateTextField("System Text") {
        protected void save(String value) {
            saveSetting(systemTextSetting, value);
        }//from  w  w  w  . j  a  va 2  s .  co m
    };
    systemTextField.setDescription(
            "Set HTML content to be displayed in the top bar that can identify a particular environment");
    systemTextField.setValue(systemTextSetting.getValue());
    systemTextField.setWidth(25f, Unit.EM);
    form.addComponent(systemTextField);
    systemTextField.focus();

    addComponent(form);
    setMargin(true);
}