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
.reference
.ReferenceBase
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
27 import eu
.etaxonomy
.taxeditor
.model
.TaxonUtil
;
28 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
31 * Change the taxonomic parent of a given taxon.
37 public class MoveTaxonOperation
extends AbstractPostOperation
{
39 @SuppressWarnings("unused")
40 private static final Logger logger
= Logger
.getLogger(MoveTaxonOperation
.class);
42 * A reference to the new taxonomical parent.
44 private TaxonNode newParentTaxonNode
;
46 * A reference to the former taxonomical parent
48 private TaxonNode oldParentTaxonNode
;
50 public MoveTaxonOperation(String label
, IUndoContext undoContext
,
51 TaxonNode taxonNode
, TaxonNode newParentTaxonNode
, IPostOperationEnabled postOperationEnabled
) {
52 super(label
, undoContext
, taxonNode
, null);
54 this.newParentTaxonNode
= newParentTaxonNode
;
56 // Save old parent TaxonNode for undo
57 this.oldParentTaxonNode
= taxonNode
.getParent();
61 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
64 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
65 throws ExecutionException
{
67 TaxonNode newTaxonNode
= moveTaxonBaseIsolated(taxonNode
.getUuid(), newParentTaxonNode
.getUuid());
69 return postExecute(newTaxonNode
);
73 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
76 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
77 throws ExecutionException
{
78 return execute(monitor
, info
);
82 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
85 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
86 throws ExecutionException
{
88 moveTaxonBaseIsolated(taxonNode
.getUuid(), oldParentTaxonNode
.getUuid());
90 return Status
.OK_STATUS
;
95 * @param taxonNodeUuid
96 * @param newParentTaxonNodeUuid
99 private TaxonNode
moveTaxonBaseIsolated(UUID taxonNodeUuid
, UUID newParentTaxonNodeUuid
){
101 // get a new conversation
102 ConversationHolder conversation
= CdmStore
.NewTransactionalConversation();
103 // find the taxon node
104 TaxonNode taxonNode
= CdmStore
.getTaxonService().getTaxonNodeByUuid(taxonNodeUuid
);
105 // store all relevant information of taxon node and delete the taxon node.
106 Taxon taxon
= taxonNode
.getTaxon();
107 ReferenceBase parentChildReference
= taxonNode
.getReferenceForParentChildRelation();
108 String parentChildMicroReference
= taxonNode
.getMicroReferenceForParentChildRelation();
109 Synonym synonymUsed
= taxonNode
.getSynonymToBeUsed();
113 TaxonNode newParentTaxonNode
= CdmStore
.getTaxonService().getTaxonNodeByUuid(newParentTaxonNodeUuid
);
114 TaxonNode newChild
= newParentTaxonNode
.addChild(taxon
, parentChildReference
, parentChildMicroReference
, synonymUsed
);
115 // commit the conversation
116 conversation
.commit(true);