Moved all logging and dialog functionality to the new class MessagingUtils.
[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.ITaxonTreeNode;
24 import eu.etaxonomy.cdm.model.taxon.Taxon;
25 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
26 import eu.etaxonomy.taxeditor.model.MessagingUtils;
27 import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
28 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
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 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, IUndoContext undoContext,
56 ITaxonTreeNode 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 a {@link java.lang.String} object.
67 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
68 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
69 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
70 * @param parentNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
71 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
72 */
73 public CreateTaxonNode(String label, IUndoContext undoContext,
74 ITaxonTreeNode parentNode, Taxon taxon, IPostOperationEnabled postOperationEnabled,
75 IConversationEnabled conversationEnabled) {
76 super(label, undoContext, parentNode, postOperationEnabled, conversationEnabled);
77
78 this.newTaxon = taxon;
79 }
80
81
82 /* (non-Javadoc)
83 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
84 */
85 /** {@inheritDoc} */
86 @Override
87 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
88 throws ExecutionException {
89
90 try{
91 // add the taxon
92 bind();
93 monitor.worked(20);
94 childTaxonNode = parentNode.addChildTaxon(newTaxon, parentNode.getReference(), parentNode.getMicroReference());
95
96 monitor.worked(40);
97
98 CdmStore.getService(ITaxonNodeService.class).saveOrUpdate(childTaxonNode);
99
100 return postExecute(childTaxonNode);
101 }catch(Exception e){
102 MessagingUtils.messageDialog("Could not create taxon node", getClass(), e.getLocalizedMessage(), e);
103 return Status.CANCEL_STATUS;
104 }
105 }
106
107 /* (non-Javadoc)
108 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
109 */
110 /** {@inheritDoc} */
111 @Override
112 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
113 throws ExecutionException {
114 return execute(monitor, info);
115 }
116
117 /* (non-Javadoc)
118 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
119 */
120 /** {@inheritDoc} */
121 @Override
122 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
123 throws ExecutionException {
124
125 MessagingUtils.warn(this.getClass(), "Not yet implemented.");
126 return null;
127 }
128 }