Project

General

Profile

Download (5 KB) Statistics
| Branch: | Tag: | Revision:
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

    
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, cdmEntitySessionEnabled);
52
		this.conversationEnabled = conversationEnabled;
53
	}
54

    
55
	/**
56
	 * <p>Constructor for AbstractPersistentPostOperation.</p>
57
	 *
58
	 * @param label a {@link java.lang.String} object.
59
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
60
	 * @param taxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
61
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
62
	 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
63
	 */
64
	public AbstractPersistentPostOperation(String label,
65
			IUndoContext undoContext, TaxonNode taxonNode,
66
			IPostOperationEnabled postOperationEnabled,
67
			IConversationEnabled conversationEnabled,
68
			ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
69
		super(label, undoContext, taxonNode, postOperationEnabled, cdmEntitySessionEnabled);
70
		this.conversationEnabled = conversationEnabled;
71

    
72
	}
73

    
74
	/**
75
	 * <p>Constructor for AbstractPersistentPostOperation.</p>
76
	 *
77
	 * @param label a {@link java.lang.String} object.
78
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
79
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
80
	 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
81
	 * @param parentNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
82
	 */
83
	public AbstractPersistentPostOperation(String label,
84
			IUndoContext undoContext, ITaxonTreeNode parentNode,
85
			IPostOperationEnabled postOperationEnabled,
86
			IConversationEnabled conversationEnabled,
87
            ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
88
		super(label, undoContext, postOperationEnabled, cdmEntitySessionEnabled);
89
		this.parentNode = parentNode;
90
		this.conversationEnabled = conversationEnabled;
91

    
92
	}
93

    
94
	/* (non-Javadoc)
95
	 * @see eu.etaxonomy.taxeditor.operations.AbstractPostOperation#postExecute(eu.etaxonomy.cdm.model.common.CdmBase)
96
	 */
97
	/** {@inheritDoc} */
98
	@Override
99
    protected IStatus postExecute(CdmBase objectAffectedByOperation) {
100
		Assert.isNotNull(conversationEnabled, "Operation has to have a valid conversation attached.");
101

    
102

    
103
		if (!conversationEnabled.getConversationHolder().isClosed()){
104
			conversationEnabled.getConversationHolder().bind();
105
			conversationEnabled.getConversationHolder().commit(true);
106
		}
107
		if(getCdmEntitySessionEnabled() != null) {
108
		    getCdmEntitySessionEnabled().getCdmEntitySession().fireNotifications();
109
		}
110
		IStatus status = super.postExecute(objectAffectedByOperation);
111

    
112
		return status;
113
	}
114

    
115
	/**
116
	 * Binds the conversation that was attached to this operation.
117
	 */
118
	public void bind(){
119
		conversationEnabled.getConversationHolder().bind();
120
		if(getCdmEntitySessionEnabled() != null) {
121
		    getCdmEntitySessionEnabled().getCdmEntitySession().bind();
122
        }
123
	}
124

    
125
}
(2-2/5)