r534 - in trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing: content/cruise content/operation content/operation/catches content/operation/catches/accidental content/operation/catches/benthos content/operation/catches/macrowaste content/operation/catches/plankton content/operation/catches/species content/operation/catches/species/frequency content/operation/catches/species/split util util/attachment util/editor util/table
Author: tchemit Date: 2013-03-05 11:45:23 +0100 (Tue, 05 Mar 2013) New Revision: 534 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/534 Log: fixes #1860: [CAMPAGNE] - Fonctionnalit?\195?\169s de pi?\195?\168ces jointes fixes #1963: [CAPTURE] - Global - Ajouter pi?\195?\168ce jointe sur tous les onglets Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentCellEditor.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentCellRenderer.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditor.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentModelAware.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/ButtonAttachmentEditor.java Removed: 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/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 Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java 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.jaxx 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/SpeciesBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiBeanUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUI.css 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUI.css 2013-03-05 10:45:23 UTC (rev 534) @@ -209,4 +209,8 @@ actionIcon: generate; text: "tutti.action.generateCampaignName"; enabled: {model.isCanGenerateName()}; +} + +#attachmentsButton { + enabled: {model.getObjectId() != null}; } \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUI.jaxx 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUI.jaxx 2013-03-05 10:45:23 UTC (rev 534) @@ -30,8 +30,10 @@ fr.ifremer.tutti.persistence.entities.referential.Gear fr.ifremer.tutti.persistence.entities.referential.Person fr.ifremer.tutti.persistence.entities.referential.Vessel + + fr.ifremer.tutti.ui.swing.TuttiUIContext fr.ifremer.tutti.ui.swing.util.TuttiUI - fr.ifremer.tutti.ui.swing.TuttiUIContext + fr.ifremer.tutti.ui.swing.util.attachment.ButtonAttachmentEditor jaxx.runtime.swing.editor.NumberEditor jaxx.runtime.swing.editor.bean.BeanComboBox @@ -93,7 +95,6 @@ <field name='comment' component='commentPane'/> </BeanValidator> - <Table fill='both'> <!-- cruise program / year / program part / name --> @@ -218,12 +219,18 @@ <!-- Form Actions --> <row> <cell columns='6'> - <JPanel layout='{new GridLayout(1, 0)}'> - <JButton id='cancelButton'/> - <JButton id='saveButton'/> + <JPanel layout='{new GridLayout(0,1)}'> + <JButton id='attachmentsButton'/> + <JPanel layout='{new GridLayout(1, 0)}'> + <JButton id='cancelButton'/> + <JButton id='saveButton'/> + </JPanel> </JPanel> </cell> </row> </Table> + <ButtonAttachmentEditor id='attachmentEditor' + initializer='ButtonAttachmentEditor.newEditor(this, attachmentsButton)'/> + </JPanel> \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIHandler.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIHandler.java 2013-03-05 10:45:23 UTC (rev 534) @@ -26,6 +26,7 @@ import com.google.common.base.Predicate; import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.Program; import fr.ifremer.tutti.persistence.entities.referential.Gear; @@ -75,27 +76,31 @@ EditCruiseUIModel model = new EditCruiseUIModel(); - // get vessels + if (context.isCruiseFilled()) { - if (!context.isCruiseFilled()) { + // load existing cruise + Cruise cruise = getDataContext().getCruise(); + model.fromBean(cruise); + + // load attachments + List<Attachment> attachments = persistenceService.getAllAttachments(Integer.valueOf(model.getObjectId())); + model.addAllAttachment(attachments); + + if (log.isDebugEnabled()) { + log.debug("Will edit cruise: " + cruise.getId()); + } + } else { + // create new cruise Program program = getDataContext().getProgram(); model.setProgram(program); model.setMultirigNumber(1); + if (log.isDebugEnabled()) { log.debug("Will create a new cruise from program: " + program); } - } else { - - // load existing program - Cruise cruise = getDataContext().getCruise(); - - model.fromBean(cruise); - if (log.isDebugEnabled()) { - log.debug("Will edit cruise: " + cruise.getId()); - } } listModelIsModify(model); ui.setContextValue(model); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIModel.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIModel.java 2013-03-05 10:45:23 UTC (rev 534) @@ -24,6 +24,9 @@ * #L% */ +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; +import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.Program; import fr.ifremer.tutti.persistence.entities.referential.Country; @@ -31,10 +34,12 @@ import fr.ifremer.tutti.persistence.entities.referential.Person; import fr.ifremer.tutti.persistence.entities.referential.Vessel; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware; import org.apache.commons.lang3.StringUtils; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; +import java.util.Collection; import java.util.Date; import java.util.List; @@ -44,7 +49,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.1 */ -public class EditCruiseUIModel extends AbstractTuttiBeanUIModel<Cruise, EditCruiseUIModel> { +public class EditCruiseUIModel extends AbstractTuttiBeanUIModel<Cruise, EditCruiseUIModel> implements AttachmentModelAware { private static final long serialVersionUID = 1L; @@ -112,6 +117,8 @@ protected VesselTypeEnum vesselType; + protected final List<Attachment> attachment = Lists.newArrayList(); + protected static Binder<EditCruiseUIModel, Cruise> toBeanBinder = BinderFactory.newBinder(EditCruiseUIModel.class, Cruise.class); @@ -284,13 +291,52 @@ return program != null && year != null; } - public static final String cruiseNameFormat = "%1$s_%2$s"; + public static final String CRUISE_NAME_FORMAT = "%1$s_%2$s"; public String getGeneratedCampaignName() { - String name = String.format(cruiseNameFormat, program.getName(), year); + String result = String.format(CRUISE_NAME_FORMAT, program.getName(), year); if (StringUtils.isNotEmpty(surveyPart)) { - name += "_" + surveyPart; + result += "_" + surveyPart; } - return name; + return result; } + + @Override + public AttachementObjectTypeEnum getObjectType() { + return AttachementObjectTypeEnum.SCIENTIFIC_CRUISE; + } + + @Override + public String getObjectId() { + return getId(); + } + + @Override + public List<Attachment> getAttachment() { + return attachment; + } + + @Override + public void addAllAttachment(Collection<Attachment> attachments) { + this.attachment.addAll(attachments); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void addAttachment(Attachment attachment) { + this.attachment.add(attachment); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void removeAllAttachment(Collection<Attachment> attachments) { + this.attachment.removeAll(attachments); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void removeAttachment(Attachment attachment) { + this.attachment.remove(attachment); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } } \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java 2013-03-05 10:45:23 UTC (rev 534) @@ -26,6 +26,7 @@ import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; @@ -52,6 +53,7 @@ import java.awt.BorderLayout; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.util.Collections; import java.util.List; import static org.nuiton.i18n.I18n._; @@ -381,6 +383,8 @@ EditFishingOperationUIModel editFishingOperationUIModel = ui.getModel(); + editFishingOperationUIModel.removeAllAttachment(editFishingOperationUIModel.getAttachment()); + handler.uninstallStartDateListener(); handler.uninstallCoordinatesListener(); @@ -450,9 +454,15 @@ HydrologyTabUI hydrologyTab = ui.getHydrologyTabContent(); hydrologyTab.getHandler().reset(bean); + Integer objectId = Integer.valueOf(editFishingOperationUIModel.getObjectId()); + + List<Attachment> attachments = + getContext().getPersistenceService().getAllAttachments(objectId); + + editFishingOperationUIModel.addAllAttachment(attachments); + editFishingOperationUIModel.setModify(false); handler.getFishingOperationMonitor().clearModified(); - handler.registerValidator(); } @@ -473,6 +483,8 @@ CatchBatch batch; + List<Attachment> attachments; + if (empty) { // create a new CatchBatch @@ -482,6 +494,8 @@ batch = new CatchBatch(); batch.setFishingOperation(bean); + attachments = Collections.emptyList(); + } else { String operationId = bean.getId(); @@ -497,6 +511,11 @@ batch = persistenceService.getCatchBatchFromFishingOperation( operationId, true); batch.setFishingOperation(bean); + + Integer objectId = Integer.valueOf(batch.getId()); + + + attachments = persistenceService.getAllAttachments(objectId); } catchesUIModel.setCatchBatch(batch); @@ -504,6 +523,8 @@ catchesUIModel.fromBean(batch); + catchesUIModel.addAllAttachment(attachments); + catchesUIModel.setModify(false); catchBatchMonitor.clearModified(); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUI.css 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUI.css 2013-03-05 10:45:23 UTC (rev 534) @@ -466,8 +466,7 @@ } #durationField { - text: {TuttiUIUtil.getDuration( - model.getGearShootingStartDate(), model.getGearShootingEndDate())}; + text: {TuttiUIUtil.getDuration(model.getGearShootingStartDate(), model.getGearShootingEndDate())}; enabled: false; _validatorLabel : {_("tutti.label.fishingOperation.duration")}; } @@ -500,5 +499,5 @@ } #attachmentsButton { - _tuttiAction: {AttachmentsAction.class}; + enabled: {model.getId() !=null} } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUI.jaxx 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUI.jaxx 2013-03-05 10:45:23 UTC (rev 534) @@ -34,6 +34,7 @@ fr.ifremer.tutti.ui.swing.content.operation.fishing.environment.EnvironmentTabUI fr.ifremer.tutti.ui.swing.content.operation.fishing.gearshooting.GearShootingTabUI fr.ifremer.tutti.ui.swing.content.operation.fishing.hydrology.HydrologyTabUI + fr.ifremer.tutti.ui.swing.util.attachment.ButtonAttachmentEditor fr.ifremer.tutti.ui.swing.util.editor.CoordinateEditorType fr.ifremer.tutti.ui.swing.util.editor.SimpleTimeEditor fr.ifremer.tutti.ui.swing.util.TuttiUIUtil @@ -158,6 +159,7 @@ <CardLayout2Ext id='gearShootingEndLatitudeLayout' constructorParams='this, "gearShootingEndLatitudePanel"'/> + <JPanel id='fishingOperationPane' constraints='BorderLayout.CENTER' layout='{new BorderLayout()}'> @@ -540,4 +542,7 @@ </JPanel> + <ButtonAttachmentEditor id='attachmentEditor' + initializer='ButtonAttachmentEditor.newEditor(this, attachmentsButton)'/> + </JPanel> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java 2013-03-05 10:45:23 UTC (rev 534) @@ -27,7 +27,9 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.Cruise; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.Program; import fr.ifremer.tutti.persistence.entities.referential.FishingOperationLocation; import fr.ifremer.tutti.persistence.entities.referential.Gear; @@ -98,7 +100,6 @@ getModel().setGearShootingEndDate(newDate); } } - }; private final PropertyChangeListener coordinatePropertiesListener = new PropertyChangeListener() { @@ -595,4 +596,14 @@ getModel().setModify(false); } + public void reset(FishingOperation bean) { + + Integer objectId = Integer.valueOf(bean.getId()); + + List<Attachment> attachments = + getContext().getPersistenceService().getAllAttachments(objectId); + + getModel().removeAllAttachment(getModel().getAttachment()); + getModel().addAllAttachment(attachments); + } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel.java 2013-03-05 10:45:23 UTC (rev 534) @@ -26,6 +26,8 @@ import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; +import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.referential.FishingOperationLocation; @@ -35,12 +37,14 @@ import fr.ifremer.tutti.persistence.spatial.SexagecimalPosition; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware; import fr.ifremer.tutti.ui.swing.util.editor.CoordinateEditorType; import org.nuiton.util.DateUtil; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; import java.util.Calendar; +import java.util.Collection; import java.util.Date; import java.util.List; @@ -52,7 +56,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.1 */ -public class EditFishingOperationUIModel extends AbstractTuttiBeanUIModel<FishingOperation, EditFishingOperationUIModel> { +public class EditFishingOperationUIModel extends AbstractTuttiBeanUIModel<FishingOperation, EditFishingOperationUIModel> implements AttachmentModelAware { private static final long serialVersionUID = 1L; @@ -132,6 +136,8 @@ public static final String PROPERTY_GEAR = "gear"; +// public static final String PROPERTY_ATTACHMENT = "attachment"; + public static final String PROPERTY_VALIDATION_CONTEXT = "validationContext"; /** @@ -183,6 +189,8 @@ protected List<Person> saisisseur = Lists.newArrayList(); + protected final List<Attachment> attachment = Lists.newArrayList(); + protected FishingOperation fishingOperation; protected String validationContext; @@ -248,6 +256,45 @@ this.cruise = cruise; } + @Override + public AttachementObjectTypeEnum getObjectType() { + return AttachementObjectTypeEnum.OPERATION; + } + + @Override + public String getObjectId() { + return getId(); + } + + @Override + public List<Attachment> getAttachment() { + return attachment; + } + + @Override + public void addAllAttachment(Collection<Attachment> attachments) { + this.attachment.addAll(attachments); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void addAttachment(Attachment attachment) { + this.attachment.add(attachment); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void removeAllAttachment(Collection<Attachment> attachments) { + this.attachment.removeAll(attachments); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void removeAttachment(Attachment attachment) { + this.attachment.remove(attachment); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + public String getStationNumber() { return stationNumber; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java 2013-03-05 10:45:23 UTC (rev 534) @@ -11,15 +11,15 @@ * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the + * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public + * + * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 2013-03-05 10:45:23 UTC (rev 534) @@ -224,6 +224,12 @@ _tuttiAction: {ImportPupitriAction.class}; } +#attachmentsButton { + actionIcon: edit-attachment; + toolTipText: "tutti.action.attachments.tip"; + text: {ButtonAttachmentEditor.getButtonText(model.getAttachment())}; +} + #benthosTab { enabled: {false}; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx 2013-03-05 10:45:23 UTC (rev 534) @@ -36,6 +36,7 @@ fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.SplitSpeciesBatchUI fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI + fr.ifremer.tutti.ui.swing.util.attachment.ButtonAttachmentEditor fr.ifremer.tutti.ui.swing.util.editor.TuttiComputedOrNotDataEditor org.jdesktop.swingx.JXTitledPanel @@ -281,6 +282,7 @@ <cell columns='2'> <JPanel layout='{new GridLayout(1,0)}'> <JButton id='importPupitriButton'/> + <JButton id='attachmentsButton'/> </JPanel> </cell> </row> @@ -350,4 +352,7 @@ </JPanel> </JPanel> + <ButtonAttachmentEditor id='attachmentEditor' + initializer='ButtonAttachmentEditor.newEditor(this, attachmentsButton)'/> + </JPanel> \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-03-05 10:45:23 UTC (rev 534) @@ -65,13 +65,6 @@ private static final Log log = LogFactory.getLog(EditCatchesUIHandler.class); -// /** -// * Persistence service. -// * -// * @since 0.3 -// */ -// private final PersistenceService persistenceService; - /** * To monitor changes on the incoming fishing operation. * Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java 2013-03-05 10:45:23 UTC (rev 534) @@ -24,15 +24,21 @@ * #L% */ +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; +import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.util.Collection; +import java.util.List; import static org.nuiton.i18n.I18n._; @@ -40,7 +46,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.3 */ -public class EditCatchesUIModel extends AbstractTuttiBeanUIModel<CatchBatch, EditCatchesUIModel> { +public class EditCatchesUIModel extends AbstractTuttiBeanUIModel<CatchBatch, EditCatchesUIModel> implements AttachmentModelAware { private static final long serialVersionUID = 1L; @@ -92,41 +98,6 @@ public static final String PROPERTY_CATCH_BATCH = "catchBatch"; - /*protected static final Binder<CatchBatch, EditCatchesUIModel> fromBeanBinder = BinderModelBuilder.newEmptyBuilder(CatchBatch.class, EditCatchesUIModel.class) - .addSimpleProperties( - PROPERTY_CATCH_TOTAL_WEIGHT, - PROPERTY_SPECIES_TOTAL_WEIGHT, - PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, - PROPERTY_SPECIES_TOTAL_UNSORTED_WEIGHT, - PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_WEIGHT, - PROPERTY_SPECIES_TOTAL_INERT_WEIGHT, - PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT, - PROPERTY_BENTHOS_TOTAL_WEIGHT, - PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, - PROPERTY_BENTHOS_TOTAL_UNSORTED_WEIGHT, - PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_WEIGHT, - PROPERTY_PLANKTON_TOTAL_WEIGHT, - PROPERTY_PLANKTON_TOTAL_SAMPLE_WEIGHT, - PROPERTY_MACRO_WASTE_TOTAL_WEIGHT - ).toBinder(); - - protected static final Binder<EditCatchesUIModel, CatchBatch> toBeanBinder = BinderModelBuilder.newEmptyBuilder(EditCatchesUIModel.class, CatchBatch.class) - .addSimpleProperties( - PROPERTY_SPECIES_TOTAL_WEIGHT, - PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, - PROPERTY_SPECIES_TOTAL_UNSORTED_WEIGHT, - PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_WEIGHT, - PROPERTY_SPECIES_TOTAL_INERT_WEIGHT, - PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT, - PROPERTY_BENTHOS_TOTAL_WEIGHT, - PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, - PROPERTY_BENTHOS_TOTAL_UNSORTED_WEIGHT, - PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_WEIGHT, - PROPERTY_PLANKTON_TOTAL_WEIGHT, - PROPERTY_PLANKTON_TOTAL_SAMPLE_WEIGHT, - PROPERTY_MACRO_WASTE_TOTAL_WEIGHT - ).toBinder();*/ - protected static final Binder<CatchBatch, EditCatchesUIModel> fromBeanBinder = BinderFactory.newBinder(CatchBatch.class, EditCatchesUIModel.class); protected static final Binder<EditCatchesUIModel, CatchBatch> toBeanBinder = BinderFactory.newBinder(EditCatchesUIModel.class, CatchBatch.class); @@ -175,6 +146,8 @@ protected CatchBatch catchBatch; + protected final List<Attachment> attachment = Lists.newArrayList(); + public EditCatchesUIModel() { super(CatchBatch.class, fromBeanBinder, toBeanBinder); speciesTotalSortedComputedOrNotWeight.addPropertyChangeListener( @@ -463,6 +436,45 @@ firePropertyChange(PROPERTY_MACRO_WASTE_TOTAL_WEIGHT, oldValue, macroWasteTotalWeight); } + @Override + public AttachementObjectTypeEnum getObjectType() { + return AttachementObjectTypeEnum.CATCH_BATCH; + } + + @Override + public String getObjectId() { + return catchBatch == null ? null : catchBatch.getId(); + } + + @Override + public List<Attachment> getAttachment() { + return attachment; + } + + @Override + public void addAllAttachment(Collection<Attachment> attachments) { + this.attachment.addAll(attachments); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void addAttachment(Attachment attachment) { + this.attachment.add(attachment); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void removeAllAttachment(Collection<Attachment> attachments) { + this.attachment.removeAll(attachments); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void removeAttachment(Attachment attachment) { + this.attachment.remove(attachment); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + public void reset() { setSpeciesTotalSampleSortedComputedWeight(null); setSpeciesTotalSortedComputedWeight(null); @@ -472,6 +484,7 @@ setCatchTotalSortedComputedWeight(null); setCatchTotalUnsortedComputedWeight(null); setCatchTotalComputedWeight(null); + removeAllAttachment(getAttachment()); } @Override Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUI.jaxx 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUI.jaxx 2013-03-05 10:45:23 UTC (rev 534) @@ -29,7 +29,6 @@ fr.ifremer.tutti.ui.swing.TuttiUIContext fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI - fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI jaxx.runtime.swing.editor.NumberEditor @@ -62,8 +61,6 @@ <LongTextEditorUI id='longTextEditor'/> - <AttachmentEditorUI id='attachmentEditor'/> - <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> <JXTable id='table' onFocusLost='handler.saveSelectedRowIfRequired(event)'/> </JScrollPane> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java 2013-03-05 10:45:23 UTC (rev 534) @@ -27,6 +27,7 @@ import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; +import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.referential.Species; @@ -35,7 +36,8 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.TuttiUI; -import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentCellEditor; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentCellRenderer; import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.logging.Log; @@ -202,7 +204,7 @@ DefaultTableColumnModelExt columnModel = new DefaultTableColumnModelExt(); - List<Species> allSpecies = persistenceService.getAllSpecies(); + List<Species> allSpecies = getDataContext().getSpecies(); { // Species (by code) column @@ -244,11 +246,15 @@ { // File column + AttachmentCellRenderer renderer = AttachmentCellRenderer.newRender( + getDecorator(Attachment.class, null), + n_("tutti.tooltip.attachment.none")); addColumnToModel(columnModel, - AttachmentCellComponent.newEditor(ui.getAttachmentEditor()), - AttachmentCellComponent.newRender( - getDecorator(Attachment.class, null), - n_("tutti.tooltip.attachment.none")), + AttachmentCellEditor.newEditor(ui, + renderer, + AttachementObjectTypeEnum.SAMPLE + ), + renderer, AccidentalBatchTableModel.ATTACHMENTS); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-03-05 10:45:23 UTC (rev 534) @@ -24,14 +24,18 @@ * #L% */ +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware; import org.apache.commons.collections.CollectionUtils; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; +import java.util.Collection; import java.util.List; /** @@ -40,7 +44,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.2 */ -public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<SpeciesBatch, BenthosBatchRowModel> { +public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<SpeciesBatch, BenthosBatchRowModel> implements AttachmentModelAware { private static final long serialVersionUID = 1L; @@ -111,11 +115,11 @@ protected String comment; /** - * Attachments + * Attachments (should never be null). * * @since 0.2 */ - protected List<Attachment> attachments; + protected final List<Attachment> attachment = Lists.newArrayList(); /** * Parent of this batch (can be null if batch is root). @@ -244,15 +248,47 @@ firePropertyChange(PROPERTY_COMMENT, oldValue, comment); } - public List<Attachment> getAttachments() { - return attachments; + //------------------------------------------------------------------------// + //-- AttachmentModelAware --// + //------------------------------------------------------------------------// + + @Override + public AttachementObjectTypeEnum getObjectType() { + return AttachementObjectTypeEnum.SAMPLE; } - public void setAttachments(List<Attachment> attachments) { - Object oldValue = getAttachments(); - this.attachments = attachments; - firePropertyChange(PROPERTY_ATTACHMENTS, oldValue, attachments); + @Override + public String getObjectId() { + return getId(); } + @Override + public List<Attachment> getAttachment() { + return attachment; + } + @Override + public void addAllAttachment(Collection<Attachment> attachments) { + this.attachment.addAll(attachments); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void addAttachment(Attachment attachment) { + this.attachment.add(attachment); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void removeAllAttachment(Collection<Attachment> attachments) { + this.attachment.removeAll(attachments); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void removeAttachment(Attachment attachment) { + this.attachment.remove(attachment); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java 2013-03-05 10:45:23 UTC (rev 534) @@ -70,8 +70,8 @@ n_("tutti.table.benthos.batch.header.comment"), n_("tutti.table.benthos.batch.header.comment")); - public static final ColumnIdentifier<BenthosBatchRowModel> ATTACHMENTS = ColumnIdentifier.newId( - SpeciesBatchRowModel.PROPERTY_ATTACHMENTS, + public static final ColumnIdentifier<BenthosBatchRowModel> ATTACHMENT = ColumnIdentifier.newId( + BenthosBatchRowModel.PROPERTY_ATTACHMENT, n_("tutti.table.benthos.batch.header.file"), n_("tutti.table.benthos.batch.header.file")); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.jaxx 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUI.jaxx 2013-03-05 10:45:23 UTC (rev 534) @@ -28,8 +28,8 @@ fr.ifremer.tutti.ui.swing.util.TuttiUI fr.ifremer.tutti.ui.swing.TuttiUIContext + fr.ifremer.tutti.ui.swing.util.attachment.ButtonAttachmentEditor fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI - fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI jaxx.runtime.swing.editor.NumberEditor @@ -79,7 +79,7 @@ <LongTextEditorUI id='longTextEditor'/> - <AttachmentEditorUI id='attachmentEditor'/> + <!--<AttachmentEditorUI id='attachmentEditor'/>--> <Table id='form' fill='both' constraints='BorderLayout.NORTH'> @@ -116,6 +116,27 @@ <JTextField id='benthosTotalUnsortedWeightField'/> </cell> </row> + + <!-- Toolbar / Filter --> + <row> + <cell columns="4"> + <JPanel id='tableToolbar' layout='{new BorderLayout()}'> + <JPanel layout='{new GridLayout(1,0)}' constraints='BorderLayout.WEST'> + <!--<JButton id='createSpeciesBatchButton' onActionPerformed='handler.createSpeciesBatch()'/>--> + <JButton id='attachmentsButton'/> + </JPanel> + <!--JPanel id='filterTablePane' constraints='BorderLayout.CENTER'> + <JLabel id='filterSpeciesBatchLabel'/> + <JRadioButton id='filterSpeciesBatchAllButton' + onActionPerformed='model.setTableViewMode(TableViewMode.ALL)'/> + <JRadioButton id='filterSpeciesBatchLeafButton' + onActionPerformed='model.setTableViewMode(TableViewMode.LEAF)'/> + <JRadioButton id='filterSpeciesBatchRootButton' + onActionPerformed='model.setTableViewMode(TableViewMode.ROOT)'/> + </JPanel--> + </JPanel> + </cell> + </row> </Table> <JScrollPane id='tableScrollPane' constraints='BorderLayout.CENTER'> @@ -123,4 +144,7 @@ onFocusLost='handler.saveSelectedRowIfRequired(event)'/> </JScrollPane> + <ButtonAttachmentEditor id='attachmentEditor' + initializer='ButtonAttachmentEditor.newEditor(this, attachmentsButton)'/> + </JPanel> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-03-05 10:45:23 UTC (rev 534) @@ -26,6 +26,7 @@ import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; @@ -35,7 +36,8 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.TuttiUI; -import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentCellEditor; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentCellRenderer; import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.logging.Log; @@ -262,12 +264,15 @@ { // File column + AttachmentCellRenderer renderer = AttachmentCellRenderer.newRender( + getDecorator(Attachment.class, null), + n_("tutti.tooltip.attachment.none")); addColumnToModel(columnModel, - AttachmentCellComponent.newEditor(ui.getAttachmentEditor()), - AttachmentCellComponent.newRender( - getDecorator(Attachment.class, null), - n_("tutti.tooltip.attachment.none")), - BenthosBatchTableModel.ATTACHMENTS); + AttachmentCellEditor.newEditor(ui, + renderer, + AttachementObjectTypeEnum.SAMPLE), + renderer, + BenthosBatchTableModel.ATTACHMENT); } { // Species to confirm column Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.jaxx 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUI.jaxx 2013-03-05 10:45:23 UTC (rev 534) @@ -29,7 +29,6 @@ fr.ifremer.tutti.ui.swing.TuttiUIContext fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI - fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI jaxx.runtime.swing.editor.NumberEditor @@ -72,8 +71,6 @@ <LongTextEditorUI id='longTextEditor'/> - <AttachmentEditorUI id='attachmentEditor'/> - <Table id='form' fill='both' constraints='BorderLayout.NORTH'> <!-- Poids total --> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java 2013-03-05 10:45:23 UTC (rev 534) @@ -26,6 +26,7 @@ import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.MacroWasteBatch; @@ -34,7 +35,8 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.TuttiUI; -import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentCellEditor; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentCellRenderer; import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.logging.Log; @@ -45,6 +47,7 @@ import java.util.List; +import static org.nuiton.i18n.I18n._; import static org.nuiton.i18n.I18n.n_; /** @@ -253,11 +256,14 @@ { // File column + AttachmentCellRenderer renderer = AttachmentCellRenderer.newRender( + getDecorator(Attachment.class, null), + n_("tutti.tooltip.attachment.none")); addColumnToModel(columnModel, - AttachmentCellComponent.newEditor(ui.getAttachmentEditor()), - AttachmentCellComponent.newRender( - getDecorator(Attachment.class, null), - n_("tutti.tooltip.attachment.none")), + AttachmentCellEditor.newEditor(ui, + renderer, + AttachementObjectTypeEnum.SAMPLE), + renderer, MacroWasteBatchTableModel.ATTACHMENTS); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.jaxx 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUI.jaxx 2013-03-05 10:45:23 UTC (rev 534) @@ -28,7 +28,6 @@ fr.ifremer.tutti.ui.swing.util.TuttiUI fr.ifremer.tutti.ui.swing.TuttiUIContext fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI - fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI jaxx.runtime.swing.editor.NumberEditor @@ -73,8 +72,6 @@ <LongTextEditorUI id='longTextEditor'/> - <AttachmentEditorUI id='attachmentEditor'/> - <Table id='form' fill='both' constraints='BorderLayout.NORTH'> <!-- Poids total --> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java 2013-03-05 10:45:23 UTC (rev 534) @@ -26,6 +26,7 @@ import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.PlanktonBatch; @@ -35,7 +36,8 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.TuttiUI; -import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentCellEditor; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentCellRenderer; import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.logging.Log; @@ -46,6 +48,7 @@ import java.util.List; +import static org.nuiton.i18n.I18n._; import static org.nuiton.i18n.I18n.n_; /** @@ -249,11 +252,14 @@ { // File column + AttachmentCellRenderer renderer = AttachmentCellRenderer.newRender( + getDecorator(Attachment.class, null), + n_("tutti.tooltip.attachment.none")); addColumnToModel(columnModel, - AttachmentCellComponent.newEditor(ui.getAttachmentEditor()), - AttachmentCellComponent.newRender( - getDecorator(Attachment.class, null), - n_("tutti.tooltip.attachment.none")), + AttachmentCellEditor.newEditor(ui, + renderer, + AttachementObjectTypeEnum.SAMPLE), + renderer, PlanktonBatchTableModel.ATTACHMENTS); } 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 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-03-05 10:45:23 UTC (rev 534) @@ -25,6 +25,7 @@ */ import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; @@ -34,12 +35,14 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyRowModel; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware; import org.apache.commons.collections.CollectionUtils; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.util.Collection; import java.util.Collections; import java.util.List; @@ -49,7 +52,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.2 */ -public class SpeciesBatchRowModel extends AbstractTuttiBeanUIModel<SpeciesBatch, SpeciesBatchRowModel> { +public class SpeciesBatchRowModel extends AbstractTuttiBeanUIModel<SpeciesBatch, SpeciesBatchRowModel> implements AttachmentModelAware { private static final long serialVersionUID = 1L; @@ -101,8 +104,6 @@ public static final String PROPERTY_COMPUTED_WEIGHT = "computedOrNotWeight"; - public static final String PROPERTY_ATTACHMENTS = "attachments"; - public static final String PROPERTY_PARENT_BATCH = "parentBatch"; public static final String PROPERTY_CHILD_BATCH = "childBatch"; @@ -200,14 +201,14 @@ * * @since 0.2 */ - protected final List<Attachment> attachments; + protected final List<Attachment> attachment = Lists.newArrayList(); /** * List of frequencies observed for this batch. * * @since 0.2 */ - protected List<SpeciesFrequencyRowModel> frequency; + protected List<SpeciesFrequencyRowModel> frequency = Lists.newArrayList(); /** * Parent of this batch (can be null if batch is root). @@ -235,8 +236,6 @@ 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); @@ -286,7 +285,7 @@ List<SpeciesFrequencyRowModel> frequencyRows = SpeciesFrequencyRowModel.fromBeans(frequencies); frequency.addAll(frequencyRows); - this.attachments.addAll(attachments); + this.attachment.addAll(attachments); Collections.sort(frequency); } @@ -556,6 +555,49 @@ } //------------------------------------------------------------------------// + //-- AttachmentModelAware --// + //------------------------------------------------------------------------// + + @Override + public AttachementObjectTypeEnum getObjectType() { + return AttachementObjectTypeEnum.SAMPLE; + } + + @Override + public String getObjectId() { + return getId(); + } + + @Override + public List<Attachment> getAttachment() { + return attachment; + } + + @Override + public void addAllAttachment(Collection<Attachment> attachments) { + this.attachment.addAll(attachments); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void addAttachment(Attachment attachment) { + this.attachment.add(attachment); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void removeAllAttachment(Collection<Attachment> attachments) { + this.attachment.removeAll(attachments); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void removeAttachment(Attachment attachment) { + this.attachment.remove(attachment); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + //------------------------------------------------------------------------// //-- Other properties --// //------------------------------------------------------------------------// @@ -596,15 +638,9 @@ } public List<Attachment> getAttachments() { - return attachments; + return attachment; } -// 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 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java 2013-03-05 10:45:23 UTC (rev 534) @@ -139,8 +139,8 @@ n_("tutti.table.species.batch.header.comment"), n_("tutti.table.species.batch.header.comment")); - public static final ColumnIdentifier<SpeciesBatchRowModel> ATTACHMENTS = ColumnIdentifier.newReadOnlyId( - SpeciesBatchRowModel.PROPERTY_ATTACHMENTS, + public static final ColumnIdentifier<SpeciesBatchRowModel> ATTACHMENT = ColumnIdentifier.newReadOnlyId( + SpeciesBatchRowModel.PROPERTY_ATTACHMENT, 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.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx 2013-03-05 10:45:23 UTC (rev 534) @@ -27,8 +27,8 @@ <import> fr.ifremer.tutti.ui.swing.util.TuttiUI + fr.ifremer.tutti.ui.swing.util.attachment.ButtonAttachmentEditor fr.ifremer.tutti.ui.swing.util.editor.LongTextEditorUI - fr.ifremer.tutti.ui.swing.util.editor.AttachmentEditorUI fr.ifremer.tutti.ui.swing.util.editor.TuttiComputedOrNotDataEditor org.jdesktop.swingx.JXTable @@ -75,8 +75,6 @@ <LongTextEditorUI id='longTextEditor'/> - <!--<AttachmentEditorUI id='attachmentEditor'/>--> - <JPopupMenu id='tablePopup'> <!--onPopupMenuWillBecomeVisible='handler.updateTablePopup()'>--> <JMenuItem id='splitSpeciesBatchMenu' @@ -143,8 +141,11 @@ <row> <cell columns="4"> <JPanel id='tableToolbar' layout='{new BorderLayout()}'> - <JButton id='createSpeciesBatchButton' constraints='BorderLayout.WEST' - onActionPerformed='handler.createSpeciesBatch()'/> + <JPanel layout='{new GridLayout(1,0)}' constraints='BorderLayout.WEST'> + <JButton id='createSpeciesBatchButton' + onActionPerformed='handler.createSpeciesBatch()'/> + <JButton id='attachmentsButton'/> + </JPanel> <JPanel id='filterTablePane' constraints='BorderLayout.CENTER'> <JLabel id='filterSpeciesBatchLabel'/> <JRadioButton id='filterSpeciesBatchAllButton' @@ -165,4 +166,7 @@ onMouseClicked='handler.autoSelectRowInTable(event, tablePopup)'/> </JScrollPane> + <ButtonAttachmentEditor id='attachmentEditor' + initializer='ButtonAttachmentEditor.newEditor(this, attachmentsButton)'/> + </JPanel> 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 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-03-05 10:45:23 UTC (rev 534) @@ -10,15 +10,15 @@ * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the + * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public + * + * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% @@ -57,7 +57,8 @@ import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.TuttiUI; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; -import fr.ifremer.tutti.ui.swing.util.editor.AttachmentCellComponent; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentCellEditor; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentCellRenderer; import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; import fr.ifremer.tutti.ui.swing.util.editor.TuttiComputedOrNotDataTableCell; import fr.ifremer.tutti.ui.swing.util.table.AbstractSelectTableAction; @@ -145,7 +146,7 @@ SpeciesBatchRowModel.PROPERTY_WEIGHT, SpeciesBatchRowModel.PROPERTY_NUMBER, SpeciesBatchRowModel.PROPERTY_COMMENT, - SpeciesBatchRowModel.PROPERTY_ATTACHMENTS, + SpeciesBatchRowModel.PROPERTY_ATTACHMENT, SpeciesBatchRowModel.PROPERTY_FREQUENCY, SpeciesBatchRowModel.PROPERTY_SPECIES_TO_CONFIRM); tableFilters = new EnumMap<TableViewMode, RowFilter<SpeciesBatchTableModel, Integer>>(TableViewMode.class); @@ -209,6 +210,8 @@ } rows = Lists.newArrayList(); + model.removeAllAttachment(model.getAttachment()); + if (!TuttiEntities.isNew(bean)) { // get all batch species root (says the one with only a species sample category) @@ -217,15 +220,16 @@ model.setRootBatchId(rootSpeciesBatch.getId()); + List<Attachment> attachments = + persistenceService.getAllAttachments(Integer.valueOf(model.getObjectId())); + model.addAllAttachment(attachments); + if (log.isInfoEnabled()) { log.info("species root batch id: " + model.getRootBatchId()); } List<SpeciesBatch> catches = rootSpeciesBatch.getChildren(); -// List<SpeciesBatch> catches = -// persistenceService.getAllRootSpeciesBatch(bean.getId()); -// for (SpeciesBatch aBatch : catches) { // root batch sample categroy is species @@ -622,15 +626,15 @@ { // File column + AttachmentCellRenderer renderer = AttachmentCellRenderer.newRender( + getDecorator(Attachment.class, null), + n_("tutti.tooltip.attachment.none")); addColumnToModel(columnModel, - AttachmentCellComponent.newEditor(ui, - AttachementObjectTypeEnum.SAMPLE, - "id", - _(SpeciesBatchTableModel.ATTACHMENTS.getHeaderI18nKey())), - AttachmentCellComponent.newRender( - getDecorator(Attachment.class, null), - n_("tutti.tooltip.attachment.none")), - SpeciesBatchTableModel.ATTACHMENTS); + AttachmentCellEditor.newEditor(ui, + renderer, + AttachementObjectTypeEnum.SAMPLE), + renderer, + SpeciesBatchTableModel.ATTACHMENT); } { // Species to confirm column @@ -938,7 +942,7 @@ } public String getFilterSpeciesBatchRootButtonText(int rootNumber) { - return _("tutti.label.filterSpeciesBatchMode.mode.root", getModel().getRootNumber()); + return _("tutti.label.filterSpeciesBatchMode.mode.root", rootNumber); } protected void recomputeBatchActionEnable() { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java 2013-03-05 10:45:23 UTC (rev 534) @@ -25,20 +25,25 @@ */ import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Lists; import com.google.common.collect.Multimap; +import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; +import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchUIModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware; +import java.util.Collection; import java.util.List; /** * @author tchemit <chemit@codelutin.com> * @since 0.1 */ -public class SpeciesBatchUIModel extends AbstractTuttiBatchUIModel<SpeciesBatchRowModel, SpeciesBatchUIModel> { +public class SpeciesBatchUIModel extends AbstractTuttiBatchUIModel<SpeciesBatchRowModel, SpeciesBatchUIModel> implements AttachmentModelAware { private static final long serialVersionUID = 1L; @@ -138,6 +143,8 @@ /** @since 1.0 */ protected int leafNumber; + protected final List<Attachment> attachment = Lists.newArrayList(); + private boolean renameSpeciesBatchEnabled; private String rootBatchId; @@ -346,4 +353,44 @@ public String getRootBatchId() { return rootBatchId; } + + @Override + public AttachementObjectTypeEnum getObjectType() { + return AttachementObjectTypeEnum.CATCH_BATCH; + } + + @Override + public String getObjectId() { + return rootBatchId; + } + + @Override + public List<Attachment> getAttachment() { + return attachment; + } + + @Override + public void addAllAttachment(Collection<Attachment> attachments) { + this.attachment.addAll(attachments); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void addAttachment(Attachment attachment) { + this.attachment.add(attachment); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void removeAllAttachment(Collection<Attachment> attachments) { + this.attachment.removeAll(attachments); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + + @Override + public void removeAttachment(Attachment attachment) { + this.attachment.remove(attachment); + firePropertyChange(PROPERTY_ATTACHMENT, null, getAttachment()); + } + } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java 2013-03-05 10:45:23 UTC (rev 534) @@ -10,15 +10,15 @@ * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the + * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public + * + * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java 2013-03-05 10:45:23 UTC (rev 534) @@ -10,15 +10,15 @@ * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the + * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public + * + * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% @@ -434,4 +434,4 @@ getModel().setRows(rows); } -} \ No newline at end of file +} Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiBeanUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiBeanUIModel.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiBeanUIModel.java 2013-03-05 10:45:23 UTC (rev 534) @@ -24,8 +24,8 @@ * #L% */ +import fr.ifremer.tutti.TuttiTechnicalException; import fr.ifremer.tutti.persistence.entities.IdAware; -import fr.ifremer.tutti.TuttiTechnicalException; import org.jdesktop.beans.AbstractSerializableBean; import org.nuiton.util.beans.Binder; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java 2013-03-05 10:45:23 UTC (rev 534) @@ -38,6 +38,7 @@ import fr.ifremer.tutti.ui.swing.content.MainUIHandler; import fr.ifremer.tutti.ui.swing.util.action.AbstractTuttiAction; import fr.ifremer.tutti.ui.swing.util.action.TuttiUIAction; +import fr.ifremer.tutti.ui.swing.util.attachment.ButtonAttachmentEditor; import fr.ifremer.tutti.ui.swing.util.editor.SimpleTimeEditor; import jaxx.runtime.JAXXUtil; import jaxx.runtime.SwingUtil; @@ -309,6 +310,9 @@ } else if (component instanceof SimpleTimeEditor) { initTimeEditor((SimpleTimeEditor) component); + } else if (component instanceof ButtonAttachmentEditor) { + initButtonAttachmentEditor((ButtonAttachmentEditor) component); + } else if (component instanceof JLabel) { JLabel jLabel = (JLabel) component; Boolean strongStyle = (Boolean) jLabel.getClientProperty("strongStyle"); @@ -346,6 +350,11 @@ } } + protected void initButtonAttachmentEditor(ButtonAttachmentEditor component) { + + component.init(); + } + protected <A extends AbstractTuttiAction> void initAction(AbstractButton abstractButton, Class<A> actionName) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java 2013-03-05 10:45:23 UTC (rev 534) @@ -1,7 +1,7 @@ package fr.ifremer.tutti.ui.swing.util; -import org.jdesktop.beans.AbstractBean; +import org.jdesktop.beans.AbstractSerializableBean; /* * #%L @@ -28,12 +28,14 @@ */ /** @author kmorin <kmorin@codelutin.com> */ -public class TuttiComputedOrNotData<N extends Number> extends AbstractBean { +public class TuttiComputedOrNotData<N extends Number> extends AbstractSerializableBean { public static final String PROPERTY_DATA = "data"; public static final String PROPERTY_COMPUTED_DATA = "computedData"; + private static final long serialVersionUID = 1L; + protected N data; protected N computedData; Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentCellEditor.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentCellEditor.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentCellEditor.java 2013-03-05 10:45:23 UTC (rev 534) @@ -0,0 +1,201 @@ +package fr.ifremer.tutti.ui.swing.util.attachment; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; +import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; +import fr.ifremer.tutti.ui.swing.util.TuttiUI; +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 jaxx.runtime.SwingUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.AbstractCellEditor; +import javax.swing.JTable; +import javax.swing.border.LineBorder; +import javax.swing.table.TableCellEditor; +import java.awt.Color; +import java.awt.Component; +import java.awt.Frame; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import static org.nuiton.i18n.I18n._; + +/** + * To edit attachments from a table cell. + * + * @author tchemit <chemit@codelutin.com> + * @author kmorin <morin@codelutin.com> + * @since 1.0.2 + */ +public class AttachmentCellEditor extends AbstractCellEditor implements TableCellEditor { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = LogFactory.getLog(AttachmentCellEditor.class); + + public static TableCellEditor newEditor(TuttiUI ui, + AttachmentCellRenderer renderer, + AttachementObjectTypeEnum objectType) { + + Frame frame = SwingUtil.getParentContainer(ui, Frame.class); + + renderer.setBorder(new LineBorder(Color.BLACK)); + + return new AttachmentCellEditor(frame, renderer, objectType); + } + + protected final AttachmentCellRenderer component; + + protected AttachmentEditor attachmentEditor; + + protected JTable table; + + protected AbstractTuttiTableModel<AbstractTuttiBeanUIModel> tableModel; + + protected ColumnIdentifier<AbstractTuttiBeanUIModel> columnIdentifier; + + protected AttachmentModelAware editRow; + + protected Integer rowIndex; + + protected Integer columnIndex; + + protected PropertyChangeListener reloadAttachmentEditorTextListener; + + public AttachmentCellEditor(Frame frame, + AttachmentCellRenderer component, + AttachementObjectTypeEnum objectTypeProperty) { + + this.component = component; + + reloadAttachmentEditorTextListener = new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + + tableModel.fireTableCellUpdated(rowIndex, columnIndex); +// List<Attachment> attachment = (List<Attachment>) evt.getNewValue(); +// AttachmentCellEditor.this.component.setText(ButtonAttachmentEditor.getButtonText(attachment)); + } + }; + + this.attachmentEditor = new AttachmentEditor(frame, + component, + objectTypeProperty, + _("tutti.table.accidental.batch.header.file")) { + + private static final long serialVersionUID = 1L; + + @Override + protected AttachmentModelAware getBean() { + return editRow; + } + + @Override + public void startEdit() { + + ((AbstractTuttiBeanUIModel) getBean()).addPropertyChangeListener(AttachmentModelAware.PROPERTY_ATTACHMENT, reloadAttachmentEditorTextListener); + + try { + super.startEdit(); + int r = rowIndex; + int c = columnIndex; + + // stop edition + stopCellEditing(); + + // refresh cell + tableModel.fireTableCellUpdated(r, c); + + // reselect this cell + AbstractSelectTableAction.doSelectCell(table, r, c); + + // focus on table + table.requestFocus(); + } finally { + + ((AbstractTuttiBeanUIModel) getBean()).removePropertyChangeListener(AttachmentModelAware.PROPERTY_ATTACHMENT, reloadAttachmentEditorTextListener); + } + } + }; + } + + @Override + public Component getTableCellEditorComponent(JTable table, + Object value, + boolean isSelected, + int row, + int column) { + this.table = table; + this.tableModel = (AbstractTuttiTableModel<AbstractTuttiBeanUIModel>) table.getModel(); + columnIdentifier = tableModel.getPropertyName(column); + + rowIndex = row; + columnIndex = column; + + editRow = (AttachmentModelAware) 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; + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentCellEditor.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentCellRenderer.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentCellRenderer.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentCellRenderer.java 2013-03-05 10:45:23 UTC (rev 534) @@ -0,0 +1,115 @@ +package fr.ifremer.tutti.ui.swing.util.attachment; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import jaxx.runtime.SwingUtil; +import org.apache.commons.collections.CollectionUtils; +import org.nuiton.util.decorator.Decorator; + +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; +import java.awt.Component; +import java.util.Collection; + +import static org.nuiton.i18n.I18n._; + +/** + * Renderer of a attachement editor in a table cell. + * + * @author kmorin <morin@codelutin.com> + * @author tchemit <chemit@codelutin.com> + * @since 1.0.2 + */ +public class AttachmentCellRenderer extends DefaultTableCellRenderer { + + + public static final String TEXT_PATTERN = "<html><body>%s</body></html>"; + + private static final long serialVersionUID = 1L; + + private final String noneText; + + private final Decorator<Attachment> decorator; + + public static AttachmentCellRenderer newRender(Decorator<Attachment> decorator, + String noneText) { + return new AttachmentCellRenderer(decorator, noneText); + } + + protected AttachmentCellRenderer(Decorator<Attachment> decorator, + String noneText) { + setHorizontalAlignment(CENTER); + setIcon(SwingUtil.createActionIcon("edit-attachment")); + this.noneText = noneText; + this.decorator = decorator; + } + + @Override + protected void setValue(Object value) { + // do nothing + } + + @Override + public Component getTableCellRendererComponent(JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + int row, + int column) { + +// if (table != null) { + + Collection<Attachment> attachments = (Collection<Attachment>) value; + + String textValue; + String toolTipTextValue; + + if (CollectionUtils.isEmpty(attachments)) { + + // use HTML to show the tooltip in italic + toolTipTextValue = "<i>" + _(noneText) + "</i>"; + + textValue = null; + } else { + + StringBuilder sb = new StringBuilder(); + for (Attachment attachment : attachments) { + sb.append("<br/>").append(decorator.toString(attachment)); + } + // use html to display the tooltip on several lines + toolTipTextValue = sb.substring(5); + textValue = "(" + attachments.size() + ")"; + } + boolean editable = table.isCellEditable(row, column); + toolTipTextValue = String.format(TEXT_PATTERN, toolTipTextValue); + setEnabled(editable); + setText(textValue); + setToolTipText(toolTipTextValue); +// } + + return this; + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentCellRenderer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditor.java (from rev 531, 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/attachment/AttachmentEditor.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditor.java 2013-03-05 10:45:23 UTC (rev 534) @@ -0,0 +1,155 @@ +package fr.ifremer.tutti.ui.swing.util.attachment; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.ezware.oxbow.swingbits.util.Preconditions; +import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; +import jaxx.runtime.JAXXUtil; +import jaxx.runtime.swing.ComponentMover; +import jaxx.runtime.swing.ComponentResizer; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.BorderFactory; +import javax.swing.JComponent; +import javax.swing.JDialog; +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.WindowAdapter; +import java.awt.event.WindowEvent; + +/** + * Editor of attachment. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0.2 + */ +public abstract class AttachmentEditor extends JDialog { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = LogFactory.getLog(AttachmentEditor.class); + + protected AttachmentEditorUI editor; + + protected JComponent component; + + public AttachmentEditor(Frame owner, + JComponent component, + AttachementObjectTypeEnum objectType, + String title) { + super(owner, true); + + Preconditions.checkNotNull( + component, + "AttachmentEditor.component can not be null"); + this.component = component; + this.editor = new AttachmentEditorUI(); + editor.setBorder(BorderFactory.createTitledBorder(title)); + editor.setObjectType(objectType); + editor.setObjectIdProperty(AttachmentModelAware.PROPERTY_OBJECT_ID); + + setUndecorated(true); + add(editor); + setResizable(true); + pack(); + + ComponentResizer cr = new ComponentResizer(); + cr.registerComponent(this); + ComponentMover cm = new ComponentMover(); + cm.setDragInsets(cr.getDragInsets()); + cm.registerComponent(this); + + 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); + } + }); + + component.addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER || + e.getKeyCode() == KeyEvent.VK_SPACE) { + e.consume(); + if (((JComponent) e.getSource()).isEnabled()) { + startEdit(); + } + } + } + }); + + component.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + e.consume(); + if (((JComponent) e.getSource()).isEnabled()) { + startEdit(); + } + } + }); + } + + protected abstract AttachmentModelAware getBean(); + + public void startEdit() { + + editor.setBean(getBean()); + + // 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(); + } + + pack(); + // if the editor is too big on the right, + // then align its right side to the right side of the cell + if (x + getWidth() > getOwner().getX() + getOwner().getWidth()) { + x = x - getWidth() + component.getWidth(); + } + setLocation(x, y); + setVisible(true); + } + + protected JComponent getComponent() { + return component; + } +} Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUI.css (from rev 529, 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/attachment/AttachmentEditorUI.css (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUI.css 2013-03-05 10:45:23 UTC (rev 534) @@ -0,0 +1,47 @@ +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +#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"; + mnemonic: F; +} Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUI.jaxx (from rev 530, 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/attachment/AttachmentEditorUI.jaxx (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUI.jaxx 2013-03-05 10:45:23 UTC (rev 534) @@ -0,0 +1,92 @@ +<!-- + #%L + Tutti :: UI + $Id$ + $HeadURL$ + %% + Copyright (C) 2012 Ifremer + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --> +<Table id='mainPanel'> + + <import> + fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel + fr.ifremer.tutti.persistence.entities.data.Attachment + fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum + jaxx.runtime.swing.editor.FileEditor + </import> + + <!-- bean property where to find the objectId to attach to Attachment (see Attachment#objectId) --> + <String id='objectIdProperty' javaBean='""'/> + + <!-- object type of attachments (see Attachment#objectType) --> + <AttachementObjectTypeEnum id='objectType' javaBean='null'/> + + <!-- 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 --> + <AttachmentModelAware id='bean' javaBean='null'/> + + <AttachmentEditorUIHandler id='handler' constructorParams='this'/> + + <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'> + <FileEditor id='file'/> + </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/attachment/AttachmentEditorUIHandler.java (from rev 531, 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/attachment/AttachmentEditorUIHandler.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUIHandler.java 2013-03-05 10:45:23 UTC (rev 534) @@ -0,0 +1,186 @@ +package fr.ifremer.tutti.ui.swing.util.attachment; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.ui.swing.TuttiUIContext; +import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; +import jaxx.runtime.SwingUtil; +import jaxx.runtime.swing.HBox; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.SwingConstants; +import java.awt.Cursor; +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.util.List; + +/** + * @author kmorin <morin@codelutin.com> + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class AttachmentEditorUIHandler { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(AttachmentEditorUIHandler.class); + + private final AttachmentEditorUI ui; + + private final PersistenceService persistenceService; + + public AttachmentEditorUIHandler(AttachmentEditorUI ui) { + this.ui = ui; + persistenceService = + TuttiUIContext.getApplicationContext().getPersistenceService(); + + + this.ui.addPropertyChangeListener(new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + init(); + } + }); + } + + public void init() { + resetFields(); + ui.getAttachments().removeAll(); + AttachmentModelAware bean = ui.getBean(); + if (bean != null) { + List<Attachment> list = bean.getAttachment(); + 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() { + + @Override + public void actionPerformed(ActionEvent e) { + AttachmentModelAware bean = ui.getBean(); + + persistenceService.deleteAttachment(attachment.getId()); + + bean.removeAttachment(attachment); + + 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) { + File file = persistenceService.getAttachmentFile(attachment.getId()); + SwingUtil.openLink("file://" + file.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 addAttachment() { + AttachmentModelAware bean = ui.getBean(); + Attachment attachment = new Attachment(); + + File file = ui.getFile().getSelectedFile(); + if (file != null) { + String name = ui.getFileName().getText(); + if (StringUtils.isEmpty(name)) { + name = file.getName(); + } + attachment.setObjectType(ui.getObjectType()); + attachment.setObjectId(Integer.valueOf(String.valueOf(TuttiUIUtil.getProperty(bean, ui.getObjectIdProperty())))); + attachment.setName(name); + attachment.setComment(ui.getFileComment().getText()); + + attachment = persistenceService.createAttachment(attachment, file); + bean.addAttachment(attachment); + + resetFields(); + addAttachment(attachment); + + JDialog parent = SwingUtil.getParentContainer(ui, JDialog.class); + parent.pack(); + } + } + + protected void resetFields() { + ui.getFile().setSelectedFile((File) null); + ui.getFileName().setText(""); + ui.getFileComment().setText(""); + } + +} Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentModelAware.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentModelAware.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentModelAware.java 2013-03-05 10:45:23 UTC (rev 534) @@ -0,0 +1,60 @@ +package fr.ifremer.tutti.ui.swing.util.attachment; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; +import fr.ifremer.tutti.persistence.entities.data.Attachment; + +import java.io.Serializable; +import java.util.Collection; +import java.util.List; + +/** + * To place on model wich supports attachments. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0.2 + */ +public interface AttachmentModelAware extends Serializable { + + String PROPERTY_ATTACHMENT = "attachment"; + + String PROPERTY_OBJECT_ID = "objectId"; + + AttachementObjectTypeEnum getObjectType(); + + String getObjectId(); + + List<Attachment> getAttachment(); + + void addAllAttachment(Collection<Attachment> attachments); + + void addAttachment(Attachment attachment); + + void removeAllAttachment(Collection<Attachment> attachments); + + void removeAttachment(Attachment attachment); + +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentModelAware.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/ButtonAttachmentEditor.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/ButtonAttachmentEditor.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/ButtonAttachmentEditor.java 2013-03-05 10:45:23 UTC (rev 534) @@ -0,0 +1,103 @@ +package fr.ifremer.tutti.ui.swing.util.attachment; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.ui.swing.util.TuttiUI; +import jaxx.runtime.SwingUtil; +import org.jdesktop.beans.AbstractSerializableBean; + +import javax.swing.JButton; +import java.awt.Frame; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Collections; +import java.util.List; + +import static org.nuiton.i18n.I18n._; + +/** + * To show attachment editor on a button. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0.2 + */ +public class ButtonAttachmentEditor extends AttachmentEditor { + + private static final long serialVersionUID = 1L; + + public static String getButtonText(List<Attachment> attachment) { + return _("tutti.action.attachments", attachment.size()); + } + + public static ButtonAttachmentEditor newEditor(TuttiUI ui, + JButton button) { + + Frame frame = SwingUtil.getParentContainer(ui, Frame.class); + + return new ButtonAttachmentEditor(frame, + button, + (AttachmentModelAware) ui.getModel() + ); + } + + protected final AttachmentModelAware model; + + protected ButtonAttachmentEditor(Frame owner, + JButton component, + AttachmentModelAware model) { + super(owner, + component, + model.getObjectType(), + null); + this.model = model; + } + + @Override + protected AttachmentModelAware getBean() { + return model; + } + + protected JButton getComponent() { + return (JButton) component; + } + + public void init() { + + JButton button = getComponent(); + button.setIcon(SwingUtil.createActionIcon("edit-attachment")); + button.setToolTipText(_("tutti.action.attachments.tip")); + ((AbstractSerializableBean) model).addPropertyChangeListener(AttachmentModelAware.PROPERTY_ATTACHMENT, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + List<Attachment> attachment = (List<Attachment>) evt.getNewValue(); + getComponent().setText(ButtonAttachmentEditor.getButtonText(attachment)); + } + }); + AttachmentModelAware bean = getBean(); + List<Attachment> attachment = bean == null ? Collections.<Attachment>emptyList() : bean.getAttachment(); + button.setText(ButtonAttachmentEditor.getButtonText(attachment)); + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/ButtonAttachmentEditor.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: 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 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java 2013-03-05 10:45:23 UTC (rev 534) @@ -1,368 +0,0 @@ -package fr.ifremer.tutti.ui.swing.util.editor; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Preconditions; -import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; -import fr.ifremer.tutti.persistence.entities.data.Attachment; -import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; -import fr.ifremer.tutti.ui.swing.util.TuttiUI; -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 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; - -import javax.swing.AbstractCellEditor; -import javax.swing.JTable; -import javax.swing.border.LineBorder; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableCellRenderer; -import java.awt.Color; -import java.awt.Component; -import java.awt.Frame; -import java.util.Collection; - -import static org.nuiton.i18n.I18n._; - -/** - * Component to edit a cell containing attachments. - * - * @author kmorin - * @since 0.2 - */ -public class AttachmentCellComponent extends DefaultTableCellRenderer { - - /** Logger. */ - private static final Log log = LogFactory.getLog(AttachmentCellComponent.class); - - private static final long serialVersionUID = 1L; - - public AttachmentCellComponent() { - setHorizontalAlignment(CENTER); - setIcon(SwingUtil.createActionIcon("edit-attachment")); - } - - @Override - protected void setValue(Object value) { - // do nothing - } - - public static TableCellRenderer newRender(Decorator<Attachment> decorator, String noneText) { - return new AttachmentCellRenderer(decorator, noneText); - } - - //FIXME remove this - public static TableCellEditor newEditor(AttachmentEditorUI ui) { - return new AttachmentCellEditor(null, null, null, null, null); - } - - public static TableCellEditor newEditor(TuttiUI ui, - AttachementObjectTypeEnum objectType, - String objectIdProperty, - String title) { - - Frame frame = SwingUtil.getParentContainer(ui, Frame.class); - - AttachmentCellComponent component = new AttachmentCellComponent(); - component.setBorder(new LineBorder(Color.BLACK)); - - return new AttachmentCellEditor(frame, - component, - objectType, - objectIdProperty, - title); - } - - public static class AttachmentCellEditor extends AbstractCellEditor implements TableCellEditor { - - private static final long serialVersionUID = 1L; - - protected final AttachmentCellComponent component; - - protected AttachmentEditor attachmentEditor; - - 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(Frame frame, - AttachmentCellComponent component, - AttachementObjectTypeEnum objectTypeProperty, - String objectIdProperty, - String title) { - - this.component = component; - this.attachmentEditor = new AttachmentEditor(frame, - component, - objectTypeProperty, - objectIdProperty, - title) { - - private static final long serialVersionUID = 1L; - - @Override - protected AbstractTuttiBeanUIModel getBean() { - return editRow; - } - - @Override - protected String getProperty() { - return columnIdentifier.getPropertyName(); - } - - @Override - public void startEdit() { - super.startEdit(); - int r = rowIndex; - int c = columnIndex; - - // stop edition - stopCellEditing(); - - // refresh cell - tableModel.fireTableCellUpdated(r, c); - - // reselect this cell - AbstractSelectTableAction.doSelectCell(table, r, c); - - // focus on table - table.requestFocus(); - } - }; - } - -// public AttachmentCellEditor(AttachmentEditorUI ui) { -// this.ui = ui; -// -// this.attachmentEditor = new AttachmentEditor(SwingUtil.getParentContainer(ui, Frame.class)); -// -// 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); -// table.requestFocus(); -// } - - @Override - public Component getTableCellEditorComponent(JTable table, - Object value, - boolean isSelected, - int row, - int column) { - this.table = table; - this.tableModel = (AbstractTuttiTableModel<AbstractTuttiBeanUIModel>) table.getModel(); - 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; - - public static final String TEXT_PATTERN = "<html><body>%s</body></html>"; - - private final String noneText; - - private final Decorator<Attachment> decorator; - - public AttachmentCellRenderer(Decorator<Attachment> decorator, - String noneText) { - component = new AttachmentCellComponent(); - this.noneText = noneText; - this.decorator = decorator; - } - - @Override - public Component getTableCellRendererComponent(JTable table, - Object value, - boolean isSelected, - boolean hasFocus, - int row, - int column) { - AttachmentCellComponent result = - (AttachmentCellComponent) component.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - - if (table != null) { - - Collection<Attachment> attachments = (Collection<Attachment>) value; - - String textValue; - - if (CollectionUtils.isEmpty(attachments)) { - - // use HTML to show the tooltip in italic - textValue = "<i>" + _(noneText) + "</i>"; - - } else { - - StringBuilder sb = new StringBuilder(); - for (Attachment attachment : attachments) { - sb.append("<br/>").append(decorator.toString(attachment)); - } - // use html to display the tooltip on several lines - textValue = sb.substring(5); - } - String text = String.format(TEXT_PATTERN, textValue); - boolean editable = table.isCellEditable(row, column); - result.setEnabled(editable); - result.setToolTipText(text); - } - - return result; - } - } -} Deleted: 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 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditor.java 2013-03-05 10:45:23 UTC (rev 534) @@ -1,147 +0,0 @@ -package fr.ifremer.tutti.ui.swing.util.editor; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; -import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; -import jaxx.runtime.JAXXUtil; -import jaxx.runtime.swing.ComponentMover; -import jaxx.runtime.swing.ComponentResizer; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.BorderFactory; -import javax.swing.JComponent; -import javax.swing.JDialog; -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.WindowAdapter; -import java.awt.event.WindowEvent; - -/** - * Editor of attachment. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.0.2 - */ -public abstract class AttachmentEditor extends JDialog { - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Log log = LogFactory.getLog(AttachmentEditor.class); - - protected AttachmentEditorUI editor; - - protected JComponent component; - - public AttachmentEditor(Frame owner, - JComponent component, - AttachementObjectTypeEnum objectType, - String objectIdProperty, - String title) { - super(owner, true); - - this.component = component; - editor = new AttachmentEditorUI(); - editor.setBorder(BorderFactory.createTitledBorder(title)); - editor.setObjectType(objectType); - editor.setObjectIdProperty(objectIdProperty); - - setUndecorated(true); - add(editor); - setResizable(true); - pack(); - - ComponentResizer cr = new ComponentResizer(); - cr.registerComponent(this); - ComponentMover cm = new ComponentMover(); - cm.setDragInsets(cr.getDragInsets()); - cm.registerComponent(this); - - 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); - } - }); - - 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 abstract AbstractTuttiBeanUIModel getBean(); - - protected abstract String getProperty(); - - public void startEdit() { - - editor.setBean(getBean()); - editor.setProperty(getProperty()); - - // 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 + getWidth() > getOwner().getX() + getOwner().getWidth()) { - x = x - getWidth() + component.getWidth(); - } - setLocation(x, y); - setVisible(true); - } - -} Deleted: 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.css 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.css 2013-03-05 10:45:23 UTC (rev 534) @@ -1,47 +0,0 @@ -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -#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"; - mnemonic: F; -} Deleted: 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/AttachmentEditorUI.jaxx 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUI.jaxx 2013-03-05 10:45:23 UTC (rev 534) @@ -1,92 +0,0 @@ -<!-- - #%L - Tutti :: UI - $Id$ - $HeadURL$ - %% - Copyright (C) 2012 Ifremer - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program. If not, see - <http://www.gnu.org/licenses/gpl-3.0.html>. - #L% - --> -<Table id='mainPanel'> - - <import> - fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel - fr.ifremer.tutti.persistence.entities.data.Attachment - fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum - jaxx.runtime.swing.editor.FileEditor - </import> - - <!-- bean property where to find the objectId to attach to Attachment (see Attachment#objectId) --> - <String id='objectIdProperty' javaBean='""'/> - - <!-- object type of attachments (see Attachment#objectType) --> - <AttachementObjectTypeEnum id='objectType' javaBean='null'/> - - <!-- 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'/> - - <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'> - <FileEditor id='file'/> - </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 Deleted: 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 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java 2013-03-05 10:45:23 UTC (rev 534) @@ -1,197 +0,0 @@ -package fr.ifremer.tutti.ui.swing.util.editor; - -/* - * #%L - * Tutti :: UI - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.ezware.oxbow.swingbits.util.Preconditions; -import fr.ifremer.tutti.persistence.entities.data.Attachment; -import fr.ifremer.tutti.service.PersistenceService; -import fr.ifremer.tutti.ui.swing.TuttiUIContext; -import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; -import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; -import jaxx.runtime.SwingUtil; -import jaxx.runtime.swing.HBox; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.SwingConstants; -import java.awt.Cursor; -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.util.List; - -/** - * @author kmorin <morin@codelutin.com> - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class AttachmentEditorUIHandler { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(AttachmentEditorUIHandler.class); - - private final AttachmentEditorUI ui; - - private final PersistenceService persistenceService; - - public AttachmentEditorUIHandler(AttachmentEditorUI ui) { - this.ui = ui; - persistenceService = - TuttiUIContext.getApplicationContext().getPersistenceService(); - - - this.ui.addPropertyChangeListener(new PropertyChangeListener() { - - @Override - 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() { - - @Override - public void actionPerformed(ActionEvent e) { - AbstractTuttiBeanUIModel bean = ui.getBean(); - - persistenceService.deleteAttachment(attachment.getId()); - - String property = ui.getProperty(); - List<Attachment> list = (List<Attachment>) TuttiUIUtil.getProperty(bean, property); - Preconditions.checkNotNull(list); - - list.remove(attachment); - - 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) { - File file = persistenceService.getAttachmentFile(attachment.getId()); - SwingUtil.openLink("file://" + file.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 addAttachment() { - AbstractTuttiBeanUIModel bean = ui.getBean(); - String property = ui.getProperty(); - List<Attachment> list = (List<Attachment>) TuttiUIUtil.getProperty(bean, property); - Preconditions.checkNotNull(list, "Attachments list can not be null"); - Attachment attachment = new Attachment(); - - File file = ui.getFile().getSelectedFile(); - if (file != null) { - String name = ui.getFileName().getText(); - if (StringUtils.isEmpty(name)) { - name = file.getName(); - } - attachment.setObjectType(ui.getObjectType()); - attachment.setObjectId(Integer.valueOf(String.valueOf(TuttiUIUtil.getProperty(bean, ui.getObjectIdProperty())))); - attachment.setName(name); - attachment.setComment(ui.getFileComment().getText()); - - attachment = persistenceService.createAttachment(attachment, file); - - list.add(attachment); - - resetFields(); - addAttachment(attachment); - - JDialog parent = SwingUtil.getParentContainer(ui, JDialog.class); - parent.pack(); - } - } - - protected void resetFields() { - ui.getFile().setSelectedFile((File) null); - ui.getFileName().setText(""); - ui.getFileComment().setText(""); - } - -} Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableModel.java 2013-03-04 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableModel.java 2013-03-05 10:45:23 UTC (rev 534) @@ -10,15 +10,15 @@ * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the + * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public + * + * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% 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 20:23:40 UTC (rev 533) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java 2013-03-05 10:45:23 UTC (rev 534) @@ -315,7 +315,7 @@ // paint in a special color for attachment cell (when some attachments) Highlighter attachmentHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( new HighlightPredicate.AndHighlightPredicate( - new MyIdentifierHighlightPredicate(SpeciesBatchTableModel.ATTACHMENTS), + new MyIdentifierHighlightPredicate(SpeciesBatchTableModel.ATTACHMENT), // for not null value new HighlightPredicate() { @Override
participants (1)
-
tchemit@users.forge.codelutin.com