r602 - in trunk/tutti-ui-swing/src/main: java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton java/fr/ifremer/tutti/ui/swing/content/operation/catches/species java/fr/ifremer/tutti/ui/swing/util java/fr/ifremer/tutti/ui/swing/util/action java/fr/ifremer/tutti/ui/swing/util/attachme
Author: tchemit Date: 2013-03-13 10:20:00 +0100 (Wed, 13 Mar 2013) New Revision: 602 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/602 Log: fixes #2129: [ERGO] Normalisation des commentaires dans les cellules refs #2075: [TECH] Action longue (probl?\195?\168me de cin?\195?\169matique) (toujours fermer le loading quand l'action est termin?\195?\169e) Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/ButtonComment.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentCellEditor.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentCellRenderer.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentEditorUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentEditorUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentEditorUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentModelAware.java Removed: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUIHandler.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchTableModel.java 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/BenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchTableModel.java 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/PlanktonBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchTableModel.java 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/SpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/AbstractTuttiAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionSwingWorker.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiUIAction.java 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/ButtonAttachment.java trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchRowModel.java 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchRowModel.java 2013-03-13 09:20:00 UTC (rev 602) @@ -24,13 +24,18 @@ * #L% */ +import com.google.common.collect.Lists; 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.referential.Species; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware; +import fr.ifremer.tutti.ui.swing.util.comment.CommentModelAware; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; +import java.util.Collection; import java.util.List; /** @@ -39,7 +44,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.2 */ -public class AccidentalBatchRowModel extends AbstractTuttiBeanUIModel<AccidentalBatch, AccidentalBatchRowModel> { +public class AccidentalBatchRowModel extends AbstractTuttiBeanUIModel<AccidentalBatch, AccidentalBatchRowModel> implements AttachmentModelAware, CommentModelAware { private static final long serialVersionUID = 1L; @@ -47,10 +52,6 @@ public static final String PROPERTY_WEIGHT = "weight"; - public static final String PROPERTY_COMMENT = "comment"; - - public static final String PROPERTY_ATTACHMENTS = "attachments"; - /** * Species observed. * @@ -66,18 +67,18 @@ protected Float weight; /** - * Comment on this catches. + * Comment. * * @since 0.2 */ protected String comment; /** - * Attachments + * Attachments. * * @since 0.2 */ - protected List<Attachment> attachments; + protected List<Attachment> attachment = Lists.newArrayList(); protected static final Binder<AccidentalBatch, AccidentalBatchRowModel> fromBeanBinder = BinderFactory.newBinder(AccidentalBatch.class, @@ -116,23 +117,62 @@ firePropertyChange(PROPERTY_WEIGHT, oldValue, weight); } + //------------------------------------------------------------------------// + //-- CommentModelAware --// + //------------------------------------------------------------------------// + + @Override public String getComment() { return comment; } + @Override public void setComment(String comment) { Object oldValue = getComment(); this.comment = comment; 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/accidental/AccidentalBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchTableModel.java 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchTableModel.java 2013-03-13 09:20:00 UTC (rev 602) @@ -59,8 +59,8 @@ n_("tutti.table.accidental.batch.header.comment"), n_("tutti.table.accidental.batch.header.comment")); - public static final ColumnIdentifier<AccidentalBatchRowModel> ATTACHMENTS = ColumnIdentifier.newId( - AccidentalBatchRowModel.PROPERTY_ATTACHMENTS, + public static final ColumnIdentifier<AccidentalBatchRowModel> ATTACHMENT = ColumnIdentifier.newId( + AccidentalBatchRowModel.PROPERTY_ATTACHMENT, n_("tutti.table.accidental.batch.header.file"), n_("tutti.table.accidental.batch.header.file")); 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-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/accidental/AccidentalBatchUIHandler.java 2013-03-13 09:20:00 UTC (rev 602) @@ -36,7 +36,8 @@ import fr.ifremer.tutti.ui.swing.util.TuttiUI; 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.comment.CommentCellEditor; +import fr.ifremer.tutti.ui.swing.util.comment.CommentCellRenderer; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -46,8 +47,6 @@ import java.util.List; -import static org.nuiton.i18n.I18n.n_; - /** * @author tchemit <chemit@codelutin.com> * @since 0.2 @@ -237,8 +236,8 @@ { // Comment column addColumnToModel(columnModel, - LongTextCellComponent.newEditor(ui.getLongTextEditor()), - LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), + CommentCellEditor.newEditor(ui), + CommentCellRenderer.newRender(), AccidentalBatchTableModel.COMMENT); } @@ -246,11 +245,9 @@ Decorator<Attachment> decorator = getDecorator(Attachment.class, null); addColumnToModel(columnModel, - AttachmentCellEditor.newEditor( - ui - ), + AttachmentCellEditor.newEditor(ui), AttachmentCellRenderer.newRender(decorator), - AccidentalBatchTableModel.ATTACHMENTS); + AccidentalBatchTableModel.ATTACHMENT); } // create table model 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-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-03-13 09:20:00 UTC (rev 602) @@ -31,6 +31,7 @@ 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 fr.ifremer.tutti.ui.swing.util.comment.CommentModelAware; import org.apache.commons.collections.CollectionUtils; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; @@ -44,7 +45,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.2 */ -public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<SpeciesBatch, BenthosBatchRowModel> implements AttachmentModelAware { +public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<SpeciesBatch, BenthosBatchRowModel> implements AttachmentModelAware, CommentModelAware { private static final long serialVersionUID = 1L; @@ -58,10 +59,8 @@ public static final String PROPERTY_SAMPLE_WEIGHT = "sampleWeight"; - public static final String PROPERTY_COMMENT = "comment"; +// public static final String PROPERTY_ATTACHMENTS = "attachments"; - public static final String PROPERTY_ATTACHMENTS = "attachments"; - public static final String PROPERTY_PARENT_BATCH = "parentBatch"; public static final String PROPERTY_CHILD_BATCH = "childBatch"; @@ -108,7 +107,7 @@ /** - * Comment on this catches. + * Comment. * * @since 0.2 */ @@ -238,10 +237,16 @@ firePropertyChange(PROPERTY_NUMBER, oldValue, number); } + //------------------------------------------------------------------------// + //-- CommentModelAware --// + //------------------------------------------------------------------------// + + @Override public String getComment() { return comment; } + @Override public void setComment(String comment) { Object oldValue = getComment(); this.comment = comment; 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-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-03-13 09:20:00 UTC (rev 602) @@ -36,7 +36,8 @@ import fr.ifremer.tutti.ui.swing.util.TuttiUI; 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.comment.CommentCellEditor; +import fr.ifremer.tutti.ui.swing.util.comment.CommentCellRenderer; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -46,8 +47,6 @@ import java.util.List; -import static org.nuiton.i18n.I18n.n_; - /** * @author tchemit <chemit@codelutin.com> * @since 0.1 @@ -255,16 +254,15 @@ { // Comment column addColumnToModel(columnModel, - LongTextCellComponent.newEditor(ui.getLongTextEditor()), - LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), + CommentCellEditor.newEditor(ui), + CommentCellRenderer.newRender(), BenthosBatchTableModel.COMMENT); } { // File column addColumnToModel(columnModel, - AttachmentCellEditor.newEditor(ui - ), + AttachmentCellEditor.newEditor(ui), AttachmentCellRenderer.newRender(getDecorator(Attachment.class, null)), BenthosBatchTableModel.ATTACHMENT); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchRowModel.java 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchRowModel.java 2013-03-13 09:20:00 UTC (rev 602) @@ -24,13 +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.MacroWasteBatch; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; +import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware; +import fr.ifremer.tutti.ui.swing.util.comment.CommentModelAware; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; +import java.util.Collection; import java.util.List; /** @@ -39,7 +44,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.2 */ -public class MacroWasteBatchRowModel extends AbstractTuttiBeanUIModel<MacroWasteBatch, MacroWasteBatchRowModel> { +public class MacroWasteBatchRowModel extends AbstractTuttiBeanUIModel<MacroWasteBatch, MacroWasteBatchRowModel> implements AttachmentModelAware, CommentModelAware { private static final long serialVersionUID = 1L; @@ -51,10 +56,6 @@ public static final String PROPERTY_NUMBER = "number"; - public static final String PROPERTY_COMMENT = "comment"; - - public static final String PROPERTY_ATTACHMENTS = "attachments"; - /** * MacroWaste category. * @@ -91,11 +92,11 @@ protected String comment; /** - * Attachments. + * Attachments (should never be null). * * @since 0.2 */ - protected List<Attachment> attachments; + protected final List<Attachment> attachment = Lists.newArrayList(); protected static final Binder<MacroWasteBatch, MacroWasteBatchRowModel> fromBeanBinder = BinderFactory.newBinder(MacroWasteBatch.class, @@ -154,23 +155,62 @@ firePropertyChange(PROPERTY_NUMBER, oldValue, number); } + //------------------------------------------------------------------------// + //-- CommentModelAware --// + //------------------------------------------------------------------------// + + @Override public String getComment() { return comment; } + @Override public void setComment(String comment) { Object oldValue = getComment(); this.comment = comment; 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/macrowaste/MacroWasteBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchTableModel.java 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchTableModel.java 2013-03-13 09:20:00 UTC (rev 602) @@ -63,8 +63,8 @@ n_("tutti.table.macrowaste.batch.header.comment"), n_("tutti.table.macrowaste.batch.header.comment")); - public static final ColumnIdentifier<MacroWasteBatchRowModel> ATTACHMENTS = ColumnIdentifier.newId( - MacroWasteBatchRowModel.PROPERTY_ATTACHMENTS, + public static final ColumnIdentifier<MacroWasteBatchRowModel> ATTACHMENT = ColumnIdentifier.newId( + MacroWasteBatchRowModel.PROPERTY_ATTACHMENT, n_("tutti.table.macrowaste.batch.header.file"), n_("tutti.table.macrowaste.batch.header.file")); 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-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/macrowaste/MacroWasteBatchUIHandler.java 2013-03-13 09:20:00 UTC (rev 602) @@ -36,7 +36,8 @@ import fr.ifremer.tutti.ui.swing.util.TuttiUI; 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.comment.CommentCellEditor; +import fr.ifremer.tutti.ui.swing.util.comment.CommentCellRenderer; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -46,8 +47,6 @@ import java.util.List; -import static org.nuiton.i18n.I18n.n_; - /** * @author tchemit <chemit@codelutin.com> * @since 0.2 @@ -247,18 +246,17 @@ { // Comment column addColumnToModel(columnModel, - LongTextCellComponent.newEditor(ui.getLongTextEditor()), - LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), + CommentCellEditor.newEditor(ui), + CommentCellRenderer.newRender(), MacroWasteBatchTableModel.COMMENT); } { // File column addColumnToModel(columnModel, - AttachmentCellEditor.newEditor(ui - ), + AttachmentCellEditor.newEditor(ui), AttachmentCellRenderer.newRender(getDecorator(Attachment.class, null)), - MacroWasteBatchTableModel.ATTACHMENTS); + MacroWasteBatchTableModel.ATTACHMENT); } // create table model Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchRowModel.java 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchRowModel.java 2013-03-13 09:20:00 UTC (rev 602) @@ -24,13 +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.PlanktonBatch; 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 fr.ifremer.tutti.ui.swing.util.comment.CommentModelAware; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; +import java.util.Collection; import java.util.List; /** @@ -39,7 +44,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.2 */ -public class PlanktonBatchRowModel extends AbstractTuttiBeanUIModel<PlanktonBatch, PlanktonBatchRowModel> { +public class PlanktonBatchRowModel extends AbstractTuttiBeanUIModel<PlanktonBatch, PlanktonBatchRowModel> implements AttachmentModelAware, CommentModelAware { private static final long serialVersionUID = 1L; @@ -51,10 +56,6 @@ public static final String PROPERTY_SAMPLE_WEIGHT = "sampleWeight"; - public static final String PROPERTY_COMMENT = "comment"; - - public static final String PROPERTY_ATTACHMENTS = "attachments"; - /** * Species observed. * @@ -84,18 +85,18 @@ protected Float sampleWeight; /** - * Comment on this catches. + * Comment. * * @since 0.2 */ protected String comment; /** - * Attachments + * Attachments (should never be null). * * @since 0.2 */ - protected List<Attachment> attachments; + protected final List<Attachment> attachment = Lists.newArrayList(); protected static final Binder<PlanktonBatch, PlanktonBatchRowModel> fromBeanBinder = BinderFactory.newBinder(PlanktonBatch.class, @@ -154,23 +155,62 @@ firePropertyChange(PROPERTY_SAMPLE_WEIGHT, oldValue, sampleWeight); } + //------------------------------------------------------------------------// + //-- CommentModelAware --// + //------------------------------------------------------------------------// + + @Override public String getComment() { return comment; } + @Override public void setComment(String comment) { Object oldValue = getComment(); this.comment = comment; 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/plankton/PlanktonBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchTableModel.java 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchTableModel.java 2013-03-13 09:20:00 UTC (rev 602) @@ -68,8 +68,8 @@ n_("tutti.table.plankton.batch.header.comment"), n_("tutti.table.plankton.batch.header.comment")); - public static final ColumnIdentifier<PlanktonBatchRowModel> ATTACHMENTS = ColumnIdentifier.newId( - PlanktonBatchRowModel.PROPERTY_ATTACHMENTS, + public static final ColumnIdentifier<PlanktonBatchRowModel> ATTACHMENT = ColumnIdentifier.newId( + PlanktonBatchRowModel.PROPERTY_ATTACHMENT, n_("tutti.table.plankton.batch.header.file"), n_("tutti.table.plankton.batch.header.file")); 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-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/plankton/PlanktonBatchUIHandler.java 2013-03-13 09:20:00 UTC (rev 602) @@ -36,7 +36,8 @@ import fr.ifremer.tutti.ui.swing.util.TuttiUI; 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.comment.CommentCellEditor; +import fr.ifremer.tutti.ui.swing.util.comment.CommentCellRenderer; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -46,8 +47,6 @@ import java.util.List; -import static org.nuiton.i18n.I18n.n_; - /** * @author tchemit <chemit@codelutin.com> * @since 0.2 @@ -240,18 +239,17 @@ { // Comment column addColumnToModel(columnModel, - LongTextCellComponent.newEditor(ui.getLongTextEditor()), - LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), + CommentCellEditor.newEditor(ui), + CommentCellRenderer.newRender(), PlanktonBatchTableModel.COMMENT); } { // File column addColumnToModel(columnModel, - AttachmentCellEditor.newEditor(ui - ), + AttachmentCellEditor.newEditor(ui), AttachmentCellRenderer.newRender(getDecorator(Attachment.class, null)), - PlanktonBatchTableModel.ATTACHMENTS); + PlanktonBatchTableModel.ATTACHMENT); } { // Species to confirm column 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-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-03-13 09:20:00 UTC (rev 602) @@ -36,6 +36,7 @@ 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 fr.ifremer.tutti.ui.swing.util.comment.CommentModelAware; import org.apache.commons.collections.CollectionUtils; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; @@ -52,7 +53,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.2 */ -public class SpeciesBatchRowModel extends AbstractTuttiBeanUIModel<SpeciesBatch, SpeciesBatchRowModel> implements AttachmentModelAware { +public class SpeciesBatchRowModel extends AbstractTuttiBeanUIModel<SpeciesBatch, SpeciesBatchRowModel> implements AttachmentModelAware, CommentModelAware { private static final long serialVersionUID = 1L; @@ -96,8 +97,6 @@ public static final String PROPERTY_NUMBER = "number"; - public static final String PROPERTY_COMMENT = "comment"; - public static final String PROPERTY_FREQUENCY = "frequency"; public static final String PROPERTY_COMPUTED_NUMBER = "computedOrNotNumber"; @@ -190,7 +189,7 @@ new TuttiComputedOrNotData<Integer>(); /** - * Comment on this catches. + * Comment. * * @since 0.2 */ @@ -555,6 +554,22 @@ } //------------------------------------------------------------------------// + //-- CommentModelAware --// + //------------------------------------------------------------------------// + + @Override + public String getComment() { + return comment; + } + + @Override + public void setComment(String comment) { + Object oldValue = getComment(); + this.comment = comment; + firePropertyChange(PROPERTY_COMMENT, oldValue, comment); + } + + //------------------------------------------------------------------------// //-- AttachmentModelAware --// //------------------------------------------------------------------------// @@ -627,20 +642,6 @@ computedOrNotNumber.setData(number); } - public String getComment() { - return comment; - } - - public void setComment(String comment) { - Object oldValue = getComment(); - this.comment = comment; - firePropertyChange(PROPERTY_COMMENT, oldValue, comment); - } - - public List<Attachment> getAttachments() { - return attachment; - } - public List<SpeciesFrequencyRowModel> getFrequency() { return frequency; } 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-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-03-13 09:20:00 UTC (rev 602) @@ -57,7 +57,8 @@ import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; 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.comment.CommentCellEditor; +import fr.ifremer.tutti.ui.swing.util.comment.CommentCellRenderer; import fr.ifremer.tutti.ui.swing.util.editor.TuttiComputedOrNotDataTableCell; import fr.ifremer.tutti.ui.swing.util.table.AbstractSelectTableAction; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; @@ -92,7 +93,6 @@ import java.util.Set; import static org.nuiton.i18n.I18n._; -import static org.nuiton.i18n.I18n.n_; /** * @author tchemit <chemit@codelutin.com> @@ -618,16 +618,15 @@ { // Comment column addColumnToModel(columnModel, - LongTextCellComponent.newEditor(ui.getLongTextEditor()), - LongTextCellComponent.newRender(n_("tutti.tooltip.comment.none")), + CommentCellEditor.newEditor(ui), + CommentCellRenderer.newRender(), SpeciesBatchTableModel.COMMENT); } { // File column addColumnToModel(columnModel, - AttachmentCellEditor.newEditor(ui - ), + AttachmentCellEditor.newEditor(ui), AttachmentCellRenderer.newRender(getDecorator(Attachment.class, null)), SpeciesBatchTableModel.ATTACHMENT); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/AbstractTuttiAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/AbstractTuttiAction.java 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/AbstractTuttiAction.java 2013-03-13 09:20:00 UTC (rev 602) @@ -48,6 +48,8 @@ private static final Log log = LogFactory.getLog(AbstractTuttiAction.class); + public static final String PROPERTY_DONE = "done"; + protected final H handler; protected String actionDescription; @@ -70,6 +72,7 @@ protected void releaseAction() { // by default nothing to clean + firePropertyChange(PROPERTY_DONE, null, true); } public void postSuccessAction() { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionSwingWorker.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionSwingWorker.java 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionSwingWorker.java 2013-03-13 09:20:00 UTC (rev 602) @@ -28,7 +28,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import javax.swing.SwingUtilities; import javax.swing.SwingWorker; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.util.Timer; import java.util.TimerTask; @@ -78,26 +81,8 @@ if (!isCancelled()) { - timer = new TimerTask() { + timer = new TuttiActionTimerTask(); - @Override - public void run() { - if (isCancelled() || isDone()) { - - if (log.isDebugEnabled()) { - log.debug("Task [" + action + "] was already canceled or done, do nothing"); - } - } else { - - if (log.isDebugEnabled()) { - log.debug("Task [" + action + "] is started, show waiting dialog"); - } - - actionUI.open(action); - } - } - }; - t.schedule(timer, 1000); try { @@ -136,7 +121,6 @@ // fail hook action.postFailedAction(error); - } if (timer != null) { @@ -160,6 +144,47 @@ if (hideBody) { mainUI.getBody().setVisible(!busy); } + } + protected class TuttiActionTimerTask extends TimerTask { + + public TuttiActionTimerTask() { + action.addPropertyChangeListener(AbstractTuttiAction.PROPERTY_DONE, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + + if (actionUI.isVisible()) { + actionUI.close(); + } + + // we do NOt want the timer to wake up then the actionUI dialog + cancel(); + + + } + }); + } + + @Override + public void run() { + if (isCancelled() || isDone()) { + + if (log.isDebugEnabled()) { + log.debug("Task [" + action + "] was already canceled or done, do nothing"); + } + } else { + + if (log.isDebugEnabled()) { + log.debug("Task [" + action + "] is started, show waiting dialog"); + } + + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + actionUI.open(action); + } + }); + } + } } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiUIAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiUIAction.java 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiUIAction.java 2013-03-13 09:20:00 UTC (rev 602) @@ -170,7 +170,7 @@ } public A getLogicAction() { - return (A) getValue("logicAction"); + return (A) getValue(LOGIC_ACTION); } } Modified: 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/AttachmentEditorUI.jaxx 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUI.jaxx 2013-03-13 09:20:00 UTC (rev 602) @@ -54,15 +54,6 @@ } ]]></script> - <!-- 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'/> Modified: 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/AttachmentEditorUIHandler.java 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUIHandler.java 2013-03-13 09:20:00 UTC (rev 602) @@ -83,17 +83,6 @@ this.context = context; this.ui = ui; this.persistenceService = context.getPersistenceService(); - -// this.ui.addPropertyChangeListener(new PropertyChangeListener() { -// -// @Override -// public void propertyChange(PropertyChangeEvent evt) { -// if (log.isInfoEnabled()) { -// log.info("Init (property " + evt.getPropertyName() + " changed)."); -// } -// init(); -// } -// }); } protected void beforeInitUI() { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/ButtonAttachment.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/ButtonAttachment.java 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/ButtonAttachment.java 2013-03-13 09:20:00 UTC (rev 602) @@ -69,21 +69,6 @@ popup = new AttachmentEditorUI(context); -// popup.addComponentListener(new ComponentAdapter() { -// -// @Override -// public void componentMoved(ComponentEvent e) { -// Component component = e.getComponent(); -// if (component.isShowing() && !popupMoving) { -// popupPosition = component.getLocationOnScreen(); -// -// if (log.isInfoEnabled()) { -// log.info("Popup has moved by user, keeping his position: " + popupPosition); -// } -// } -// } -// }); - popup.addWindowListener(new WindowAdapter() { @Override Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/ButtonComment.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/ButtonComment.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/ButtonComment.java 2013-03-13 09:20:00 UTC (rev 602) @@ -0,0 +1,138 @@ +package fr.ifremer.tutti.ui.swing.util.comment; + +/* + * #%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.ui.swing.TuttiUIContext; +import jaxx.runtime.SwingUtil; + +import javax.swing.JToggleButton; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.Point; +import java.awt.event.HierarchyBoundsAdapter; +import java.awt.event.HierarchyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * A toggleButton to show (or hide) comment editor. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.1 + */ +public class ButtonComment extends JToggleButton { + + private static final long serialVersionUID = 1L; + + protected final CommentEditorUI popup; + + protected Point popupPosition = null; + + protected boolean popupMoving; + + public ButtonComment(TuttiUIContext context, + CommentModelAware model) { + + setIcon(SwingUtil.createActionIcon("edit-comment")); + setToolTipText(_("tutti.action.comment.tip")); + + popup = new CommentEditorUI(context); + + popup.addWindowListener(new WindowAdapter() { + + @Override + public void windowOpened(WindowEvent e) { + setSelected(true); + } + + @Override + public void windowClosing(WindowEvent e) { + setSelected(false); + } + + @Override + public void windowClosed(WindowEvent e) { + setSelected(false); + } + }); + + addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + if (isSelected()) { + popup.openEditor(ButtonComment.this); + } else { + popup.closeEditor(); + } + } + }); + + addHierarchyBoundsListener(new HierarchyBoundsAdapter() { + + @Override + public void ancestorMoved(HierarchyEvent e) { + if (popup.isShowing()) { + + // place dialog just under the button + Point point = new Point(getLocationOnScreen()); + point.translate(-popup.getWidth() + getWidth(), getHeight()); + popupMoving = true; + try { + popup.setLocation(point); + } finally { + popupMoving = false; + } + } + } + }); + setBean(model); + } + + public void init() { + popup.getHandler().init(); + } + + public void init(CommentModelAware model) { + setBean(model); + init(); + } + + public void onCloseUI() { + setSelected(false); + } + + public CommentModelAware getBean() { + return popup.getBean(); + } + + protected void setBean(CommentModelAware model) { + popup.setBean(model); + init(); + + } + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/ButtonComment.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/comment/CommentCellEditor.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentCellEditor.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentCellEditor.java 2013-03-13 09:20:00 UTC (rev 602) @@ -0,0 +1,142 @@ +package fr.ifremer.tutti.ui.swing.util.comment; + +/* + * #%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.ui.swing.TuttiUIContext; +import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; +import fr.ifremer.tutti.ui.swing.util.TuttiUI; +import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; +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.event.CellEditorListener; +import javax.swing.event.ChangeEvent; +import javax.swing.table.TableCellEditor; +import java.awt.Color; +import java.awt.Component; +import java.util.EventObject; + +/** + * To edit a comment in a table cell using a nice dialog for this. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.1 + */ +public class CommentCellEditor extends AbstractCellEditor implements TableCellEditor { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = LogFactory.getLog(CommentCellEditor.class); + + public static TableCellEditor newEditor(TuttiUI ui) { + + return new CommentCellEditor(ui.getHandler().getContext()); + } + + protected JTable table; + + protected AbstractTuttiTableModel<AbstractTuttiBeanUIModel> tableModel; + + protected Integer rowIndex; + + protected Integer columnIndex; + + protected final ButtonComment editorButton; + + public CommentCellEditor(TuttiUIContext context) { + + this.editorButton = new ButtonComment(context, null); + this.editorButton.setBorder(new LineBorder(Color.BLACK)); + addCellEditorListener(new CellEditorListener() { + @Override + public void editingStopped(ChangeEvent e) { + editorButton.setSelected(false); + } + + @Override + public void editingCanceled(ChangeEvent e) { + editorButton.setSelected(false); + } + }); + } + + @Override + public Component getTableCellEditorComponent(JTable table, + Object value, + boolean isSelected, + int row, + int column) { + this.table = table; + this.tableModel = (AbstractTuttiTableModel<AbstractTuttiBeanUIModel>) table.getModel(); + + rowIndex = row; + columnIndex = column; + + CommentModelAware model = (CommentModelAware) tableModel.getEntry(row); + + editorButton.init(model); + + return editorButton; + } + + @Override + public boolean shouldSelectCell(EventObject anEvent) { + return false; + } + + @Override + public Object getCellEditorValue() { + + CommentModelAware model = editorButton.getBean(); + Preconditions.checkNotNull(model, "No model found in editor."); + + Object result = model.getComment(); + if (log.isInfoEnabled()) { + log.info("editor value: " + result); + } + + return result; + } + + @Override + public boolean stopCellEditing() { + boolean b = super.stopCellEditing(); + if (b) { + editorButton.setBean(null); + } + return b; + } + + @Override + public void cancelCellEditing() { + editorButton.setBean(null); + super.cancelCellEditing(); + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentCellEditor.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/comment/CommentCellRenderer.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentCellRenderer.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentCellRenderer.java 2013-03-13 09:20:00 UTC (rev 602) @@ -0,0 +1,97 @@ +package fr.ifremer.tutti.ui.swing.util.comment; + +/* + * #%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 jaxx.runtime.SwingUtil; +import org.apache.commons.lang3.StringUtils; + +import javax.swing.JComponent; +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; + +import static org.nuiton.i18n.I18n._; +import static org.nuiton.i18n.I18n.n_; + +/** + * To render a comment in a table cell. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.1 + */ +public class CommentCellRenderer extends DefaultTableCellRenderer { + + public static final String TEXT_PATTERN = "<html><body>%s</body></html>"; + + private static final long serialVersionUID = 1L; + + private final String noneText; + + public static CommentCellRenderer newRender() { + return new CommentCellRenderer(); + } + + protected CommentCellRenderer() { + setHorizontalAlignment(CENTER); + setIcon(SwingUtil.createActionIcon("edit-comment")); + this.noneText = n_("tutti.tooltip.comment.none"); + } + + @Override + protected void setValue(Object value) { + // do nothing + } + + @Override + public JComponent getTableCellRendererComponent(JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + int row, + int column) { + + String comment = (String) value; + + String toolTipTextValue; + + if (StringUtils.isEmpty(comment)) { + + // use HTML to show the tooltip in italic + toolTipTextValue = "<i>" + _(noneText) + "</i>"; + + + } else { + + // use html to display the tooltip on several lines + toolTipTextValue = String.valueOf(value).replace("\n", "<br/>"); + + } + boolean editable = table.isCellEditable(row, column); + toolTipTextValue = String.format(TEXT_PATTERN, toolTipTextValue); + setEnabled(editable); + setToolTipText(toolTipTextValue); + + return this; + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentCellRenderer.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/comment/CommentEditorUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentEditorUI.css (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentEditorUI.css 2013-03-13 09:20:00 UTC (rev 602) @@ -0,0 +1,38 @@ +/* + * #%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% + */ + +#commentDialog { + undecorated: true; + alwaysOnTop: true; +} + +#commentEditorTopPanel { + title: "tutti.title.comment"; +} + +#closeButton { + actionIcon: close; + text: "tutti.action.close"; + mnemonic: F; +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentEditorUI.css ___________________________________________________________________ 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/comment/CommentEditorUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentEditorUI.jaxx (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentEditorUI.jaxx 2013-03-13 09:20:00 UTC (rev 602) @@ -0,0 +1,70 @@ +<!-- + #%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% + --> +<JDialog id='commentDialog' layout='{new BorderLayout()}'> + + <import> + fr.ifremer.tutti.ui.swing.TuttiUIContext + + org.jdesktop.swingx.JXTitledPanel + javax.swing.JComponent + </import> + + <script><![CDATA[ + +public CommentEditorUI(TuttiUIContext context) { + super(context.getMainUI()); + setContextValue(context); + CommentEditorUIHandler handler = new CommentEditorUIHandler(context, this); + setContextValue(handler); + handler.beforeInitUI(); +} + +protected void $afterCompleteSetup() { + getHandler().afterInitUI(); +} + +public void openEditor(JComponent component) { + handler.openEditor(component); +} + +public void closeEditor() { + handler.closeEditor(); +} + ]]></script> + + <!-- bean property --> + <CommentModelAware id='bean' javaBean='null'/> + + <CommentEditorUIHandler id='handler' + initializer='getContextValue(CommentEditorUIHandler.class)'/> + + <JXTitledPanel id='commentEditorTopPanel' constraints='BorderLayout.CENTER'> + + <JScrollPane> + <JTextArea id='textContent' + onKeyReleased='handler.setText(((JTextArea)event.getSource()).getText())'/> + </JScrollPane> + + </JXTitledPanel> +</JDialog> \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentEditorUI.jaxx ___________________________________________________________________ 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/comment/CommentEditorUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentEditorUIHandler.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentEditorUIHandler.java 2013-03-13 09:20:00 UTC (rev 602) @@ -0,0 +1,188 @@ +package fr.ifremer.tutti.ui.swing.util.comment; + +/* + * #%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.ui.swing.TuttiUIContext; +import jaxx.runtime.SwingUtil; +import jaxx.runtime.swing.ComponentMover; +import jaxx.runtime.swing.ComponentResizer; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JRootPane; +import javax.swing.JToolBar; +import javax.swing.KeyStroke; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 1.1 + */ +public class CommentEditorUIHandler { + + private static final int DEFAULT_EDITOR_WIDTH = 400; + + private static final int DEFAULT_EDITOR_HEIGHT = 200; + + public static final String CLOSE_DIALOG_ACTION = "closeDialog"; + + public static final String SHOW_DIALOG_ACTION = "showDialog"; + + protected final TuttiUIContext context; + + private final CommentEditorUI ui; + + public CommentEditorUIHandler(TuttiUIContext context, CommentEditorUI ui) { + this.context = context; + this.ui = ui; + } + + protected void beforeInitUI() { + } + + protected void afterInitUI() { + + ui.pack(); + ui.setResizable(true); +// ui.setSize(800, 300); + + ui.setSize(DEFAULT_EDITOR_WIDTH, DEFAULT_EDITOR_HEIGHT); + + ComponentResizer cr = new ComponentResizer(); + cr.registerComponent(ui); + ComponentMover cm = new ComponentMover(); + cm.setDragInsets(cr.getDragInsets()); + cm.registerComponent(ui); + + JRootPane rootPane = ui.getRootPane(); + + KeyStroke shortcutClosePopup = + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); + + rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( + shortcutClosePopup, CLOSE_DIALOG_ACTION); + + closeAction = new AbstractAction() { + private static final long serialVersionUID = 1L; + + @Override + public void actionPerformed(ActionEvent e) { + ui.dispose(); + ui.setVisible(false); + } + }; + + openAction = new AbstractAction() { + + private static final long serialVersionUID = 1L; + + @Override + public void actionPerformed(ActionEvent e) { + ui.setVisible(true); + } + }; + + ImageIcon actionIcon = SwingUtil.createActionIcon("close-dialog"); + closeAction.putValue(Action.SMALL_ICON, actionIcon); + closeAction.putValue(Action.LARGE_ICON_KEY, actionIcon); + closeAction.putValue(Action.ACTION_COMMAND_KEY, "close"); + closeAction.putValue(Action.NAME, "close"); + closeAction.putValue(Action.SHORT_DESCRIPTION, _("tutti.action.closeCommentEditor.tip")); + + rootPane.getActionMap().put(CLOSE_DIALOG_ACTION, closeAction); + rootPane.getActionMap().put(SHOW_DIALOG_ACTION, openAction); + + JButton closeButton = new JButton(closeAction); + closeButton.setText(null); + closeButton.setFocusPainted(false); + closeButton.setRequestFocusEnabled(false); + closeButton.setFocusable(false); + + JToolBar jToolBar = new JToolBar(); + jToolBar.setOpaque(false); + jToolBar.add(closeAction); + jToolBar.setBorderPainted(false); + jToolBar.setFloatable(false); + ui.getCommentEditorTopPanel().setRightDecoration(jToolBar); + } + + protected Action closeAction; + + protected Action openAction; + + public void closeEditor() { + + closeAction.actionPerformed(null); + } + + public void openEditor(JComponent component) { + + if (component != null) { + place(component); + } + openAction.actionPerformed(null); + } + + public void init() { + + CommentModelAware bean = ui.getBean(); + String content = bean == null ? null : bean.getComment(); + ui.getTextContent().setText(content); + } + + public void place(JComponent component) { + // 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(); + } + +// ui.pack(); + // if the editor is too big on the right, + // then align its right side to the right side of the cell + if (x + ui.getWidth() > ui.getOwner().getX() + ui.getOwner().getWidth()) { + x = x - ui.getWidth() + component.getWidth(); + } + ui.setLocation(x, y); + } + + /** pushes the typed text in the property of the bean */ + public void setText(String value) { + CommentModelAware bean = ui.getBean(); + bean.setComment(value); + } + +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentEditorUIHandler.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/comment/CommentModelAware.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentModelAware.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentModelAware.java 2013-03-13 09:20:00 UTC (rev 602) @@ -0,0 +1,40 @@ +package fr.ifremer.tutti.ui.swing.util.comment; + +/* + * #%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% + */ + +/** + * To place on model wich supports comment. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.1 + */ +public interface CommentModelAware { + + String PROPERTY_COMMENT= "comment"; + + String getComment(); + + void setComment(String comment); +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/comment/CommentModelAware.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/LongTextCellComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java 2013-03-13 09:20:00 UTC (rev 602) @@ -1,312 +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.ui.swing.util.AbstractTuttiBeanUIModel; -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.JAXXUtil; -import jaxx.runtime.SwingUtil; -import jaxx.runtime.swing.ComponentMover; -import jaxx.runtime.swing.ComponentResizer; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.AbstractCellEditor; -import javax.swing.BorderFactory; -import javax.swing.JDialog; -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.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; - -import static org.nuiton.i18n.I18n._; - -/** - * Component to edit a cell in a popup with a text area - * - * @author kmorin - * @since 0.2 - */ -public class LongTextCellComponent extends DefaultTableCellRenderer { - - /** Logger. */ - private static final Log log = LogFactory.getLog(LongTextCellComponent.class); - - private static final long serialVersionUID = 1L; - - public LongTextCellComponent() { - setHorizontalAlignment(CENTER); - setIcon(SwingUtil.createActionIcon("edit-comment")); - } - - @Override - protected void setValue(Object value) { - // do nothing - } - - public static TableCellRenderer newRender(String noneText) { - return new LongTextCellRenderer(noneText); - } - - public static TableCellEditor newEditor(LongTextEditorUI ui) { - return new LongTextCellEditor(ui); - } - - - public static class LongTextCellEditor extends AbstractCellEditor implements TableCellEditor { - - public static final int DEFAULT_EDITOR_WIDTH = 400; - - public static final int DEFAULT_EDITOR_HEIGHT = 200; - - private static final long serialVersionUID = 1L; - - protected final LongTextCellComponent component; - - protected final LongTextEditorUI ui; - - protected Frame frame; - - protected JTable table; - - protected AbstractTuttiTableModel<AbstractTuttiBeanUIModel> tableModel; - - protected ColumnIdentifier<AbstractTuttiBeanUIModel> columnIdentifier; - - protected AbstractTuttiBeanUIModel editRow; - - protected Integer rowIndex; - - protected Integer columnIndex; - - public LongTextCellEditor(LongTextEditorUI ui) { - this.ui = ui; - - component = new LongTextCellComponent(); - 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.setSize(DEFAULT_EDITOR_WIDTH, DEFAULT_EDITOR_HEIGHT); - editor.setResizable(true); - 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) { - if (tableModel == null) { - tableModel = (AbstractTuttiTableModel<AbstractTuttiBeanUIModel>) table.getModel(); - this.table = table; - columnIdentifier = tableModel.getPropertyName(column); - } - - rowIndex = row; - columnIndex = column; - - editRow = tableModel.getEntry(row); - - return component; - } - - @Override - public Object getCellEditorValue() { - - Preconditions.checkNotNull(editRow, "No editRow found in editor."); - - String propertyName = columnIdentifier.getPropertyName(); - Object result = TuttiUIUtil.getProperty(editRow, propertyName); - if (log.isInfoEnabled()) { - log.info("editor value (" + propertyName + "): " + result); - } - - return result; - } - - @Override - public boolean stopCellEditing() { - boolean b = super.stopCellEditing(); - if (b) { - rowIndex = null; - editRow = null; - columnIndex = null; - } - return b; - } - - @Override - public void cancelCellEditing() { - super.cancelCellEditing(); - rowIndex = null; - columnIndex = null; - editRow = null; - } - } - - public static class LongTextCellRenderer implements TableCellRenderer { - - protected final LongTextCellComponent component; - - protected String propertyName; - - public static final String TEXT_PATTERN = "<html><body>%s</body></html>"; - - private final String noneText; - - public LongTextCellRenderer(String noneText) { - component = new LongTextCellComponent(); - this.noneText = noneText; - } - - @Override - public Component getTableCellRendererComponent(JTable table, - Object value, - boolean isSelected, - boolean hasFocus, - int row, - int column) { - - LongTextCellComponent result = - (LongTextCellComponent) component.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - - if (table != null) { - String textValue; - if (StringUtils.isBlank((String) value)) { - if (propertyName == null) { - AbstractTuttiTableModel tableModel = - (AbstractTuttiTableModel) table.getModel(); - ColumnIdentifier columnIdentifier = - tableModel.getPropertyName(column); - propertyName = columnIdentifier.getPropertyName(); - } - // use HTML to show the tooltip in italic - textValue = "<i>" + _(noneText) + "</i>"; - - } else { - // use html to display the tooltip on several lines - textValue = String.valueOf(value).replace("\n", "<br/>"); - } - - 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/LongTextEditorUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUI.css 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUI.css 2013-03-13 09:20:00 UTC (rev 602) @@ -1,28 +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% - */ -#closeButton { - actionIcon: close; - text: "tutti.action.close"; - mnemonic: F; -} Deleted: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUI.jaxx 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUI.jaxx 2013-03-13 09:20:00 UTC (rev 602) @@ -1,48 +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'> - - <!-- bean property linked state --> - <String id='property' javaBean='""'/> - - <!-- bean property --> - <Object id='bean' javaBean='null'/> - - <LongTextEditorUIHandler id='handler' constructorParams='this'/> - - <row weighty='1' fill='both'> - <cell fill='both' weightx='1'> - <JScrollPane> - <JTextArea id='textContent' - onKeyReleased='handler.setText(((JTextArea)event.getSource()).getText())'/> - </JScrollPane> - </cell> - </row> - <row fill='both'> - <!-- actions --> - <cell fill='both' weightx='1'> - <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/LongTextEditorUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUIHandler.java 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUIHandler.java 2013-03-13 09:20:00 UTC (rev 602) @@ -1,81 +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 fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; -import jaxx.runtime.SwingUtil; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.awt.Window; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; - -/** - * Handler of the LongTextEditorUI - * - * @author kmorin - * @since 0.2 - */ -public class LongTextEditorUIHandler { - - private static final Log log = - LogFactory.getLog(LongTextEditorUIHandler.class); - - private final LongTextEditorUI ui; - - public LongTextEditorUIHandler(LongTextEditorUI longTextEditorUI) { - ui = longTextEditorUI; - - ui.addPropertyChangeListener(new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - Object bean = ui.getBean(); - String property = ui.getProperty(); - if (bean != null && !StringUtils.isEmpty(property)) { - Object value = TuttiUIUtil.getProperty(bean, property); - ui.getTextContent().setText(SwingUtil.getStringValue(value)); - } - } - }); - } - - /** pushes the typed text in the property of the bean */ - public void setText(String value) { - Object bean = ui.getBean(); - String property = ui.getProperty(); - TuttiUIUtil.setProperty(bean, property, value); - } - - /** closes the editor */ - public void close() { - if (log.isInfoEnabled()) { - log.info("Will close UI " + ui); - } - SwingUtil.getParentContainer(ui, Window.class).dispose(); - } - -} Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-03-13 09:20:00 UTC (rev 602) @@ -26,7 +26,9 @@ tutti.action.cloneProtocol= tutti.action.close= tutti.action.closeAttachment.tip= +tutti.action.closeCommentEditor.tip= tutti.action.closeDb= +tutti.action.comment.tip= tutti.action.computeWeights= tutti.action.computeWeights.error.incoherentCategoryWeight= tutti.action.computeWeights.error.incoherentParentCategoryWeight= @@ -436,6 +438,7 @@ tutti.title.choose.protocolImportFile= tutti.title.choose.protocolSpeciesExportFile= tutti.title.choose.protocolSpeciesImportFile= +tutti.title.comment= tutti.title.create.cruise= tutti.title.create.program= tutti.title.create.protocol= Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-03-13 07:33:30 UTC (rev 601) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-03-13 09:20:00 UTC (rev 602) @@ -26,7 +26,9 @@ tutti.action.cloneProtocol=Cloner tutti.action.close=Fermer tutti.action.closeAttachment.tip=Fermer la fenêtre des picèes-jointes +tutti.action.closeCommentEditor.tip=Fermer la fenêtre des commentaires tutti.action.closeDb=Fermer +tutti.action.comment.tip=Commentaire tutti.action.computeWeights=Elever les poids tutti.action.computeWeights.error.incoherentCategoryWeight=Le poids total des mensurations est supérieur au poids de la catégorie tutti.action.computeWeights.error.incoherentCategoryWeight.title=Incohérence @@ -459,6 +461,7 @@ tutti.title.choose.protocolImportFile=Importer le protocole tutti.title.choose.protocolSpeciesExportFile=Exporter les espèces tutti.title.choose.protocolSpeciesImportFile=Importer les espèces +tutti.title.comment=Commentaire tutti.title.create.cruise=Créer une nouvelle campagne tutti.title.create.program=Créer une nouvelle série de campagne tutti.title.create.protocol=Créer un nouveau protocol de saisie
participants (1)
-
tchemit@users.forge.codelutin.com