09a2a532aa574018ce778b6948a509b2267e60ea
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / operation / AbstractPersistentPostOperation.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 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
11 package eu.etaxonomy.taxeditor.operation;
12
13 import org.eclipse.core.commands.operations.IUndoContext;
14 import org.eclipse.core.runtime.Assert;
15 import org.eclipse.core.runtime.IStatus;
16
17 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
18 import eu.etaxonomy.cdm.model.common.CdmBase;
19 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
20 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
21 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
22
23 /**
24 * Superclass for all operation that have to be committed imediately after execution.
25 *
26 * Note: You have to call the {@link #bind()} method in the {@link #execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)},
27 * {@link #undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)} and {@link #redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}
28 * methods so the correct persistence context gets bound.
29 *
30 * @author n.hoffmann
31 * @created 08.05.2009
32 * @version 1.0
33 */
34 public abstract class AbstractPersistentPostOperation extends AbstractPostTaxonOperation {
35 private final IConversationEnabled conversationEnabled;
36 private final ICdmEntitySessionEnabled cdmEntitySessionEnabled;
37 protected ITaxonTreeNode parentNode;
38
39 /**
40 * <p>Constructor for AbstractPersistentPostOperation.</p>
41 *
42 * @param label a {@link java.lang.String} object.
43 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
44 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
45 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
46 */
47 protected AbstractPersistentPostOperation(String label, IUndoContext undoContext,
48 IPostOperationEnabled postOperationEnabled,
49 IConversationEnabled conversationEnabled,
50 ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
51 super(label, undoContext, postOperationEnabled);
52 this.conversationEnabled = conversationEnabled;
53 this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
54 }
55
56 /**
57 * <p>Constructor for AbstractPersistentPostOperation.</p>
58 *
59 * @param label a {@link java.lang.String} object.
60 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
61 * @param taxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
62 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
63 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
64 */
65 public AbstractPersistentPostOperation(String label,
66 IUndoContext undoContext, TaxonNode taxonNode,
67 IPostOperationEnabled postOperationEnabled,
68 IConversationEnabled conversationEnabled,
69 ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
70 super(label, undoContext, taxonNode, postOperationEnabled);
71 this.conversationEnabled = conversationEnabled;
72 this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
73 }
74
75 /**
76 * <p>Constructor for AbstractPersistentPostOperation.</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 postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
81 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
82 * @param parentNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
83 */
84 public AbstractPersistentPostOperation(String label,
85 IUndoContext undoContext, ITaxonTreeNode parentNode,
86 IPostOperationEnabled postOperationEnabled,
87 IConversationEnabled conversationEnabled,
88 ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
89 super(label, undoContext, postOperationEnabled);
90 this.parentNode = parentNode;
91 this.conversationEnabled = conversationEnabled;
92 this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
93 }
94
95 /* (non-Javadoc)
96 * @see eu.etaxonomy.taxeditor.operations.AbstractPostOperation#postExecute(eu.etaxonomy.cdm.model.common.CdmBase)
97 */
98 /** {@inheritDoc} */
99 @Override
100 protected IStatus postExecute(CdmBase objectAffectedByOperation) {
101 Assert.isNotNull(conversationEnabled, "Operation has to have a valid conversation attached.");
102
103
104 if (!conversationEnabled.getConversationHolder().isClosed()){
105 conversationEnabled.getConversationHolder().bind();
106 conversationEnabled.getConversationHolder().commit(true);
107 }
108 if(cdmEntitySessionEnabled != null) {
109 cdmEntitySessionEnabled.getCdmEntitySession().fireNotifications();
110 }
111 IStatus status = super.postExecute(objectAffectedByOperation);
112
113 return status;
114 }
115
116 /**
117 * Binds the conversation that was attached to this operation.
118 */
119 public void bind(){
120 conversationEnabled.getConversationHolder().bind();
121 }
122
123 }