- fixed compile error in test
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / operation / CreateTaxonNode.java
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.navigation.operation;
12
13 import org.eclipse.core.commands.ExecutionException;
14 import org.eclipse.core.commands.operations.IUndoContext;
15 import org.eclipse.core.runtime.IAdaptable;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Status;
19
20 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
21 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
22 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
23 import eu.etaxonomy.cdm.model.taxon.ITreeNode;
24 import eu.etaxonomy.cdm.model.taxon.Taxon;
25 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
26 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
27 import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
28 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
29 import eu.etaxonomy.taxeditor.store.CdmStore;
30 import eu.etaxonomy.taxeditor.store.StoreUtil;
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 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.ITreeNode} object.
54 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
55 */
56 public CreateTaxonNode(String label, IUndoContext undoContext,
57 ITreeNode parentNode, TaxonNameBase<?, ?> name, IPostOperationEnabled postOperationEnabled,
58 IConversationEnabled conversationEnabled) {
59 super(label, undoContext, parentNode, postOperationEnabled, conversationEnabled);
60
61 newTaxon = Taxon.NewInstance(name, null);
62 }
63
64 /**
65 * Add a taxon to a taxonomic tree
66 *
67 * @param label a {@link java.lang.String} object.
68 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
69 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
70 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
71 * @param parentNode a {@link eu.etaxonomy.cdm.model.taxon.ITreeNode} object.
72 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
73 */
74 public CreateTaxonNode(String label, IUndoContext undoContext,
75 ITreeNode parentNode, Taxon taxon, IPostOperationEnabled postOperationEnabled,
76 IConversationEnabled conversationEnabled) {
77 super(label, undoContext, parentNode, postOperationEnabled, conversationEnabled);
78
79 this.newTaxon = taxon;
80 }
81
82
83 /* (non-Javadoc)
84 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
85 */
86 /** {@inheritDoc} */
87 @Override
88 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
89 throws ExecutionException {
90
91 try{
92 // add the taxon
93 bind();
94 monitor.worked(20);
95 childTaxonNode = parentNode.addChildTaxon(newTaxon, parentNode.getReference(), parentNode.getMicroReference());
96
97 monitor.worked(40);
98
99 CdmStore.getService(ITaxonNodeService.class).saveOrUpdate(childTaxonNode);
100
101 return postExecute(childTaxonNode);
102 }catch(Exception e){
103 NavigationUtil.errorDialog("Could not create taxon node", getClass(), e.getLocalizedMessage(), e);
104 return Status.CANCEL_STATUS;
105 }
106 }
107
108 /* (non-Javadoc)
109 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
110 */
111 /** {@inheritDoc} */
112 @Override
113 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
114 throws ExecutionException {
115 return execute(monitor, info);
116 }
117
118 /* (non-Javadoc)
119 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
120 */
121 /** {@inheritDoc} */
122 @Override
123 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
124 throws ExecutionException {
125
126 StoreUtil.warn(this.getClass(), "Not yet implemented.");
127 return null;
128 }
129 }