e8b8a0d6ff24b82d2a72ca0cdf9eee7b0abc86d5
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / operations / 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.operations;
11
12 import java.util.UUID;
13
14 import org.apache.log4j.Logger;
15 import org.eclipse.core.commands.operations.AbstractOperation;
16 import org.eclipse.core.commands.operations.IUndoContext;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Status;
19
20 import eu.etaxonomy.cdm.model.common.CdmBase;
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
23
24 /**
25 * @author p.ciardelli
26 * @created 14.01.2009
27 * @version 1.0
28 * @author n.hoffmann
29 */
30 public abstract class AbstractPostOperation extends AbstractOperation {
31
32 private static final Logger logger = Logger
33 .getLogger(AbstractPostOperation.class);
34
35 /**
36 *
37 */
38 protected IPostOperationEnabled postOperationEnabled;
39
40 /**
41 * A reference to the taxon the concrete operation is working on
42 */
43 protected Taxon taxon;
44
45 /**
46 * A reference to the taxons TaxonNode
47 */
48 protected TaxonNode taxonNode;
49
50 protected UUID parentNodeUuid;
51
52 /**
53 *
54 * @param label
55 * @param undoContext
56 * @param taxon
57 */
58 protected AbstractPostOperation(String label, IUndoContext undoContext) {
59 super(label);
60 addContext(undoContext);
61 }
62
63 /**
64 *
65 * @param label
66 * @param undoContext
67 * @param taxon
68 */
69 public AbstractPostOperation(String label, IUndoContext undoContext,
70 Taxon taxon) {
71 this(label, undoContext);
72
73 this.taxon = taxon;
74 }
75
76 /**
77 *
78 * @param label
79 * @param undoContext
80 * @param taxon
81 * @param postOperationEnabled
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 *
91 * @param label
92 * @param undoContext
93 * @param taxonNode
94 * @param postOperationEnabled
95 */
96 public AbstractPostOperation(String label, IUndoContext undoContext, TaxonNode taxonNode, IPostOperationEnabled postOperationEnabled){
97 this(label, undoContext, taxonNode.getTaxon(), postOperationEnabled);
98 this.taxonNode = taxonNode;
99 }
100
101 public AbstractPostOperation(String label, IUndoContext undoContext, UUID parentNodeUuid, IPostOperationEnabled postOperationEnabled){
102 this(label, undoContext);
103
104 this.parentNodeUuid = parentNodeUuid;
105 this.postOperationEnabled = postOperationEnabled;
106 }
107
108 /**
109 * This method will try to call the post operation on a possibly registered
110 * IPostOperationEnabled implementor. Objects that were affected by the operation
111 * may be passed to the registered IPostOperationEnabled implementor.
112 *
113 *
114 * @param objectAffectedByOperation the affected object. Should be <code>null</code> if not needed
115 *
116 * @return
117 */
118 protected IStatus postExecute(CdmBase objectAffectedByOperation) {
119 if(postOperationEnabled != null){
120 logger.trace("executing post operation");
121 return postOperationEnabled.postOperation(objectAffectedByOperation) ? Status.OK_STATUS : Status.CANCEL_STATUS;
122 }
123 return Status.OK_STATUS;
124 }
125 }