use of com.vaadin.data.util.DefaultItemSorter in project esup-ecandidat by EsupPortail.
the class PieceJustifViewTemplate method init.
/**
* Initialise la vue
*/
@PostConstruct
public void init() {
/* Style */
setSizeFull();
setMargin(true);
setSpacing(true);
/* Titre */
titleParam.addStyleName(StyleConstants.VIEW_TITLE);
addComponent(titleParam);
/* Boutons */
buttonsLayout.setWidth(100, Unit.PERCENTAGE);
buttonsLayout.setSpacing(true);
addComponent(buttonsLayout);
btnNew.setCaption(applicationContext.getMessage("pieceJustif.btnNouveau", null, UI.getCurrent().getLocale()));
btnNew.setEnabled(true);
buttonsLayout.addComponent(btnNew);
buttonsLayout.setComponentAlignment(btnNew, Alignment.MIDDLE_LEFT);
btnEdit.setCaption(applicationContext.getMessage("btnEdit", null, UI.getCurrent().getLocale()));
btnEdit.setEnabled(false);
btnEdit.addClickListener(e -> {
if (pieceJustifTable.getValue() instanceof PieceJustif) {
pieceJustifController.editPieceJustif((PieceJustif) pieceJustifTable.getValue());
}
});
buttonsLayout.addComponent(btnEdit);
buttonsLayout.setComponentAlignment(btnEdit, Alignment.MIDDLE_CENTER);
OneClickButton btnDelete = new OneClickButton(applicationContext.getMessage("btnDelete", null, UI.getCurrent().getLocale()), FontAwesome.TRASH_O);
btnDelete.setEnabled(false);
btnDelete.addClickListener(e -> {
if (pieceJustifTable.getValue() instanceof PieceJustif) {
pieceJustifController.deletePieceJustif((PieceJustif) pieceJustifTable.getValue());
}
});
buttonsLayout.addComponent(btnDelete);
buttonsLayout.setComponentAlignment(btnDelete, Alignment.MIDDLE_RIGHT);
/* Table des pieceJustifs */
pieceJustifTable.addBooleanColumn(PieceJustif_.tesPj.getName());
pieceJustifTable.addBooleanColumn(PieceJustif_.temCommunPj.getName());
pieceJustifTable.addBooleanColumn(PieceJustif_.temUnicitePj.getName());
pieceJustifTable.addBooleanColumn(PieceJustif_.temConditionnelPj.getName());
/* Type de traitement */
pieceJustifTable.addGeneratedColumn(PieceJustif_.typeTraitement.getName(), new ColumnGenerator() {
@Override
public Object generateCell(final Table source, final Object itemId, final Object columnId) {
final PieceJustif pieceJustif = (PieceJustif) itemId;
if (pieceJustif.getTypeTraitement() != null) {
return pieceJustif.getTypeTraitement().getLibTypTrait();
} else {
return applicationContext.getMessage("typeTraitement.lib.all", null, UI.getCurrent().getLocale());
}
}
});
if (!fileController.getModeDematBackoffice().equals(ConstanteUtils.TYPE_FICHIER_STOCK_NONE)) {
pieceJustifTable.addGeneratedColumn(PieceJustif_.fichier.getName(), new ColumnGenerator() {
@Override
public Object generateCell(final Table source, final Object itemId, final Object columnId) {
final PieceJustif pieceJustif = (PieceJustif) itemId;
if (pieceJustif.getFichier() == null) {
if (isVisuPjCommunMode && !isReadOnly) {
OneClickButton btnAdd = new OneClickButton(FontAwesome.PLUS);
btnAdd.addStyleName(StyleConstants.ON_DEMAND_FILE_LAYOUT);
btnAdd.setDescription(applicationContext.getMessage("file.btnAdd", null, UI.getCurrent().getLocale()));
btnAdd.addClickListener(e -> pieceJustifController.addFileToPieceJustificative(pieceJustif));
return btnAdd;
}
return null;
} else {
OnDemandFileLayout fileLayout = new OnDemandFileLayout(pieceJustif.getFichier().getNomFichier());
/* Delete */
if (isVisuPjCommunMode && !isReadOnly) {
fileLayout.addBtnDelClickListener(e -> pieceJustifController.deleteFileToPieceJustificative(pieceJustif));
}
/* Viewer si JPG */
if (MethodUtils.isImgFileName(pieceJustif.getFichier().getNomFichier())) {
fileLayout.addBtnViewerClickListener(e -> {
OnDemandFile file = new OnDemandFile(pieceJustif.getFichier().getNomFichier(), fileController.getInputStreamFromFichier(pieceJustif.getFichier()));
ImageViewerWindow iv = new ImageViewerWindow(file, null);
UI.getCurrent().addWindow(iv);
});
/* Opener si PDF */
} else if (MethodUtils.isPdfFileName(pieceJustif.getFichier().getNomFichier())) {
fileLayout.addBtnViewerPdfBrowserOpener(new OnDemandStreamFile() {
@Override
public OnDemandFile getOnDemandFile() {
return new OnDemandFile(pieceJustif.getFichier().getNomFichier(), fileController.getInputStreamFromFichier(pieceJustif.getFichier()));
}
});
}
/* Download */
fileLayout.addBtnDownloadFileDownloader(new OnDemandStreamFile() {
@Override
public OnDemandFile getOnDemandFile() {
return new OnDemandFile(pieceJustif.getFichier().getNomFichier(), fileController.getInputStreamFromFichier(pieceJustif.getFichier()));
}
});
return fileLayout;
}
}
});
FIELDS_ORDER = FIELDS_ORDER_FILE;
} else {
FIELDS_ORDER = FIELDS_ORDER_NO_FILE;
}
pieceJustifTable.setSizeFull();
pieceJustifTable.setVisibleColumns((Object[]) FIELDS_ORDER);
for (String fieldName : FIELDS_ORDER) {
pieceJustifTable.setColumnHeader(fieldName, applicationContext.getMessage("pieceJustif.table." + fieldName, null, UI.getCurrent().getLocale()));
}
container.setItemSorter(new DefaultItemSorter() {
@Override
public int compare(final Object itemId1, final Object itemId2) {
return ((PieceJustif) itemId1).compareTo((PieceJustif) itemId2);
}
});
pieceJustifTable.addHeaderClickListener(e -> {
container.setItemSorter(new DefaultItemSorter());
isOrderEnable = false;
});
pieceJustifTable.setColumnCollapsingAllowed(true);
pieceJustifTable.setColumnReorderingAllowed(true);
pieceJustifTable.setSelectable(true);
pieceJustifTable.setImmediate(true);
pieceJustifTable.setColumnWidth(PieceJustif_.orderPj.getName(), 60);
pieceJustifTable.addItemSetChangeListener(e -> pieceJustifTable.sanitizeSelection());
pieceJustifTable.addValueChangeListener(e -> {
/*
* Les boutons d'édition et de suppression de pieceJustif sont actifs seulement
* si une pieceJustif est sélectionnée.
*/
boolean pieceJustifIsSelected = pieceJustifTable.getValue() instanceof PieceJustif;
btnEdit.setEnabled(pieceJustifIsSelected);
btnDelete.setEnabled(pieceJustifIsSelected);
});
addComponent(pieceJustifTable);
setExpandRatio(pieceJustifTable, 1);
}
Aggregations