Did some code cleanup. Removed obsolete and deprecated classes.
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / operations / CreateTaxonNodeOperation.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.operations;
12
13 import java.util.UUID;
14
15 import org.apache.log4j.Logger;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.core.commands.operations.IUndoContext;
18 import org.eclipse.core.runtime.IAdaptable;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.IStatus;
21 import org.eclipse.core.runtime.Status;
22
23 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
24 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
25 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
26 import eu.etaxonomy.cdm.model.taxon.ITreeNode;
27 import eu.etaxonomy.cdm.model.taxon.Taxon;
28 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
29 import eu.etaxonomy.taxeditor.store.CdmStore;
30 import eu.etaxonomy.taxeditor.store.StoreUtil;
31 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
32
33 /**
34 * @author n.hoffmann
35 * @created 08.05.2009
36 * @version 1.0
37 */
38 public class CreateTaxonNodeOperation extends AbstractPersistentPostOperation {
39
40 private static final Logger logger = Logger.getLogger(CreateTaxonNodeOperation.class);
41
42 private Taxon newTaxon;
43
44 private TaxonNode childTaxonNode;
45
46 /**
47 * Add a name to a taxonomic tree
48 *
49 * @param label
50 * @param undoContext
51 * @param parentNodeUuid
52 * @param name
53 * @param postOperationEnabled
54 */
55 public CreateTaxonNodeOperation(String label, IUndoContext undoContext,
56 ITreeNode parentNode, TaxonNameBase<?, ?> name, IPostOperationEnabled postOperationEnabled,
57 IConversationEnabled conversationEnabled) {
58 super(label, undoContext, parentNode, postOperationEnabled, conversationEnabled);
59
60 newTaxon = Taxon.NewInstance(name, null);
61 }
62
63 /**
64 * Add a taxon to a taxonomic tree
65 *
66 * @param label
67 * @param undoContext
68 * @param parentNodeUuid
69 * @param taxon
70 * @param postOperationEnabled
71 */
72 public CreateTaxonNodeOperation(String label, IUndoContext undoContext,
73 ITreeNode parentNode, Taxon taxon, IPostOperationEnabled postOperationEnabled,
74 IConversationEnabled conversationEnabled) {
75 super(label, undoContext, parentNode, postOperationEnabled, conversationEnabled);
76
77 this.newTaxon = taxon;
78 }
79
80
81 /* (non-Javadoc)
82 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
83 */
84 @Override
85 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
86 throws ExecutionException {
87 bind();
88 // Start the main progress monitor.
89 IProgressMonitor newMonitor = StoreUtil.startMainMonitor(monitor,"Creating Taxon Node", 3);
90
91 // Do one step
92 newMonitor.worked(1);
93
94 try {
95 // Operation steps
96
97 newTaxon.setSec(parentNode.getReference());
98 StoreUtil.isCanceled(newMonitor, 1);
99
100 // add the taxon
101 childTaxonNode = parentNode.addChildTaxon(newTaxon, parentNode.getReference(), parentNode.getMicroReference(), null);
102 StoreUtil.isCanceled(newMonitor, 1);
103 }
104 finally {
105
106 // Stop the progress monitor.
107 newMonitor.done();
108 }
109
110 return postExecute(childTaxonNode);
111 }
112
113 /* (non-Javadoc)
114 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
115 */
116 @Override
117 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
118 throws ExecutionException {
119 return execute(monitor, info);
120 }
121
122 /* (non-Javadoc)
123 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
124 */
125 @Override
126 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
127 throws ExecutionException {
128
129 logger.warn("Not yet implemented.");
130 return null;
131 }
132 }