Author: tchemit Date: 2013-03-04 19:03:49 +0100 (Mon, 04 Mar 2013) New Revision: 531 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/531 Log: fixes #1861: [CAPTURE] - Fonctionnalit?\195?\169s de pi?\195?\168ces jointes Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 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/AttachmentEditor.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/ColumnIdentifier.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-03-04 17:05:50 UTC (rev 530) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-03-04 18:03:49 UTC (rev 531) @@ -196,11 +196,11 @@ protected String comment; /** - * Attachments + * Attachments (should never be null). * * @since 0.2 */ - protected List<Attachment> attachments; + protected final List<Attachment> attachments; /** * List of frequencies observed for this batch. @@ -236,6 +236,7 @@ public SpeciesBatchRowModel() { super(SpeciesBatch.class, fromBeanBinder, toBeanBinder); frequency = Lists.newArrayList(); + attachments = Lists.newArrayList(); sortedUnsortedCategory = SampleCategory.newSample(SampleCategoryType.sortedUnsorted); sizeCategory = SampleCategory.newSample(SampleCategoryType.size); sexCategory = SampleCategory.newSample(SampleCategoryType.sex); @@ -278,12 +279,14 @@ } public SpeciesBatchRowModel(SpeciesBatch aBatch, - List<SpeciesBatchFrequency> frequencies) { + List<SpeciesBatchFrequency> frequencies, + List<Attachment> attachments) { this(); fromBean(aBatch); List<SpeciesFrequencyRowModel> frequencyRows = SpeciesFrequencyRowModel.fromBeans(frequencies); frequency.addAll(frequencyRows); + this.attachments.addAll(attachments); Collections.sort(frequency); } @@ -596,11 +599,11 @@ return attachments; } - public void setAttachments(List<Attachment> attachments) { - Object oldValue = getAttachments(); - this.attachments = attachments; - firePropertyChange(PROPERTY_ATTACHMENTS, oldValue, 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/catches/species/SpeciesBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java 2013-03-04 17:05:50 UTC (rev 530) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java 2013-03-04 18:03:49 UTC (rev 531) @@ -139,7 +139,7 @@ n_("tutti.table.species.batch.header.comment"), n_("tutti.table.species.batch.header.comment")); - public static final ColumnIdentifier<SpeciesBatchRowModel> ATTACHMENTS = ColumnIdentifier.newId( + public static final ColumnIdentifier<SpeciesBatchRowModel> ATTACHMENTS = ColumnIdentifier.newReadOnlyId( SpeciesBatchRowModel.PROPERTY_ATTACHMENTS, n_("tutti.table.species.batch.header.file"), n_("tutti.table.species.batch.header.file")); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css 2013-03-04 17:05:50 UTC (rev 530) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.css 2013-03-04 18:03:49 UTC (rev 531) @@ -178,7 +178,7 @@ } #filterSpeciesBatchRootButton { - text: {_("tutti.label.filterSpeciesBatchMode.mode.root", model.getRootNumber())}; + text: {handler.getFilterSpeciesBatchRootButtonText(model.getRootNumber())}; toolTipText: "tutti.label.filterSpeciesBatchMode.mode.root.tip"; value: "root"; selected: {model.isTableViewModeRoot()}; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-03-04 17:05:50 UTC (rev 530) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-03-04 18:03:49 UTC (rev 531) @@ -937,6 +937,10 @@ row.setFrequency(frequencyRows); } + public String getFilterSpeciesBatchRootButtonText(int rootNumber) { + return _("tutti.label.filterSpeciesBatchMode.mode.root", getModel().getRootNumber()); + } + protected void recomputeBatchActionEnable() { int rowIndex = getTable().getSelectedRow(); @@ -1051,11 +1055,16 @@ SpeciesBatchRowModel parentRow, List<SpeciesBatchRowModel> rows) { + String id = aBatch.getId(); + List<SpeciesBatchFrequency> frequencies = - persistenceService.getAllSpeciesBatchFrequency(aBatch.getId()); + persistenceService.getAllSpeciesBatchFrequency(id); + List<Attachment> attachments = + persistenceService.getAllAttachments(Integer.valueOf(id)); + SpeciesBatchRowModel newRow = - new SpeciesBatchRowModel(aBatch, frequencies); + new SpeciesBatchRowModel(aBatch, frequencies, attachments); SampleCategoryEnum sampleCategoryEnum = aBatch.getSampleCategoryType(); Modified: 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/AttachmentCellComponent.java 2013-03-04 17:05:50 UTC (rev 530) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java 2013-03-04 18:03:49 UTC (rev 531) @@ -34,6 +34,7 @@ import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; import jaxx.runtime.SwingUtil; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.util.decorator.Decorator; @@ -106,8 +107,6 @@ protected final AttachmentCellComponent component; -// protected final AttachmentEditorUI ui; - protected AttachmentEditor attachmentEditor; protected Frame frame; @@ -158,8 +157,13 @@ // stop edition stopCellEditing(); + // refresh cell + tableModel.fireTableCellUpdated(r, c); + // reselect this cell AbstractSelectTableAction.doSelectCell(table, r, c); + + // focus on table table.requestFocus(); } }; @@ -315,8 +319,6 @@ private final Decorator<Attachment> decorator; - protected String propertyName; - public AttachmentCellRenderer(Decorator<Attachment> decorator, String noneText) { component = new AttachmentCellComponent(); @@ -336,19 +338,17 @@ if (table != null) { + Collection<Attachment> attachments = (Collection<Attachment>) value; + String textValue; - if (value == null) { - if (propertyName == null) { - AbstractTuttiTableModel tableModel = - (AbstractTuttiTableModel) table.getModel(); - ColumnIdentifier columnIdentifier = tableModel.getPropertyName(column); - propertyName = columnIdentifier.getPropertyName(); - } + + if (CollectionUtils.isEmpty(attachments)) { + // use HTML to show the tooltip in italic textValue = "<i>" + _(noneText) + "</i>"; } else { - Collection<Attachment> attachments = (Collection<Attachment>) value; + StringBuilder sb = new StringBuilder(); for (Attachment attachment : attachments) { sb.append("<br/>").append(decorator.toString(attachment)); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditor.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditor.java 2013-03-04 17:05:50 UTC (rev 530) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditor.java 2013-03-04 18:03:49 UTC (rev 531) @@ -77,6 +77,7 @@ setUndecorated(true); add(editor); setResizable(true); + pack(); ComponentResizer cr = new ComponentResizer(); cr.registerComponent(this); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java 2013-03-04 17:05:50 UTC (rev 530) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java 2013-03-04 18:03:49 UTC (rev 531) @@ -25,7 +25,6 @@ */ import com.ezware.oxbow.swingbits.util.Preconditions; -import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.ui.swing.TuttiUIContext; @@ -115,7 +114,6 @@ Preconditions.checkNotNull(list); list.remove(attachment); - TuttiUIUtil.setProperty(bean, property, list); ui.getAttachments().remove(hbox); @@ -164,10 +162,7 @@ AbstractTuttiBeanUIModel bean = ui.getBean(); String property = ui.getProperty(); List<Attachment> list = (List<Attachment>) TuttiUIUtil.getProperty(bean, property); - if (list == null) { - list = Lists.newArrayList(); - TuttiUIUtil.setProperty(bean, property, list); - } + Preconditions.checkNotNull(list, "Attachments list can not be null"); Attachment attachment = new Attachment(); File file = ui.getFile().getSelectedFile(); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java 2013-03-04 17:05:50 UTC (rev 530) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java 2013-03-04 18:03:49 UTC (rev 531) @@ -73,6 +73,7 @@ import java.awt.event.MouseEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.util.Collection; import java.util.Enumeration; import java.util.List; import java.util.Set; @@ -312,7 +313,12 @@ new HighlightPredicate.AndHighlightPredicate( new MyIdentifierHighlightPredicate(SpeciesBatchTableModel.ATTACHMENTS), // for not null value - new HighlightPredicate.NotHighlightPredicate(new HighlightPredicate.EqualsHighlightPredicate()) + new HighlightPredicate() { + @Override + public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { + return CollectionUtils.isNotEmpty((Collection) adapter.getValue()); + } + } ), cellWithValueColor); table.addHighlighter(attachmentHighlighter); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/ColumnIdentifier.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/ColumnIdentifier.java 2013-03-04 17:05:50 UTC (rev 530) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/ColumnIdentifier.java 2013-03-04 18:03:49 UTC (rev 531) @@ -50,6 +50,22 @@ headerTipI18nKey); } + public static <R> ColumnIdentifier<R> newReadOnlyId(String propertyName, + String headerI18nKey, + String headerTipI18nKey) { + return new ColumnIdentifier<R>(propertyName, + headerI18nKey, + headerTipI18nKey) { + + private static final long serialVersionUID = 1L; + + @Override + public void setValue(R entry, Object value) { + // no set + } + }; + } + protected ColumnIdentifier(String propertyName, String headerI18nKey, String headerTipI18nKey) {