- implemented functionality to reuse media in MediaView (#2385)
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / media / operation / AddMediaToImageGalleryOperation.java
index eb8f66380b6cf03b8e4b0fc53d5b5268b0d77013..ed396f0a9de4b1ae1dc082fb8888e54b2e84a378 100644 (file)
@@ -1,8 +1,8 @@
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
@@ -21,7 +21,7 @@ import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 /**
- * <p>AddMediaToImageGalleryOperation class.</p>
+ * This operation creates a new {@link Media} and adds it to the currently selected {@link DescriptionBase}.
  *
  * @author p.ciardelli
  * @author n.hoffmann
@@ -29,8 +29,8 @@ import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
  * @version 1.0
  */
 public class AddMediaToImageGalleryOperation extends AbstractPostTaxonOperation {
-       
-       private DescriptionBase description;
+
+       private final DescriptionBase<?> description;
        private Media media;
 
        /**
@@ -43,11 +43,17 @@ public class AddMediaToImageGalleryOperation extends AbstractPostTaxonOperation
         * @param description a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
         */
        public AddMediaToImageGalleryOperation(String label,
-                       IUndoContext undoContext, DescriptionBase description, IPostOperationEnabled postOperationEnabled) {
-               super(label, undoContext, postOperationEnabled);
+                       IUndoContext undoContext, DescriptionBase<?> description, IPostOperationEnabled postOperationEnabled) {
+           this(null, label, undoContext, description, postOperationEnabled);
+           media = Media.NewInstance();
+       }
+
+       protected AddMediaToImageGalleryOperation(Media media, String label,
+               IUndoContext undoContext, DescriptionBase<?> description, IPostOperationEnabled postOperationEnabled) {
+           super(label, undoContext, postOperationEnabled);
 
-               this.description = description;
-               media = Media.NewInstance();
+           this.description = description;
+           this.media = media;
        }
 
        /* (non-Javadoc)
@@ -59,11 +65,11 @@ public class AddMediaToImageGalleryOperation extends AbstractPostTaxonOperation
                        throws ExecutionException {
 
                monitor.worked(20);
-               
+
                ImagesUtility.addMediaToGallery(description, media);
-               
+
                monitor.worked(40);
-        
+
                return postExecute(media);
        }