Author: kmorin Date: 2014-05-30 11:36:13 +0200 (Fri, 30 May 2014) New Revision: 109 Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/109 Log: fixes #5154 Bug ?\195?\160 l'ajout d'une pi?\195?\168ce jointe dans une r?\195?\169ponse ?\195?\160 un message Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/ReplyFormUIHandler.java Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/ReplyFormUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/ReplyFormUIHandler.java 2014-05-30 09:17:12 UTC (rev 108) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/ReplyFormUIHandler.java 2014-05-30 09:36:13 UTC (rev 109) @@ -25,6 +25,10 @@ */ import static org.nuiton.i18n.I18n.t; + +import com.franciaflex.faxtomail.persistence.entities.AttachmentFileImpl; +import org.apache.commons.io.FileUtils; +import org.nuiton.util.FileUtil; import org.nuiton.validator.bean.simple.SimpleBeanValidator; import java.awt.Component; @@ -207,13 +211,30 @@ public void addAttachment() { JComboBox addAttachmentFile = ui.getAddAttachmentFile(); - AttachmentFile file = (AttachmentFile) addAttachmentFile.getSelectedItem(); - if (file != null) { + AttachmentFile attachmentFile = null; + Object selectedItem = addAttachmentFile.getSelectedItem(); + if (AttachmentFile.class.isAssignableFrom(selectedItem.getClass())) { + attachmentFile = (AttachmentFile) selectedItem; + + } else if (File.class.isAssignableFrom(selectedItem.getClass())) { + File file = (File) selectedItem; + attachmentFile = new AttachmentFileImpl(); + attachmentFile.setFilename(file.getName()); + try { + attachmentFile.setContent(FileUtils.readFileToByteArray(file)); + + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Error while converting the file " + file.getName() + " into a byte[]", e); + } + } + } + if (attachmentFile != null) { ReplyFormUIModel model = getModel(); - model.addAttachment(file); + model.addAttachment(attachmentFile); - model.removeAvailableAttachment(file); - ui.getAddAttachmentFile().removeItem(file); + model.removeAvailableAttachment(attachmentFile); + ui.getAddAttachmentFile().removeItem(attachmentFile); addAttachmentFile.setSelectedItem(null); } @@ -282,13 +303,22 @@ @Override public void setItem(Object anObject) { String text; - //FIXME kmorin 20140523 if set from the filechooser, classcastexception - AttachmentFile file = (AttachmentFile) anObject; + AttachmentFile attachmentFile = null; + if (anObject != null) { + if (AttachmentFile.class.isAssignableFrom(anObject.getClass())) { + attachmentFile = (AttachmentFile) anObject; - if ( anObject != null ) { - text = decorate(file); - oldValue = file; + } else if (File.class.isAssignableFrom(anObject.getClass())) { + File file = (File) anObject; + attachmentFile = new AttachmentFileImpl(); + attachmentFile.setFilename(file.getName()); + } + } + if (attachmentFile != null) { + text = decorate(attachmentFile); + oldValue = attachmentFile; + } else { text = ""; }
participants (1)
-
kmorin@users.forge.codelutin.com