use of com.vaadin.ui.Grid.SingleSelectionModel in project esup-ecandidat by EsupPortail.
the class CandidatureViewTemplate method init.
/**
* Initialise la vue
*/
/**
* @param modeModification
* @param typGestionCandidature
* @param isCanceled
* @param isArchived
*/
public void init(final Boolean modeModification, final String typGestionCandidature, final Boolean isCanceled, final Boolean isArchived) {
modeModif = modeModification;
/* Style */
setSizeFull();
layout.setMargin(true);
layout.setSpacing(true);
layout.setSizeFull();
addComponent(layout);
/* Titre */
final HorizontalLayout hlTitle = new HorizontalLayout();
hlTitle.setWidth(100, Unit.PERCENTAGE);
hlTitle.setSpacing(true);
titleView.setSizeUndefined();
titleView.addStyleName(StyleConstants.VIEW_TITLE);
hlTitle.addComponent(titleView);
/* PopUp Légende */
pvLegende = new PopupView(applicationContext.getMessage("legend.popup.link", null, UI.getCurrent().getLocale()), null);
pvLegende.setVisible(false);
hlTitle.addComponent(pvLegende);
hlTitle.setComponentAlignment(pvLegende, Alignment.MIDDLE_LEFT);
final Label spacer1 = new Label();
spacer1.setWidth(100, Unit.PERCENTAGE);
hlTitle.addComponent(spacer1);
hlTitle.setExpandRatio(spacer1, 1);
/* Label du nombre de candidatures */
nbCandidatureLabel.setSizeUndefined();
nbCandidatureLabel.addStyleName(ValoTheme.LABEL_COLORED);
nbCandidatureLabel.addStyleName(StyleConstants.LABEL_ITALIC);
hlTitle.addComponent(nbCandidatureLabel);
hlTitle.setComponentAlignment(nbCandidatureLabel, Alignment.BOTTOM_RIGHT);
final Label labelSpaceNb = new Label(" - ");
labelSpaceNb.setSizeUndefined();
labelSpaceNb.addStyleName(ValoTheme.LABEL_COLORED);
labelSpaceNb.addStyleName(StyleConstants.LABEL_ITALIC);
hlTitle.addComponent(labelSpaceNb);
hlTitle.setComponentAlignment(labelSpaceNb, Alignment.BOTTOM_RIGHT);
nbCandidatureLabelSelected.setSizeUndefined();
nbCandidatureLabelSelected.addStyleName(ValoTheme.LABEL_COLORED);
nbCandidatureLabelSelected.addStyleName(StyleConstants.LABEL_MORE_BOLD);
nbCandidatureLabelSelected.addStyleName(StyleConstants.LABEL_ITALIC);
hlTitle.addComponent(nbCandidatureLabelSelected);
hlTitle.setComponentAlignment(nbCandidatureLabelSelected, Alignment.BOTTOM_RIGHT);
layout.addComponent(hlTitle);
/* Les droits sur les candidatures */
final List<DroitFonctionnalite> listeDroitFonc = droitProfilController.getCandidatureFonctionnalite(typGestionCandidature, null);
Boolean droitOpenCandidature = false;
final Authentication auth = userController.getCurrentAuthentication();
if (MethodUtils.isGestionCandidatureCtrCand(typGestionCandidature)) {
/* Récupération du centre de candidature en cours */
securityCtrCandFonc = userController.getCtrCandFonctionnalite(NomenclatureUtils.FONCTIONNALITE_GEST_CANDIDATURE, auth);
if (securityCtrCandFonc.hasNoRight()) {
return;
}
/* Verification que l'utilisateur a le droit d'ouvrir la candidature */
final SecurityCtrCandFonc openCandidatureFonc = userController.getCtrCandFonctionnalite(NomenclatureUtils.FONCTIONNALITE_GEST_FENETRE_CAND, auth);
if (!openCandidatureFonc.hasNoRight()) {
droitOpenCandidature = true;
}
/* Chooser de commissions */
final List<Commission> liste = commissionController.getCommissionsEnServiceByCtrCand(securityCtrCandFonc.getCtrCand(), securityCtrCandFonc.getIsGestAllCommission(), securityCtrCandFonc.getListeIdCommission(), isArchived);
liste.sort(Comparator.comparing(Commission::getGenericLibelleAlternatif));
cbCommission.setWidth(500, Unit.PIXELS);
cbCommission.setItemCaptionPropertyId(ConstanteUtils.GENERIC_LIBELLE_ALTERNATIF);
cbCommission.setTextInputAllowed(true);
cbCommission.filterListValue(liste);
cbCommission.setFilteringMode(FilteringMode.CONTAINS);
cbCommission.setItemCaptionMode(ItemCaptionMode.PROPERTY);
cbCommission.setPageLength(25);
if (liste.size() > 0) {
final Integer idCommEnCours = preferenceController.getPrefCandIdComm();
if (idCommEnCours != null) {
if (!cbCommission.setCommissionValue(idCommEnCours)) {
cbCommission.setValue(liste.get(0));
}
} else {
cbCommission.setValue(liste.get(0));
}
}
cbCommission.addValueChangeListener(e -> {
majContainer();
preferenceController.setPrefCandIdComm(getCommission());
});
/* Filtrage */
final Panel panelCommission = new Panel();
panelCommission.setWidth(100, Unit.PERCENTAGE);
final HorizontalLayout filtreLayout = new HorizontalLayout();
filtreLayout.setMargin(true);
layout.addComponent(panelCommission);
filtreLayout.setSpacing(true);
final Label labelFiltre = new Label(applicationContext.getMessage("candidature.change.commission", null, UI.getCurrent().getLocale()));
filtreLayout.addComponent(labelFiltre);
filtreLayout.setComponentAlignment(labelFiltre, Alignment.MIDDLE_LEFT);
filtreLayout.addComponent(cbCommission);
filtreLayout.setComponentAlignment(cbCommission, Alignment.BOTTOM_LEFT);
// popup astuce
final PopupView pvAstuce = new PopupView(createPopUpAstuce());
filtreLayout.addComponent(pvAstuce);
filtreLayout.setComponentAlignment(pvAstuce, Alignment.MIDDLE_LEFT);
panelCommission.setContent(filtreLayout);
} else if (MethodUtils.isGestionCandidatureCommission(typGestionCandidature)) {
/* Récupération de la commission en cours en cours */
securityCommissionFonc = userController.getCommissionFonctionnalite(NomenclatureUtils.FONCTIONNALITE_GEST_CANDIDATURE, auth);
if (securityCommissionFonc.hasNoRight()) {
return;
}
/* Verification que l'utilisateur a le droit d'ouvrir la candidature */
final SecurityCommissionFonc openCandidatureFonc = userController.getCommissionFonctionnalite(NomenclatureUtils.FONCTIONNALITE_GEST_FENETRE_CAND, auth);
if (!openCandidatureFonc.hasNoRight()) {
droitOpenCandidature = true;
}
}
/* Mise a jour des listes utilisées */
listeAlertesSva = alertSvaController.getAlertSvaEnService();
listeTags = tagController.getTagEnServiceByCtrCand(getCentreCandidature());
final Boolean droitOpenCandidatureFinal = droitOpenCandidature;
/* Boutons */
final HorizontalLayout buttonsLayout = new HorizontalLayout();
buttonsLayout.setWidth(100, Unit.PERCENTAGE);
buttonsLayout.setSpacing(true);
layout.addComponent(buttonsLayout);
/* Bouton d'ouverture de candidature */
btnOpen.setCaption(applicationContext.getMessage("btnOpen", null, UI.getCurrent().getLocale()));
btnOpen.setEnabled(false);
btnOpen.addClickListener(e -> {
final Candidature candidature = getCandidatureSelected();
if (droitOpenCandidatureFinal && candidature != null) {
candidatureController.openCandidatureGestionnaire(candidature, isCanceled, isArchived, listeDroitFonc);
}
});
buttonsLayout.addComponent(btnOpen);
buttonsLayout.setComponentAlignment(btnOpen, Alignment.MIDDLE_LEFT);
if (modeModif && listeDroitFonc.stream().filter(e -> !e.getCodFonc().equals(NomenclatureUtils.FONCTIONNALITE_GEST_FENETRE_CAND)).count() > 0) {
/* Bouton d'action */
btnAction.setCaption(applicationContext.getMessage("btnAction", null, UI.getCurrent().getLocale()));
btnAction.setEnabled(false);
btnAction.addClickListener(e -> {
final List<Candidature> listeCheck = getListeCandidatureSelected();
if (listeCheck.size() == 0) {
Notification.show(applicationContext.getMessage("candidature.noselected", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
} else if (listeCheck.size() > ConstanteUtils.SIZE_MAX_EDITION_MASSE) {
Notification.show(applicationContext.getMessage("candidature.toomuchselected", new Object[] { ConstanteUtils.SIZE_MAX_EDITION_MASSE }, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
return;
} else {
candidatureCtrCandController.editActionCandidatureMasse(listeCheck, listeDroitFonc, getCentreCandidature(), this);
}
});
buttonsLayout.addComponent(btnAction);
buttonsLayout.setComponentAlignment(btnAction, Alignment.MIDDLE_CENTER);
}
/* Les options */
final HorizontalLayout hlOption = new HorizontalLayout();
hlOption.setSpacing(true);
buttonsLayout.addComponent(hlOption);
buttonsLayout.setComponentAlignment(hlOption, Alignment.MIDDLE_RIGHT);
/* Export de la liste de candidature */
btnExport.setDescription(applicationContext.getMessage("btnExport", null, UI.getCurrent().getLocale()));
btnExport.addClickListener(e -> {
@SuppressWarnings("unchecked") final List<Candidature> listeCand = (List<Candidature>) candidatureGrid.getContainerDataSource().getItemIds();
if (listeCand.size() == 0) {
return;
}
final CtrCandExportWindow window = new CtrCandExportWindow(getCommission(), listeCand);
UI.getCurrent().addWindow(window);
});
hlOption.addComponent(btnExport);
/* Filtres de comboBox perso */
final String libFilterNull = applicationContext.getMessage("filter.null", null, UI.getCurrent().getLocale());
final String libFilterExceptAtt = applicationContext.getMessage("filter.except.attente", null, UI.getCurrent().getLocale());
final List<ComboBoxFilterPresentation> listeCbFilter = new ArrayList<>();
/* Filtre de tag */
listeCbFilter.add(new ComboBoxFilterPresentation(Candidature_.tags.getName(), getComboBoxFilterTag(), getNullTag(), TypeFilter.LIST_CONTAINS));
/* Les filtres sur les Strings */
listeCbFilter.add(new ComboBoxFilterPresentation(Candidature_.typeStatut.getName() + "." + TypeStatut_.libTypStatut.getName(), libFilterExceptAtt, tableRefController.getTypeStatutEnAttente().getLibTypStatut(), getComboBoxTypStatut(libFilterExceptAtt)));
listeCbFilter.add(new ComboBoxFilterPresentation(Candidature_.typeTraitement.getName() + "." + TypeTraitement_.libTypTrait.getName(), libFilterExceptAtt, tableRefController.getTypeTraitementEnAttente().getLibTypTrait(), getComboBoxTypTrait(libFilterExceptAtt)));
listeCbFilter.add(new ComboBoxFilterPresentation(LAST_TYPE_DECISION_PREFIXE + TypeDecisionCandidature_.typeDecision.getName() + "." + TypeDecision_.libTypDec.getName(), getComboBoxTypDec(libFilterNull), libFilterNull, TypeFilter.EQUALS));
listeCbFilter.add(new ComboBoxFilterPresentation(Candidature_.siScolCatExoExt.getName() + "." + SiScolCatExoExt.DISPLAY_LIB_FIELD, getComboBoxCatExoExt(libFilterNull), libFilterNull, TypeFilter.EQUALS));
/* La colonne de tag n'est plus automatiquement visibles si aucun tags en service */
final String[] fieldsOrderVisibletoUse = (listeTags.size() != 0) ? FIELDS_ORDER_VISIBLE : (String[]) ArrayUtils.removeElement(FIELDS_ORDER_VISIBLE, Candidature_.tags.getName());
/* Les préférences */
final Integer frozen = preferenceController.getPrefCandFrozenColonne(1);
final String[] visibleColonne = preferenceController.getPrefCandColonnesVisible(fieldsOrderVisibletoUse, FIELDS_ORDER);
final String[] orderColonne = preferenceController.getPrefCandColonnesOrder(FIELDS_ORDER);
final List<SortOrder> sortColonne = preferenceController.getPrefCandSortColonne(FIELDS_ORDER);
/* Bouton de modification de preferences */
final OneClickButton btnPref = new OneClickButton(FontAwesome.COG);
btnPref.setDescription(applicationContext.getMessage("preference.view.btn", null, UI.getCurrent().getLocale()));
btnPref.addClickListener(e -> {
final CtrCandPreferenceViewWindow window = new CtrCandPreferenceViewWindow(candidatureGrid.getColumns(), candidatureGrid.getFrozenColumnCount(), FIELDS_ORDER.length, candidatureGrid.getSortOrder());
window.addPreferenceViewListener(new PreferenceViewListener() {
@Override
public void saveInSession(final String valeurColonneVisible, final String valeurColonneOrder, final Integer frozenCols, final List<SortOrder> listeSortOrder) {
preferenceController.savePrefCandInSession(valeurColonneVisible, valeurColonneOrder, frozenCols, listeSortOrder, true);
candidatureGrid.setFrozenColumnCount(frozenCols);
candidatureGrid.sort(listeSortOrder);
}
@Override
public void saveInDb(final String valeurColonneVisible, final String valeurColonneOrder, final Integer frozenCols, final List<SortOrder> listeSortOrder) {
preferenceController.savePrefCandInDb(valeurColonneVisible, valeurColonneOrder, frozenCols, listeSortOrder);
candidatureGrid.setFrozenColumnCount(frozenCols);
candidatureGrid.sort(listeSortOrder);
}
@Override
public void initPref() {
preferenceController.initPrefCand();
candidatureGrid.setFrozenColumnCount(1);
candidatureGrid.initColumn(FIELDS_ORDER, FIELDS_ORDER_VISIBLE, FIELDS_ORDER, "candidature.table.", preferenceController.getDefaultSortOrder(), listeCbFilter);
candidatureGrid.sort();
}
});
UI.getCurrent().addWindow(window);
});
/* Download du dossier */
btnDownload.setEnabled(false);
final Integer nb = parametreController.getNbDownloaMultipliedMax();
if (nb.equals(1)) {
btnDownload.setDescription(applicationContext.getMessage("candidature.download.btn", null, UI.getCurrent().getLocale()));
} else {
btnDownload.setDescription(applicationContext.getMessage("candidature.download.multiple.btn", new Object[] { nb }, UI.getCurrent().getLocale()));
}
new OnDemandFileDownloader(new OnDemandStreamFile() {
@Override
public OnDemandFile getOnDemandFile() {
final OnDemandFile file = candidatureController.downlaodMultipleDossier(getListeCandidatureSelected(), getCommission());
if (file != null) {
btnDownload.setEnabled(true);
return file;
}
btnDownload.setEnabled(true);
return null;
}
}, btnDownload);
/* Download des PJ */
btnDownloadPj.setEnabled(false);
btnDownloadPj.setDescription(applicationContext.getMessage("candidature.download.pj.btn", new Object[] { nb }, UI.getCurrent().getLocale()));
btnDownloadPj.addClickListener(e -> {
UI.getCurrent().addWindow(new CtrCandDownloadPJWindow(getCommission(), getListeCandidatureSelected()));
});
hlOption.addComponent(btnExport);
hlOption.addComponent(btnDownload);
hlOption.addComponent(btnDownloadPj);
hlOption.addComponent(btnPref);
/* Grid des candidatures */
candidatureGrid.initColumn(FIELDS_ORDER, visibleColonne, orderColonne, "candidature.table.", sortColonne, listeCbFilter);
/* Ajout des colonnes gelées */
candidatureGrid.setFrozenColumnCount(frozen);
/* Ajout du flag */
candidatureGrid.setColumnConverter(Candidature_.tags.getName(), new TagsToHtmlSquareConverter());
candidatureGrid.setColumnRenderer(Candidature_.tags.getName(), new HtmlRenderer());
/* Formatage monnétaire */
candidatureGrid.setColumnConverter(Candidature_.mntChargeCand.getName(), new BigDecimalMonetaireToStringConverter());
candidatureGrid.setColumnRenderer(Candidature_.mntChargeCand.getName(), new HtmlRenderer());
/* Mise a jour des données lors du filtre */
candidatureGrid.addFilterListener(() -> {
deselectFilter();
});
/* Mode de selection de la grid */
if (modeModif) {
candidatureGrid.setSelectionMode(SelectionMode.MULTI);
final MultiSelectionModel selection = (MultiSelectionModel) candidatureGrid.getSelectionModel();
selection.setSelectionLimit(ConstanteUtils.SIZE_MAX_EDITION_MASSE);
candidatureGrid.addSelectionListener(e -> {
if (candidatureGrid.getSelectedRows().size() == ConstanteUtils.SIZE_MAX_EDITION_MASSE) {
Notification.show(applicationContext.getMessage("candidature.maxselected", new Object[] { ConstanteUtils.SIZE_MAX_EDITION_MASSE }, UI.getCurrent().getLocale()), Type.TRAY_NOTIFICATION);
}
});
} else {
candidatureGrid.setSelectionMode(SelectionMode.SINGLE);
}
/* Selection de la grid */
candidatureGrid.addSelectionListener(e -> {
setButtonState(droitOpenCandidatureFinal, listeDroitFonc);
majNbCandidatures();
});
/* CLique sur un item */
candidatureGrid.addItemClickListener(e -> {
/* Suivant le mode de slection de la grid on fait un traitement */
if (modeModif) {
final MultiSelectionModel selection = (MultiSelectionModel) candidatureGrid.getSelectionModel();
selection.deselectAll();
try {
selection.select(e.getItemId());
} catch (final Exception e1) {
Notification.show(applicationContext.getMessage("candidature.select.error", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
majContainer();
return;
}
setButtonState(droitOpenCandidatureFinal, listeDroitFonc);
if (droitOpenCandidatureFinal && e.isDoubleClick()) {
if (e.getItemId() instanceof Candidature) {
candidatureController.openCandidatureGestionnaire((Candidature) e.getItemId(), isCanceled, isArchived, listeDroitFonc);
}
}
majNbCandidatures();
} else {
final SingleSelectionModel selection = (SingleSelectionModel) candidatureGrid.getSelectionModel();
try {
selection.select(e.getItemId());
} catch (final Exception e1) {
Notification.show(applicationContext.getMessage("candidature.select.error", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
majContainer();
return;
}
setButtonState(droitOpenCandidatureFinal, listeDroitFonc);
if (e.isDoubleClick()) {
if (droitOpenCandidatureFinal && e.getItemId() instanceof Candidature) {
candidatureController.openCandidatureGestionnaire((Candidature) e.getItemId(), isCanceled, isArchived, listeDroitFonc);
}
}
majNbCandidatures();
}
});
/* Ajustement de la taille de colonnes */
candidatureGrid.setColumnWidth(Candidature_.candidat.getName() + "." + Candidat_.compteMinima.getName() + "." + CompteMinima_.numDossierOpiCptMin.getName(), 120);
candidatureGrid.setColumnWidth(Candidature_.candidat.getName() + "." + Candidat_.nomPatCandidat.getName(), 130);
candidatureGrid.setColumnWidth(Candidature_.candidat.getName() + "." + Candidat_.prenomCandidat.getName(), 120);
candidatureGrid.setColumnWidth(Candidature_.formation.getName() + "." + Formation_.codForm.getName(), 130);
candidatureGrid.setColumnWidth(Candidature_.formation.getName() + "." + Formation_.libForm.getName(), 200);
candidatureGrid.setColumnWidth(LAST_TYPE_DECISION_PREFIXE + TypeDecisionCandidature_.commentTypeDecCand.getName(), 120);
candidatureGrid.setColumnWidth(LAST_TYPE_DECISION_PREFIXE + TypeDecisionCandidature_.motivationAvis.getName() + "." + MotivationAvis_.libMotiv.getName(), 120);
candidatureGrid.setColumnWidth(Candidature_.typeStatut.getName() + "." + TypeStatut_.libTypStatut.getName(), 145);
candidatureGrid.setColumnWidth(Candidature_.typeTraitement.getName() + "." + TypeTraitement_.libTypTrait.getName(), 157);
candidatureGrid.setColumnWidth(Candidature_.temAcceptCand.getName(), 151);
candidatureGrid.setColumnWidth(Candidature_.tags.getName(), 100);
candidatureGrid.setColumnWidth(Candidature_.datNewConfirmCand.getName(), 210);
candidatureGrid.setColumnWidth(Candidature_.datNewRetourCand.getName(), 180);
layout.addComponent(candidatureGrid);
layout.setExpandRatio(candidatureGrid, 1);
candidatureGrid.setSizeFull();
/* Ajoute les alertes SVA */
addAlertSva(isCanceled, isArchived);
/* Ajoute la légende */
addLegend();
}
Aggregations