Project

General

Profile

Download (5.05 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.TaxonName;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
24
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
25
import eu.etaxonomy.taxeditor.model.MessagingUtils;
26
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
27
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
28
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
29
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
30
import eu.etaxonomy.taxeditor.store.CdmStore;
31

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

    
42
	private final Taxon newTaxon;
43

    
44
	private TaxonNode childTaxonNode;
45

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

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

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

    
86
		this.newTaxon = taxon;
87
	}
88

    
89

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

    
98
		try{
99
			// add the taxon
100
			bind();
101
			monitor.worked(20);
102
			TaxonNode node = CdmStore.getService(ITaxonNodeService.class).find(parentNode.getUuid());
103
			childTaxonNode = node.addChildTaxon(newTaxon, node.getReference(), node.getMicroReference());
104

    
105
			monitor.worked(40);
106

    
107
			CdmStore.getService(ITaxonNodeService.class).saveOrUpdate(childTaxonNode);
108

    
109
			return postExecute(childTaxonNode);
110
		}catch(Exception e){
111
			MessagingUtils.messageDialog(Messages.CreateTaxonNode_CREATE_FAILED, getClass(), e.getLocalizedMessage(), e);
112
			return Status.CANCEL_STATUS;
113
		}
114
	}
115

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

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

    
134
		MessagingUtils.warn(this.getClass(), "Not yet implemented."); //$NON-NLS-1$
135
		return null;
136
	}
137
}
(5-5/5)