use of fr.univlorraine.ecandidat.vaadin.components.OnDemandFile in project esup-ecandidat by EsupPortail.
the class CandidatureController method downlaodMultipleDossierZip.
/**
* @param liste
* @param nameFile
* @return un zip contenant tous les dossiers
*/
private OnDemandFile downlaodMultipleDossierZip(final List<Candidature> liste, final String nameFile) {
final ByteArrayInOutStream out = new ByteArrayInOutStream();
final ZipOutputStream zos = new ZipOutputStream(out);
Boolean error = false;
for (final Candidature candidature : liste) {
OnDemandFile bisDossier = null;
try {
// le dossier outStream
bisDossier = downloadDossier(candidature, getInformationsCandidature(candidature, false), getInformationsDateCandidature(candidature, false), candidaturePieceController.getPjCandidature(candidature), candidaturePieceController.getFormulaireCandidature(candidature), parametreController.getIsDownloadMultipleAddPj());
final String fileName = applicationContext.getMessage("candidature.download.file", new Object[] { candidature.getCandidat().getCompteMinima().getNumDossierOpiCptMin(), candidature.getCandidat().getNomPatCandidat(), candidature.getCandidat().getPrenomCandidat(), candidature.getFormation().getCodForm() }, UI.getCurrent().getLocale());
zos.putNextEntry(new ZipEntry(fileName));
int count;
final byte[] data = new byte[2048];
while ((count = bisDossier.getInputStream().read(data, 0, 2048)) != -1) {
zos.write(data, 0, count);
}
zos.closeEntry();
} catch (final IOException e) {
error = true;
logger.error("erreur a la génération d'un dossier lors du zip", e);
} finally {
/* Nettoyage des ressources */
// MethodUtils.closeRessource(bisDossier);
}
}
if (error) {
Notification.show(applicationContext.getMessage("candidature.download.multiple.error.file", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
}
try {
zos.finish();
zos.close();
return new OnDemandFile(nameFile + ".zip", out.getInputStream());
} catch (final IOException e) {
logger.error("erreur a la génération du zip", e);
Notification.show(applicationContext.getMessage("candidature.download.multiple.error.zip", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
return null;
} finally {
/* Nettoyage des ressources */
MethodUtils.closeRessource(zos);
MethodUtils.closeRessource(out);
}
}
use of fr.univlorraine.ecandidat.vaadin.components.OnDemandFile in project esup-ecandidat by EsupPortail.
the class CandidatureController method downloadDossier.
/**
* telecharge le dossier
* @param candidature
* @param listePresentation
* @param listeDatePresentation
* @param listePj
* @param listeForm
* @param addPj
* @return l'InputStream du dossier
*/
public OnDemandFile downloadDossier(final Candidature candidature, final List<SimpleTablePresentation> listePresentation, final List<SimpleTablePresentation> listeDatePresentation, final List<PjPresentation> listePj, final List<FormulairePresentation> listeForm, final Boolean addPj) {
/* Variables utiles */
final String numDossier = candidature.getCandidat().getCompteMinima().getNumDossierOpiCptMin();
final String nom = candidature.getCandidat().getNomPatCandidat();
final String prenom = candidature.getCandidat().getPrenomCandidat();
final String codForm = candidature.getFormation().getCodForm();
final String libForm = candidature.getFormation().getLibForm();
/* Nom du fichier */
final String fileName = applicationContext.getMessage("candidature.download.file", new Object[] { numDossier, nom, prenom, codForm }, UI.getCurrent().getLocale());
// Les parametres des PJ
final Boolean enableAddApogeePJDossier = parametreController.getIsAddApogeePJDossier();
// Font
final PDFont font = PDType1Font.HELVETICA_BOLD;
// le dossier outStream
ByteArrayInputStream bisDossier = null;
// liste des InputStream à fermer
final List<InputStream> listeInputStreamToClose = new ArrayList<>();
/* Génération du dossier principal */
try {
bisDossier = generateDossier(candidature, listePresentation, listeDatePresentation, listePj, listeForm);
if (bisDossier == null) {
Notification.show(applicationContext.getMessage("candidature.download.error", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
return null;
}
} catch (IOException | XDocReportException e2) {
Notification.show(applicationContext.getMessage("candidature.download.error", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
logger.error("erreur a la génération du dossier", e2);
return null;
}
ByteArrayInOutStream out = new ByteArrayInOutStream();
InputStream is = null;
try {
/* Merger */
final PDFMergerUtility ut = new PDFMergerUtility();
/* Propriétés du document */
final PDDocumentInformation info = new PDDocumentInformation();
info.setTitle(numDossier + "_" + nom + "_" + prenom + "_" + codForm);
info.setAuthor(ConstanteUtils.APP_NAME);
info.setSubject(nom + " " + prenom + " (" + numDossier + ") / " + libForm + " (" + codForm + ")");
final Calendar calendar = Calendar.getInstance(UI.getCurrent().getLocale());
info.setCreationDate(calendar);
info.setModificationDate(calendar);
ut.setDestinationDocumentInformation(info);
/* Ajout du dossier */
ut.addSource(bisDossier);
/* Gestion des erreurs de pj */
Boolean errorAddPj = false;
final List<String> fileNameError = new ArrayList<>();
/* Calcul si besoin d'ajouter les pj */
Integer nbFilePJ = 0;
for (final PjPresentation pj : listePj) {
if (pj.getFilePj() != null) {
nbFilePJ++;
}
}
if (addPj && nbFilePJ > 0 && !fileController.isFileServiceMaintenance(applicationContext.getMessage("file.service.maintenance.dossier", null, UI.getCurrent().getLocale()))) {
for (final PjPresentation e : listePj) {
// listePj.forEach(e->{
try {
// titre header
final String textHeader = e.getLibPj();
// PJ doit etre à true
if (e.getFilePj() != null && (e.getPjCandidatFromApogee() == null || (e.getPjCandidatFromApogee() != null && enableAddApogeePJDossier))) {
final Fichier file = e.getFilePj();
final String nameFile = file.getNomFichier();
final InputStream inputStreamFile = fileController.getInputStreamFromPjPresentation(e);
// on doit fermer l'inputStream apres le merge donc je stock le stream et le ferme apres
listeInputStreamToClose.add(inputStreamFile);
// cas du PDF
if (inputStreamFile != null && MethodUtils.isPdfFileName(nameFile)) {
// chargement du pdf avant de l'ajouter -> evite de compiler avec des fichiers corrompus
final BufferedInputStream bufferedInputStreamFile = new BufferedInputStream(inputStreamFile);
// on doit fermer l'inputStream apres le merge donc je stock le stream et le ferme apres
listeInputStreamToClose.add(bufferedInputStreamFile);
try {
// on place un marker au max du buffer du stream (mark = nb byte qu'il peut lire avant d'etre invalide.. mais comme on lit tout le fichier..)
bufferedInputStreamFile.mark(ConstanteUtils.MAX_BUFFER_SIZE);
// lecture du fichier pour vérifier s'il n'est pas corrompue
final PDDocument doc = PDDocument.load(bufferedInputStreamFile);
// cloture immédiate du fichier pour libérer la mémoire
MethodUtils.closeRessource(doc);
// on replace le bufferedInputStreamFile au début
bufferedInputStreamFile.reset();
// on ajoute l'inputStream
ut.addSource(bufferedInputStreamFile);
} catch (final Exception ex1) {
logger.warn("fichier pdf '" + nameFile + "' en erreur et non ajouté au dossier '" + fileName + "'", ex1);
errorAddPj = true;
fileNameError.add(nameFile);
}
} else if (inputStreamFile != null && MethodUtils.isImgFileName(nameFile)) {
// creation document
final PDDocument document = new PDDocument();
final ByteArrayInOutStream baosImg = new ByteArrayInOutStream();
ByteArrayInputStream bis = null;
try {
// chargement page A4
final PDRectangle PAGE_SIZE_A4 = PDRectangle.A4;
// creation page
final PDPage page = new PDPage(PAGE_SIZE_A4);
// ajout de la page
document.addPage(page);
// Stream du document
final PDPageContentStream contentStream = new PDPageContentStream(document, page);
// margin top est calculée si un text de titre a été ajouté
Float marginTop = addHeaderPJ(textHeader, font, PAGE_SIZE_A4, contentStream);
// on ajoute la marge sous le text (ou la marge depuis le haut du doc si pas de
// text)
marginTop = marginTop + ConstanteUtils.DOSSIER_MARGIN;
// creation de l'image
PDImageXObject img = null;
// JPG
if (MethodUtils.isJpgFileName(nameFile)) {
img = JPEGFactory.createFromStream(document, inputStreamFile);
} else // PNG
if (MethodUtils.isPngFileName(nameFile)) {
img = LosslessFactory.createFromImage(document, ImageIO.read(inputStreamFile));
}
// calcul de la largeur et hauteur de l'image
Float imgWidth = (float) img.getWidth();
Float imgHeight = (float) img.getHeight();
// calcul de la largeur et hauteur de la page moins les deux marges
final Float a4Width = PAGE_SIZE_A4.getWidth() - 2 * ConstanteUtils.DOSSIER_MARGIN;
final Float a4Height = PAGE_SIZE_A4.getHeight() - ConstanteUtils.DOSSIER_MARGIN - marginTop;
// calcul du coef à appliquer si l'image est trop grande
Float coef = 1.0f;
if (imgWidth > a4Width) {
coef = a4Width / imgWidth;
imgWidth = imgWidth * coef;
imgHeight = imgHeight * coef;
}
// le nouveau coef
if (imgHeight > a4Height) {
coef = a4Height / imgHeight;
imgWidth = imgWidth * coef;
imgHeight = imgHeight * coef;
}
// ecriture de l'image
contentStream.drawImage(img, ConstanteUtils.DOSSIER_MARGIN, PAGE_SIZE_A4.getHeight() - imgHeight - marginTop, imgWidth, imgHeight);
// il faut d'abord fermer le flux
MethodUtils.closeRessource(contentStream);
document.save(baosImg);
/* Creation du flux */
bis = baosImg.getInputStream();
/* Ajout de la page au document */
ut.addSource(bis);
} catch (final Exception e1) {
errorAddPj = true;
fileNameError.add(nameFile);
logger.warn("fichier image '" + nameFile + "' en erreur et non ajouté au dossier '" + fileName + "'", e1);
} finally {
/* Nettoyage des ressources */
MethodUtils.closeRessource(document);
MethodUtils.closeRessource(bis);
MethodUtils.closeRessource(baosImg);
}
}
}
} catch (final Exception e1) {
errorAddPj = true;
final String nameFile = e.getFilePj() != null ? e.getFilePj().getNomFichier() : "-";
if (e.getFilePj() != null) {
fileNameError.add(e.getFilePj().getNomFichier());
}
logger.warn("fichier '" + nameFile + "' en erreur et non ajouté au dossier '" + fileName + "'", e1);
}
}
}
if (errorAddPj) {
String fileNamesError = "";
if (fileNameError.size() > 0) {
fileNamesError = " : " + fileNameError.stream().collect(Collectors.joining(", "));
}
Notification.show(applicationContext.getMessage("candidature.download.encoding.pj", null, UI.getCurrent().getLocale()) + fileNamesError, Type.WARNING_MESSAGE);
}
ut.setDestinationFileName(fileName);
ut.setDestinationStream(out);
ut.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
is = pdfManager.cryptAndSignPdf(out, UI.getCurrent().getLocale());
return new OnDemandFile(fileName, is);
} catch (final Exception e) {
logger.warn("erreur a la génération du dossier '" + fileName + "'", e);
try {
out = new ByteArrayInOutStream();
final PDFMergerUtility ut = new PDFMergerUtility();
ut.addSource(generateDossier(candidature, listePresentation, listeDatePresentation, listePj, listeForm));
ut.setDestinationFileName(fileName);
ut.setDestinationStream(out);
ut.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
is = pdfManager.cryptAndSignPdf(out, UI.getCurrent().getLocale());
Notification.show(applicationContext.getMessage("candidature.download.error.pj", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
return new OnDemandFile(fileName, is);
} catch (final Exception e2) {
Notification.show(applicationContext.getMessage("candidature.download.error", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
logger.error("erreur a la génération du dossier", e2);
return null;
}
} finally {
// fermeture des fichiers
MethodUtils.closeRessource(is);
MethodUtils.closeRessource(out);
MethodUtils.closeRessource(bisDossier);
/* besoin de fermer les pdf apres coup */
listeInputStreamToClose.forEach(inputStreamFile -> {
MethodUtils.closeRessource(inputStreamFile);
});
listeInputStreamToClose.clear();
}
}
use of fr.univlorraine.ecandidat.vaadin.components.OnDemandFile in project esup-ecandidat by EsupPortail.
the class CandidatureCtrCandController method generateExport.
/**
* Exporte les candidatures
* @param liste
* @param allOptions
* @param optionChecked
* @return le fichier
*/
private OnDemandFile generateExport(final String code, final String libelle, final List<Candidature> liste, final LinkedHashSet<ExportListCandidatureOption> allOptions, final Set<ExportListCandidatureOption> optionChecked, final Boolean temFooter) {
if (liste == null || liste.size() == 0) {
return null;
}
final Map<String, Object> beans = new HashMap<>();
/* Traitement des dates */
liste.forEach(candidature -> {
candidature.setDatCreCandStr(candidature.getDatCreCand().format(formatterDateTime));
candidature.getCandidat().setAdresseCandidatExport(generateAdresse(candidature.getCandidat().getAdresse()));
candidature.getCandidat().setDatNaissanceCandidatStr(MethodUtils.formatDate(candidature.getCandidat().getDatNaissCandidat(), formatterDate));
if (candidature.getLastTypeDecision() != null) {
candidature.getLastTypeDecision().setDatValidTypeDecCandStr(MethodUtils.formatDate(candidature.getLastTypeDecision().getDatValidTypeDecCand(), formatterDate));
candidature.getLastTypeDecision().setPreselectStr(getComplementPreselectMail(candidature.getLastTypeDecision()));
candidature.getLastTypeDecision().setPreselectDateTypeDecCandStr(MethodUtils.formatDate(candidature.getLastTypeDecision().getPreselectDateTypeDecCand(), formatterDate));
}
candidature.setDatModTypStatutCandStr(MethodUtils.formatDate(candidature.getDatModTypStatutCand(), formatterDateTime));
candidature.setDatReceptDossierCandStr(MethodUtils.formatDate(candidature.getDatReceptDossierCand(), formatterDate));
candidature.setDatTransDossierCandStr(MethodUtils.formatDate(candidature.getDatTransDossierCand(), formatterDateTime));
candidature.setDatCompletDossierCandStr(MethodUtils.formatDate(candidature.getDatCompletDossierCand(), formatterDate));
candidature.setDatAnnulCandStr(MethodUtils.formatDate(candidature.getDatAnnulCand(), formatterDateTime));
candidature.setDatNewConfirmCandStr(MethodUtils.formatDate(candidature.getDatNewConfirmCand(), formatterDate));
candidature.setDatNewRetourCandStr(MethodUtils.formatDate(candidature.getDatNewRetourCand(), formatterDate));
candidature.setDatIncompletDossierCandStr(MethodUtils.formatDate(candidature.getDatIncompletDossierCand(), formatterDate));
candidature.setDatModPjForm(getDatModPjForm(candidature));
/* Tags */
candidature.setTagsStr(formatLongCellSize(candidature.getTags().stream().map(e -> e.getLibTag()).collect(Collectors.joining(" / "))));
/* Bloc note */
if (parametreController.getIsExportBlocNote()) {
candidature.setBlocNoteStr(formatLongCellSize(getPostIt(candidature).stream().map(e -> e.getMessagePostIt()).collect(Collectors.joining(" / "))));
} else {
allOptions.add(new ExportListCandidatureOption("postItHide", applicationContext.getMessage("export.option.postit", null, UI.getCurrent().getLocale())));
}
/* Exoneration */
if (candidature.getSiScolCatExoExt() != null) {
candidature.setCatExoStr(candidature.getSiScolCatExoExt().getDisplayLibelle());
}
candidature.setMntChargeStr(MethodUtils.parseBigDecimalAsString(candidature.getMntChargeCand()));
/* Opi */
if (candidature.getOpi() != null) {
candidature.setDatPassageOpiStr(MethodUtils.formatDate(candidature.getOpi().getDatPassageOpi(), formatterDateTime));
candidature.setCodOpiStr(candidature.getOpi().getCodOpi());
}
/* Definition du dernier etablissement frequenté */
final Candidat candidat = candidature.getCandidat();
String lastEtab = "";
String lastDiplome = "";
String lastLibelleDiplome = "";
Integer annee = 0;
for (final CandidatCursusInterne cursus : candidat.getCandidatCursusInternes()) {
if (cursus.getAnneeUnivCursusInterne() > annee) {
annee = cursus.getAnneeUnivCursusInterne();
lastEtab = applicationContext.getMessage("universite.title", null, UI.getCurrent().getLocale());
lastDiplome = cursus.getLibCursusInterne();
}
}
for (final CandidatCursusPostBac cursus : candidat.getCandidatCursusPostBacs()) {
if (cursus.getAnneeUnivCursus() > annee && cursus.getSiScolEtablissement() != null) {
annee = cursus.getAnneeUnivCursus();
lastEtab = cursus.getSiScolEtablissement().getLibEtb();
lastDiplome = cursus.getSiScolDipAutCur().getLibDac();
lastLibelleDiplome = cursus.getLibCursus();
}
}
candidat.setLastEtab(lastEtab);
candidat.setLastDiplome(lastDiplome);
candidat.setLastLibDiplome(lastLibelleDiplome);
});
if (code != null) {
beans.put("code", code);
}
beans.put("candidatures", liste);
allOptions.stream().forEach(exportOption -> {
addExportOption(exportOption, optionChecked, beans);
});
if (temFooter) {
beans.put("footer", applicationContext.getMessage("export.footer", new Object[] { libelle, liste.size(), formatterDateTime.format(LocalDateTime.now()) }, UI.getCurrent().getLocale()));
} else {
beans.put("footer", "");
}
final String libFile = applicationContext.getMessage("export.nom.fichier", new Object[] { libelle, DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss").format(LocalDateTime.now()) }, UI.getCurrent().getLocale());
return exportController.generateXlsxExport(beans, "candidatures_template", libFile, Arrays.asList(0));
}
use of fr.univlorraine.ecandidat.vaadin.components.OnDemandFile 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);
}
use of fr.univlorraine.ecandidat.vaadin.components.OnDemandFile in project esup-ecandidat by EsupPortail.
the class StatViewTemplate method init.
/**
* Initialise le template
*
* @param title
* @param code
* @param libelle
*/
public void init(final String title, final String code, final String libelle, final String libelleHs) {
/* Style */
setSizeFull();
setMargin(true);
setSpacing(true);
/* Titre */
Label titleParam = new Label(title);
titleParam.addStyleName(StyleConstants.VIEW_TITLE);
addComponent(titleParam);
/* Boutons */
HorizontalLayout buttonsLayout = new HorizontalLayout();
buttonsLayout.setWidth(100, Unit.PERCENTAGE);
buttonsLayout.setSpacing(true);
addComponent(buttonsLayout);
/* Choix de campagne */
HorizontalLayout campagneLayout = new HorizontalLayout();
campagneLayout.setWidth(100, Unit.PERCENTAGE);
campagneLayout.setSpacing(true);
buttonsLayout.addComponent(campagneLayout);
/* Label campagne */
Label labelCampagne = new Label(applicationContext.getMessage("stat.change.camp", null, UI.getCurrent().getLocale()));
labelCampagne.setSizeUndefined();
campagneLayout.addComponent(labelCampagne);
campagneLayout.setComponentAlignment(labelCampagne, Alignment.MIDDLE_LEFT);
/* ListeBox campagne */
List<Campagne> listeCampagne = campagneController.getCampagnes();
listeCampagne.sort(Comparator.comparing(Campagne::getCodCamp).reversed());
cbCampagne = new RequiredComboBox<>(listeCampagne, Campagne.class);
cbCampagne.setValue(campagneController.getCampagneActive());
campagneLayout.addComponent(cbCampagne);
campagneLayout.setExpandRatio(cbCampagne, 1);
campagneLayout.setComponentAlignment(cbCampagne, Alignment.BOTTOM_LEFT);
cbCampagne.addValueChangeListener(e -> {
majContainer();
});
cbDisplayHs.setCaption(libelleHs);
campagneLayout.addComponent(cbDisplayHs);
campagneLayout.setComponentAlignment(cbDisplayHs, Alignment.MIDDLE_LEFT);
cbDisplayHs.addValueChangeListener(e -> {
majContainer();
});
/* Export des candidatures désactivé */
/*
* OneClickButton btnExportCandidature = new
* OneClickButton(applicationContext.getMessage("stat.export.candidature.btn",
* null, UI.getCurrent().getLocale()), FontAwesome.FILE_EXCEL_O);
* btnExportCandidature.setDescription(applicationContext.getMessage(
* "stat.export.candidature.btn", null, UI.getCurrent().getLocale()));
* btnExportCandidature.addClickListener(e->{ CtrCandExportWindow window = new
* CtrCandExportWindow(securityCtrCandFonc.getCtrCand());
* UI.getCurrent().addWindow(window); });
*/
/* La grid */
grid = new GridFormatting<>(StatFormationPresentation.class);
grid.initColumn(new String[] { StatFormationPresentation.CHAMPS_COD, StatFormationPresentation.CHAMPS_LIB, StatFormationPresentation.CHAMPS_LIB_SUPP, StatFormationPresentation.CHAMPS_NB_CANDIDATURE_TOTAL, StatFormationPresentation.CHAMPS_NB_CANDIDATURE_CANCEL, StatFormationPresentation.CHAMPS_NB_STATUT_ATTENTE, StatFormationPresentation.CHAMPS_NB_STATUT_RECEPTIONNE, StatFormationPresentation.CHAMPS_NB_STATUT_COMPLET, StatFormationPresentation.CHAMPS_NB_STATUT_INCOMPLET, StatFormationPresentation.CHAMPS_NB_AVIS_FAVORABLE, StatFormationPresentation.CHAMPS_NB_AVIS_DEFAVORABLE, StatFormationPresentation.CHAMPS_NB_AVIS_LISTECOMP, StatFormationPresentation.CHAMPS_NB_AVIS_LISTEATTENTE, StatFormationPresentation.CHAMPS_NB_AVIS_PRESELECTION, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL_VALIDE, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL_NON_VALIDE, StatFormationPresentation.CHAMPS_NB_CONFIRM, StatFormationPresentation.CHAMPS_NB_DESIST, StatFormationPresentation.CHAMPS_CAPACITE_ACCUEIL }, "stat.table.", StatFormationPresentation.CHAMPS_LIB);
grid.setSizeFull();
grid.setFrozenColumnCount(2);
grid.setSelectionMode(SelectionMode.NONE);
/* Largeur des colonnes */
grid.setColumnWidth(StatFormationPresentation.CHAMPS_COD, 150);
grid.setColumnsWidth(300, StatFormationPresentation.CHAMPS_LIB, StatFormationPresentation.CHAMPS_LIB_SUPP);
grid.setColumnsWidth(115, StatFormationPresentation.CHAMPS_NB_CANDIDATURE_TOTAL, StatFormationPresentation.CHAMPS_NB_CANDIDATURE_CANCEL, StatFormationPresentation.CHAMPS_NB_STATUT_ATTENTE, StatFormationPresentation.CHAMPS_NB_STATUT_RECEPTIONNE, StatFormationPresentation.CHAMPS_NB_STATUT_COMPLET, StatFormationPresentation.CHAMPS_NB_STATUT_INCOMPLET, StatFormationPresentation.CHAMPS_NB_AVIS_FAVORABLE, StatFormationPresentation.CHAMPS_NB_AVIS_DEFAVORABLE, StatFormationPresentation.CHAMPS_NB_AVIS_LISTECOMP, StatFormationPresentation.CHAMPS_NB_AVIS_LISTEATTENTE, StatFormationPresentation.CHAMPS_NB_AVIS_PRESELECTION, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL_VALIDE, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL_NON_VALIDE, StatFormationPresentation.CHAMPS_NB_CONFIRM, StatFormationPresentation.CHAMPS_NB_DESIST);
grid.removeFilterCells(StatFormationPresentation.CHAMPS_NB_CANDIDATURE_TOTAL, StatFormationPresentation.CHAMPS_NB_CANDIDATURE_CANCEL, StatFormationPresentation.CHAMPS_NB_STATUT_ATTENTE, StatFormationPresentation.CHAMPS_NB_STATUT_RECEPTIONNE, StatFormationPresentation.CHAMPS_NB_STATUT_COMPLET, StatFormationPresentation.CHAMPS_NB_STATUT_INCOMPLET, StatFormationPresentation.CHAMPS_NB_AVIS_FAVORABLE, StatFormationPresentation.CHAMPS_NB_AVIS_DEFAVORABLE, StatFormationPresentation.CHAMPS_NB_AVIS_LISTECOMP, StatFormationPresentation.CHAMPS_NB_AVIS_LISTEATTENTE, StatFormationPresentation.CHAMPS_NB_AVIS_PRESELECTION, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL_VALIDE, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL_NON_VALIDE, StatFormationPresentation.CHAMPS_NB_CONFIRM, StatFormationPresentation.CHAMPS_NB_DESIST);
/* Header */
HeaderRow headerRow = grid.prependHeaderRow();
headerRow.setStyleName(ValoTheme.TEXTFIELD_ALIGN_CENTER);
headerRow.join(StatFormationPresentation.CHAMPS_COD, StatFormationPresentation.CHAMPS_LIB).setText("");
headerRow.join(StatFormationPresentation.CHAMPS_NB_CANDIDATURE_TOTAL, StatFormationPresentation.CHAMPS_NB_CANDIDATURE_CANCEL).setText(applicationContext.getMessage("stat.table.header.join.nbCandidature", null, UI.getCurrent().getLocale()));
headerRow.join(StatFormationPresentation.CHAMPS_NB_STATUT_ATTENTE, StatFormationPresentation.CHAMPS_NB_STATUT_RECEPTIONNE, StatFormationPresentation.CHAMPS_NB_STATUT_COMPLET, StatFormationPresentation.CHAMPS_NB_STATUT_INCOMPLET).setText(applicationContext.getMessage("stat.table.header.join.statut", null, UI.getCurrent().getLocale()));
headerRow.join(StatFormationPresentation.CHAMPS_NB_AVIS_FAVORABLE, StatFormationPresentation.CHAMPS_NB_AVIS_DEFAVORABLE, StatFormationPresentation.CHAMPS_NB_AVIS_LISTECOMP, StatFormationPresentation.CHAMPS_NB_AVIS_LISTEATTENTE, StatFormationPresentation.CHAMPS_NB_AVIS_PRESELECTION).setText(applicationContext.getMessage("stat.table.header.join.avis", null, UI.getCurrent().getLocale()));
headerRow.join(StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL_VALIDE, StatFormationPresentation.CHAMPS_NB_AVIS_TOTAL_NON_VALIDE).setText(applicationContext.getMessage("stat.table.header.join.avis.total", null, UI.getCurrent().getLocale()));
headerRow.join(StatFormationPresentation.CHAMPS_NB_CONFIRM, StatFormationPresentation.CHAMPS_NB_DESIST).setText(applicationContext.getMessage("stat.table.header.join.confirm", null, UI.getCurrent().getLocale()));
addComponent(grid);
setExpandRatio(grid, 1);
/* Ajout des totaux dans le footer */
footerRow = grid.prependFooterRow();
footerRow.setStyleName(StyleConstants.GRID_FOOTER);
FooterCell cellTxt = footerRow.join(StatFormationPresentation.CHAMPS_COD, StatFormationPresentation.CHAMPS_LIB);
cellTxt.setText(applicationContext.getMessage("stat.table.footer.join.sum", null, UI.getCurrent().getLocale()));
cellTxt.setStyleName(StyleConstants.GRID_FOOTER_TITLE);
grid.addFilterListener(new FilterListener() {
@Override
public void filter() {
updateFooter();
}
});
grid.setRowStyleGenerator(new RowStyleGenerator() {
@Override
public String getStyle(final RowReference row) {
StatFormationPresentation pres = (StatFormationPresentation) row.getItemId();
if (!pres.getTes()) {
return StyleConstants.GRID_ROW_STAT_HS;
}
return null;
}
});
/* Export */
Button btnExport = new Button(applicationContext.getMessage("btnExport", null, UI.getCurrent().getLocale()), FontAwesome.FILE_EXCEL_O);
btnExport.setDescription(applicationContext.getMessage("btnExport", null, UI.getCurrent().getLocale()));
buttonsLayout.addComponent(btnExport);
buttonsLayout.setComponentAlignment(btnExport, Alignment.MIDDLE_RIGHT);
btnExport.setDisableOnClick(true);
new OnDemandFileDownloader(new OnDemandStreamFile() {
@Override
public OnDemandFile getOnDemandFile() {
OnDemandFile file = statController.generateExport(getCampagne(), code, libelle, grid.getItems(), footerStat, getLibelleExport(), getLibelleSuppExport(), getDisplayCapaciteAccueil());
if (file != null) {
btnExport.setEnabled(true);
return file;
}
btnExport.setEnabled(true);
return null;
}
}, btnExport);
}
Aggregations