Search in sources :

Example 1 with CellDescriptionGenerator

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

the class CtrCandFormationView method init.

/**
 * Initialise la vue
 */
@PostConstruct
public void init() {
    /* Style */
    setSizeFull();
    setMargin(true);
    setSpacing(true);
    /* Récupération du centre de canidature en cours */
    securityCtrCandFonc = userController.getCtrCandFonctionnalite(NomenclatureUtils.FONCTIONNALITE_GEST_FORMATION);
    if (securityCtrCandFonc.hasNoRight()) {
        return;
    }
    /* Titre */
    HorizontalLayout hlTitle = new HorizontalLayout();
    hlTitle.setSpacing(true);
    addComponent(hlTitle);
    Label titleParam = new Label(applicationContext.getMessage("formation.title", new Object[] { securityCtrCandFonc.getCtrCand().getLibCtrCand() }, UI.getCurrent().getLocale()));
    titleParam.addStyleName(StyleConstants.VIEW_TITLE);
    hlTitle.addComponent(titleParam);
    PopupView puv = new PopupView(applicationContext.getMessage("formation.table.flagEtat.tooltip", null, UI.getCurrent().getLocale()), getLegendLayout());
    hlTitle.addComponent(puv);
    hlTitle.setComponentAlignment(puv, Alignment.MIDDLE_LEFT);
    /* Boutons */
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setWidth(100, Unit.PERCENTAGE);
    buttonsLayout.setSpacing(true);
    addComponent(buttonsLayout);
    /* Nouvelle formation */
    OneClickButton btnNew = new OneClickButton(applicationContext.getMessage("formation.btnNouveau", null, UI.getCurrent().getLocale()), FontAwesome.PLUS);
    btnNew.setEnabled(true);
    btnNew.addClickListener(e -> {
        formationController.editNewFormation(securityCtrCandFonc);
    });
    buttonsLayout.addComponent(btnNew);
    buttonsLayout.setComponentAlignment(btnNew, Alignment.MIDDLE_LEFT);
    /* Edition de formation */
    OneClickButton btnEdit = new OneClickButton(applicationContext.getMessage("btnEdit", null, UI.getCurrent().getLocale()), FontAwesome.PENCIL);
    btnEdit.setEnabled(false);
    btnEdit.addClickListener(e -> {
        Formation f = getFormation();
        if (f instanceof Formation) {
            formationController.editFormation(f, securityCtrCandFonc);
        }
    });
    buttonsLayout.addComponent(btnEdit);
    buttonsLayout.setComponentAlignment(btnEdit, Alignment.MIDDLE_CENTER);
    /* Edition de dates */
    // 
    OneClickButton btnEditDate = new OneClickButton(applicationContext.getMessage("formation.btnEditDate", null, UI.getCurrent().getLocale()), FontAwesome.CALENDAR);
    btnEditDate.setDescription(applicationContext.getMessage("formation.btnEditDate.desc", null, UI.getCurrent().getLocale()));
    btnEditDate.setEnabled(false);
    btnEditDate.addClickListener(e -> {
        formationController.editDates(getFormations(), securityCtrCandFonc.getCtrCand());
    });
    buttonsLayout.addComponent(btnEditDate);
    buttonsLayout.setComponentAlignment(btnEditDate, Alignment.MIDDLE_CENTER);
    /* Edition des pièces */
    OneClickButton btnEditPieceComp = new OneClickButton(applicationContext.getMessage("formation.btnEditPiece", null, UI.getCurrent().getLocale()), FontAwesome.FILE_TEXT_O);
    btnEditPieceComp.setEnabled(false);
    btnEditPieceComp.addClickListener(e -> {
        formationController.editPieceCompFormation(getFormations(), securityCtrCandFonc.getCtrCand());
    });
    buttonsLayout.addComponent(btnEditPieceComp);
    buttonsLayout.setComponentAlignment(btnEditPieceComp, Alignment.MIDDLE_CENTER);
    /* Suppression formation */
    OneClickButton btnDelete = new OneClickButton(applicationContext.getMessage("btnDelete", null, UI.getCurrent().getLocale()), FontAwesome.TRASH_O);
    btnDelete.setEnabled(false);
    btnDelete.addClickListener(e -> {
        Formation f = getFormation();
        if (f instanceof Formation) {
            formationController.deleteFormation(f);
        }
    });
    buttonsLayout.addComponent(btnDelete);
    buttonsLayout.setComponentAlignment(btnDelete, Alignment.MIDDLE_RIGHT);
    OneClickButton btnExport = new OneClickButton(FontAwesome.FILE_EXCEL_O);
    /* Export de la liste des formations */
    btnExport.setDescription(applicationContext.getMessage("btnExport", null, UI.getCurrent().getLocale()));
    btnExport.setDisableOnClick(true);
    new OnDemandFileDownloader(new OnDemandStreamFile() {

        @Override
        public OnDemandFile getOnDemandFile() {
            @SuppressWarnings("unchecked") List<Formation> listeForm = (List<Formation>) formationGrid.getContainerDataSource().getItemIds();
            if (listeForm.size() == 0) {
                btnExport.setEnabled(true);
                return null;
            }
            /* Téléchargement */
            OnDemandFile file = formationController.generateExport(listeForm, securityCtrCandFonc);
            if (file != null) {
                btnExport.setEnabled(true);
                return file;
            }
            btnExport.setEnabled(true);
            return null;
        }
    }, btnExport);
    buttonsLayout.addComponent(btnExport);
    buttonsLayout.setComponentAlignment(btnExport, Alignment.MIDDLE_RIGHT);
    /* Table des formations */
    formationGrid.initColumn(FIELDS_ORDER, "formation.table.", Formation_.codForm.getName());
    formationGrid.setSelectionMode(SelectionMode.MULTI);
    formationGrid.addItems(formationController.getFormationsByCtrCand(securityCtrCandFonc));
    formationGrid.getColumn(Formation.FLAG_COLUMN_NAME).setRenderer(new ImageRenderer(), new StringToThemeRessourceConverter());
    formationGrid.setCellDescriptionGenerator(new CellDescriptionGenerator() {

        @Override
        public String getDescription(final CellReference cell) {
            Formation f = (Formation) cell.getItemId();
            if (cell.getPropertyId().equals(Formation.FLAG_COLUMN_NAME)) {
                try {
                    String code = null;
                    if (cell.getPropertyId().equals(Formation.FLAG_COLUMN_NAME)) {
                        code = f.getFlagEtat();
                        if (code != null) {
                            return applicationContext.getMessage("formation.table.flagEtat.tooltip." + code, null, UI.getCurrent().getLocale());
                        }
                    }
                } catch (Exception e) {
                }
            }
            return null;
        }
    });
    formationGrid.removeFilterCells(Formation.FLAG_COLUMN_NAME);
    formationGrid.setColumnsWidth(62, Formation.FLAG_COLUMN_NAME);
    formationGrid.setColumnsWidth(130, Formation_.codForm.getName());
    formationGrid.setColumnsWidth(143, Formation_.temDematForm.getName());
    formationGrid.setColumnsWidth(100, Formation_.tesForm.getName());
    formationGrid.setColumnsWidth(200, Formation.DAT_VOEUX_COLUMN_NAME);
    formationGrid.setColumnsWidth(260, Formation_.commission.getName() + "." + Commission_.libComm.getName());
    formationGrid.addSelectionListener(e -> {
        /*
			 * Les boutons d'édition et de suppression de formation sont actifs seulement si
			 * une formation est sélectionnée.
			 */
        Integer nb = formationGrid.getSelectedRows().size();
        btnEdit.setEnabled(nb == 1);
        btnDelete.setEnabled(nb == 1);
        btnEditPieceComp.setEnabled(nb >= 1);
        btnEditDate.setEnabled(nb >= 1);
    });
    formationGrid.addItemClickListener(e -> {
        /* Suivant le mode de slection de la grid on fait un traitement */
        MultiSelectionModel selection = (MultiSelectionModel) formationGrid.getSelectionModel();
        selection.deselectAll();
        try {
            selection.select(e.getItemId());
        } catch (Exception e1) {
            return;
        }
    });
    addComponent(formationGrid);
    setExpandRatio(formationGrid, 1);
    formationGrid.setSizeFull();
    /* Gestion du readOnly */
    if (securityCtrCandFonc.isWrite()) {
        formationGrid.addItemClickListener(e -> {
            if (e.isDoubleClick()) {
                formationGrid.select(e.getItemId());
                btnEdit.click();
            }
        });
        buttonsLayout.setVisible(true);
    } else {
        buttonsLayout.setVisible(false);
    }
    /* Inscrit la vue aux mises à jour de formation */
    formationEntityPusher.registerEntityPushListener(this);
}
Also used : OnDemandStreamFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileUtils.OnDemandStreamFile) OneClickButton(fr.univlorraine.ecandidat.vaadin.components.OneClickButton) OnDemandFileDownloader(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileDownloader) MultiSelectionModel(com.vaadin.ui.Grid.MultiSelectionModel) Label(com.vaadin.ui.Label) PopupView(com.vaadin.ui.PopupView) OnDemandFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFile) StringToThemeRessourceConverter(fr.univlorraine.ecandidat.vaadin.components.GridConverter.StringToThemeRessourceConverter) CellReference(com.vaadin.ui.Grid.CellReference) CellDescriptionGenerator(com.vaadin.ui.Grid.CellDescriptionGenerator) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ImageRenderer(com.vaadin.ui.renderers.ImageRenderer) List(java.util.List) Formation(fr.univlorraine.ecandidat.entities.ecandidat.Formation) PostConstruct(javax.annotation.PostConstruct)

Aggregations

CellDescriptionGenerator (com.vaadin.ui.Grid.CellDescriptionGenerator)1 CellReference (com.vaadin.ui.Grid.CellReference)1 MultiSelectionModel (com.vaadin.ui.Grid.MultiSelectionModel)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Label (com.vaadin.ui.Label)1 PopupView (com.vaadin.ui.PopupView)1 ImageRenderer (com.vaadin.ui.renderers.ImageRenderer)1 Formation (fr.univlorraine.ecandidat.entities.ecandidat.Formation)1 StringToThemeRessourceConverter (fr.univlorraine.ecandidat.vaadin.components.GridConverter.StringToThemeRessourceConverter)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 OneClickButton (fr.univlorraine.ecandidat.vaadin.components.OneClickButton)1 List (java.util.List)1 PostConstruct (javax.annotation.PostConstruct)1