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