smaller fixes
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / operation / AbstractPostOperation.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.operation;
11
12 import java.util.UUID;
13
14 import org.eclipse.core.commands.operations.AbstractOperation;
15 import org.eclipse.core.commands.operations.IUndoContext;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
18
19 import eu.etaxonomy.cdm.model.common.CdmBase;
20 import eu.etaxonomy.cdm.model.common.ITreeNode;
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
23
24 /**
25 * <p>Abstract AbstractPostOperation class.</p>
26 *
27 * @author p.ciardelli
28 * @author n.hoffmann
29 * @created 14.01.2009
30 * @version 1.0
31 */
32 public abstract class AbstractPostOperation extends AbstractOperation {
33
34 /**
35 *
36 */
37 protected IPostOperationEnabled postOperationEnabled;
38
39 /**
40 * A reference to the taxon the concrete operation is working on
41 */
42 protected Taxon taxon;
43
44 /**
45 * A reference to the taxons TaxonNode
46 */
47 protected ITreeNode taxonNode;
48
49 protected UUID parentNodeUuid;
50
51 /**
52 * <p>Constructor for AbstractPostOperation.</p>
53 *
54 * @param label a {@link java.lang.String} object.
55 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
56 */
57 protected AbstractPostOperation(String label, IUndoContext undoContext) {
58 super(label);
59 addContext(undoContext);
60 }
61
62 /**
63 * <p>Constructor for AbstractPostOperation.</p>
64 *
65 * @param label a {@link java.lang.String} object.
66 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
67 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
68 */
69 public AbstractPostOperation(String label, IUndoContext undoContext,
70 Taxon taxon) {
71 this(label, undoContext);
72
73 this.taxon = taxon;
74 }
75
76 /**
77 * <p>Constructor for AbstractPostOperation.</p>
78 *
79 * @param label a {@link java.lang.String} object.
80 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
81 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
82 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
83 */
84 public AbstractPostOperation(String label, IUndoContext undoContext,
85 Taxon taxon, IPostOperationEnabled postOperationEnabled) {
86 this(label, undoContext, taxon);
87 this.postOperationEnabled = postOperationEnabled;
88 }
89
90 /**
91 * <p>Constructor for AbstractPostOperation.</p>
92 *
93 * @param label a {@link java.lang.String} object.
94 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
95 * @param taxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
96 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
97 */
98 public AbstractPostOperation(String label, IUndoContext undoContext, TaxonNode taxonNode, IPostOperationEnabled postOperationEnabled){
99 this(label, undoContext, taxonNode.getTaxon(), postOperationEnabled);
100 this.taxonNode = taxonNode;
101 }
102
103 /**
104 * <p>Constructor for AbstractPostOperation.</p>
105 *
106 * @param label a {@link java.lang.String} object.
107 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
108 * @param parentNodeUuid a {@link java.util.UUID} object.
109 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
110 */
111 public AbstractPostOperation(String label, IUndoContext undoContext, UUID parentNodeUuid, IPostOperationEnabled postOperationEnabled){
112 this(label, undoContext);
113
114 this.parentNodeUuid = parentNodeUuid;
115 this.postOperationEnabled = postOperationEnabled;
116 }
117
118 /**
119 * <p>Constructor for AbstractPostOperation.</p>
120 *
121 * @param label a {@link java.lang.String} object.
122 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
123 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
124 */
125 public AbstractPostOperation(String label, IUndoContext undoContext,
126 IPostOperationEnabled postOperationEnabled) {
127 this(label, undoContext);
128 this.postOperationEnabled = postOperationEnabled;
129 }
130
131 /**
132 * This method will try to call the post operation on a possibly registered
133 * IPostOperationEnabled implementor. Objects that were affected by the operation
134 * may be passed to the registered IPostOperationEnabled implementor.
135 *
136 * @param objectAffectedByOperation the affected object. Should be <code>null</code> if not needed
137 * @return a {@link org.eclipse.core.runtime.IStatus} object.
138 */
139 protected IStatus postExecute(CdmBase objectAffectedByOperation) {
140 if(postOperationEnabled != null){
141 return postOperationEnabled.postOperation(objectAffectedByOperation) ? Status.OK_STATUS : Status.CANCEL_STATUS;
142 }
143 return Status.OK_STATUS;
144 }
145
146 /**
147 * <p>Getter for the field <code>postOperationEnabled</code>.</p>
148 *
149 * @return a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
150 */
151 public IPostOperationEnabled getPostOperationEnabled() {
152 return postOperationEnabled;
153 }
154
155
156 }