5b7c68ec8230074a7de6ef72c0fd5ae812bb3636
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / operation / AbstractPostOperation.java
1 // $Id$
2 /**
3 * Copyright (C) 2013 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.taxeditor.operation;
11
12 import org.eclipse.core.commands.operations.AbstractOperation;
13 import org.eclipse.core.commands.operations.IUndoContext;
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.core.runtime.Status;
16
17 import eu.etaxonomy.cdm.model.common.CdmBase;
18 import eu.etaxonomy.cdm.model.common.ICdmBase;
19
20 /**
21 * @author pplitzner
22 * @date 03.12.2013
23 *
24 */
25 public abstract class AbstractPostOperation<T extends ICdmBase> extends AbstractOperation {
26
27
28 /**
29 * A reference to the {@link ICdmBase} element the concrete operation is working on
30 */
31 protected T element;
32
33 /**
34 *
35 */
36 protected IPostOperationEnabled postOperationEnabled;
37
38
39 /**
40 * <p>Constructor for AbstractPostOperation.</p>
41 *
42 * @param label a {@link java.lang.String} object.
43 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
44 */
45 protected AbstractPostOperation(String label, IUndoContext undoContext) {
46 super(label);
47 addContext(undoContext);
48 }
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 * @param element a {@link ICdmBase} object on which this operation is working.
56 */
57 public AbstractPostOperation(String label, IUndoContext undoContext, T element) {
58 this(label, undoContext);
59 this.element = element;
60 }
61
62 /**
63 * @param label
64 * @param element
65 * @param postOperationEnabled
66 */
67 public AbstractPostOperation(String label, IUndoContext undoContext,
68 T element, IPostOperationEnabled postOperationEnabled) {
69 this(label, undoContext);
70 this.element = element;
71 this.postOperationEnabled = postOperationEnabled;
72 }
73
74 /**
75 * This method will try to call the post operation on a possibly registered
76 * IPostOperationEnabled implementor. Objects that were affected by the operation
77 * may be passed to the registered IPostOperationEnabled implementor.
78 *
79 * @param objectAffectedByOperation the affected object. Should be <code>null</code> if not needed
80 * @return a {@link org.eclipse.core.runtime.IStatus} object.
81 */
82 protected IStatus postExecute(CdmBase objectAffectedByOperation) {
83 if(postOperationEnabled != null){
84 return postOperationEnabled.postOperation(objectAffectedByOperation) ? Status.OK_STATUS : Status.CANCEL_STATUS;
85 }
86 return Status.OK_STATUS;
87 }
88
89 /**
90 * <p>Getter for the field <code>postOperationEnabled</code>.</p>
91 *
92 * @return a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
93 */
94 public IPostOperationEnabled getPostOperationEnabled() {
95 return postOperationEnabled;
96 }
97
98 }