Search in sources :

Example 1 with DefaultItemSorter

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);
}
Also used : OnDemandStreamFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileUtils.OnDemandStreamFile) VerticalLayout(com.vaadin.ui.VerticalLayout) PieceJustif(fr.univlorraine.ecandidat.entities.ecandidat.PieceJustif) Alignment(com.vaadin.ui.Alignment) UI(com.vaadin.ui.UI) OnDemandFileLayout(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileLayout) PieceJustif_(fr.univlorraine.ecandidat.entities.ecandidat.PieceJustif_) FontAwesome(com.vaadin.server.FontAwesome) Label(com.vaadin.ui.Label) ColumnGenerator(com.vaadin.ui.Table.ColumnGenerator) I18nController(fr.univlorraine.ecandidat.controllers.I18nController) ConstanteUtils(fr.univlorraine.ecandidat.utils.ConstanteUtils) DefaultItemSorter(com.vaadin.data.util.DefaultItemSorter) MethodUtils(fr.univlorraine.ecandidat.utils.MethodUtils) Resource(javax.annotation.Resource) StyleConstants(fr.univlorraine.ecandidat.StyleConstants) FileController(fr.univlorraine.ecandidat.controllers.FileController) ApplicationContext(org.springframework.context.ApplicationContext) PieceJustifController(fr.univlorraine.ecandidat.controllers.PieceJustifController) BeanItemContainer(com.vaadin.data.util.BeanItemContainer) ImageViewerWindow(fr.univlorraine.ecandidat.views.windows.ImageViewerWindow) Table(com.vaadin.ui.Table) HorizontalLayout(com.vaadin.ui.HorizontalLayout) OnDemandFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFile) PostConstruct(javax.annotation.PostConstruct) TableFormating(fr.univlorraine.ecandidat.vaadin.components.TableFormating) OneClickButton(fr.univlorraine.ecandidat.vaadin.components.OneClickButton) OnDemandStreamFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileUtils.OnDemandStreamFile) Table(com.vaadin.ui.Table) DefaultItemSorter(com.vaadin.data.util.DefaultItemSorter) OneClickButton(fr.univlorraine.ecandidat.vaadin.components.OneClickButton) OnDemandFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFile) ImageViewerWindow(fr.univlorraine.ecandidat.views.windows.ImageViewerWindow) ColumnGenerator(com.vaadin.ui.Table.ColumnGenerator) PieceJustif(fr.univlorraine.ecandidat.entities.ecandidat.PieceJustif) OnDemandFileLayout(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileLayout) PostConstruct(javax.annotation.PostConstruct)

Aggregations

BeanItemContainer (com.vaadin.data.util.BeanItemContainer)1 DefaultItemSorter (com.vaadin.data.util.DefaultItemSorter)1 FontAwesome (com.vaadin.server.FontAwesome)1 Alignment (com.vaadin.ui.Alignment)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Label (com.vaadin.ui.Label)1 Table (com.vaadin.ui.Table)1 ColumnGenerator (com.vaadin.ui.Table.ColumnGenerator)1 UI (com.vaadin.ui.UI)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 StyleConstants (fr.univlorraine.ecandidat.StyleConstants)1 FileController (fr.univlorraine.ecandidat.controllers.FileController)1 I18nController (fr.univlorraine.ecandidat.controllers.I18nController)1 PieceJustifController (fr.univlorraine.ecandidat.controllers.PieceJustifController)1 PieceJustif (fr.univlorraine.ecandidat.entities.ecandidat.PieceJustif)1 PieceJustif_ (fr.univlorraine.ecandidat.entities.ecandidat.PieceJustif_)1 ConstanteUtils (fr.univlorraine.ecandidat.utils.ConstanteUtils)1 MethodUtils (fr.univlorraine.ecandidat.utils.MethodUtils)1 OnDemandFile (fr.univlorraine.ecandidat.vaadin.components.OnDemandFile)1 OnDemandFileLayout (fr.univlorraine.ecandidat.vaadin.components.OnDemandFileLayout)1