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
.operations
;
12 import java
.util
.UUID
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
17 import org
.eclipse
.core
.runtime
.IAdaptable
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
19 import org
.eclipse
.core
.runtime
.IStatus
;
20 import org
.eclipse
.core
.runtime
.Status
;
22 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.ITreeNode
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.IllegalAncestryException
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
26 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
27 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
30 * Change the taxonomic parent of a given taxon.
36 public class MoveTaxonOperation
extends AbstractPostOperation
{
38 @SuppressWarnings("unused")
39 private static final Logger logger
= Logger
.getLogger(MoveTaxonOperation
.class);
41 * A reference to the new taxonomical parent.
43 private ITreeNode newParentTreeNode
;
45 * A reference to the former taxonomical parent
47 private TaxonNode oldParentTaxonNode
;
49 public MoveTaxonOperation(String label
, IUndoContext undoContext
,
50 TaxonNode taxonNode
, ITreeNode newParentTreeNode
, IPostOperationEnabled postOperationEnabled
) {
51 super(label
, undoContext
, taxonNode
, null);
53 this.newParentTreeNode
= newParentTreeNode
;
55 // Save old parent TaxonNode for undo
56 this.oldParentTaxonNode
= taxonNode
.getParent();
60 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
63 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
64 throws ExecutionException
{
66 TaxonNode newTaxonNode
= moveTaxonBaseIsolated(taxonNode
.getUuid(), newParentTreeNode
.getUuid());
68 return postExecute(newTaxonNode
);
72 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
75 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
76 throws ExecutionException
{
77 return execute(monitor
, info
);
81 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
84 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
85 throws ExecutionException
{
87 moveTaxonBaseIsolated(taxonNode
.getUuid(), oldParentTaxonNode
.getUuid());
89 return Status
.OK_STATUS
;
94 * @param taxonNodeUuid
95 * @param newParentTaxonNodeUuid
98 private TaxonNode
moveTaxonBaseIsolated(UUID taxonNodeUuid
, UUID newParentTreeNodeUuid
){
100 // get a new conversation
101 ConversationHolder conversation
= CdmStore
.NewTransactionalConversation();
104 TaxonNode taxonNode
= CdmStore
.getTaxonTreeService().getTaxonNodeByUuid(taxonNodeUuid
);
106 // find the new parent node
107 ITreeNode newParentTreeNode
= CdmStore
.getTaxonTreeService().getTreeNodeByUuid(newParentTreeNodeUuid
);
108 // add node to new parent
110 TaxonNode newChild
= newParentTreeNode
.addChildNode(taxonNode
, newParentTreeNode
.getReference(), newParentTreeNode
.getMicroReference(), taxonNode
.getSynonymToBeUsed());
111 // commit the conversation
112 conversation
.commit(true);
114 }catch(IllegalAncestryException e
){
115 StoreUtil
.warningDialog("Illegal ancestry", e
.getMessage());
119 conversation
.close();