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);
}
Aggregations