Search in sources :

Example 1 with OnDemandFileLayout

use of fr.univlorraine.ecandidat.vaadin.components.OnDemandFileLayout 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)

Example 2 with OnDemandFileLayout

use of fr.univlorraine.ecandidat.vaadin.components.OnDemandFileLayout in project esup-ecandidat by EsupPortail.

the class CtrCandCommissionView 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_COMMISSION);
    if (securityCtrCandFonc.hasNoRight()) {
        return;
    }
    /* Table des centres de candidatures */
    VerticalLayout commissionLayout = new VerticalLayout();
    commissionLayout.setSizeFull();
    commissionLayout.setSpacing(true);
    /* Titre */
    Label titleParam = new Label(applicationContext.getMessage("commission.title", new Object[] { securityCtrCandFonc.getCtrCand().getLibCtrCand() }, UI.getCurrent().getLocale()));
    titleParam.addStyleName(StyleConstants.VIEW_TITLE);
    commissionLayout.addComponent(titleParam);
    /* Boutons */
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setWidth(100, Unit.PERCENTAGE);
    buttonsLayout.setSpacing(true);
    commissionLayout.addComponent(buttonsLayout);
    OneClickButton btnNew = new OneClickButton(applicationContext.getMessage("commission.btnNouveau", null, UI.getCurrent().getLocale()), FontAwesome.PLUS);
    btnNew.setEnabled(true);
    btnNew.addClickListener(e -> {
        commissionController.editNewCommission(securityCtrCandFonc.getCtrCand());
    });
    buttonsLayout.addComponent(btnNew);
    buttonsLayout.setComponentAlignment(btnNew, Alignment.MIDDLE_LEFT);
    if (!securityCtrCandFonc.getIsGestAllCommission()) {
        btnNew.setEnabled(false);
        btnNew.setDescription(applicationContext.getMessage("commission.create.disable", null, UI.getCurrent().getLocale()));
    }
    OneClickButton btnEdit = new OneClickButton(applicationContext.getMessage("btnEdit", null, UI.getCurrent().getLocale()), FontAwesome.PENCIL);
    btnEdit.setEnabled(false);
    btnEdit.addClickListener(e -> {
        if (commissionTable.getValue() instanceof Commission) {
            commissionController.editCommission((Commission) commissionTable.getValue(), true);
        }
    });
    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 (commissionTable.getValue() instanceof Commission) {
            commissionController.deleteCommission((Commission) commissionTable.getValue());
        }
    });
    buttonsLayout.addComponent(btnDelete);
    buttonsLayout.setComponentAlignment(btnDelete, Alignment.MIDDLE_RIGHT);
    Button btnExport = new Button(applicationContext.getMessage("btnExport", null, UI.getCurrent().getLocale()), 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<Commission> listeCommission = (List<Commission>) commissionTable.getContainerDataSource().getItemIds();
            if (listeCommission.size() == 0) {
                btnExport.setEnabled(true);
                return null;
            }
            /* Téléchargement */
            OnDemandFile file = commissionController.generateExport(listeCommission, 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 commissions */
    BeanItemContainer<Commission> container = new BeanItemContainer<>(Commission.class, commissionController.getCommissionsByCtrCand(securityCtrCandFonc.getCtrCand(), securityCtrCandFonc.getIsGestAllCommission(), securityCtrCandFonc.getListeIdCommission()));
    commissionTable.setContainerDataSource(container);
    commissionTable.addBooleanColumn(Commission_.tesComm.getName());
    commissionTable.addBooleanColumn(Commission_.temEditLettreComm.getName());
    commissionTable.setSortContainerPropertyId(Commission_.codComm.getName());
    commissionTable.setColumnCollapsingAllowed(true);
    commissionTable.setColumnReorderingAllowed(true);
    commissionTable.setSelectable(true);
    commissionTable.setImmediate(true);
    commissionTable.addItemSetChangeListener(e -> commissionTable.sanitizeSelection());
    commissionTable.addValueChangeListener(e -> {
        /* Les boutons d'édition et de suppression de commission sont actifs seulement si une commission est sélectionnée. */
        boolean commissionIsSelected = commissionTable.getValue() instanceof Commission;
        btnEdit.setEnabled(commissionIsSelected);
        btnDelete.setEnabled(commissionIsSelected);
        btnNewMembre.setEnabled(commissionIsSelected);
        if (commissionIsSelected) {
            majMembreTable((Commission) commissionTable.getValue());
        } else {
            majMembreTable(null);
        }
    });
    if (!fileController.getModeDematBackoffice().equals(ConstanteUtils.TYPE_FICHIER_STOCK_NONE)) {
        commissionTable.addGeneratedColumn(PieceJustif_.fichier.getName(), new ColumnGenerator() {

            /**
             * serialVersionUID
             */
            private static final long serialVersionUID = -1750183076315269277L;

            @Override
            public Object generateCell(final Table source, final Object itemId, final Object columnId) {
                final Commission commission = (Commission) itemId;
                if (commission.getFichier() == null) {
                    if (securityCtrCandFonc.isWrite()) {
                        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 -> commissionController.addFileToSignataire(commission));
                        return btnAdd;
                    }
                    return null;
                } else {
                    OnDemandFileLayout fileLayout = new OnDemandFileLayout(commission.getFichier().getNomFichier());
                    /* Delete */
                    if (securityCtrCandFonc.isWrite()) {
                        fileLayout.addBtnDelClickListener(e -> commissionController.deleteFileToSignataire(commission));
                    }
                    /* Show */
                    fileLayout.addBtnViewerClickListener(e -> {
                        OnDemandFile file = new OnDemandFile(commission.getFichier().getNomFichier(), fileController.getInputStreamFromFichier(commission.getFichier()));
                        ImageViewerWindow iv = new ImageViewerWindow(file, applicationContext.getMessage("commission.signataire.warning", null, UI.getCurrent().getLocale()));
                        UI.getCurrent().addWindow(iv);
                    });
                    /* Download */
                    fileLayout.addBtnDownloadFileDownloader(new OnDemandStreamFile() {

                        @Override
                        public OnDemandFile getOnDemandFile() {
                            return new OnDemandFile(commission.getFichier().getNomFichier(), fileController.getInputStreamFromFichier(commission.getFichier()));
                        }
                    });
                    return fileLayout;
                }
            }
        });
        FIELDS_ORDER = FIELDS_ORDER_FILE;
    } else {
        FIELDS_ORDER = FIELDS_ORDER_NO_FILE;
    }
    commissionTable.setVisibleColumns((Object[]) FIELDS_ORDER);
    for (String fieldName : FIELDS_ORDER) {
        commissionTable.setColumnHeader(fieldName, applicationContext.getMessage("commission.table." + fieldName, null, UI.getCurrent().getLocale()));
    }
    commissionLayout.addComponent(commissionTable);
    commissionLayout.setExpandRatio(commissionTable, 1);
    commissionTable.setSizeFull();
    addComponent(commissionLayout);
    setExpandRatio(commissionLayout, 3);
    /* Commission Membre */
    VerticalLayout commissionMembreLayout = new VerticalLayout();
    commissionMembreLayout.setSizeFull();
    commissionMembreLayout.setSpacing(true);
    /* Titre */
    HorizontalLayout layoutMembreLabel = new HorizontalLayout();
    layoutMembreLabel.setSpacing(true);
    Label titleMembre = new Label(applicationContext.getMessage("commission.title.membre", null, UI.getCurrent().getLocale()));
    titleMembre.addStyleName(StyleConstants.VIEW_SUBTITLE);
    layoutMembreLabel.addComponent(titleMembre);
    layoutMembreLabel.setComponentAlignment(titleMembre, Alignment.BOTTOM_LEFT);
    labelMembre.setValue(applicationContext.getMessage("commission.membre.nocomm", null, UI.getCurrent().getLocale()));
    labelMembre.addStyleName(ValoTheme.LABEL_SMALL);
    layoutMembreLabel.addComponent(labelMembre);
    layoutMembreLabel.setComponentAlignment(labelMembre, Alignment.BOTTOM_LEFT);
    commissionMembreLayout.addComponent(layoutMembreLabel);
    /* Boutons */
    HorizontalLayout buttonsLayoutMembre = new HorizontalLayout();
    buttonsLayoutMembre.setWidth(100, Unit.PERCENTAGE);
    buttonsLayoutMembre.setSpacing(true);
    commissionMembreLayout.addComponent(buttonsLayoutMembre);
    btnNewMembre.setCaption(applicationContext.getMessage("droitprofilind.btnNouveauMembre", null, UI.getCurrent().getLocale()));
    btnNewMembre.setEnabled(false);
    btnNewMembre.addClickListener(e -> {
        commissionController.addProfilToMembre((Commission) commissionTable.getValue());
    });
    buttonsLayoutMembre.addComponent(btnNewMembre);
    buttonsLayoutMembre.setComponentAlignment(btnNewMembre, Alignment.MIDDLE_LEFT);
    /* Edit profil */
    OneClickButton btnEditMembre = new OneClickButton(applicationContext.getMessage("btnEdit", null, UI.getCurrent().getLocale()), FontAwesome.PENCIL);
    btnEditMembre.setEnabled(false);
    btnEditMembre.addClickListener(e -> {
        if (commissionMembreTable.getValue() instanceof CommissionMembre) {
            commissionController.updateProfilToMembre((CommissionMembre) commissionMembreTable.getValue());
        }
    });
    buttonsLayoutMembre.addComponent(btnEditMembre);
    buttonsLayoutMembre.setComponentAlignment(btnEditMembre, Alignment.MIDDLE_CENTER);
    /* Delete profil */
    OneClickButton btnDeleteMembre = new OneClickButton(applicationContext.getMessage("btnDelete", null, UI.getCurrent().getLocale()), FontAwesome.TRASH_O);
    btnDeleteMembre.setEnabled(false);
    btnDeleteMembre.addClickListener(e -> {
        if (commissionMembreTable.getValue() instanceof CommissionMembre) {
            commissionController.deleteProfilToMembre((CommissionMembre) commissionMembreTable.getValue());
        }
    });
    buttonsLayoutMembre.addComponent(btnDeleteMembre);
    buttonsLayoutMembre.setComponentAlignment(btnDeleteMembre, Alignment.MIDDLE_RIGHT);
    /* Table des CommissionMembre */
    BeanItemContainer<CommissionMembre> containerMembre = new BeanItemContainer<>(CommissionMembre.class);
    containerMembre.addNestedContainerProperty(CommissionMembre_.droitProfilInd.getName() + "." + DroitProfilInd_.individu.getName() + "." + Individu_.loginInd.getName());
    containerMembre.addNestedContainerProperty(CommissionMembre_.droitProfilInd.getName() + "." + DroitProfilInd_.individu.getName() + "." + Individu_.libelleInd.getName());
    containerMembre.addNestedContainerProperty(CommissionMembre_.droitProfilInd.getName() + "." + DroitProfilInd_.droitProfil.getName() + "." + DroitProfil_.libProfil.getName());
    commissionMembreTable.setContainerDataSource(containerMembre);
    commissionMembreTable.addBooleanColumn(CommissionMembre_.temIsPresident.getName());
    commissionMembreTable.setVisibleColumns((Object[]) FIELDS_ORDER_MEMBRE);
    for (String fieldName : FIELDS_ORDER_MEMBRE) {
        commissionMembreTable.setColumnHeader(fieldName, applicationContext.getMessage("droit." + fieldName, null, UI.getCurrent().getLocale()));
    }
    commissionMembreTable.setSortContainerPropertyId(CommissionMembre_.droitProfilInd.getName() + "." + DroitProfilInd_.individu.getName() + "." + Individu_.loginInd.getName());
    commissionMembreTable.setColumnCollapsingAllowed(true);
    commissionMembreTable.setColumnReorderingAllowed(true);
    commissionMembreTable.setSelectable(true);
    commissionMembreTable.setImmediate(true);
    commissionMembreTable.addItemSetChangeListener(e -> commissionMembreTable.sanitizeSelection());
    commissionMembreTable.addValueChangeListener(e -> {
        /* Les boutons d'édition et de suppression de commission sont actifs seulement si une commission est sélectionnée. */
        boolean membreIsSelected = commissionMembreTable.getValue() instanceof CommissionMembre;
        btnDeleteMembre.setEnabled(membreIsSelected);
        btnEditMembre.setEnabled(membreIsSelected);
    });
    commissionMembreLayout.addComponent(commissionMembreTable);
    commissionMembreLayout.setExpandRatio(commissionMembreTable, 1);
    commissionMembreTable.setSizeFull();
    addComponent(commissionMembreLayout);
    setExpandRatio(commissionMembreLayout, 2);
    /* Gestion du readOnly */
    if (securityCtrCandFonc.isWrite()) {
        commissionTable.addItemClickListener(e -> {
            if (e.isDoubleClick()) {
                commissionTable.select(e.getItemId());
                btnEdit.click();
            }
        });
        commissionMembreTable.addItemClickListener(e -> {
            if (e.isDoubleClick()) {
                commissionMembreTable.select(e.getItemId());
                btnEditMembre.click();
            }
        });
        buttonsLayout.setVisible(true);
        buttonsLayoutMembre.setVisible(true);
    } else {
        buttonsLayout.setVisible(false);
        buttonsLayoutMembre.setVisible(false);
    }
    /* Inscrit la vue aux mises à jour de commission */
    commissionEntityPusher.registerEntityPushListener(this);
}
Also used : OnDemandStreamFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileUtils.OnDemandStreamFile) CommissionController(fr.univlorraine.ecandidat.controllers.CommissionController) OnDemandStreamFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileUtils.OnDemandStreamFile) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) VerticalLayout(com.vaadin.ui.VerticalLayout) Alignment(com.vaadin.ui.Alignment) UI(com.vaadin.ui.UI) Commission_(fr.univlorraine.ecandidat.entities.ecandidat.Commission_) OnDemandFileLayout(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileLayout) PieceJustif_(fr.univlorraine.ecandidat.entities.ecandidat.PieceJustif_) DroitProfilInd_(fr.univlorraine.ecandidat.entities.ecandidat.DroitProfilInd_) FontAwesome(com.vaadin.server.FontAwesome) Individu_(fr.univlorraine.ecandidat.entities.ecandidat.Individu_) NomenclatureUtils(fr.univlorraine.ecandidat.utils.NomenclatureUtils) Label(com.vaadin.ui.Label) ViewChangeEvent(com.vaadin.navigator.ViewChangeListener.ViewChangeEvent) SpringView(com.vaadin.spring.annotation.SpringView) ValoTheme(com.vaadin.ui.themes.ValoTheme) OnDemandFileDownloader(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileDownloader) ColumnGenerator(com.vaadin.ui.Table.ColumnGenerator) ConstanteUtils(fr.univlorraine.ecandidat.utils.ConstanteUtils) SecurityCtrCandFonc(fr.univlorraine.ecandidat.services.security.SecurityCtrCandFonc) DroitProfil_(fr.univlorraine.ecandidat.entities.ecandidat.DroitProfil_) EntityPushListener(fr.univlorraine.tools.vaadin.EntityPushListener) Resource(javax.annotation.Resource) StyleConstants(fr.univlorraine.ecandidat.StyleConstants) FileController(fr.univlorraine.ecandidat.controllers.FileController) ApplicationContext(org.springframework.context.ApplicationContext) BeanItemContainer(com.vaadin.data.util.BeanItemContainer) Commission(fr.univlorraine.ecandidat.entities.ecandidat.Commission) ImageViewerWindow(fr.univlorraine.ecandidat.views.windows.ImageViewerWindow) List(java.util.List) Button(com.vaadin.ui.Button) Table(com.vaadin.ui.Table) CommissionMembre_(fr.univlorraine.ecandidat.entities.ecandidat.CommissionMembre_) HorizontalLayout(com.vaadin.ui.HorizontalLayout) OnDemandFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFile) PostConstruct(javax.annotation.PostConstruct) TableFormating(fr.univlorraine.ecandidat.vaadin.components.TableFormating) CommissionMembre(fr.univlorraine.ecandidat.entities.ecandidat.CommissionMembre) UserController(fr.univlorraine.ecandidat.controllers.UserController) EntityPusher(fr.univlorraine.tools.vaadin.EntityPusher) View(com.vaadin.navigator.View) OneClickButton(fr.univlorraine.ecandidat.vaadin.components.OneClickButton) DroitProfilController(fr.univlorraine.ecandidat.controllers.DroitProfilController) Table(com.vaadin.ui.Table) CommissionMembre(fr.univlorraine.ecandidat.entities.ecandidat.CommissionMembre) OneClickButton(fr.univlorraine.ecandidat.vaadin.components.OneClickButton) OnDemandFileDownloader(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileDownloader) Label(com.vaadin.ui.Label) Commission(fr.univlorraine.ecandidat.entities.ecandidat.Commission) BeanItemContainer(com.vaadin.data.util.BeanItemContainer) OnDemandFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFile) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ImageViewerWindow(fr.univlorraine.ecandidat.views.windows.ImageViewerWindow) ColumnGenerator(com.vaadin.ui.Table.ColumnGenerator) Button(com.vaadin.ui.Button) OneClickButton(fr.univlorraine.ecandidat.vaadin.components.OneClickButton) VerticalLayout(com.vaadin.ui.VerticalLayout) List(java.util.List) OnDemandFileLayout(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileLayout) PostConstruct(javax.annotation.PostConstruct)

Example 3 with OnDemandFileLayout

use of fr.univlorraine.ecandidat.vaadin.components.OnDemandFileLayout in project esup-ecandidat by EsupPortail.

the class CandidatAdminView method init.

/**
 * Initialise la vue
 */
@PostConstruct
public void init() {
    isSiScolApo = parametreController.getSiScolMode().equals(ConstanteUtils.SI_SCOL_APOGEE);
    isSiScolApoPJ = parametreController.getSiScolMode().equals(ConstanteUtils.SI_SCOL_APOGEE) && candidatPieceController.isWsPJEnable();
    setSizeFull();
    setMargin(true);
    setSpacing(true);
    globalLayout.setSizeFull();
    globalLayout.setSpacing(true);
    addComponent(globalLayout);
    addComponent(errorLabel);
    /* Titre */
    title.addStyleName(StyleConstants.VIEW_TITLE);
    globalLayout.addComponent(title);
    /* Lock */
    lockLabel.addStyleName(ValoTheme.LABEL_FAILURE);
    lockLabel.setVisible(false);
    globalLayout.addComponent(lockLabel);
    /* Layout pour le compte */
    VerticalLayout cptMinLayout = new VerticalLayout();
    cptMinLayout.setSizeFull();
    cptMinLayout.setSpacing(true);
    /* Layout de controle */
    controlLayout.setWidth(100, Unit.PERCENTAGE);
    controlLayout.setSpacing(true);
    cptMinLayout.addComponent(controlLayout);
    /* Boutons candidat */
    buttonsLayout.setWidth(100, Unit.PERCENTAGE);
    buttonsLayout.setSpacing(true);
    controlLayout.addComponent(buttonsLayout);
    controlLayout.setExpandRatio(buttonsLayout, 1);
    OneClickButton btnEdit = new OneClickButton(applicationContext.getMessage("btnEdit", null, UI.getCurrent().getLocale()), FontAwesome.PENCIL);
    btnEdit.addClickListener(e -> {
        candidatController.editAdminCptMin(cptMin, this);
    });
    buttonsLayout.addComponent(btnEdit);
    buttonsLayout.setComponentAlignment(btnEdit, Alignment.MIDDLE_LEFT);
    if (isSiScolApo) {
        Button btnSyncApogee = new Button(applicationContext.getMessage("btnSyncApo", null, UI.getCurrent().getLocale()), FontAwesome.REFRESH);
        btnSyncApogee.setDisableOnClick(true);
        btnSyncApogee.addClickListener(e -> {
            candidatController.synchronizeCandidat(cptMin, this);
            btnSyncApogee.setEnabled(true);
        });
        buttonsLayout.addComponent(btnSyncApogee);
        buttonsLayout.setComponentAlignment(btnSyncApogee, Alignment.MIDDLE_CENTER);
    }
    OneClickButton btnDelete = new OneClickButton(applicationContext.getMessage("btnDelete", null, UI.getCurrent().getLocale()), FontAwesome.TRASH_O);
    btnDelete.addClickListener(e -> {
        candidatController.deleteCandidat(cptMin, this);
    });
    buttonsLayout.addComponent(btnDelete);
    buttonsLayout.setComponentAlignment(btnDelete, Alignment.MIDDLE_RIGHT);
    btnDeleteCnil.setCaption(applicationContext.getMessage("candidat.delete.cnil", null, UI.getCurrent().getLocale()));
    btnDeleteCnil.addClickListener(e -> {
        candidatController.deleteCandidatCnil(cptMin, this);
    });
    controlLayout.addComponent(btnDeleteCnil);
    controlLayout.setComponentAlignment(btnDeleteCnil, Alignment.MIDDLE_RIGHT);
    /* La table */
    table.addBooleanColumn(SimpleTablePresentation.CHAMPS_VALUE, false);
    table.setVisibleColumns((Object[]) FIELDS_ORDER);
    table.setColumnCollapsingAllowed(false);
    table.setColumnReorderingAllowed(false);
    table.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
    table.setSelectable(false);
    table.setImmediate(true);
    table.setColumnWidth(SimpleTablePresentation.CHAMPS_TITLE, 250);
    table.setCellStyleGenerator((components, itemId, columnId) -> {
        if (columnId != null && columnId.equals(SimpleTablePresentation.CHAMPS_TITLE)) {
            return (ValoTheme.LABEL_BOLD);
        }
        return null;
    });
    cptMinLayout.addComponent(table);
    cptMinLayout.setExpandRatio(table, 1);
    table.setSizeFull();
    globalLayout.addComponent(cptMinLayout);
    globalLayout.setExpandRatio(cptMinLayout, 3);
    /* Les pièces */
    if (isSiScolApoPJ) {
        VerticalLayout pjLayout = new VerticalLayout();
        pjLayout.setSizeFull();
        pjLayout.setSpacing(true);
        /* Titre */
        titlePJ.addStyleName(StyleConstants.VIEW_TITLE);
        globalLayout.addComponent(titlePJ);
        /* Boutons candidat */
        buttonsLayoutPj.setWidth(100, Unit.PERCENTAGE);
        buttonsLayoutPj.setSpacing(true);
        pjLayout.addComponent(buttonsLayoutPj);
        Button btnSyncPjApogee = new Button(applicationContext.getMessage("candidat.admin.pj.btnSyncPjApo", null, UI.getCurrent().getLocale()), FontAwesome.REFRESH);
        btnSyncPjApogee.setDisableOnClick(true);
        btnSyncPjApogee.addClickListener(e -> {
            candidatPieceController.adminSynchronizePJCandidat(cptMin, this);
            btnSyncPjApogee.setEnabled(true);
        });
        buttonsLayoutPj.addComponent(btnSyncPjApogee);
        buttonsLayoutPj.setComponentAlignment(btnSyncPjApogee, Alignment.MIDDLE_CENTER);
        containerPj.addNestedContainerProperty(PjCandidat_.id.getName() + "." + PjCandidatPK_.codAnuPjCandidat.getName());
        containerPj.addNestedContainerProperty(PjCandidat_.id.getName() + "." + PjCandidatPK_.codTpjPjCandidat.getName());
        for (String fieldName : FIELDS_ORDER_PJ) {
            tablePj.setColumnHeader(fieldName, applicationContext.getMessage("candidat.admin.pj.table." + fieldName, null, UI.getCurrent().getLocale()));
        }
        tablePj.addGeneratedColumn("file", new ColumnGenerator() {

            @Override
            public Object generateCell(final Table source, final Object itemId, final Object columnId) {
                final PjCandidat pjCandidat = (PjCandidat) itemId;
                if (pjCandidat != null && pjCandidat.getNomFicPjCandidat() != null && !pjCandidat.getNomFicPjCandidat().equals("")) {
                    String nomFichier = pjCandidat.getNomFicPjCandidat();
                    OnDemandFileLayout fileLayout = new OnDemandFileLayout(pjCandidat.getNomFicPjCandidat());
                    /* Viewer si JPG */
                    if (MethodUtils.isImgFileName(nomFichier)) {
                        fileLayout.addBtnViewerClickListener(e -> {
                            InputStream is = fileController.getInputStreamFromPjCandidat(pjCandidat);
                            if (is != null) {
                                ImageViewerWindow iv = new ImageViewerWindow(new OnDemandFile(nomFichier, is), null);
                                UI.getCurrent().addWindow(iv);
                            }
                        });
                    /* Opener si PDF */
                    } else if (MethodUtils.isPdfFileName(nomFichier)) {
                        fileLayout.addBtnViewerPdfBrowserOpener(new OnDemandStreamFile() {

                            @Override
                            public OnDemandFile getOnDemandFile() {
                                InputStream is = fileController.getInputStreamFromPjCandidat(pjCandidat);
                                return new OnDemandFile(nomFichier, is);
                            }
                        });
                    }
                    /* Bouton download */
                    fileLayout.addBtnDownloadFileDownloader(new OnDemandStreamFile() {

                        @Override
                        public OnDemandFile getOnDemandFile() {
                            InputStream is = fileController.getInputStreamFromPjCandidat(pjCandidat);
                            if (is != null) {
                                return new OnDemandFile(nomFichier, is);
                            }
                            return null;
                        }
                    });
                    return fileLayout;
                }
                return null;
            }
        });
        tablePj.setVisibleColumns((Object[]) FIELDS_ORDER_PJ);
        tablePj.setColumnCollapsingAllowed(true);
        tablePj.setColumnReorderingAllowed(true);
        tablePj.setSelectable(false);
        tablePj.setImmediate(true);
        globalLayout.addComponent(tablePj);
        globalLayout.setExpandRatio(tablePj, 1);
        pjLayout.addComponent(tablePj);
        pjLayout.setExpandRatio(tablePj, 1);
        tablePj.setSizeFull();
        globalLayout.addComponent(pjLayout);
        globalLayout.setExpandRatio(pjLayout, 2);
    }
}
Also used : PjCandidat(fr.univlorraine.ecandidat.entities.ecandidat.PjCandidat) OnDemandStreamFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileUtils.OnDemandStreamFile) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) VerticalLayout(com.vaadin.ui.VerticalLayout) Alignment(com.vaadin.ui.Alignment) UI(com.vaadin.ui.UI) OnDemandFileLayout(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileLayout) FontAwesome(com.vaadin.server.FontAwesome) CandidatAdminListener(fr.univlorraine.ecandidat.utils.ListenerUtils.CandidatAdminListener) CompteMinima(fr.univlorraine.ecandidat.entities.ecandidat.CompteMinima) Label(com.vaadin.ui.Label) ViewChangeEvent(com.vaadin.navigator.ViewChangeListener.ViewChangeEvent) SpringView(com.vaadin.spring.annotation.SpringView) ValoTheme(com.vaadin.ui.themes.ValoTheme) CandidatPieceController(fr.univlorraine.ecandidat.controllers.CandidatPieceController) SimpleTablePresentation(fr.univlorraine.ecandidat.utils.bean.presentation.SimpleTablePresentation) ColumnGenerator(com.vaadin.ui.Table.ColumnGenerator) ConstanteUtils(fr.univlorraine.ecandidat.utils.ConstanteUtils) PjCandidat_(fr.univlorraine.ecandidat.entities.ecandidat.PjCandidat_) 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) BeanItemContainer(com.vaadin.data.util.BeanItemContainer) PjCandidatPK_(fr.univlorraine.ecandidat.entities.ecandidat.PjCandidatPK_) ImageViewerWindow(fr.univlorraine.ecandidat.views.windows.ImageViewerWindow) ColumnHeaderMode(com.vaadin.ui.Table.ColumnHeaderMode) ParametreController(fr.univlorraine.ecandidat.controllers.ParametreController) PjCandidat(fr.univlorraine.ecandidat.entities.ecandidat.PjCandidat) List(java.util.List) Button(com.vaadin.ui.Button) 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) UserController(fr.univlorraine.ecandidat.controllers.UserController) View(com.vaadin.navigator.View) OneClickButton(fr.univlorraine.ecandidat.vaadin.components.OneClickButton) InputStream(java.io.InputStream) CandidatController(fr.univlorraine.ecandidat.controllers.CandidatController) OnDemandStreamFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileUtils.OnDemandStreamFile) Table(com.vaadin.ui.Table) OneClickButton(fr.univlorraine.ecandidat.vaadin.components.OneClickButton) InputStream(java.io.InputStream) OnDemandFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFile) ImageViewerWindow(fr.univlorraine.ecandidat.views.windows.ImageViewerWindow) ColumnGenerator(com.vaadin.ui.Table.ColumnGenerator) Button(com.vaadin.ui.Button) OneClickButton(fr.univlorraine.ecandidat.vaadin.components.OneClickButton) VerticalLayout(com.vaadin.ui.VerticalLayout) OnDemandFileLayout(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileLayout) PostConstruct(javax.annotation.PostConstruct)

Aggregations

BeanItemContainer (com.vaadin.data.util.BeanItemContainer)3 FontAwesome (com.vaadin.server.FontAwesome)3 Alignment (com.vaadin.ui.Alignment)3 HorizontalLayout (com.vaadin.ui.HorizontalLayout)3 Label (com.vaadin.ui.Label)3 Table (com.vaadin.ui.Table)3 ColumnGenerator (com.vaadin.ui.Table.ColumnGenerator)3 UI (com.vaadin.ui.UI)3 VerticalLayout (com.vaadin.ui.VerticalLayout)3 StyleConstants (fr.univlorraine.ecandidat.StyleConstants)3 FileController (fr.univlorraine.ecandidat.controllers.FileController)3 ConstanteUtils (fr.univlorraine.ecandidat.utils.ConstanteUtils)3 OnDemandFile (fr.univlorraine.ecandidat.vaadin.components.OnDemandFile)3 OnDemandFileLayout (fr.univlorraine.ecandidat.vaadin.components.OnDemandFileLayout)3 OnDemandStreamFile (fr.univlorraine.ecandidat.vaadin.components.OnDemandFileUtils.OnDemandStreamFile)3 OneClickButton (fr.univlorraine.ecandidat.vaadin.components.OneClickButton)3 TableFormating (fr.univlorraine.ecandidat.vaadin.components.TableFormating)3 ImageViewerWindow (fr.univlorraine.ecandidat.views.windows.ImageViewerWindow)3 PostConstruct (javax.annotation.PostConstruct)3 Resource (javax.annotation.Resource)3