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
.model
.AbstractUtility
;
26 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPersistentPostOperation
;
27 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
28 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
31 * Change the taxonomic parent of a given taxon.
37 public class ChangeSynonymToAcceptedTaxonOperation
extends AbstractPersistentPostOperation
{
39 private Taxon newTaxon
;
40 private final Synonym synonym
;
41 private final ITaxonTreeNode parentNode
;
43 private TaxonNode newNode
;
45 private final Synonym
[] synonymsInHomotypicalGroup
;
48 * <p>Constructor for ChangeSynonymToAcceptedTaxonOperation.</p>
50 * @param label a {@link java.lang.String} object.
51 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
52 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
53 * @param parentNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
54 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
55 * @param synonymsInHomotypicalGroup an array of {@link eu.etaxonomy.cdm.model.taxon.Synonym} objects.
56 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
57 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
59 public ChangeSynonymToAcceptedTaxonOperation(String label
, IUndoContext undoContext
,
60 Taxon taxon
, ITaxonTreeNode parentNode
, Synonym synonym
, Synonym
[] synonymsInHomotypicalGroup
, IPostOperationEnabled postOperationEnabled
, IConversationEnabled conversationEnabled
) {
61 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
);
64 this.parentNode
= parentNode
;
65 this.synonym
= synonym
;
66 this.synonymsInHomotypicalGroup
= synonymsInHomotypicalGroup
;
70 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
74 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
75 throws ExecutionException
{
78 newTaxon
= CdmStore
.getService(ITaxonService
.class).changeSynonymToAcceptedTaxon(synonym
, element
, true, true, null, null);
79 } catch (HomotypicalGroupChangeException e
) {
80 AbstractUtility
.warningDialog("Operation may lead to inconsistent data", getClass(), e
.getMessage());
81 return postExecute(null);
86 newNode
= parentNode
.addChildTaxon(newTaxon
, null, null);
88 if(synonymsInHomotypicalGroup
!= null){
89 Taxon taxon
= newNode
.getTaxon();
90 for (Synonym synonym
: synonymsInHomotypicalGroup
){
91 taxon
.addHomotypicSynonym(synonym
, null, null);
97 return postExecute(newNode
);
101 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
105 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
106 throws ExecutionException
{
107 return execute(monitor
, info
);
111 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
115 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
116 throws ExecutionException
{
118 // TODO implement - biggest problem is that any window open for new taxon must be closed first
119 AbstractUtility
.warn(this.getClass(), "Not yet implemented");
121 return postExecute(element
);