Project

General

Profile

Download (4.4 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

    
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 AbstractPostOperation {
34
	private 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
		super(label, undoContext, postOperationEnabled);
50
		this.conversationEnabled = conversationEnabled;
51
	}
52

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

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

    
88
	/* (non-Javadoc)
89
	 * @see eu.etaxonomy.taxeditor.operations.AbstractPostOperation#postExecute(eu.etaxonomy.cdm.model.common.CdmBase)
90
	 */
91
	/** {@inheritDoc} */
92
	@Override
93
    protected IStatus postExecute(CdmBase objectAffectedByOperation) {
94
		Assert.isNotNull(conversationEnabled, "Operation has to have a valid conversation attached.");
95

    
96
		
97
		if (!conversationEnabled.getConversationHolder().isClosed()){
98
			conversationEnabled.getConversationHolder().commit(true);
99
		}
100
		IStatus status = super.postExecute(objectAffectedByOperation);
101

    
102
		return status;
103
	}
104

    
105
	/**
106
	 * Binds the conversation that was attached to this operation.
107
	 */
108
	public void bind(){
109
		conversationEnabled.getConversationHolder().bind();
110
	}
111

    
112
}
(1-1/3)