Example usage for com.vaadin.ui.themes ValoTheme FORMLAYOUT_LIGHT

List of usage examples for com.vaadin.ui.themes ValoTheme FORMLAYOUT_LIGHT

Introduction

In this page you can find the example usage for com.vaadin.ui.themes ValoTheme FORMLAYOUT_LIGHT.

Prototype

String FORMLAYOUT_LIGHT

To view the source code for com.vaadin.ui.themes ValoTheme FORMLAYOUT_LIGHT.

Click Source Link

Document

Removes the borders and background from any direct child field components (TextField, TextArea, DateField, ComboBox) in the layout.

Usage

From source file:dhbw.clippinggorilla.userinterface.windows.PreferencesWindow.java

private Component buildClippingsTab(User user) {
    HorizontalLayout root = new HorizontalLayout();
    root.setCaption(Language.get(Word.CLIPPINGS));
    root.setIcon(VaadinIcons.NEWSPAPER);
    root.setWidth("100%");
    root.setSpacing(true);//from w w w . j a  v  a  2  s . co  m
    root.setMargin(true);

    FormLayout formLayoutClippingDetails = new FormLayout();
    formLayoutClippingDetails.addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    root.addComponent(formLayoutClippingDetails);

    CheckBox checkBoxReceiveEmails = new CheckBox();
    checkBoxReceiveEmails.setValue(UserUtils.getEmailNewsletter(user));
    checkBoxReceiveEmails.addValueChangeListener(v -> UserUtils.setEmailNewsletter(user, v.getValue()));
    HorizontalLayout layoutCheckBoxReceiveEmails = new HorizontalLayout(checkBoxReceiveEmails);
    layoutCheckBoxReceiveEmails.setCaption(Language.get(Word.EMAIL_SUBSCRIPTION));
    layoutCheckBoxReceiveEmails.setMargin(false);
    layoutCheckBoxReceiveEmails.setSpacing(false);

    HorizontalLayout layoutAddNewClippingTime = new HorizontalLayout();
    layoutAddNewClippingTime.setMargin(false);
    layoutAddNewClippingTime.setCaption(Language.get(Word.ADD_CLIPPING_TIME));
    layoutAddNewClippingTime.setWidth("100%");

    InlineDateTimeField dateFieldNewClippingTime = new InlineDateTimeField();
    LocalDateTime value = LocalDateTime.now(ZoneId.of("Europe/Berlin"));
    dateFieldNewClippingTime.setValue(value);
    dateFieldNewClippingTime.setLocale(VaadinSession.getCurrent().getLocale());
    dateFieldNewClippingTime.setResolution(DateTimeResolution.MINUTE);
    dateFieldNewClippingTime.addStyleName("time-only");

    Button buttonAddClippingTime = new Button();
    buttonAddClippingTime.setIcon(VaadinIcons.PLUS);
    buttonAddClippingTime.addStyleName(ValoTheme.BUTTON_PRIMARY);
    buttonAddClippingTime.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
    buttonAddClippingTime.addClickListener(e -> {
        LocalTime generalTime = dateFieldNewClippingTime.getValue().toLocalTime();
        layoutClippingTimes.addComponent(getTimeRow(user, generalTime));
        UserUtils.addClippingSendTime(user, generalTime);
    });
    layoutAddNewClippingTime.addComponents(dateFieldNewClippingTime, buttonAddClippingTime);
    layoutAddNewClippingTime.setComponentAlignment(dateFieldNewClippingTime, Alignment.MIDDLE_LEFT);
    layoutAddNewClippingTime.setComponentAlignment(buttonAddClippingTime, Alignment.MIDDLE_CENTER);
    layoutAddNewClippingTime.setExpandRatio(dateFieldNewClippingTime, 5);

    layoutClippingTimes = new VerticalLayout();
    layoutClippingTimes.setMargin(new MarginInfo(true, false, false, true));
    layoutClippingTimes.setCaption(Language.get(Word.CLIPPING_TIMES));
    layoutClippingTimes.setWidth("100%");
    layoutClippingTimes.addStyleName("times");

    Set<LocalTime> userTimes = user.getClippingTime();
    userTimes.forEach(t -> layoutClippingTimes.addComponent(getTimeRow(user, t)));

    formLayoutClippingDetails.addComponents(layoutCheckBoxReceiveEmails, layoutAddNewClippingTime,
            layoutClippingTimes);

    return root;
}

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  ww w  .j  a  v a2s .  c o  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:management.limbr.ui.login.LogInViewImpl.java

License:Open Source License

@PostConstruct
public void init() {
    setSizeFull();//from w w w.j  a  v  a  2 s .  co  m

    usernameField = new TextField(messages.get("usernameFieldLabel"));
    usernameField.setWidth(20.0f, Unit.EM);
    usernameField.setRequired(true);
    usernameField.setInputPrompt(messages.get("usernameFieldPrompt"));
    usernameField
            .addValidator(new StringLengthValidator(messages.get("usernameFieldValidation"), 3, 256, false));
    usernameField.setImmediate(true);
    usernameField.setInvalidAllowed(false);

    passwordField = new PasswordField(messages.get("passwordFieldLabel"));
    passwordField.setWidth(20.0f, Unit.EM);
    passwordField.setInputPrompt(messages.get("passwordFieldPrompt"));
    passwordField
            .addValidator(new StringLengthValidator(messages.get("passwordFieldValidation"), 8, 256, false));
    passwordField.setImmediate(true);
    passwordField.setRequired(true);
    passwordField.setNullRepresentation("");

    Button logInButton = new Button(messages.get("logInButtonLabel"));
    logInButton.addClickListener(event -> {
        usernameField.setValidationVisible(false);
        passwordField.setValidationVisible(false);
        try {
            usernameField.commit();
            passwordField.commit();
        } catch (Validator.InvalidValueException e) {
            Notification.show(e.getMessage());
            usernameField.setValidationVisible(true);
            passwordField.setValidationVisible(true);
            LOG.debug("Validation of log in fields failed.", e);
        }
        listeners.forEach(LogInViewListener::logInClicked);
    });

    VerticalLayout fields = new VerticalLayout(usernameField, passwordField, logInButton);
    fields.setCaption(messages.get("logInCaption", LimbrApplication.getApplicationName()));
    fields.setSpacing(true);
    fields.setMargin(new MarginInfo(true, true, true, false));
    fields.setSizeUndefined();

    VerticalLayout mainLayout = new VerticalLayout(fields);
    mainLayout.setSizeFull();
    mainLayout.setComponentAlignment(fields, Alignment.MIDDLE_CENTER);
    mainLayout.setStyleName(ValoTheme.FORMLAYOUT_LIGHT);

    setCompositionRoot(mainLayout);

    listeners.forEach(listener -> listener.viewInitialized(this));
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.admin.AdminScreenProvider.java

License:Apache License

private Component displaySetting(VmSetting s, boolean edit) {
    Panel form = new Panel(TRANSLATOR.translate("setting.detail"));
    FormLayout layout = new FormLayout();
    form.setContent(layout);/*www .  j a  va2s  .c  o m*/
    form.addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    BeanFieldGroup binder = new BeanFieldGroup(s.getClass());
    binder.setItemDataSource(s);
    Field<?> id = (TextField) binder.buildAndBind(TRANSLATOR.translate("general.setting"), "setting");
    layout.addComponent(id);
    Field bool = binder.buildAndBind(TRANSLATOR.translate("bool.value"), "boolVal");
    bool.setSizeFull();
    layout.addComponent(bool);
    Field integerVal = binder.buildAndBind(TRANSLATOR.translate("int.value"), "intVal");
    integerVal.setSizeFull();
    layout.addComponent(integerVal);
    Field longVal = binder.buildAndBind(TRANSLATOR.translate("long.val"), "longVal");
    longVal.setSizeFull();
    layout.addComponent(longVal);
    Field stringVal = binder.buildAndBind(TRANSLATOR.translate("string.val"), "stringVal", TextArea.class);
    stringVal.setSizeFull();
    layout.addComponent(stringVal);
    Button cancel = new Button(TRANSLATOR.translate("general.cancel"));
    cancel.addClickListener((Button.ClickEvent event) -> {
        binder.discard();
    });
    //Editing existing one
    Button update = new Button(TRANSLATOR.translate("general.update"));
    update.addClickListener((Button.ClickEvent event) -> {
        try {
            binder.commit();
            displaySetting(s);
        } catch (FieldGroup.CommitException ex) {
            LOG.log(Level.SEVERE, null, ex);
            Notification.show(TRANSLATOR.translate("general.error.record.update"), ex.getLocalizedMessage(),
                    Notification.Type.ERROR_MESSAGE);
        }
    });
    boolean blocked = !s.getSetting().startsWith("version.");
    if (blocked) {
        HorizontalLayout hl = new HorizontalLayout();
        hl.addComponent(update);
        hl.addComponent(cancel);
        layout.addComponent(hl);
    }
    binder.setBuffered(true);
    binder.setReadOnly(edit);
    binder.bindMemberFields(form);
    //The version settigns are not modifiable from the GUI
    binder.setEnabled(blocked);
    //Id is always blocked.
    id.setEnabled(false);
    form.setSizeFull();
    return form;
}

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

License:Apache License

public BaselineComponent(Baseline baseline, boolean edit, RequirementSpec rs) {
    super(TRANSLATOR.translate("baseline.detail"));
    FormLayout layout = new FormLayout();
    setContent(layout);/*from   w w  w.j av a  2 s . c  o  m*/
    addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    BeanFieldGroup binder = new BeanFieldGroup(baseline.getClass());
    binder.setItemDataSource(baseline);
    Field<?> id = binder.buildAndBind(TRANSLATOR.translate("general.name"), "baselineName");
    layout.addComponent(id);
    Field desc = binder.buildAndBind(TRANSLATOR.translate("general.description"), "description",
            TextArea.class);
    desc.setSizeFull();
    layout.addComponent(desc);
    Button cancel = new Button(TRANSLATOR.translate("general.cancel"));
    if (rs != null) {
        List<History> potential = new ArrayList<>();
        Tool.extractRequirements(rs).forEach((r) -> {
            potential.add(r.getHistoryList().get(r.getHistoryList().size() - 1));
        });
        layout.addComponent(((ValidationManagerUI) UI.getCurrent())
                .createRequirementHistoryTable(TRANSLATOR.translate("included.requirements"), potential, true));
    } else {
        layout.addComponent(((ValidationManagerUI) UI.getCurrent()).createRequirementHistoryTable(
                TRANSLATOR.translate("included.requirements"), baseline.getHistoryList(), true));
    }
    cancel.addClickListener((Button.ClickEvent event) -> {
        binder.discard();
        ((ValidationManagerUI) UI.getCurrent())
                .displayObject(((ValidationManagerUI) UI.getCurrent()).getTree().getValue());
    });
    if (edit) {
        if (baseline.getId() == null) {
            //Creating a new one
            Button save = new Button(TRANSLATOR.translate("general.save"));
            save.addClickListener((Button.ClickEvent event) -> {
                try {
                    binder.commit();
                    if (rs != null) {
                        MessageBox prompt = MessageBox.createQuestion()
                                .withCaption(TRANSLATOR.translate("save.baseline.title"))
                                .withMessage(TRANSLATOR.translate("save.baseine.message")
                                        + "requirements will be released to a new major version")
                                .withYesButton(() -> {
                                    Baseline entity = BaselineServer.createBaseline(baseline.getBaselineName(),
                                            baseline.getDescription(), rs).getEntity();
                                    ((ValidationManagerUI) UI.getCurrent()).updateProjectList();
                                    ((ValidationManagerUI) UI.getCurrent()).buildProjectTree(entity);
                                    ((ValidationManagerUI) UI.getCurrent()).displayObject(entity, false);
                                    ((ValidationManagerUI) UI.getCurrent()).updateScreen();
                                }, ButtonOption.focus(), ButtonOption.icon(VaadinIcons.CHECK))
                                .withNoButton(() -> {
                                    ((ValidationManagerUI) UI.getCurrent()).displayObject(
                                            ((ValidationManagerUI) UI.getCurrent()).getTree().getValue());
                                }, ButtonOption.icon(VaadinIcons.CLOSE));
                        prompt.getWindow().setIcon(ValidationManagerUI.SMALL_APP_ICON);
                        prompt.open();
                    } else {
                        //Recreate the tree to show the addition
                        ((ValidationManagerUI) UI.getCurrent()).displayObject(baseline, true);
                    }
                    ((ValidationManagerUI) UI.getCurrent()).updateProjectList();
                    ((ValidationManagerUI) UI.getCurrent()).updateScreen();
                } catch (FieldGroup.CommitException ex) {
                    LOG.log(Level.SEVERE, null, ex);
                }
            });
            HorizontalLayout hl = new HorizontalLayout();
            hl.addComponent(save);
            hl.addComponent(cancel);
            layout.addComponent(hl);
        } else {
            //Editing existing one
            Button update = new Button(TRANSLATOR.translate("general.update"));
            update.addClickListener((Button.ClickEvent event) -> {
                try {
                    ((ValidationManagerUI) UI.getCurrent()).handleVersioning(baseline, () -> {
                        try {
                            new BaselineJpaController(DataBaseManager.getEntityManagerFactory()).edit(baseline);
                            //Recreate the tree to show the addition
                            ((ValidationManagerUI) UI.getCurrent()).buildProjectTree(baseline);
                            ((ValidationManagerUI) UI.getCurrent()).displayBaseline(baseline, false);
                        } catch (NonexistentEntityException ex) {
                            LOG.log(Level.SEVERE, null, ex);
                            Notification.show(TRANSLATOR.translate("general.error.record.update"),
                                    ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE);
                        } catch (Exception ex) {
                            LOG.log(Level.SEVERE, null, ex);
                            Notification.show(TRANSLATOR.translate("general.error.record.update"),
                                    ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE);
                        }
                    });
                } catch (Exception ex) {
                    LOG.log(Level.SEVERE, null, ex);
                    Notification.show(TRANSLATOR.translate("general.error.record.update"),
                            ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE);
                }
            });
            HorizontalLayout hl = new HorizontalLayout();
            hl.addComponent(update);
            hl.addComponent(cancel);
            layout.addComponent(hl);
        }
    }
    binder.setBuffered(true);
    binder.setReadOnly(!edit);
    binder.bindMemberFields(this);
    setSizeFull();
}

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

License:Apache License

private void init() {
    FormLayout layout = new FormLayout();
    setContent(layout);//w w  w  . j av a  2s . c  om
    addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    BeanFieldGroup binder = new BeanFieldGroup(es.getClass());
    binder.setItemDataSource(es);
    FieldGroupFieldFactory defaultFactory = binder.getFieldFactory();
    binder.setFieldFactory(new FieldGroupFieldFactory() {

        @Override
        public <T extends Field> T createField(Class<?> dataType, Class<T> fieldType) {
            if (dataType.isAssignableFrom(VmUser.class)) {
                BeanItemContainer<VmUser> userEntityContainer = new BeanItemContainer<>(VmUser.class);
                userEntityContainer.addBean(es.getAssignee());
                Field field = new TextField(
                        es.getAssignee() == null ? TRANSLATOR.translate("general.not.applicable")
                                : es.getAssignee().getFirstName() + " " + es.getAssignee().getLastName());
                return fieldType.cast(field);
            }

            return defaultFactory.createField(dataType, fieldType);
        }
    });
    layout.addComponent(((VMUI) UI.getCurrent()).createStepHistoryTable(TRANSLATOR.translate("step.detail"),
            Arrays.asList(es.getStepHistory()), false));
    if (es.getResultId() != null) {
        Field<?> result = binder.buildAndBind(TRANSLATOR.translate("general.result"), "resultId.resultName");
        layout.addComponent(result);
    }
    if (es.getComment() != null) {
        TextArea comment = new TextArea(TRANSLATOR.translate("general.comment"));
        binder.bind(comment, "comment");
        layout.addComponent(comment);
    }
    if (es.getAssignee() != null) {
        TextField assignee = new TextField(TRANSLATOR.translate("general.assignee"));
        VmUser u = es.getAssignee();
        assignee.setValue(u.toString());
        assignee.setReadOnly(true);
        layout.addComponent(assignee);
    }
    if (es.getExecutionStart() != null) {
        Field<?> start = binder.buildAndBind(TRANSLATOR.translate("execution.start"), "executionStart");
        layout.addComponent(start);
    }
    if (es.getExecutionEnd() != null) {
        Field<?> end = binder.buildAndBind(TRANSLATOR.translate("execution.end"), "executionEnd");
        layout.addComponent(end);
    }
    if (es.getExecutionTime() != null && es.getExecutionTime() > 0) {
        Field<?> time = binder.buildAndBind(TRANSLATOR.translate("execution.time"), "executionTime");
        layout.addComponent(time);
    }
    if (!es.getHistoryList().isEmpty()) {
        layout.addComponent(((VMUI) UI.getCurrent()).createRequirementHistoryTable(
                TRANSLATOR.translate("related.requirements"), es.getHistoryList(), true));
    }
    Button cancel = new Button(TRANSLATOR.translate("general.cancel"));
    cancel.addClickListener((Button.ClickEvent event) -> {
        binder.discard();
        if (es.getExecutionStepPK() == null) {
            ((VMUI) UI.getCurrent()).displayObject(((VMUI) UI.getCurrent()).getSelectdValue());
        } else {
            ((VMUI) UI.getCurrent()).displayObject(es, false);
        }
    });
    binder.setReadOnly(true);
    binder.bindMemberFields(this);
    layout.setSizeFull();
    setSizeFull();
}

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

License:Apache License

private void init() {
    FormLayout layout = new FormLayout();
    setContent(layout);//from w w w  .  jav  a 2s . c o m
    addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    BeanFieldGroup binder = new BeanFieldGroup(ir.getClass());
    binder.setItemDataSource(ir);
    Field<?> name = binder.buildAndBind(TRANSLATOR.translate("general.name"), "name");
    layout.addComponent(name);
    if (edit) {
        Button update = new Button(ir.getId() == null ? TRANSLATOR.translate("general.create")
                : TRANSLATOR.translate("general.update"));
        update.addClickListener((Button.ClickEvent event) -> {
            IssueResolutionJpaController c = new IssueResolutionJpaController(
                    DataBaseManager.getEntityManagerFactory());
            if (ir.getId() == null) {
                ir.setName((String) name.getValue());
                c.create(ir);
            } else {
                try {
                    binder.commit();
                } catch (FieldGroup.CommitException ex) {
                    LOG.log(Level.SEVERE, null, ex);
                }
            }
        });
        Button cancel = new Button(
                Lookup.getDefault().lookup(InternationalizationProvider.class).translate("general.cancel"));
        cancel.addClickListener((Button.ClickEvent event) -> {
            binder.discard();
            ((VMUI) UI.getCurrent()).updateScreen();
        });
        binder.setReadOnly(!edit);
        binder.setBuffered(true);
        HorizontalLayout hl = new HorizontalLayout();
        hl.addComponent(update);
        hl.addComponent(cancel);
        layout.addComponent(hl);
    }
}

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

License:Apache License

private void init() {
    FormLayout layout = new FormLayout();
    setContent(layout);//from   ww w .ja v  a 2s  .  co m
    addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    BeanFieldGroup binder = new BeanFieldGroup(it.getClass());
    binder.setItemDataSource(it);
    Field<?> name = binder.buildAndBind(TRANSLATOR.translate("general.name"), "typeName");
    layout.addComponent(name);
    Field<?> desc = binder.buildAndBind(TRANSLATOR.translate("general.description"), "description");
    layout.addComponent(desc);
    if (edit) {
        Button update = new Button(it.getId() == null ? TRANSLATOR.translate("general.create")
                : TRANSLATOR.translate("general.update"));
        update.addClickListener((Button.ClickEvent event) -> {
            IssueTypeJpaController c = new IssueTypeJpaController(DataBaseManager.getEntityManagerFactory());
            if (it.getId() == null) {
                it.setDescription((String) desc.getValue());
                it.setTypeName((String) name.getValue());
                c.create(it);
            } else {
                try {
                    binder.commit();
                } catch (FieldGroup.CommitException ex) {
                    LOG.log(Level.SEVERE, null, ex);
                }
            }
        });
        Button cancel = new Button(
                Lookup.getDefault().lookup(InternationalizationProvider.class).translate("general.cancel"));
        cancel.addClickListener((Button.ClickEvent event) -> {
            binder.discard();
            ((VMUI) UI.getCurrent()).updateScreen();
        });
        binder.setReadOnly(!edit);
        binder.setBuffered(true);
        HorizontalLayout hl = new HorizontalLayout();
        hl.addComponent(update);
        hl.addComponent(cancel);
        layout.addComponent(hl);
    }
}

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

License:Apache License

private void init() {
    addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    type = new ComboBox(TRANSLATOR.translate("general.type"));
    FormLayout layout = new FormLayout();
    setContent(layout);/*  ww w  .jav a 2 s  .  c  om*/
    BeanFieldGroup binder = new BeanFieldGroup(getProject().getClass());
    binder.setItemDataSource(getProject());
    name = (TextField) binder.buildAndBind(TRANSLATOR.translate("general.name"), "name", TextField.class);
    name.setNullRepresentation("");
    notes = (TextArea) binder.buildAndBind(TRANSLATOR.translate("general.notes"), "notes", TextArea.class);
    getNotes().setNullRepresentation("");
    getNotes().setSizeFull();
    getName().setRequired(true);
    getName().setRequiredError(TRANSLATOR.translate("missing.name.message"));
    layout.addComponent(getName());
    layout.addComponent(getNotes());
    type.setNewItemsAllowed(false);
    type.setTextInputAllowed(false);
    type.addValidator(new NullValidator(TRANSLATOR.translate("message.required.field.missing").replaceAll("%f",
            TRANSLATOR.translate("general.type")), false));
    BeanItemContainer<ProjectType> container = new BeanItemContainer<>(ProjectType.class,
            new ProjectTypeJpaController(DataBaseManager.getEntityManagerFactory()).findProjectTypeEntities());
    type.setContainerDataSource(container);
    type.getItemIds().forEach(id -> {
        ProjectType temp = ((ProjectType) id);
        type.setItemCaption(id, TRANSLATOR.translate(temp.getTypeName()));
    });
    layout.addComponent(type);
    binder.bind(type, "projectTypeId");
    Button cancel = new Button(TRANSLATOR.translate("general.cancel"));
    cancel.addClickListener((Button.ClickEvent event) -> {
        binder.discard();
        if (getProject().getId() == null) {
            ((VMUI) UI.getCurrent()).displayObject(((VMUI) UI.getCurrent()).getSelectdValue());
        } else {
            ((VMUI) UI.getCurrent()).displayObject(getProject(), false);
        }
    });
    if (edit) {
        if (getProject().getId() == null) {
            //Creating a new one
            getSave().addClickListener((Button.ClickEvent event) -> {
                if (getName().getValue() == null) {
                    Notification.show(getName().getRequiredError(), Notification.Type.ERROR_MESSAGE);
                    return;
                }
                getProject().setName(getName().getValue());
                if (getNotes().getValue() != null) {
                    getProject().setNotes(getNotes().getValue());
                }
                if (type.getValue() == null) {
                    Notification.show(type.getRequiredError(), Notification.Type.ERROR_MESSAGE);
                    return;
                }
                getProject().setProjectTypeId((ProjectType) type.getValue());
                new ProjectJpaController(DataBaseManager.getEntityManagerFactory()).create(getProject());
                //Recreate the tree to show the addition
                ((VMUI) UI.getCurrent()).updateProjectList();
                ((VMUI) UI.getCurrent()).buildProjectTree(getProject());
                ((VMUI) UI.getCurrent()).displayObject(getProject(), false);
                ((VMUI) UI.getCurrent()).updateScreen();
            });
            HorizontalLayout hl = new HorizontalLayout();
            hl.addComponent(getSave());
            hl.addComponent(cancel);
            layout.addComponent(hl);
        } else {
            //Editing existing one
            getUpdate().addClickListener((Button.ClickEvent event) -> {
                ((VMUI) UI.getCurrent()).handleVersioning(getProject(), null);
                try {
                    getProject().setName(getName().getValue());
                    if (getNotes().getValue() != null) {
                        getProject().setNotes(getNotes().getValue());
                    }
                    if (type.getValue() == null) {
                        Notification.show(type.getRequiredError(), Notification.Type.ERROR_MESSAGE);
                        return;
                    }
                    getProject().setProjectTypeId((ProjectType) type.getValue());
                    new ProjectJpaController(DataBaseManager.getEntityManagerFactory()).edit(getProject());
                } catch (NonexistentEntityException ex) {
                    LOG.log(Level.SEVERE, null, ex);
                    Notification.show(TRANSLATOR.translate("general.error.record.update"),
                            ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE);
                } catch (Exception ex) {
                    LOG.log(Level.SEVERE, null, ex);
                    Notification.show(TRANSLATOR.translate("general.error.record.update"),
                            ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE);
                }
                //Recreate the tree to show the addition
                ((VMUI) UI.getCurrent()).updateProjectList();
                ((VMUI) UI.getCurrent()).buildProjectTree(getProject());
                ((VMUI) UI.getCurrent()).displayObject(getProject(), false);
                ((VMUI) UI.getCurrent()).updateScreen();
            });
            HorizontalLayout hl = new HorizontalLayout();
            hl.addComponent(getUpdate());
            hl.addComponent(cancel);
            layout.addComponent(hl);
        }
    }
    binder.setBuffered(true);
    binder.setReadOnly(!edit);
    binder.bindMemberFields(this);
    setSizeFull();
}

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

License:Apache License

private void init() {
    FormLayout layout = new FormLayout();
    setContent(layout);//from  w w w. j a v a  2  s.  c om
    addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    BeanFieldGroup binder = new BeanFieldGroup(req.getClass());
    binder.setItemDataSource(req);
    TextField id = (TextField) binder.buildAndBind(TRANSLATOR.translate("requirement.id"), "uniqueId",
            TextField.class);
    id.setNullRepresentation("");
    layout.addComponent(id);
    TextArea desc = (TextArea) binder.buildAndBind(TRANSLATOR.translate("general.description"), "description",
            TextArea.class);
    desc.setNullRepresentation("");
    desc.setSizeFull();
    layout.addComponent(desc);
    TextArea notes = (TextArea) binder.buildAndBind(TRANSLATOR.translate("general.notes"), "notes",
            TextArea.class);
    notes.setNullRepresentation("");
    notes.setSizeFull();
    layout.addComponent(notes);
    if (req.getParentRequirementId() != null) {
        TextField tf = new TextField(TRANSLATOR.translate("general.parent"));
        tf.setValue(req.getParentRequirementId().getUniqueId());
        tf.setReadOnly(true);
        layout.addComponent(tf);
    }
    if (req.getRequirementList() == null) {
        req.setRequirementList(new ArrayList<>());
    }
    if (!req.getRequirementList().isEmpty() && !edit) {
        layout.addComponent(((VMUI) UI.getCurrent()).getDisplayRequirementList(
                TRANSLATOR.translate("related.requirements"), req.getRequirementList()));
    } else if (edit) {
        //Allow user to add children
        AbstractSelect as = ((VMUI) UI.getCurrent()).getRequirementSelectionComponent();
        req.getRequirementList().forEach(sub -> {
            as.select(sub);
        });
        as.addValueChangeListener(event -> {
            Set<Requirement> selected = (Set<Requirement>) event.getProperty().getValue();
            req.getRequirementList().clear();
            selected.forEach(r -> {
                req.getRequirementList().add(r);
            });
        });
        layout.addComponent(as);
    }
    Button cancel = new Button(TRANSLATOR.translate("general.cancel"));
    cancel.addClickListener((Button.ClickEvent event) -> {
        binder.discard();
        if (req.getId() == null) {
            ((VMUI) UI.getCurrent()).displayObject(req.getRequirementSpecNode());
        } else {
            ((VMUI) UI.getCurrent()).displayObject(req, false);
        }
    });
    if (edit) {
        if (req.getId() == null) {
            //Creating a new one
            Button save = new Button(TRANSLATOR.translate("general.save"));
            save.addClickListener((Button.ClickEvent event) -> {
                req.setUniqueId(id.getValue().toString());
                req.setNotes(notes.getValue().toString());
                req.setDescription(desc.getValue().toString());
                req.setRequirementSpecNode((RequirementSpecNode) ((VMUI) UI.getCurrent()).getSelectdValue());
                new RequirementJpaController(DataBaseManager.getEntityManagerFactory()).create(req);
                setVisible(false);
                //Recreate the tree to show the addition
                ((VMUI) UI.getCurrent()).buildProjectTree(req);
                ((VMUI) UI.getCurrent()).displayObject(req, true);
            });
            HorizontalLayout hl = new HorizontalLayout();
            hl.addComponent(save);
            hl.addComponent(cancel);
            layout.addComponent(hl);
        } else {
            //Editing existing one
            Button update = new Button(TRANSLATOR.translate("general.update"));
            update.addClickListener((Button.ClickEvent event) -> {
                try {
                    RequirementServer rs = new RequirementServer(req);
                    rs.setDescription(((TextArea) desc).getValue());
                    rs.setNotes(((TextArea) notes).getValue());
                    rs.setUniqueId(((TextField) id).getValue());
                    ((VMUI) UI.getCurrent()).handleVersioning(rs, () -> {
                        try {
                            rs.write2DB();
                            //Recreate the tree to show the addition
                            ((VMUI) UI.getCurrent()).buildProjectTree(rs.getEntity());
                            ((VMUI) UI.getCurrent()).displayObject(rs.getEntity(), false);
                        } catch (NonexistentEntityException ex) {
                            LOG.log(Level.SEVERE, null, ex);
                            Notification.show(TRANSLATOR.translate("general.error.record.update"),
                                    ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE);
                        } catch (Exception ex) {
                            LOG.log(Level.SEVERE, null, ex);
                            Notification.show(TRANSLATOR.translate("general.error.record.update"),
                                    ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE);
                        }
                    });
                    setVisible(false);
                } catch (VMException ex) {
                    LOG.log(Level.SEVERE, null, ex);
                    Notification.show(TRANSLATOR.translate("general.error.record.update"),
                            ex.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE);
                }
            });
            HorizontalLayout hl = new HorizontalLayout();
            hl.addComponent(update);
            hl.addComponent(cancel);
            layout.addComponent(hl);
        }
    }
    try {
        //Add a history section
        if (req.getId() != null) {
            List<History> versions = new RequirementServer(req).getHistoryList();
            if (!versions.isEmpty()) {
                layout.addComponent(((VMUI) UI.getCurrent()).createRequirementHistoryTable(
                        TRANSLATOR.translate("general.history"), versions, true));
            }
        }
    } catch (VMException ex) {
        LOG.log(Level.SEVERE, null, ex);
    }
    binder.setBuffered(true);
    binder.setReadOnly(!edit);
    binder.bindMemberFields(this);
    setSizeFull();
}