7d6a77f97b34669491b6bfc7f5197bf4fdc9a358
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / operations / CreateDescriptionElementOperation.java
1 /**
2 * Copyright (C) 2007 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
10 package eu.etaxonomy.taxeditor.store.operations;
11
12 import org.eclipse.core.commands.ExecutionException;
13 import org.eclipse.core.commands.operations.IUndoContext;
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.IStatus;
17
18 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
19 import eu.etaxonomy.cdm.model.description.Feature;
20 import eu.etaxonomy.cdm.model.description.TaxonDescription;
21 import eu.etaxonomy.cdm.model.description.TextData;
22 import eu.etaxonomy.cdm.model.taxon.Taxon;
23
24 /**
25 * @author p.ciardelli
26 * @created 05.02.2009
27 * @version 1.0
28 * @author n.hoffmann
29 */
30 public class CreateDescriptionElementOperation extends AbstractPostOperation {
31
32 private TaxonDescription description;
33 private Feature feature;
34 private DescriptionElementBase element;
35
36 public CreateDescriptionElementOperation(String label, IUndoContext undoContext,
37 Taxon taxon, TaxonDescription description, Feature feature, IPostOperationEnabled postOperationEnabled) {
38 super(label, undoContext, taxon, postOperationEnabled);
39
40 this.description = description;
41 this.feature = feature;
42 }
43
44 /**
45 * @param name
46 * @param undoContext
47 * @param taxon
48 * @param description
49 * @param feature
50 * @param element
51 * @param postOperationEnabled
52 */
53 public CreateDescriptionElementOperation(String label,
54 IUndoContext undoContext, Taxon taxon,
55 TaxonDescription description, Feature feature,
56 DescriptionElementBase element, IPostOperationEnabled postOperationEnabled) {
57 this(label, undoContext, taxon, description, feature, postOperationEnabled);
58
59 this.element = element;
60 }
61
62 /* (non-Javadoc)
63 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
64 */
65 @Override
66 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
67 throws ExecutionException {
68
69 if (element == null) {
70 element = TextData.NewInstance(feature);
71 }
72 description.addElement(element);
73
74 return postExecute(element);
75 }
76
77 /* (non-Javadoc)
78 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
79 */
80 @Override
81 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
82 throws ExecutionException {
83
84 description.addElement(element);
85
86 return postExecute(element);
87 }
88
89 /* (non-Javadoc)
90 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
91 */
92 @Override
93 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
94 throws ExecutionException {
95
96 description.removeElement(element);
97
98 return postExecute(null);
99 }
100 }