Project

General

Profile

Download (4.92 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.navigation.operation;
11

    
12
import org.eclipse.core.commands.ExecutionException;
13
import org.eclipse.core.commands.operations.IUndoContext;
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.Status;
18

    
19
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
20
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
21
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
22
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
25
import eu.etaxonomy.taxeditor.model.MessagingUtils;
26
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
27
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
28
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
29
import eu.etaxonomy.taxeditor.store.CdmStore;
30

    
31
/**
32
 * <p>CreateTaxonNodeOperation class.</p>
33
 *
34
 * @author n.hoffmann
35
 * @created 08.05.2009
36
 * @version 1.0
37
 */
38
@Deprecated // we do not undo creation of elements
39
public class CreateTaxonNode extends AbstractPersistentPostOperation {
40

    
41
	private final Taxon newTaxon;
42

    
43
	private TaxonNode childTaxonNode;
44

    
45
	/**
46
	 * Add a name to a taxonomic tree
47
	 *
48
	 * @param label a {@link java.lang.String} object.
49
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
50
	 * @param name a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
51
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
52
	 * @param parentNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
53
	 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
54
	 */
55
	public CreateTaxonNode(String label,
56
	        IUndoContext undoContext,
57
	        ITaxonTreeNode parentNode, TaxonNameBase<?, ?> name,
58
	        IPostOperationEnabled postOperationEnabled,
59
			IConversationEnabled conversationEnabled,
60
            ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
61
		super(label, undoContext, parentNode, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
62

    
63
		newTaxon = Taxon.NewInstance(name, null);
64
	}
65

    
66
	/**
67
	 * Add a taxon to a taxonomic tree
68
	 *
69
	 * @param label a {@link java.lang.String} object.
70
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
71
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
72
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
73
	 * @param parentNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
74
	 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
75
	 */
76
	public CreateTaxonNode(String label,
77
	        IUndoContext undoContext,
78
	        ITaxonTreeNode parentNode,
79
	        Taxon taxon,
80
	        IPostOperationEnabled postOperationEnabled,
81
			IConversationEnabled conversationEnabled,
82
            ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
83
		super(label, undoContext, parentNode, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
84

    
85
		this.newTaxon = taxon;
86
	}
87

    
88

    
89
	/* (non-Javadoc)
90
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
91
	 */
92
	/** {@inheritDoc} */
93
	@Override
94
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
95
			throws ExecutionException {
96

    
97
		try{
98
			// add the taxon
99
			bind();
100
			monitor.worked(20);
101
			childTaxonNode = parentNode.addChildTaxon(newTaxon, parentNode.getReference(), parentNode.getMicroReference());
102

    
103
			monitor.worked(40);
104

    
105
			CdmStore.getService(ITaxonNodeService.class).saveOrUpdate(childTaxonNode);
106

    
107
			return postExecute(childTaxonNode);
108
		}catch(Exception e){
109
			MessagingUtils.messageDialog("Could not create taxon node", getClass(), e.getLocalizedMessage(), e);
110
			return Status.CANCEL_STATUS;
111
		}
112
	}
113

    
114
	/* (non-Javadoc)
115
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
116
	 */
117
	/** {@inheritDoc} */
118
	@Override
119
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
120
			throws ExecutionException {
121
		return execute(monitor, info);
122
	}
123

    
124
	/* (non-Javadoc)
125
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
126
	 */
127
	/** {@inheritDoc} */
128
	@Override
129
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
130
			throws ExecutionException {
131

    
132
		MessagingUtils.warn(this.getClass(), "Not yet implemented.");
133
		return null;
134
	}
135
}
(5-5/5)