Author: kmorin Date: 2012-12-14 17:59:59 +0100 (Fri, 14 Dec 2012) New Revision: 61 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/61 Log: add attachment editor to the species table Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java trunk/tutti-ui-swing/src/main/resources/icons/action-delete.png Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUIHandler.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchRowModel.java 2012-12-14 16:59:03 UTC (rev 60) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchRowModel.java 2012-12-14 16:59:59 UTC (rev 61) @@ -25,6 +25,7 @@ */ import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.VracHorsVracEnum; @@ -76,6 +77,8 @@ public static final String PROPERTY_COMPUTED_NUMBER = "computedNumber"; public static final String PROPERTY_COMPUTED_WEIGHT = "computedWeight"; + + public static final String PROPERTY_ATTACHMENTS = "attachments"; /** * Species observed. @@ -167,6 +170,13 @@ * @since 0.2 */ protected String comment; + + /** + * Attachments + * + * @since 0.2 + */ + protected List<Attachment> attachments; /** * List of frequencies observed for this batch. @@ -334,6 +344,16 @@ firePropertyChange(PROPERTY_COMMENT, oldValue, comment); } + public List<Attachment> getAttachments() { + return attachments; + } + + public void setAttachments(List<Attachment> attachments) { + Object oldValue = getAttachments(); + this.attachments = attachments; + firePropertyChange(PROPERTY_ATTACHMENTS, oldValue, attachments); + } + public List<SpeciesFrequencyRowModel> getFrequency() { return frequency; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTableModel.java 2012-12-14 16:59:03 UTC (rev 60) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchTableModel.java 2012-12-14 16:59:59 UTC (rev 61) @@ -111,8 +111,8 @@ n_("tutti.table.species.batch.header.comment"), n_("tutti.table.species.batch.header.comment")); - public static final ColumnIdentifier<SpeciesBatchRowModel> FILE = ColumnIdentifier.newId( - null, + public static final ColumnIdentifier<SpeciesBatchRowModel> ATTACHMENTS = ColumnIdentifier.newId( + SpeciesBatchRowModel.PROPERTY_ATTACHMENTS, n_("tutti.table.species.batch.header.file"), n_("tutti.table.species.batch.header.file")); @@ -124,8 +124,8 @@ setNoneEditableCols( SAMPLE_WEIGHT, - SAMPLING_RATIO, - FILE + SAMPLING_RATIO/*, + FILE*/ ); noneEditableColIfNoSpecies = Sets.newHashSet(); noneEditableColIfNoSpecies.add(COMPUTED_NUMBER); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUI.jaxx 2012-12-14 16:59:03 UTC (rev 60) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUI.jaxx 2012-12-14 16:59:59 UTC (rev 61) @@ -31,6 +31,7 @@ fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUI fr.ifremer.tutti.ui.swing.content.operation.species.SpeciesFrequencyUI fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI + fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI org.jdesktop.swingx.JXTable @@ -79,6 +80,8 @@ <SpeciesFrequencyUI id='frequencyUI' constructorParams='handler.getContext()'/> <LongTextEditorUI id='longTextEditorUI'/> + + <AttachmentEditorUI id='attachmentEditorUI'/> <Table id='form' fill='both' constraints='BorderLayout.NORTH'> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUIHandler.java 2012-12-14 16:59:03 UTC (rev 60) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/species/SpeciesBatchUIHandler.java 2012-12-14 16:59:59 UTC (rev 61) @@ -41,6 +41,7 @@ import fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUI; import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; +import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; import fr.ifremer.tutti.ui.swing.util.table.TableRowModificationListener; @@ -117,6 +118,7 @@ SpeciesBatchRowModel.PROPERTY_AGE, SpeciesBatchRowModel.PROPERTY_WEIGHT, SpeciesBatchRowModel.PROPERTY_COMMENT, + SpeciesBatchRowModel.PROPERTY_ATTACHMENTS, SpeciesBatchRowModel.PROPERTY_FREQUENCY); this.ui = ui; this.persistenceService = context.getService(PersistenceService.class); @@ -308,7 +310,9 @@ { // File column addColumnToModel(columnModel, - SpeciesBatchTableModel.FILE); + AttachmentCellComponent.newEditor(ui.getAttachmentEditorUI()), + AttachmentCellComponent.newRender(), + SpeciesBatchTableModel.ATTACHMENTS); } return columnModel; } Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java (from rev 57, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java 2012-12-14 16:59:59 UTC (rev 61) @@ -0,0 +1,260 @@ +package fr.ifremer.tutti.ui.swing.util.editor; + +import fr.ifremer.tutti.ui.swing.util.ComponentResizer; +import com.google.common.base.Preconditions; +import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; +import fr.ifremer.tutti.ui.swing.util.ComponentMover; +import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; +import fr.ifremer.tutti.ui.swing.util.table.AbstractSelectTableAction; +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; +import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; +import java.awt.event.WindowAdapter; +import java.awt.Color; +import java.awt.Component; +import java.awt.Frame; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.WindowEvent; +import javax.swing.AbstractCellEditor; +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JTable; +import javax.swing.border.LineBorder; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import jaxx.runtime.JAXXUtil; +import jaxx.runtime.SwingUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import static org.nuiton.i18n.I18n._; + +/** + * Component to edit a cell containing attachments + * + * @author kmorin + * @since 0.2 + */ +public class AttachmentCellComponent extends JButton { + + /** Logger. */ + private static final Log log = LogFactory.getLog(AttachmentCellComponent.class); + + public AttachmentCellComponent() { + setContentAreaFilled(false); + setOpaque(false); + setIcon(SwingUtil.createActionIcon("edit")); + } + + public static TableCellRenderer newRender() { + return new AttachmentCellRenderer(); + } + + public static TableCellEditor newEditor(AttachmentEditorUI ui) { + return new AttachmentCellEditor(ui); + } + + + public static class AttachmentCellEditor extends AbstractCellEditor implements TableCellEditor { + + protected final AttachmentCellComponent component; + + protected final AttachmentEditorUI ui; + + protected Frame frame; + + protected JTable table; + + protected AbstractTuttiTableModel<AbstractTuttiBeanUIModel> tableModel; + + protected ColumnIdentifier<AbstractTuttiBeanUIModel> columnIdentifier; + + protected AbstractTuttiBeanUIModel editRow; + + protected Integer rowIndex; + + protected Integer columnIndex; + + public AttachmentCellEditor(AttachmentEditorUI ui) { + this.ui = ui; + + component = new AttachmentCellComponent(); + component.setBorder(new LineBorder(Color.BLACK)); + component.addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER || + e.getKeyCode() == KeyEvent.VK_SPACE) { + e.consume(); + startEdit(); + } + } + }); + + component.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + e.consume(); + startEdit(); + } + }); + } + + protected void startEdit() { + if (frame == null) { + frame = SwingUtil.getParentContainer(ui, Frame.class); + } + + ui.setBorder(BorderFactory.createTitledBorder(_(columnIdentifier.getHeaderI18nKey()))); + ui.setBean(editRow); + ui.setProperty(columnIdentifier.getPropertyName()); + + JDialog editor = new JDialog(frame, true); + editor.setUndecorated(true); + editor.add(ui); + editor.setResizable(true); + editor.pack(); + + ComponentResizer cr = new ComponentResizer(); + cr.registerComponent(editor); + ComponentMover cm = new ComponentMover(); + cm.setDragInsets(cr.getDragInsets()); + cm.registerComponent(editor); + + editor.addWindowListener(new WindowAdapter() { + + @Override + public void windowClosed(WindowEvent e) { + Component ui = (Component) e.getSource(); + if (log.isInfoEnabled()) { + log.info("Destroy ui " + ui); + } + JAXXUtil.destroy(ui); + } + }); + + // Computes the location of bottom left corner of the cell + Component comp = component; + int x = 0; + int y = component.getHeight(); + while (comp != null) { + x += comp.getX(); + y += comp.getY(); + comp = comp.getParent(); + } + // if the editor is too big on the right, + // then align its right side to the right side of the cell + if (x + editor.getWidth() > frame.getX() + frame.getWidth()) { + x = x - editor.getWidth() + component.getWidth(); + } + editor.setLocation(x, y); + editor.setVisible(true); + + int r = rowIndex; + int c = columnIndex; + + // stop edition + stopCellEditing(); + + // reselect this cell + AbstractSelectTableAction.doSelectCell(table, r, c); + } + + @Override + public Component getTableCellEditorComponent(JTable table, + Object value, + boolean isSelected, + int row, + int column) { + if (tableModel == null) { + tableModel = (AbstractTuttiTableModel<AbstractTuttiBeanUIModel>) table.getModel(); + this.table = table; + columnIdentifier = tableModel.getPropertyName(column); + } + + rowIndex = row; + columnIndex = column; + + editRow = tableModel.getEntry(row); + + return component; + } + + @Override + public Object getCellEditorValue() { + + Preconditions.checkNotNull(editRow, "No editRow found in editor."); + + String propertyName = columnIdentifier.getPropertyName(); + Object result = TuttiUIUtil.getProperty(editRow, propertyName); + if (log.isInfoEnabled()) { + log.info("editor value (" + propertyName + "): " + result); + } + + return result; + } + + @Override + public boolean stopCellEditing() { + boolean b = super.stopCellEditing(); + if (b) { + rowIndex = null; + editRow = null; + columnIndex = null; + } + return b; + } + + @Override + public void cancelCellEditing() { + super.cancelCellEditing(); + rowIndex = null; + columnIndex = null; + editRow = null; + } + } + + public static class AttachmentCellRenderer implements TableCellRenderer { + + protected final AttachmentCellComponent component; + + protected String propertyName; + + public AttachmentCellRenderer() { + component = new AttachmentCellComponent(); + } + + @Override + public Component getTableCellRendererComponent(JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + int row, + int column) { + + String text; + if (value == null) { + if (propertyName == null) { + AbstractTuttiTableModel tableModel = + (AbstractTuttiTableModel) table.getModel(); + ColumnIdentifier columnIdentifier = tableModel.getPropertyName(column); + propertyName = columnIdentifier.getPropertyName(); + } + // use HTML to show the tooltip in italic + text = "<html><body><i>" + _("tutti.tooltip." + propertyName + ".none") + "</i></body></html>"; + + } else { + // use html to display the tooltip on several lines + text = "<html><body>" + String.valueOf(value).replace("\n", "<br/>") + "</body></html>"; + } + + boolean editable = table.isCellEditable(row, column); + component.setEnabled(editable); + component.setToolTipText(text); + return component; + } + } +} Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.css (from rev 57, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUI.css) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.css (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.css 2012-12-14 16:59:59 UTC (rev 61) @@ -0,0 +1,23 @@ +#fileLabel { + text: "tutti.label.attachmentEditor.file"; + labelFor: {file}; +} + +#fileNameLabel { + text: "tutti.label.attachmentEditor.fileName"; + labelFor: {fileName}; +} + +#fileCommentLabel { + text: "tutti.label.attachmentEditor.fileComment"; + labelFor: {fileComment}; +} + +#addButton { + actionIcon: "add"; +} + +#closeButton { + actionIcon: "close"; + text: "tutti.action.close"; +} Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.jaxx (from rev 57, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUI.jaxx) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.jaxx (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.jaxx 2012-12-14 16:59:59 UTC (rev 61) @@ -0,0 +1,64 @@ +<Table id='mainPanel'> + + <import> + fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel + fr.ifremer.tutti.persistence.entities.data.Attachment + </import> + + <!-- bean property linked state --> + <String id='property' javaBean='""'/> + + <!-- if true, display the form to add attachments + and the button to remove existing attachments --> + <Boolean id='editable' javaBean='true'/> + + <!-- bean property --> + <AbstractTuttiBeanUIModel id='bean' javaBean='null'/> + + <AttachmentEditorUIHandler id='handler' constructorParams='this'/> + + <Attachment id='model' javaBean='null'/> + + <row fill='both'> + <cell fill='both' weightx='1' columns='3'> + <VBox id='attachments'></VBox> + </cell> + </row> + <row fill='both'> + <cell fill='both' weightx='1'> + <JLabel id='fileLabel'/> + </cell> + <cell fill='both' weightx='1'> + <JTextField id='file' + onMouseClicked='handler.chooseFile()'/> + </cell> + <cell fill='both' rows='3'> + <JButton id='addButton' + onActionPerformed='handler.addAttachment()'/> + </cell> + </row> + <row fill='both'> + <cell fill='both' weightx='1'> + <JLabel id='fileNameLabel'/> + </cell> + <cell fill='both' weightx='1'> + <JTextField id='fileName'/> + </cell> + </row> + <row fill='both' weighty='1'> + <cell fill='both' weightx='1'> + <JLabel id='fileCommentLabel'/> + </cell> + <cell fill='both' weightx='1'> + <JScrollPane> + <JTextArea id='fileComment' rows='3'/> + </JScrollPane> + </cell> + </row> + <row fill='both'> + <!-- actions --> + <cell fill='both' weightx='1' columns='3'> + <JButton id='closeButton' onActionPerformed='handler.close()'/> + </cell> + </row> +</Table> \ No newline at end of file Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java (from rev 57, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUIHandler.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java 2012-12-14 16:59:59 UTC (rev 61) @@ -0,0 +1,174 @@ +package fr.ifremer.tutti.ui.swing.util.editor; + +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; +import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; +import java.awt.Cursor; +import java.awt.Desktop; +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.SwingConstants; +import jaxx.runtime.SwingUtil; +import jaxx.runtime.swing.HBox; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Handler of the LongTextEditorUI + * @author kmorin + * @since 0.2 + */ +public class AttachmentEditorUIHandler { + + private static final Log log = LogFactory.getLog(AttachmentEditorUIHandler.class); + + private final AttachmentEditorUI ui; + + private JFileChooser fileChooser = new JFileChooser(); + + public AttachmentEditorUIHandler(AttachmentEditorUI attachmentEditorUI) { + ui = attachmentEditorUI; + + ui.addPropertyChangeListener(new PropertyChangeListener() { + + public void propertyChange(PropertyChangeEvent evt) { + init(); + } + }); + } + + public void init() { + resetFields(); + ui.getAttachments().removeAll(); + AbstractTuttiBeanUIModel bean = ui.getBean(); + String property = ui.getProperty(); + if (bean != null && !StringUtils.isEmpty(property)) { + List<Attachment> list = (List<Attachment>) TuttiUIUtil.getProperty(bean, property); + if (list != null) { + for (Attachment attachment : list) { + addAttachment(attachment); + } + } + } + } + + protected void addAttachment(final Attachment attachment) { + final HBox hbox = new HBox(); + hbox.setVerticalAlignment(SwingConstants.CENTER); + + JButton deleteButton = new JButton(SwingUtil.createActionIcon("delete")); + deleteButton.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + AbstractTuttiBeanUIModel bean = ui.getBean(); + String property = ui.getProperty(); + List<Attachment> list = (List<Attachment>) TuttiUIUtil.getProperty(bean, property); + if (list != null) { + list.remove(attachment); + TuttiUIUtil.setProperty(bean, property, list); + } + + ui.getAttachments().remove(hbox); + + JDialog parent = SwingUtil.getParentContainer(ui, JDialog.class); + parent.pack(); + } + }); + hbox.add(deleteButton); + + final JLabel label = new JLabel("<html><body><a href=''>" + + attachment.getName() + "</a></body></html>"); + label.setToolTipText(attachment.getComment()); + label.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + SwingUtil.openLink("file://" + attachment.getFile().getAbsolutePath()); + } + + @Override + public void mouseEntered(MouseEvent e) { + label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + } + + @Override + public void mouseExited(MouseEvent e) { + label.setCursor(Cursor.getDefaultCursor()); + } + + }); + hbox.add(label); + + ui.getAttachments().add(hbox); + } + + /** + * closes the editor + */ + public void close() { + if (log.isInfoEnabled()) { + log.info("Will close UI " + ui); + } + SwingUtil.getParentContainer(ui, Window.class).dispose(); + } + + public void chooseFile() { + if (fileChooser.showOpenDialog(ui) == JFileChooser.APPROVE_OPTION) { + File file = fileChooser.getSelectedFile(); + ui.getModel().setFile(file); + ui.getFile().setText(file.getAbsolutePath()); + } + } + + public void addAttachment() { + AbstractTuttiBeanUIModel bean = ui.getBean(); + String property = ui.getProperty(); + List<Attachment> list = (List<Attachment>) TuttiUIUtil.getProperty(bean, property); + if (list == null) { + list = Lists.newArrayList(); + } + Attachment attachment = ui.getModel(); + File file = attachment.getFile(); + if (file != null) { + String name = ui.getFileName().getText(); + if (StringUtils.isEmpty(name)) { + name = file.getName(); + } + attachment.setName(name); + attachment.setComment(ui.getFileComment().getText()); + list.add(attachment); + TuttiUIUtil.setProperty(bean, property, list); + + resetFields(); + addAttachment(attachment); + + JDialog parent = SwingUtil.getParentContainer(ui, JDialog.class); + parent.pack(); + } + } + + protected void resetFields() { + ui.setModel(new Attachment()); + fileChooser.setSelectedFile(null); + ui.getFile().setText(""); + ui.getFileName().setText(""); + ui.getFileComment().setText(""); + } + +} Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java 2012-12-14 16:59:03 UTC (rev 60) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java 2012-12-14 16:59:59 UTC (rev 61) @@ -1,7 +1,3 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package fr.ifremer.tutti.ui.swing.util.editor; import fr.ifremer.tutti.ui.swing.util.ComponentResizer; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUIHandler.java 2012-12-14 16:59:03 UTC (rev 60) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUIHandler.java 2012-12-14 16:59:59 UTC (rev 61) @@ -1,7 +1,3 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package fr.ifremer.tutti.ui.swing.util.editor; import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; Added: trunk/tutti-ui-swing/src/main/resources/icons/action-delete.png =================================================================== (Binary files differ) Property changes on: trunk/tutti-ui-swing/src/main/resources/icons/action-delete.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream