54d8685b96ad9059a79da09e4b4aea836672823c
[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 org.apache.log4j.Logger;
13 import org.eclipse.core.commands.operations.AbstractOperation;
14 import org.eclipse.core.commands.operations.IUndoContext;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17
18 import eu.etaxonomy.cdm.model.common.CdmBase;
19 import eu.etaxonomy.cdm.model.taxon.Taxon;
20 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
21
22 /**
23 * @author p.ciardelli
24 * @created 14.01.2009
25 * @version 1.0
26 * @author n.hoffmann
27 */
28 public abstract class AbstractPostOperation extends AbstractOperation {
29
30 private static final Logger logger = Logger
31 .getLogger(AbstractPostOperation.class);
32
33 /**
34 *
35 */
36 protected 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 /**
49 *
50 * @param label
51 * @param undoContext
52 * @param taxon
53 */
54 public AbstractPostOperation(String label, IUndoContext undoContext,
55 Taxon taxon) {
56 super(label);
57 addContext(undoContext);
58
59 this.taxon = taxon;
60 }
61
62 /**
63 *
64 * @param label
65 * @param undoContext
66 * @param taxon
67 * @param postOperationEnabled
68 */
69 public AbstractPostOperation(String label, IUndoContext undoContext,
70 Taxon taxon, IPostOperationEnabled postOperationEnabled) {
71 this(label, undoContext, taxon);
72 this.postOperationEnabled = postOperationEnabled;
73 }
74
75 /**
76 *
77 * @param label
78 * @param undoContext
79 * @param taxonNode
80 * @param postOperationEnabled
81 */
82 public AbstractPostOperation(String label, IUndoContext undoContext, TaxonNode taxonNode, IPostOperationEnabled postOperationEnabled){
83 this(label, undoContext, taxonNode.getTaxon(), postOperationEnabled);
84 this.taxonNode = taxonNode;
85 }
86
87 /**
88 * This method will try to call the post operation on a possibly registered
89 * IPostOperationEnabled implementor. Objects that were affected by the operation
90 * may be passed to the registered IPostOperationEnabled implementor.
91 *
92 *
93 * @param objectAffectedByOperation the affected object. Should be <code>null</code> if not needed
94 *
95 * @return
96 */
97 protected IStatus postExecute(CdmBase objectAffectedByOperation) {
98 if(postOperationEnabled != null){
99 logger.trace("executing post operation");
100 return postOperationEnabled.postOperation(objectAffectedByOperation) ? Status.OK_STATUS : Status.CANCEL_STATUS;
101 }
102 return Status.OK_STATUS;
103 }
104 }