Merge branch 'release/5.19.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / operation / CreateTaxonNode.java
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 package eu.etaxonomy.taxeditor.navigation.operation;
10
11 import org.eclipse.core.commands.ExecutionException;
12 import org.eclipse.core.commands.operations.IUndoContext;
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17
18 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
19 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
20 import eu.etaxonomy.cdm.model.name.TaxonName;
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
23 import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
24 import eu.etaxonomy.taxeditor.model.MessagingUtils;
25 import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
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 */
37 @Deprecated // we do not undo creation of elements
38 public class CreateTaxonNode extends AbstractPersistentPostOperation {
39
40 private final Taxon newTaxon;
41
42 private TaxonNode childTaxonNode;
43
44 /**
45 * Add a name to a taxonomic tree
46 *
47 * @param label a {@link java.lang.String} object.
48 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
49 * @param name a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
50 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
51 * @param parentNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
52 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
53 */
54 public CreateTaxonNode(String label,
55 IUndoContext undoContext,
56 TaxonNodeDto parentNode, TaxonName name,
57 IPostOperationEnabled postOperationEnabled,
58 IConversationEnabled conversationEnabled,
59 ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
60 super(label, undoContext, parentNode, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
61
62 newTaxon = Taxon.NewInstance(name, null);
63 }
64
65 /**
66 * Add a taxon to a taxonomic tree
67 *
68 * @param label a {@link java.lang.String} object.
69 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
70 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
71 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
72 * @param parentNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
73 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
74 */
75 public CreateTaxonNode(String label,
76 IUndoContext undoContext,
77 TaxonNodeDto parentNode,
78 Taxon taxon,
79 IPostOperationEnabled postOperationEnabled,
80 IConversationEnabled conversationEnabled,
81 ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
82 super(label, undoContext, parentNode, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
83
84 this.newTaxon = taxon;
85 }
86
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 TaxonNode node = CdmStore.getService(ITaxonNodeService.class).find(parentNode.getUuid());
96 childTaxonNode = node.addChildTaxon(newTaxon, node.getReference(), node.getMicroReference());
97
98 monitor.worked(40);
99
100 CdmStore.getService(ITaxonNodeService.class).saveOrUpdate(childTaxonNode);
101
102 return postExecute(childTaxonNode);
103 }catch(Exception e){
104 MessagingUtils.messageDialog(Messages.CreateTaxonNode_CREATE_FAILED, getClass(), e.getLocalizedMessage(), e);
105 return Status.CANCEL_STATUS;
106 }
107 }
108
109 @Override
110 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
111 throws ExecutionException {
112 return execute(monitor, info);
113 }
114
115 @Override
116 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
117 throws ExecutionException {
118
119 MessagingUtils.warn(this.getClass(), "Not yet implemented."); //$NON-NLS-1$
120 return null;
121 }
122 }