2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
;
12 import java
.util
.HashMap
;
13 import java
.util
.HashSet
;
16 import java
.util
.UUID
;
18 import org
.eclipse
.core
.commands
.ExecutionException
;
19 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
20 import org
.eclipse
.core
.runtime
.IAdaptable
;
21 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
22 import org
.eclipse
.core
.runtime
.IStatus
;
23 import org
.eclipse
.core
.runtime
.Status
;
25 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
26 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
27 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
28 import eu
.etaxonomy
.cdm
.api
.service
.UpdateResult
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.IllegalAncestryException
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
32 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
33 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPersistentPostOperation
;
34 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
35 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
38 * Change the taxonomic parent of a given taxon.
44 public class MoveTaxonOperation
extends AbstractPersistentPostOperation
{
47 * A reference to the new taxonomical parent.
49 private ITaxonTreeNode newParentTreeNode
;
51 * A reference to the former taxonomical parents
53 //private Map<TaxonNode, ITaxonTreeNode> oldParentTreeNodes;
55 private TaxonNode taxonNode
;
56 private boolean moveToParentNode
;
58 * <p>Constructor for MoveTaxonOperation.</p>
60 * @param label a {@link java.lang.String} object.
61 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
62 * @param taxonNodes a {@link java.util.Set} object.
63 * @param newParentTreeNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
64 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
65 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
67 public MoveTaxonOperation(String label
, IUndoContext undoContext
,
68 TaxonNode taxonNodeToMove
, ITaxonTreeNode newParentTreeNode
, IPostOperationEnabled postOperationEnabled
, IConversationEnabled conversationEnabled
, boolean moveToParentNode
) {
69 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
);
71 this.taxonNode
= taxonNodeToMove
;
72 /*for (TaxonNode node:taxonNodes){
73 this.taxonNodes.add(service.load(node.getUuid()));
76 this.newParentTreeNode
= newParentTreeNode
;
77 this.moveToParentNode
= moveToParentNode
;
78 // Save old parent ITaxonTreeNodes for undo
80 //this.parentNode = taxonNode.getParent();
84 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
88 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
89 throws ExecutionException
{
93 UpdateResult result
= CdmStore
.getService(ITaxonNodeService
.class).moveTaxonNode(this.taxonNode
.getUuid(),newParentTreeNode
.getUuid(), moveToParentNode
);
95 // for (TaxonNode taxonNode : taxonNodes){
96 // TaxonNode newTaxonNode = newParentTreeNode.addChildNode(taxonNode,
97 // newParentTreeNode.getReference(), newParentTreeNode.getMicroReference());
98 // //taxonNodes.add(newTaxonNode);
100 // monitor.worked(2);
102 // } catch(IllegalAncestryException e) {
103 // MessagingUtils.warningDialog("Illegal ancestry", this, e.getMessage());
107 return postExecute(null);
111 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
115 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
116 throws ExecutionException
{
117 return execute(monitor
, info
);
121 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
125 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
126 throws ExecutionException
{
127 MessagingUtils
.warn(this.getClass(), "Not implemented yet.");
129 // iterate over oldParentTreeNodes, delete each TaxonNode from its actual parent and add to its former parent
131 return Status
.OK_STATUS
;