ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / operation / AbstractDescriptionPostOperation.java
1 /**
2 * Copyright (C) 2013 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.operation;
10
11 import org.eclipse.core.commands.ExecutionException;
12 import org.eclipse.core.commands.operations.IUndoContext;
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
16
17 import eu.etaxonomy.cdm.model.description.DescriptionBase;
18 import eu.etaxonomy.cdm.model.description.Feature;
19 import eu.etaxonomy.cdm.model.description.IDescribable;
20 import eu.etaxonomy.cdm.model.description.TextData;
21 import eu.etaxonomy.cdm.model.media.Media;
22
23 /**
24 * @author pplitzner
25 * @date 04.12.2013
26 *
27 */
28 public abstract class AbstractDescriptionPostOperation<T extends IDescribable<D>, D extends DescriptionBase<?>> extends AbstractPostOperation<T> {
29
30 protected D description;
31
32 private final boolean isImageGallery;
33
34 /**
35 *
36 */
37 public AbstractDescriptionPostOperation(String label, IUndoContext undoContext,
38 T describable, IPostOperationEnabled postOperationEnabled) {
39 this(label, undoContext, describable, postOperationEnabled, false);
40 }
41
42 /**
43 *
44 */
45 public AbstractDescriptionPostOperation(String label, IUndoContext undoContext,
46 T describable, IPostOperationEnabled postOperationEnabled, boolean isImageGallery) {
47 super(label, undoContext, describable, postOperationEnabled);
48 this.isImageGallery = isImageGallery;
49 }
50
51 /* (non-Javadoc)
52 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
53 */
54 /** {@inheritDoc} */
55 @Override
56 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
57 throws ExecutionException {
58
59 initDescription();
60 monitor.worked(20);
61
62 if(isImageGallery){
63 description.setImageGallery(isImageGallery);
64 // add the description element to hold the media elements for this image gallery
65 TextData element = TextData.NewInstance(Feature.IMAGE());
66 element.addMedia(Media.NewInstance());
67 description.addElement(element);
68 }
69 monitor.worked(40);
70
71 return postExecute(description);
72 }
73
74 /**
75 * Creates the description and attaches it to the operated element.
76 */
77 protected abstract void initDescription();
78
79 /** {@inheritDoc} */
80 @Override
81 public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
82
83 element.addDescription(description);
84
85 return postExecute(description);
86 }
87
88 /** {@inheritDoc} */
89 @Override
90 public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
91
92 element.removeDescription(description);
93
94 return postExecute(null);
95 }
96
97 }