Example usage for com.vaadin.ui FormLayout setMargin

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

Introduction

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

Prototype

@Override
    public void setMargin(boolean enabled) 

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();//from   www  .java 2 s.  c om
        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  om*/
 * @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: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// ww w.j av  a 2  s.  c  o  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:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * are el dilogo para autenticarse//  w w  w  . j  a v  a2  s  .  co m
 */
private void openLoginDialog(boolean gohome) {

    // Create a sub-window and set the content
    Window subWindow = new Window("Login");

    subWindow.setWidth("375px");

    FormLayout f = new FormLayout();
    f.setMargin(true);

    TextField l;
    f.addComponent(l = new TextField("Username"));
    PasswordField p;
    f.addComponent(p = new PasswordField("Password"));
    Label e;
    f.addComponent(e = new Label());

    VerticalLayout v = new VerticalLayout();
    v.addComponent(f);

    HorizontalLayout footer = new HorizontalLayout();
    footer.setWidth("100%");
    footer.setSpacing(true);
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);

    Label footerText = new Label("");
    footerText.setSizeUndefined();

    Button forgot = new Button("Forgot password", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            e.setValue("Asking for email...");
            io.mateu.ui.core.client.app.MateuUI.getBaseService().forgotPassword(l.getValue(),
                    new AsyncCallback<Void>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage());
                        }

                        @Override
                        public void onSuccess(Void result) {
                            e.setValue("Email sent. Please check your inbox");
                        }
                    });
        }
    });
    //forgot.addStyleName(ValoTheme.BUTTON_);

    Button ok = new Button("Login", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            e.setValue("Authenticating...");
            io.mateu.ui.core.client.app.MateuUI.getBaseService().authenticate(l.getValue(), p.getValue(),
                    new AsyncCallback<UserData>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage());
                        }

                        @Override
                        public void onSuccess(UserData result) {
                            e.setValue("OK!");
                            getApp().setUserData(result);
                            VaadinSession.getCurrent().setAttribute("usuario", "admin");
                            subWindow.close();

                            if (MateuUI.getApp().isFavouritesAvailable())
                                linkFavoritos.setVisible(true);
                            if (MateuUI.getApp().isLastEditedAvailable())
                                linkUltimosRegistros.setVisible(true);
                            if (MateuUI.getApp().isFavouritesAvailable())
                                linkNuevoFavorito.setVisible(true);

                            refreshSettings();
                            refreshMenu(null, null);
                            System.out.println("STATE:" + navigator.getState());
                            System.out.println("URIFRAGMENT:" + Page.getCurrent().getUriFragment());
                            navigator.navigateTo((gohome) ? "" : navigator.getState());
                        }
                    });
        }
    });
    ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER);

    Button cancel = new Button("Cancel");

    footer.addComponents(footerText, forgot, ok); //, cancel);
    footer.setExpandRatio(footerText, 1);

    v.addComponent(footer);

    subWindow.setContent(v);

    // Center it in the browser window
    subWindow.center();

    subWindow.setModal(true);

    // Open it in the UI
    UI.getCurrent().addWindow(subWindow);

    l.focus();
}

From source file:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * abre el dilogo para cambiar el password
 *
 *//* w w  w .j  ava2 s  .c  om*/
private void changePassword() {
    // Create a sub-window and set the content
    Window subWindow = new Window("Change password");

    subWindow.setWidth("375px");

    FormLayout f = new FormLayout();
    f.setMargin(true);

    PasswordField l;
    f.addComponent(l = new PasswordField("Current password"));
    PasswordField p;
    f.addComponent(p = new PasswordField("New password"));
    PasswordField p2;
    f.addComponent(p2 = new PasswordField("Repeat password"));
    Label e;
    f.addComponent(e = new Label());

    VerticalLayout v = new VerticalLayout();
    v.addComponent(f);

    HorizontalLayout footer = new HorizontalLayout();
    footer.setWidth("100%");
    footer.setSpacing(true);
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);

    Label footerText = new Label("");
    footerText.setSizeUndefined();

    Button ok = new Button("Change it!", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            if (l.getValue() == null || "".equals(l.getValue().trim()))
                e.setValue("Old password is required");
            else if (p.getValue() == null || "".equals(p.getValue().trim()))
                e.setValue("New password is required");
            else if (p2.getValue() == null || "".equals(p2.getValue().trim()))
                e.setValue("New password repeated is required");
            else if (!p.getValue().equals(p2.getValue()))
                e.setValue("New password and new password repeated must be equal");
            else {
                e.setValue("Changing password...");

                io.mateu.ui.core.client.app.MateuUI.getBaseService().changePassword(
                        getApp().getUserData().getLogin(), l.getValue(), p.getValue(),
                        new AsyncCallback<Void>() {

                            @Override
                            public void onFailure(Throwable caught) {
                                e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage());
                            }

                            @Override
                            public void onSuccess(Void result) {
                                e.setValue("OK!");
                                subWindow.close();
                            }
                        });

            }
        }
    });
    ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER);

    Button cancel = new Button("Cancel");

    footer.addComponents(footerText, ok); //, cancel);
    footer.setExpandRatio(footerText, 1);

    v.addComponent(footer);

    subWindow.setContent(v);

    // Center it in the browser window
    subWindow.center();

    subWindow.setModal(true);

    // Open it in the UI
    UI.getCurrent().addWindow(subWindow);

    l.focus();
}

From source file:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * abre el dilogo para editar el perfil/*ww w .  ja  v  a  2s . c  o  m*/
 *
 */
private void editProfile() {
    // Create a sub-window and set the content
    Window subWindow = new Window("My profile");

    subWindow.setWidth("375px");

    FormLayout f = new FormLayout();
    f.setMargin(true);

    TextField l;
    f.addComponent(l = new TextField("Name"));
    l.setValue(getApp().getUserData().getName());
    TextField p;
    f.addComponent(p = new TextField("Email"));
    p.setValue(getApp().getUserData().getEmail());
    Label e;
    f.addComponent(e = new Label());

    VerticalLayout v = new VerticalLayout();
    v.addComponent(f);

    HorizontalLayout footer = new HorizontalLayout();
    footer.setWidth("100%");
    footer.setSpacing(true);
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);

    Label footerText = new Label("");
    footerText.setSizeUndefined();

    Button ok = new Button("Update it!", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            e.setValue("Authenticating...");
            io.mateu.ui.core.client.app.MateuUI.getBaseService().updateProfile(
                    getApp().getUserData().getLogin(), l.getValue(), p.getValue(), null,
                    new AsyncCallback<Void>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage());
                        }

                        @Override
                        public void onSuccess(Void result) {
                            e.setValue("OK!");
                            getApp().getUserData().setName(l.getValue());
                            getApp().getUserData().setEmail(p.getValue());
                            subWindow.close();
                            refreshSettings();
                        }
                    });
        }
    });
    ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER);

    Button cancel = new Button("Cancel");

    footer.addComponents(footerText, ok); //, cancel);
    footer.setExpandRatio(footerText, 1);

    v.addComponent(footer);

    subWindow.setContent(v);

    // Center it in the browser window
    subWindow.center();

    subWindow.setModal(true);

    // Open it in the UI
    UI.getCurrent().addWindow(subWindow);

    l.focus();
}

From source file:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * abre el dilogo para cambiar la foto//from   w w w .  ja va 2 s .  c  o m
 *
 *
 */
private void uploadFoto() {
    // Create a sub-window and set the content
    Window subWindow = new Window("My photo");

    subWindow.setWidth("475px");

    FormLayout f = new FormLayout();
    f.setMargin(true);

    Label e = new Label();

    Image image = new Image();

    class MyUploader implements Upload.Receiver, Upload.SucceededListener {

        File file;

        public File getFile() {
            return file;
        }

        public OutputStream receiveUpload(String fileName, String mimeType) {
            // Create and return a file output stream

            System.out.println("receiveUpload(" + fileName + "," + mimeType + ")");

            FileOutputStream os = null;
            if (fileName != null && !"".equals(fileName)) {

                long id = fileId++;
                String extension = ".tmp";
                if (fileName == null || "".equals(fileName.trim()))
                    fileName = "" + id + extension;
                if (fileName.lastIndexOf(".") < fileName.length() - 1) {
                    extension = fileName.substring(fileName.lastIndexOf("."));
                    fileName = fileName.substring(0, fileName.lastIndexOf("."));
                }
                File temp = null;
                try {
                    temp = File.createTempFile(fileName, extension);
                    os = new FileOutputStream(file = temp);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            return os;
        }

        public void uploadSucceeded(Upload.SucceededEvent event) {
            // Show the uploaded file in the image viewer
            image.setSource(new FileResource(file));
            System.out.println("uploadSucceeded(" + file.getAbsolutePath() + ")");

        }

        public FileLocator getFileLocator() throws IOException {

            String extension = ".tmp";
            String fileName = file.getName();

            if (file.getName() == null || "".equals(file.getName().trim()))
                fileName = "" + getId();
            if (fileName.lastIndexOf(".") < fileName.length() - 1) {
                extension = fileName.substring(fileName.lastIndexOf("."));
                fileName = fileName.substring(0, fileName.lastIndexOf(".")).replaceAll(" ", "_");
            }

            java.io.File temp = (System.getProperty("tmpdir") == null)
                    ? java.io.File.createTempFile(fileName, extension)
                    : new java.io.File(new java.io.File(System.getProperty("tmpdir")), fileName + extension);

            System.out.println("java.io.tmpdir=" + System.getProperty("java.io.tmpdir"));
            System.out.println("Temp file : " + temp.getAbsolutePath());

            if (System.getProperty("tmpdir") == null || !temp.exists()) {
                System.out.println("writing temp file to " + temp.getAbsolutePath());
                Files.copy(file, temp);
            } else {
                System.out.println("temp file already exists");
            }

            String baseUrl = System.getProperty("tmpurl");
            URL url = null;
            try {
                if (baseUrl == null) {
                    url = file.toURI().toURL();
                } else
                    url = new URL(baseUrl + "/" + file.getName());
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            return new FileLocator(0, file.getName(), url.toString(), file.getAbsolutePath());
        }
    }
    ;
    MyUploader receiver = new MyUploader();

    Upload upload = new Upload(null, receiver);
    //upload.setImmediateMode(false);
    upload.addSucceededListener(receiver);

    f.addComponent(image);

    f.addComponent(upload);

    f.addComponent(e);

    VerticalLayout v = new VerticalLayout();
    v.addComponent(f);

    HorizontalLayout footer = new HorizontalLayout();
    footer.setWidth("100%");
    footer.setSpacing(true);
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);

    Label footerText = new Label("");
    footerText.setSizeUndefined();

    Button ok = new Button("Change it!", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            e.setValue("Changing photo...");
            try {
                FileLocator loc = receiver.getFileLocator();

                io.mateu.ui.core.client.app.MateuUI.getBaseService()
                        .updateFoto(getApp().getUserData().getLogin(), loc, new AsyncCallback<Void>() {

                            @Override
                            public void onFailure(Throwable caught) {
                                e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage());
                            }

                            @Override
                            public void onSuccess(Void result) {
                                e.setValue("OK!");
                                getApp().getUserData().setPhoto(loc.getUrl());
                                foto = (getApp().getUserData().getPhoto() != null)
                                        ? new ExternalResource(getApp().getUserData().getPhoto())
                                        : new ClassResource("profile-pic-300px.jpg");
                                subWindow.close();

                                refreshSettings();

                            }
                        });

            } catch (IOException e1) {
                e1.printStackTrace();
                io.mateu.ui.core.client.app.MateuUI.alert("" + e1.getClass().getName() + ":" + e1.getMessage());
            }

        }
    });
    ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER);

    Button cancel = new Button("Cancel");

    footer.addComponents(footerText, ok); //, cancel);
    footer.setExpandRatio(footerText, 1);

    v.addComponent(footer);

    subWindow.setContent(v);

    // Center it in the browser window
    subWindow.center();

    subWindow.setModal(true);

    // Open it in the UI
    UI.getCurrent().addWindow(subWindow);

    upload.focus();
}

From source file:local.ikram.assesment.web.SimpleFormComponent.java

private void initForm() {

    employeeId = new TextField("Employee Id: ");
    employeeId.setIcon(FontAwesome.FILE_PICTURE_O);
    employeeId.setRequired(true);//from  w  w w . ja v a  2  s.c o  m
    employeeId.addValidator(new StringLengthValidator("Must be btw 7 and 9 characters", 7, 9, false));

    firstName = new TextField("First Name: ");
    firstName.setIcon(FontAwesome.USER);
    firstName.setRequired(true);
    firstName.addValidator(new NullValidator("Cannot be empty", false));

    lastName = new TextField("Last Name: ");
    lastName.setIcon(FontAwesome.USER);
    lastName.setRequired(true);
    lastName.addValidator(new NullValidator("Cannot be empty", false));

    phoneNumber = new TextField("Phone Number: ");
    phoneNumber.setIcon(FontAwesome.PHONE_SQUARE);
    phoneNumber.setRequired(true);
    phoneNumber.addValidator(new NullValidator("Cannot be empty", false));

    department = new TextField("Department: ");
    department.setIcon(FontAwesome.DESKTOP);
    department.setRequired(true);
    department.addValidator(new NullValidator("Cannot be empty", false));

    saveBtn = new Button("Save", FontAwesome.SAVE);
    saveBtn.addStyleName("save-btn");
    saveBtn.addClickListener((Button.ClickEvent e) -> {
        try {
            employeeId.validate();
            firstName.validate();
            lastName.validate();
            phoneNumber.validate();
            department.validate();
            update(getEmployee());
        } catch (Validator.InvalidValueException ex) {
            Logger.getLogger(SimpleFormComponent.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage(),
                    ex);
        }
    });
    deleteBtn = new Button("Delete", FontAwesome.RECYCLE);
    deleteBtn.addStyleName("delete-btn");
    deleteBtn.addClickListener((Button.ClickEvent e) -> {
        delete(getEmployee());
    });
    addBtn = new Button("Add Employee", FontAwesome.PLUS_SQUARE);
    addBtn.addStyleName("add-btn");
    addBtn.addClickListener((Button.ClickEvent e) -> {
        clear();
    });

    final HorizontalLayout buttonLayout = new HorizontalLayout(saveBtn, deleteBtn);
    buttonLayout.setSpacing(true);

    final FormLayout formLayout = new FormLayout();
    formLayout.setSizeUndefined();
    formLayout.setMargin(true);
    formLayout.setData(this);
    formLayout.addComponents(employeeId, firstName, lastName, phoneNumber, department, buttonLayout);
    setCompositionRoot(formLayout);

    setEmployee(new Employee());
    BeanFieldGroup.bindFieldsUnbuffered(employee, this);
}

From source file:management.limbr.ui.entity.EntityEditorViewImpl.java

License:Open Source License

@PostConstruct
public void init() {
    FormLayout content = new FormLayout();
    content.setWidthUndefined();//from ww  w. j a v  a  2s .  c  om

    for (java.lang.reflect.Field field : entityClass.getDeclaredFields()) {
        if ("id".equals(field.getName())) {
            continue;
        }
        Field uiField = getUIField(field);
        fieldMap.put(field.getName(), uiField);
        content.addComponent(uiField);
    }

    save = new Button(messages.get("saveButtonLabel"), FontAwesome.SAVE);
    Button cancel = new Button(messages.get("cancelButtonLabel"));
    delete = new Button(messages.get("deleteButtonLabel"), FontAwesome.TRASH_O);

    CssLayout actions = new CssLayout(save, cancel, delete);
    content.addComponent(actions);

    content.setMargin(true);
    setContent(content);
    setClosable(true);
    setResizable(false);
    setModal(true);

    save.addClickListener(event -> listeners.forEach(EntityEditorView.Listener::save));
    delete.addClickListener(event -> listeners.forEach(EntityEditorView.Listener::deleteClicked));
    cancel.addClickListener(event -> listeners.forEach(EntityEditorView.Listener::cancel));
}

From source file:my.vaadin.profile.Forms.java

public Forms() {
    setSpacing(true);//from   w  w  w.  ja v a2 s  .  co  m
    setMargin(true);

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

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

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

    TextField zID = new TextField("zID");
    zID.setValue("z123456");
    zID.setRequired(true);
    form.addComponent(zID);

    TextField name = new TextField("Name");
    name.setValue("loreum");
    //name.setWidth("50%");
    form.addComponent(name);

    PasswordField pw = new PasswordField("Set Password");
    pw.setRequired(true);
    form.addComponent(pw);

    DateField birthday = new DateField("Birthday");
    birthday.setDateFormat("dd-MM-yyyy");
    birthday.setValue(new java.util.Date());
    form.addComponent(birthday);

    OptionGroup gender = new OptionGroup("Gender");
    gender.addItem("Male");
    gender.addItem("Female");
    //sex.select("Male");
    gender.addStyleName("horizontal");
    form.addComponent(gender);

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

    TextField classID = new TextField("Class ID");
    classID.setValue("INFS2605");
    classID.setRequired(true);
    //classID.setWidth("50%");
    form.addComponent(classID);

    TextField groupID = new TextField("Group ID");
    groupID.setValue("1");
    //groupID.setWidth("50%");
    groupID.setRequired(true);
    form.addComponent(groupID);

    Button confirm = new Button("Confirm");
    confirm.addStyleName("primary");
    form.addComponent(confirm);

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

}