Search in sources :

Example 1 with CommissionMembre_

use of fr.univlorraine.ecandidat.entities.ecandidat.CommissionMembre_ 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)

Aggregations

BeanItemContainer (com.vaadin.data.util.BeanItemContainer)1 View (com.vaadin.navigator.View)1 ViewChangeEvent (com.vaadin.navigator.ViewChangeListener.ViewChangeEvent)1 FontAwesome (com.vaadin.server.FontAwesome)1 SpringView (com.vaadin.spring.annotation.SpringView)1 Alignment (com.vaadin.ui.Alignment)1 Button (com.vaadin.ui.Button)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 ValoTheme (com.vaadin.ui.themes.ValoTheme)1 StyleConstants (fr.univlorraine.ecandidat.StyleConstants)1 CommissionController (fr.univlorraine.ecandidat.controllers.CommissionController)1 DroitProfilController (fr.univlorraine.ecandidat.controllers.DroitProfilController)1 FileController (fr.univlorraine.ecandidat.controllers.FileController)1 UserController (fr.univlorraine.ecandidat.controllers.UserController)1 Commission (fr.univlorraine.ecandidat.entities.ecandidat.Commission)1