r311 - in trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing: content/demande util
Author: echatellier Date: 2014-07-02 12:10:27 +0200 (Wed, 02 Jul 2014) New Revision: 311 Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/311 Log: G?\195?\169n?\195?\169ration d'une page r?\195?\169capitulatif pour les pieces jointes non imprim?\195?\169es Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java 2014-07-02 10:10:11 UTC (rev 310) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java 2014-07-02 10:10:27 UTC (rev 311) @@ -22,20 +22,68 @@ * #L% */ +import static org.nuiton.i18n.I18n.t; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.MouseEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.JComponent; +import javax.swing.JPopupMenu; +import javax.swing.JTable; +import javax.swing.JTree; +import javax.swing.ListSelectionModel; +import javax.swing.SwingUtilities; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.table.TableModel; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.TreeModel; +import javax.swing.tree.TreePath; + +import jaxx.runtime.JAXXUtil; +import jaxx.runtime.validator.swing.SwingValidator; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.io.Charsets; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.decorator.ColorHighlighter; +import org.jdesktop.swingx.decorator.ComponentAdapter; +import org.jdesktop.swingx.decorator.HighlightPredicate; +import org.nuiton.jaxx.application.swing.table.AbstractApplicationTableModel; + import com.ezware.oxbow.swingbits.table.filter.DistinctColumnItem; import com.ezware.oxbow.swingbits.table.filter.ITableFilter; import com.ezware.oxbow.swingbits.table.filter.JTableFilter; import com.ezware.oxbow.swingbits.table.filter.TableRowFilterSupport; import com.franciaflex.faxtomail.persistence.entities.Attachment; import com.franciaflex.faxtomail.persistence.entities.AttachmentFile; -import com.franciaflex.faxtomail.persistence.entities.AttachmentFileImpl; import com.franciaflex.faxtomail.persistence.entities.DemandStatus; import com.franciaflex.faxtomail.persistence.entities.Email; import com.franciaflex.faxtomail.persistence.entities.FaxToMailUser; -import com.franciaflex.faxtomail.persistence.entities.MailField; import com.franciaflex.faxtomail.persistence.entities.History; import com.franciaflex.faxtomail.persistence.entities.HistoryImpl; import com.franciaflex.faxtomail.persistence.entities.HistoryType; +import com.franciaflex.faxtomail.persistence.entities.MailField; import com.franciaflex.faxtomail.persistence.entities.MailFolder; import com.franciaflex.faxtomail.services.FaxToMailServiceUtils; import com.franciaflex.faxtomail.services.service.EmailService; @@ -49,44 +97,8 @@ import com.franciaflex.faxtomail.ui.swing.util.CloseableUI; import com.franciaflex.faxtomail.ui.swing.util.FaxToMailUIUtil; import com.franciaflex.faxtomail.ui.swing.util.FolderTreeNode; +import com.google.common.base.Strings; -import jaxx.runtime.JAXXUtil; -import jaxx.runtime.validator.swing.SwingValidator; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.decorator.ColorHighlighter; -import org.jdesktop.swingx.decorator.ComponentAdapter; -import org.jdesktop.swingx.decorator.HighlightPredicate; -import org.nuiton.jaxx.application.swing.table.AbstractApplicationTableModel; -import org.nuiton.util.pagination.PaginationParameter; - -import javax.swing.*; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; -import javax.swing.table.TableModel; -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.TreeModel; -import javax.swing.tree.TreePath; - -import java.awt.*; -import java.awt.event.MouseEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.Enumeration; -import java.util.List; -import java.util.Map; - -import static org.nuiton.i18n.I18n.t; - /** * Handler of UI {@link com.franciaflex.faxtomail.ui.swing.content.demande.DemandeListUIHandler}. * @@ -501,8 +513,7 @@ boolean take = Boolean.TRUE.equals(selectedFolder.getPrintActionEqualTakeAction()); FaxToMailUser currentUser = getContext().getCurrentUser(); - List<AttachmentFile> nonPrintedAttachment = new ArrayList<AttachmentFile>(); - //TODO kmorin 20140606 print a result page and maybe a page to separate the demands + Map<Email, Collection<AttachmentFile>> nonPrintedAttachment = new HashMap<Email, Collection<AttachmentFile>>(); List<DemandeUIModel> currentEmails = model.getCurrentEmails(); for (DemandeUIModel demandeUIModel : currentEmails) { if (take) { @@ -518,7 +529,7 @@ for (Attachment attachment : demandeUIModel.getAttachment()) { - // force lasy loading + // force lazy loading FaxToMailUIUtil.forceAttachmentFileLoading(getContext(), attachment); AttachmentFile attachmentFile = attachment.getEditedFile(); @@ -529,17 +540,53 @@ if (printable) { FaxToMailUIUtil.print(attachmentFile, true); } else { - nonPrintedAttachment.add(attachmentFile); + + Collection<AttachmentFile> emailAttachments = nonPrintedAttachment.get(email); + if (emailAttachments == null) { + emailAttachments = new ArrayList<AttachmentFile>(); + nonPrintedAttachment.put(email, emailAttachments); + } + emailAttachments.add(attachmentFile); } } } - - // generate a new page with non printed attachment - /*for () { - - }*/ + + // print another page for non printed attachments + if (MapUtils.isNotEmpty(nonPrintedAttachment)) { + InputStream errorPageStream = generateErrorPageStream(nonPrintedAttachment); + FaxToMailUIUtil.print(errorPageStream, true); + } } + /** + * Retourne un flux de données qui correspond à une page de récapitulatif des pièces jointes + * non imprimées. + * + * @param nonPrintedAttachment not printed attachment list + * @return input stream with content + */ + protected InputStream generateErrorPageStream(Map<Email, Collection<AttachmentFile>> nonPrintedAttachment) { + + // generate text content + StringBuilder builder = new StringBuilder(); + builder.append("\nLes pièces-jointes suivantes n'ont pas pu être imprimées:\n"); + + for (Map.Entry<Email, Collection<AttachmentFile>> entry : nonPrintedAttachment.entrySet()) { + Email email = entry.getKey(); + Collection<AttachmentFile> attachments = entry.getValue(); + + builder.append(" * " + Strings.nullToEmpty(email.getCompanyReference()) + " - " + Strings.nullToEmpty(email.getObject()) + " : \n"); + for (AttachmentFile attachmentFile : attachments) { + builder.append(" - " + attachmentFile.getFilename() + "\n"); + } + } + + // convert text content to inputstream + byte[] content = builder.toString().getBytes(Charsets.UTF_8); + InputStream is = new ByteArrayInputStream(content); + return is; + } + public void reply() { DemandeUIModel demand = getModel().getCurrentEmails().get(0); getContext().setCurrentEmail(demand); Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java 2014-07-02 10:10:11 UTC (rev 310) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java 2014-07-02 10:10:27 UTC (rev 311) @@ -31,9 +31,9 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -64,14 +64,11 @@ import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; -import com.google.common.collect.Lists; - import jaxx.runtime.JAXXObject; import jaxx.runtime.JAXXUtil; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.Predicate; -import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -86,7 +83,6 @@ import com.franciaflex.faxtomail.persistence.entities.Attachment; import com.franciaflex.faxtomail.persistence.entities.AttachmentFile; -import com.franciaflex.faxtomail.persistence.entities.AttachmentFileImpl; import com.franciaflex.faxtomail.persistence.entities.ExtensionCommand; import com.franciaflex.faxtomail.persistence.entities.MailFolder; import com.franciaflex.faxtomail.services.service.ConfigurationService; @@ -95,6 +91,7 @@ import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIHandler; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; import com.franciaflex.faxtomail.ui.swing.content.demande.RangeRowModel; +import com.google.common.collect.Lists; /** * @author tchemit <chemit@codelutin.com> @@ -380,14 +377,39 @@ return desktop; } + /** + * Imprime un attachment file. + * + * @param attachmentFile + * @param defaultPrinter if {@code true}, do not display print dialog and print with default printer + */ public static void print(AttachmentFile attachmentFile, boolean defaultPrinter) { FileInputStream textStream = null; try { textStream = new FileInputStream(attachmentFile.getFile()); + print(textStream, defaultPrinter); + } catch (IOException e) { + throw new ApplicationTechnicalException( + t("jaxx.application.error.cannot.print"), e); + } finally { + IOUtils.closeQuietly(textStream); + } + } + + /** + * Imprime un attachment file. + * + * @param inputStream stream to print + * @param defaultPrinter if {@code true}, do not display print dialog and print with default printer + */ + public static void print(InputStream inputStream, boolean defaultPrinter) { + + try { + DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; - Doc mydoc = new SimpleDoc(textStream, flavor, null); + Doc mydoc = new SimpleDoc(inputStream, flavor, null); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); @@ -411,7 +433,7 @@ } else { if (services.length == 0) { - if(defaultService == null) { + if (defaultService == null) { throw new ApplicationBusinessException(t("jaxx.application.error.noPrinter")); } else { @@ -431,14 +453,10 @@ } } - } catch (PrintException | IOException e) { - + } catch (PrintException e) { throw new ApplicationTechnicalException( t("jaxx.application.error.cannot.print"), e); - } finally { - IOUtils.closeQuietly(textStream); } - } public static String getEditedFileName(String originalFileName) {
participants (1)
-
echatellier@users.forge.codelutin.com