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