Search in sources :

Example 1 with OnDemandFile

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);
    }
}
Also used : ByteArrayInOutStream(fr.univlorraine.ecandidat.utils.ByteArrayInOutStream) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) CentreCandidature(fr.univlorraine.ecandidat.entities.ecandidat.CentreCandidature) TypeDecisionCandidature(fr.univlorraine.ecandidat.entities.ecandidat.TypeDecisionCandidature) Candidature(fr.univlorraine.ecandidat.entities.ecandidat.Candidature) ExportDossierCandidature(fr.univlorraine.ecandidat.utils.bean.export.ExportDossierCandidature) SecurityCentreCandidature(fr.univlorraine.ecandidat.services.security.SecurityCentreCandidature) OnDemandFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFile) IOException(java.io.IOException)

Example 2 with OnDemandFile

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();
    }
}
Also used : PDFont(org.apache.pdfbox.pdmodel.font.PDFont) PDPage(org.apache.pdfbox.pdmodel.PDPage) ArrayList(java.util.ArrayList) OnDemandFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFile) Fichier(fr.univlorraine.ecandidat.entities.ecandidat.Fichier) BufferedInputStream(java.io.BufferedInputStream) PDRectangle(org.apache.pdfbox.pdmodel.common.PDRectangle) PDDocumentInformation(org.apache.pdfbox.pdmodel.PDDocumentInformation) ByteArrayInOutStream(fr.univlorraine.ecandidat.utils.ByteArrayInOutStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Calendar(java.util.Calendar) PDFMergerUtility(org.apache.pdfbox.multipdf.PDFMergerUtility) IOException(java.io.IOException) IOException(java.io.IOException) XDocConverterException(fr.opensagres.xdocreport.converter.XDocConverterException) XDocReportException(fr.opensagres.xdocreport.core.XDocReportException) PjPresentation(fr.univlorraine.ecandidat.utils.bean.presentation.PjPresentation) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) ByteArrayInputStream(java.io.ByteArrayInputStream) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) PDPageContentStream(org.apache.pdfbox.pdmodel.PDPageContentStream) XDocReportException(fr.opensagres.xdocreport.core.XDocReportException)

Example 3 with OnDemandFile

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));
}
Also used : Arrays(java.util.Arrays) TypeStatut(fr.univlorraine.ecandidat.entities.ecandidat.TypeStatut) LoggerFactory(org.slf4j.LoggerFactory) UI(com.vaadin.ui.UI) ExportListCandidatureOption(fr.univlorraine.ecandidat.utils.bean.export.ExportListCandidatureOption) PdfAttachement(fr.univlorraine.ecandidat.utils.PdfAttachement) CentreCandidature(fr.univlorraine.ecandidat.entities.ecandidat.CentreCandidature) CompteMinima(fr.univlorraine.ecandidat.entities.ecandidat.CompteMinima) Map(java.util.Map) PostItRepository(fr.univlorraine.ecandidat.repositories.PostItRepository) Campagne(fr.univlorraine.ecandidat.entities.ecandidat.Campagne) CtrCandActionCandidatureWindow(fr.univlorraine.ecandidat.views.windows.CtrCandActionCandidatureWindow) ConstanteUtils(fr.univlorraine.ecandidat.utils.ConstanteUtils) MethodUtils(fr.univlorraine.ecandidat.utils.MethodUtils) Resource(javax.annotation.Resource) CandidatCursusPostBac(fr.univlorraine.ecandidat.entities.ecandidat.CandidatCursusPostBac) Set(java.util.Set) TypeDecisionCandidature(fr.univlorraine.ecandidat.entities.ecandidat.TypeDecisionCandidature) Collectors(java.util.stream.Collectors) List(java.util.List) Type(com.vaadin.ui.Notification.Type) OnDemandFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFile) LocalDate(java.time.LocalDate) Optional(java.util.Optional) ExportListCandidatureAdresse(fr.univlorraine.ecandidat.utils.bean.export.ExportListCandidatureAdresse) DeleteAvisWindowListener(fr.univlorraine.ecandidat.views.windows.CtrCandShowHistoWindow.DeleteAvisWindowListener) Candidature(fr.univlorraine.ecandidat.entities.ecandidat.Candidature) FormulaireCandidat(fr.univlorraine.ecandidat.entities.ecandidat.FormulaireCandidat) PjCand(fr.univlorraine.ecandidat.entities.ecandidat.PjCand) OpiRepository(fr.univlorraine.ecandidat.repositories.OpiRepository) TypeDecision(fr.univlorraine.ecandidat.entities.ecandidat.TypeDecision) AvisMailBean(fr.univlorraine.ecandidat.utils.bean.mail.AvisMailBean) MainUI(fr.univlorraine.ecandidat.MainUI) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PostIt(fr.univlorraine.ecandidat.entities.ecandidat.PostIt) NomenclatureUtils(fr.univlorraine.ecandidat.utils.NomenclatureUtils) Notification(com.vaadin.ui.Notification) FormulaireCand(fr.univlorraine.ecandidat.entities.ecandidat.FormulaireCand) CtrCandShowHistoWindow(fr.univlorraine.ecandidat.views.windows.CtrCandShowHistoWindow) Adresse(fr.univlorraine.ecandidat.entities.ecandidat.Adresse) LinkedHashSet(java.util.LinkedHashSet) TypeDecisionCandidatureRepository(fr.univlorraine.ecandidat.repositories.TypeDecisionCandidatureRepository) CandidatureMasseListener(fr.univlorraine.ecandidat.utils.ListenerUtils.CandidatureMasseListener) Logger(org.slf4j.Logger) TypeTraitement(fr.univlorraine.ecandidat.entities.ecandidat.TypeTraitement) Opi(fr.univlorraine.ecandidat.entities.ecandidat.Opi) Tag(fr.univlorraine.ecandidat.entities.ecandidat.Tag) ChangeCandidatureWindowListener(fr.univlorraine.ecandidat.views.windows.CtrCandActionCandidatureWindow.ChangeCandidatureWindowListener) ApplicationContext(org.springframework.context.ApplicationContext) DroitFonctionnalite(fr.univlorraine.ecandidat.entities.ecandidat.DroitFonctionnalite) Commission(fr.univlorraine.ecandidat.entities.ecandidat.Commission) CandidatCursusInterne(fr.univlorraine.ecandidat.entities.ecandidat.CandidatCursusInterne) Component(org.springframework.stereotype.Component) CandidatureListener(fr.univlorraine.ecandidat.utils.ListenerUtils.CandidatureListener) DateTimeFormatter(java.time.format.DateTimeFormatter) CandidatureRepository(fr.univlorraine.ecandidat.repositories.CandidatureRepository) CtrCandPostItReadWindow(fr.univlorraine.ecandidat.views.windows.CtrCandPostItReadWindow) Candidat(fr.univlorraine.ecandidat.entities.ecandidat.Candidat) Formation(fr.univlorraine.ecandidat.entities.ecandidat.Formation) InputStream(java.io.InputStream) Assert(org.springframework.util.Assert) FormulaireCandidat(fr.univlorraine.ecandidat.entities.ecandidat.FormulaireCandidat) Candidat(fr.univlorraine.ecandidat.entities.ecandidat.Candidat) ExportListCandidatureOption(fr.univlorraine.ecandidat.utils.bean.export.ExportListCandidatureOption) CandidatCursusInterne(fr.univlorraine.ecandidat.entities.ecandidat.CandidatCursusInterne) HashMap(java.util.HashMap) CandidatCursusPostBac(fr.univlorraine.ecandidat.entities.ecandidat.CandidatCursusPostBac)

Example 4 with OnDemandFile

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);
}
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 5 with OnDemandFile

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);
}
Also used : OnDemandStreamFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileUtils.OnDemandStreamFile) OnDemandFileDownloader(fr.univlorraine.ecandidat.vaadin.components.OnDemandFileDownloader) Label(com.vaadin.ui.Label) StatFormationPresentation(fr.univlorraine.ecandidat.utils.bean.presentation.StatFormationPresentation) OnDemandFile(fr.univlorraine.ecandidat.vaadin.components.OnDemandFile) FooterCell(com.vaadin.ui.Grid.FooterCell) HorizontalLayout(com.vaadin.ui.HorizontalLayout) RowReference(com.vaadin.ui.Grid.RowReference) FilterListener(fr.univlorraine.ecandidat.vaadin.components.GridFormatting.FilterListener) Button(com.vaadin.ui.Button) HeaderRow(com.vaadin.ui.Grid.HeaderRow) RowStyleGenerator(com.vaadin.ui.Grid.RowStyleGenerator) Campagne(fr.univlorraine.ecandidat.entities.ecandidat.Campagne)

Aggregations

OnDemandFile (fr.univlorraine.ecandidat.vaadin.components.OnDemandFile)15 HorizontalLayout (com.vaadin.ui.HorizontalLayout)8 Label (com.vaadin.ui.Label)8 OnDemandStreamFile (fr.univlorraine.ecandidat.vaadin.components.OnDemandFileUtils.OnDemandStreamFile)8 OneClickButton (fr.univlorraine.ecandidat.vaadin.components.OneClickButton)7 VerticalLayout (com.vaadin.ui.VerticalLayout)6 OnDemandFileDownloader (fr.univlorraine.ecandidat.vaadin.components.OnDemandFileDownloader)6 InputStream (java.io.InputStream)6 List (java.util.List)6 PostConstruct (javax.annotation.PostConstruct)6 BeanItemContainer (com.vaadin.data.util.BeanItemContainer)5 UI (com.vaadin.ui.UI)5 Candidature (fr.univlorraine.ecandidat.entities.ecandidat.Candidature)5 CentreCandidature (fr.univlorraine.ecandidat.entities.ecandidat.CentreCandidature)5 ByteArrayInOutStream (fr.univlorraine.ecandidat.utils.ByteArrayInOutStream)5 ConstanteUtils (fr.univlorraine.ecandidat.utils.ConstanteUtils)5 Resource (javax.annotation.Resource)5 ApplicationContext (org.springframework.context.ApplicationContext)5 FontAwesome (com.vaadin.server.FontAwesome)4 Alignment (com.vaadin.ui.Alignment)4