Re-implemented taxonomic tree using Common Navigator Framework.
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / 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.store.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
21 /**
22 * @author p.ciardelli
23 * @created 14.01.2009
24 * @version 1.0
25 * @author n.hoffmann
26 */
27 public abstract class AbstractPostOperation extends AbstractOperation {
28
29 private static final Logger logger = Logger
30 .getLogger(AbstractPostOperation.class);
31
32 /**
33 *
34 */
35 protected IPostOperationEnabled postOperationEnabled;
36
37 /**
38 * A reference to the taxon the concrete operation is working on
39 */
40 protected Taxon taxon;
41
42 /**
43 *
44 * @param label
45 * @param undoContext
46 * @param taxon
47 */
48 public AbstractPostOperation(String label, IUndoContext undoContext,
49 Taxon taxon) {
50 super(label);
51 addContext(undoContext);
52
53 this.taxon = taxon;
54 }
55
56 /**
57 *
58 * @param label
59 * @param undoContext
60 * @param taxon
61 * @param postOperationEnabled
62 */
63 public AbstractPostOperation(String label, IUndoContext undoContext,
64 Taxon taxon, IPostOperationEnabled postOperationEnabled) {
65 this(label, undoContext, taxon);
66 this.postOperationEnabled = postOperationEnabled;
67 }
68
69 /**
70 * This method will try to call the post operation on a possibly registered
71 * IPostOperationEnabled implementor. Objects that were affected by the operation
72 * may be passed to the registered IPostOperationEnabled implementor.
73 *
74 *
75 * @param objectAffectedByOperation the affected object. Should be <code>null</code> if not needed
76 *
77 * @return
78 */
79 protected IStatus postExecute(CdmBase objectAffectedByOperation) {
80 if(postOperationEnabled != null){
81 logger.trace("executing post operation");
82 return postOperationEnabled.postOperation(objectAffectedByOperation) ? Status.OK_STATUS : Status.CANCEL_STATUS;
83 }
84 return Status.OK_STATUS;
85 }
86 }