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
.editor
.name
.operation
;
12 import org
.eclipse
.core
.commands
.ExecutionException
;
13 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
14 import org
.eclipse
.core
.runtime
.IAdaptable
;
15 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
16 import org
.eclipse
.core
.runtime
.IStatus
;
18 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
19 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
20 import eu
.etaxonomy
.cdm
.api
.service
.exception
.HomotypicalGroupChangeException
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
25 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
26 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPersistentPostOperation
;
27 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
28 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
29 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
32 * Change the taxonomic parent of a given taxon.
38 public class ChangeSynonymToAcceptedTaxonOperation
extends AbstractPersistentPostOperation
{
40 private Taxon newTaxon
;
41 private Synonym synonym
;
42 private ITaxonTreeNode parentNode
;
44 private TaxonNode newNode
;
46 private Synonym
[] synonymsInHomotypicalGroup
;
49 * <p>Constructor for ChangeSynonymToAcceptedTaxonOperation.</p>
51 * @param label a {@link java.lang.String} object.
52 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
53 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
54 * @param parentNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
55 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
56 * @param synonymsInHomotypicalGroup an array of {@link eu.etaxonomy.cdm.model.taxon.Synonym} objects.
57 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
58 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
60 public ChangeSynonymToAcceptedTaxonOperation(String label
, IUndoContext undoContext
,
61 Taxon taxon
, ITaxonTreeNode parentNode
, Synonym synonym
, Synonym
[] synonymsInHomotypicalGroup
, IPostOperationEnabled postOperationEnabled
, IConversationEnabled conversationEnabled
) {
62 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
);
65 this.parentNode
= parentNode
;
66 this.synonym
= synonym
;
67 this.synonymsInHomotypicalGroup
= synonymsInHomotypicalGroup
;
71 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
75 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
76 throws ExecutionException
{
79 newTaxon
= CdmStore
.getService(ITaxonService
.class).changeSynonymToAcceptedTaxon(synonym
, taxon
, true, true, null, null);
80 } catch (HomotypicalGroupChangeException e
) {
81 EditorUtil
.warningDialog("Operation may lead to inconsistent data", getClass(), e
.getMessage());
82 return postExecute(null);
87 newNode
= parentNode
.addChildTaxon(newTaxon
, null, null);
89 if(synonymsInHomotypicalGroup
!= null){
90 Taxon taxon
= newNode
.getTaxon();
91 for (Synonym synonym
: synonymsInHomotypicalGroup
){
92 taxon
.addHomotypicSynonym(synonym
, null, null);
98 return postExecute(newNode
);
102 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
106 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
107 throws ExecutionException
{
108 return execute(monitor
, info
);
112 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
116 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
117 throws ExecutionException
{
119 // TODO implement - biggest problem is that any window open for new taxon must be closed first
120 StoreUtil
.warn(this.getClass(), "Not yet implemented");
122 return postExecute(taxon
);