Project

General

Profile

Download (5.6 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
        this(label, undoContext, postOperationEnabled, conversationEnabled, null);
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 postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
59
	 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
60
	 */
61
	protected AbstractPersistentPostOperation(String label, IUndoContext undoContext,
62
			IPostOperationEnabled postOperationEnabled,
63
			IConversationEnabled conversationEnabled,
64
			ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
65
		super(label, undoContext, postOperationEnabled, cdmEntitySessionEnabled);
66
		this.conversationEnabled = conversationEnabled;
67
	}
68

    
69
	/**
70
	 * <p>Constructor for AbstractPersistentPostOperation.</p>
71
	 *
72
	 * @param label a {@link java.lang.String} object.
73
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
74
	 * @param taxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} 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
	 */
78
	public AbstractPersistentPostOperation(String label,
79
			IUndoContext undoContext, TaxonNode taxonNode,
80
			IPostOperationEnabled postOperationEnabled,
81
			IConversationEnabled conversationEnabled,
82
			ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
83
		super(label, undoContext, taxonNode, postOperationEnabled, cdmEntitySessionEnabled);
84
		this.conversationEnabled = conversationEnabled;
85

    
86
	}
87

    
88
	/**
89
	 * <p>Constructor for AbstractPersistentPostOperation.</p>
90
	 *
91
	 * @param label a {@link java.lang.String} object.
92
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
93
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
94
	 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
95
	 * @param parentNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
96
	 */
97
	public AbstractPersistentPostOperation(String label,
98
			IUndoContext undoContext, ITaxonTreeNode parentNode,
99
			IPostOperationEnabled postOperationEnabled,
100
			IConversationEnabled conversationEnabled,
101
            ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
102
		super(label, undoContext, postOperationEnabled, cdmEntitySessionEnabled);
103
		this.parentNode = parentNode;
104
		this.conversationEnabled = conversationEnabled;
105

    
106
	}
107

    
108
	/* (non-Javadoc)
109
	 * @see eu.etaxonomy.taxeditor.operations.AbstractPostOperation#postExecute(eu.etaxonomy.cdm.model.common.CdmBase)
110
	 */
111
	/** {@inheritDoc} */
112
	@Override
113
    protected IStatus postExecute(CdmBase objectAffectedByOperation) {
114
		Assert.isNotNull(conversationEnabled, "Operation has to have a valid conversation attached.");
115

    
116

    
117
		if (!conversationEnabled.getConversationHolder().isClosed()){
118
			conversationEnabled.getConversationHolder().bind();
119
			conversationEnabled.getConversationHolder().commit(true);
120
		}
121
		IStatus status = super.postExecute(objectAffectedByOperation);
122

    
123
		return status;
124
	}
125

    
126
	/**
127
	 * Binds the conversation that was attached to this operation.
128
	 */
129
	public void bind(){
130
		conversationEnabled.getConversationHolder().bind();
131
		if(getCdmEntitySessionEnabled() != null) {
132
		    getCdmEntitySessionEnabled().getCdmEntitySession().bind();
133
        }
134
	}
135

    
136
}
(2-2/10)