Project

General

Profile

Download (5.61 KB) Statistics
| Branch: | Tag: | Revision:
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.persistence.dto.TaxonNodeDto;
19
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
20

    
21
/**
22
 * Superclass for all operation that have to be committed imediately after execution.
23
 *
24
 * Note: You have to call the {@link #bind()} method in the {@link #execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)},
25
 * {@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)}
26
 * methods so the correct persistence context gets bound.
27
 *
28
 * @author n.hoffmann
29
 * @created 08.05.2009
30
 * @version 1.0
31
 */
32
public abstract class AbstractPersistentPostOperation extends AbstractPostTaxonOperation {
33
	private final IConversationEnabled conversationEnabled;
34

    
35
	protected TaxonNodeDto parentNode;
36

    
37
	   /**
38
     * <p>Constructor for AbstractPersistentPostOperation.</p>
39
     *
40
     * @param label a {@link java.lang.String} object.
41
     * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
42
     * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
43
     * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
44
     */
45
    protected AbstractPersistentPostOperation(String label, IUndoContext undoContext,
46
            IPostOperationEnabled postOperationEnabled,
47
            IConversationEnabled conversationEnabled) {
48
        this(label, undoContext, postOperationEnabled, conversationEnabled, null);
49
    }
50

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

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

    
84
	}
85

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

    
104
	}
105

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

    
114

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

    
121
		return status;
122
	}
123

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

    
134
}
(2-2/11)