Search in sources :

Example 1 with HeaderRow

use of com.vaadin.ui.Grid.HeaderRow in project esup-ecandidat by EsupPortail.

the class StatViewTemplate method init.

/**
 * Initialise le template
 *
 * @param title
 * @param code
 * @param libelle
 */
public void init(final String title, final String code, final String libelle, final String libelleHs) {
    /* Style */
    setSizeFull();
    setMargin(true);
    setSpacing(true);
    /* Titre */
    Label titleParam = new Label(title);
    titleParam.addStyleName(StyleConstants.VIEW_TITLE);
    addComponent(titleParam);
    /* Boutons */
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setWidth(100, Unit.PERCENTAGE);
    buttonsLayout.setSpacing(true);
    addComponent(buttonsLayout);
    /* Choix de campagne */
    HorizontalLayout campagneLayout = new HorizontalLayout();
    campagneLayout.setWidth(100, Unit.PERCENTAGE);
    campagneLayout.setSpacing(true);
    buttonsLayout.addComponent(campagneLayout);
    /* Label campagne */
    Label labelCampagne = new Label(applicationContext.getMessage("stat.change.camp", null, UI.getCurrent().getLocale()));
    labelCampagne.setSizeUndefined();
    campagneLayout.addComponent(labelCampagne);
    campagneLayout.setComponentAlignment(labelCampagne, Alignment.MIDDLE_LEFT);
    /* ListeBox campagne */
    List<Campagne> listeCampagne = campagneController.getCampagnes();
    listeCampagne.sort(Comparator.comparing(Campagne::getCodCamp).reversed());
    cbCampagne = new RequiredComboBox<>(listeCampagne, Campagne.class);
    cbCampagne.setValue(campagneController.getCampagneActive());
    campagneLayout.addComponent(cbCampagne);
    campagneLayout.setExpandRatio(cbCampagne, 1);
    campagneLayout.setComponentAlignment(cbCampagne, Alignment.BOTTOM_LEFT);
    cbCampagne.addValueChangeListener(e -> {
        majContainer();
    });
    cbDisplayHs.setCaption(libelleHs);
    campagneLayout.addComponent(cbDisplayHs);
    campagneLayout.setComponentAlignment(cbDisplayHs, Alignment.MIDDLE_LEFT);
    cbDisplayHs.addValueChangeListener(e -> {
        majContainer();
    });
    /* Export des candidatures désactivé */
    /*
		 * OneClickButton btnExportCandidature = new
		 * OneClickButton(applicationContext.getMessage("stat.export.candidature.btn",
		 * null, UI.getCurrent().getLocale()), FontAwesome.FILE_EXCEL_O);
		 * btnExportCandidature.setDescription(applicationContext.getMessage(
		 * "stat.export.candidature.btn", null, UI.getCurrent().getLocale()));
		 * btnExportCandidature.addClickListener(e->{ CtrCandExportWindow window = new
		 * CtrCandExportWindow(securityCtrCandFonc.getCtrCand());
		 * UI.getCurrent().addWindow(window); });
		 */
    /* La grid */
    grid = new GridFormatting<>(StatFormationPresentation.class);
    grid.initColumn(new String[] { StatFormationPresentation.CHAMPS_COD, StatFormationPresentation.CHAMPS_LIB, StatFormationPresentation.CHAMPS_LIB_SUPP, StatFormationPresentation.CHAMPS_NB_CANDIDATURE_TOTAL, StatFormationPresentation.CHAMPS_NB_CANDIDATURE_CANCEL, StatFormationPresentation.CHAMPS_NB_STATUT_ATTENTE, StatFormationPresentation.CHAMPS_NB_STATUT_RECEPTIONNE, StatFormationPresentation.CHAMPS_NB_STATUT_COMPLET, StatFormationPresentation.CHAMPS_NB_STATUT_INCOMPLET, StatFormationPresentation.CHAMPS_NB_AVIS_FAVORABLE, StatFormationPresentation.CHAMPS_NB_AVIS_DEFAVORABLE, StatFormationPresentation.CHAMPS_NB_AVIS_LISTECOMP, StatFormationPresentation.CHAMPS_NB_AVIS_LISTEATTENTE, StatFormationPresentation.CHAMPS_NB_AVIS_PRESELECTION, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL_VALIDE, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL_NON_VALIDE, StatFormationPresentation.CHAMPS_NB_CONFIRM, StatFormationPresentation.CHAMPS_NB_DESIST, StatFormationPresentation.CHAMPS_CAPACITE_ACCUEIL }, "stat.table.", StatFormationPresentation.CHAMPS_LIB);
    grid.setSizeFull();
    grid.setFrozenColumnCount(2);
    grid.setSelectionMode(SelectionMode.NONE);
    /* Largeur des colonnes */
    grid.setColumnWidth(StatFormationPresentation.CHAMPS_COD, 150);
    grid.setColumnsWidth(300, StatFormationPresentation.CHAMPS_LIB, StatFormationPresentation.CHAMPS_LIB_SUPP);
    grid.setColumnsWidth(115, StatFormationPresentation.CHAMPS_NB_CANDIDATURE_TOTAL, StatFormationPresentation.CHAMPS_NB_CANDIDATURE_CANCEL, StatFormationPresentation.CHAMPS_NB_STATUT_ATTENTE, StatFormationPresentation.CHAMPS_NB_STATUT_RECEPTIONNE, StatFormationPresentation.CHAMPS_NB_STATUT_COMPLET, StatFormationPresentation.CHAMPS_NB_STATUT_INCOMPLET, StatFormationPresentation.CHAMPS_NB_AVIS_FAVORABLE, StatFormationPresentation.CHAMPS_NB_AVIS_DEFAVORABLE, StatFormationPresentation.CHAMPS_NB_AVIS_LISTECOMP, StatFormationPresentation.CHAMPS_NB_AVIS_LISTEATTENTE, StatFormationPresentation.CHAMPS_NB_AVIS_PRESELECTION, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL_VALIDE, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL_NON_VALIDE, StatFormationPresentation.CHAMPS_NB_CONFIRM, StatFormationPresentation.CHAMPS_NB_DESIST);
    grid.removeFilterCells(StatFormationPresentation.CHAMPS_NB_CANDIDATURE_TOTAL, StatFormationPresentation.CHAMPS_NB_CANDIDATURE_CANCEL, StatFormationPresentation.CHAMPS_NB_STATUT_ATTENTE, StatFormationPresentation.CHAMPS_NB_STATUT_RECEPTIONNE, StatFormationPresentation.CHAMPS_NB_STATUT_COMPLET, StatFormationPresentation.CHAMPS_NB_STATUT_INCOMPLET, StatFormationPresentation.CHAMPS_NB_AVIS_FAVORABLE, StatFormationPresentation.CHAMPS_NB_AVIS_DEFAVORABLE, StatFormationPresentation.CHAMPS_NB_AVIS_LISTECOMP, StatFormationPresentation.CHAMPS_NB_AVIS_LISTEATTENTE, StatFormationPresentation.CHAMPS_NB_AVIS_PRESELECTION, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL_VALIDE, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL_NON_VALIDE, StatFormationPresentation.CHAMPS_NB_CONFIRM, StatFormationPresentation.CHAMPS_NB_DESIST);
    /* Header */
    HeaderRow headerRow = grid.prependHeaderRow();
    headerRow.setStyleName(ValoTheme.TEXTFIELD_ALIGN_CENTER);
    headerRow.join(StatFormationPresentation.CHAMPS_COD, StatFormationPresentation.CHAMPS_LIB).setText("");
    headerRow.join(StatFormationPresentation.CHAMPS_NB_CANDIDATURE_TOTAL, StatFormationPresentation.CHAMPS_NB_CANDIDATURE_CANCEL).setText(applicationContext.getMessage("stat.table.header.join.nbCandidature", null, UI.getCurrent().getLocale()));
    headerRow.join(StatFormationPresentation.CHAMPS_NB_STATUT_ATTENTE, StatFormationPresentation.CHAMPS_NB_STATUT_RECEPTIONNE, StatFormationPresentation.CHAMPS_NB_STATUT_COMPLET, StatFormationPresentation.CHAMPS_NB_STATUT_INCOMPLET).setText(applicationContext.getMessage("stat.table.header.join.statut", null, UI.getCurrent().getLocale()));
    headerRow.join(StatFormationPresentation.CHAMPS_NB_AVIS_FAVORABLE, StatFormationPresentation.CHAMPS_NB_AVIS_DEFAVORABLE, StatFormationPresentation.CHAMPS_NB_AVIS_LISTECOMP, StatFormationPresentation.CHAMPS_NB_AVIS_LISTEATTENTE, StatFormationPresentation.CHAMPS_NB_AVIS_PRESELECTION).setText(applicationContext.getMessage("stat.table.header.join.avis", null, UI.getCurrent().getLocale()));
    headerRow.join(StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL_VALIDE, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL_NON_VALIDE).setText(applicationContext.getMessage("stat.table.header.join.avis.total", null, UI.getCurrent().getLocale()));
    headerRow.join(StatFormationPresentation.CHAMPS_NB_CONFIRM, StatFormationPresentation.CHAMPS_NB_DESIST).setText(applicationContext.getMessage("stat.table.header.join.confirm", null, UI.getCurrent().getLocale()));
    addComponent(grid);
    setExpandRatio(grid, 1);
    /* Ajout des totaux dans le footer */
    footerRow = grid.prependFooterRow();
    footerRow.setStyleName(StyleConstants.GRID_FOOTER);
    FooterCell cellTxt = footerRow.join(StatFormationPresentation.CHAMPS_COD, StatFormationPresentation.CHAMPS_LIB);
    cellTxt.setText(applicationContext.getMessage("stat.table.footer.join.sum", null, UI.getCurrent().getLocale()));
    cellTxt.setStyleName(StyleConstants.GRID_FOOTER_TITLE);
    grid.addFilterListener(new FilterListener() {

        @Override
        public void filter() {
            updateFooter();
        }
    });
    grid.setRowStyleGenerator(new RowStyleGenerator() {

        @Override
        public String getStyle(final RowReference row) {
            StatFormationPresentation pres = (StatFormationPresentation) row.getItemId();
            if (!pres.getTes()) {
                return StyleConstants.GRID_ROW_STAT_HS;
            }
            return null;
        }
    });
    /* Export */
    Button btnExport = new Button(applicationContext.getMessage("btnExport", null, UI.getCurrent().getLocale()), FontAwesome.FILE_EXCEL_O);
    btnExport.setDescription(applicationContext.getMessage("btnExport", null, UI.getCurrent().getLocale()));
    buttonsLayout.addComponent(btnExport);
    buttonsLayout.setComponentAlignment(btnExport, Alignment.MIDDLE_RIGHT);
    btnExport.setDisableOnClick(true);
    new OnDemandFileDownloader(new OnDemandStreamFile() {

        @Override
        public OnDemandFile getOnDemandFile() {
            OnDemandFile file = statController.generateExport(getCampagne(), code, libelle, grid.getItems(), footerStat, getLibelleExport(), getLibelleSuppExport(), getDisplayCapaciteAccueil());
            if (file != null) {
                btnExport.setEnabled(true);
                return file;
            }
            btnExport.setEnabled(true);
            return null;
        }
    }, btnExport);
}
Also used : OnDemandStreamFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileUtils.OnDemandStreamFile) OnDemandFileDownloader(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileDownloader) Label(com.vaadin.ui.Label) StatFormationPresentation(fr.univlorraine.ecandidat.utils.bean.presentation.StatFormationPresentation) OnDemandFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFile) FooterCell(com.vaadin.ui.Grid.FooterCell) HorizontalLayout(com.vaadin.ui.HorizontalLayout) RowReference(com.vaadin.ui.Grid.RowReference) FilterListener(fr.univlorraine.ecandidat.vaadin.components.GridFormatting.FilterListener) Button(com.vaadin.ui.Button) HeaderRow(com.vaadin.ui.Grid.HeaderRow) RowStyleGenerator(com.vaadin.ui.Grid.RowStyleGenerator) Campagne(fr.univlorraine.ecandidat.entities.ecandidat.Campagne)

Aggregations

Button (com.vaadin.ui.Button)1 FooterCell (com.vaadin.ui.Grid.FooterCell)1 HeaderRow (com.vaadin.ui.Grid.HeaderRow)1 RowReference (com.vaadin.ui.Grid.RowReference)1 RowStyleGenerator (com.vaadin.ui.Grid.RowStyleGenerator)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Label (com.vaadin.ui.Label)1 Campagne (fr.univlorraine.ecandidat.entities.ecandidat.Campagne)1 StatFormationPresentation (fr.univlorraine.ecandidat.utils.bean.presentation.StatFormationPresentation)1 FilterListener (fr.univlorraine.ecandidat.vaadin.components.GridFormatting.FilterListener)1 OnDemandFile (fr.univlorraine.ecandidat.vaadin.components.OnDemandFile)1 OnDemandFileDownloader (fr.univlorraine.ecandidat.vaadin.components.OnDemandFileDownloader)1 OnDemandStreamFile (fr.univlorraine.ecandidat.vaadin.components.OnDemandFileUtils.OnDemandStreamFile)1