Project

General

Profile

Download (5.56 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.persistence.dto.TaxonNodeDto;
18
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
19

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

    
34
	protected TaxonNodeDto parentNode;
35

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

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

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

    
83
	}
84

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

    
103
	}
104

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

    
113

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

    
120
		return status;
121
	}
122

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

    
133
}
(2-2/11)