Merge branch 'hotfix/5.45.1'
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / uses / operation / CreateUseSummaryOperation.java
1 /**
2 * Copyright (C) 2011 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.editor.view.uses.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.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 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
24 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
25
26 /**
27 * CreateUseSummaryOperation Class
28 * @author a.theys
29 * @created mar 13, 2012
30 */
31 public class CreateUseSummaryOperation extends AbstractPostOperation<Taxon> {
32
33 public static final String ID = "eu.etaxonomy.taxeditor.editor.use.createUseRecord"; //$NON-NLS-1$
34
35 private final DescriptionBase<?> description;
36 private final Feature feature;
37 private DescriptionElementBase element;
38
39 /**
40 * <p>Constructor for CreateUseSummaryOperation.</p>
41 *
42 * @param label a {@link java.lang.String} object.
43 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
44 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
45 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
46 * @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
47 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
48 */
49 public CreateUseSummaryOperation(String label, IUndoContext undoContext, DescriptionBase<?> description, Feature feature, IPostOperationEnabled postOperationEnabled) {
50 super(label, undoContext, (Taxon)null, postOperationEnabled);
51
52 this.description = description;
53 this.feature = feature;
54 }
55
56 /**
57 * <p>Constructor for CreateUseSummaryOperation.</p>
58 */
59 public CreateUseSummaryOperation(String label,
60 IUndoContext undoContext, Taxon taxon,
61 TaxonDescription description, Feature feature,
62 DescriptionElementBase element, IPostOperationEnabled postOperationEnabled) {
63
64 this(label, undoContext, description, feature, postOperationEnabled);
65 this.element = element;
66 }
67
68 @Override
69 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
70 throws ExecutionException {
71 monitor.worked(20);
72 if (element == null) {
73 element = TextData.NewInstance();
74 }
75
76 element.setFeature(feature);
77 description.addElement(element);
78 monitor.worked(40);
79
80 return postExecute(element);
81 }
82
83 @Override
84 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
85 throws ExecutionException {
86
87 description.addElement(element);
88
89 return postExecute(element);
90 }
91
92 @Override
93 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
94 throws ExecutionException {
95 description.removeElement(element);
96
97 return postExecute(null);
98 }
99 }