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
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
16 import org
.eclipse
.core
.runtime
.IAdaptable
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.core
.runtime
.IStatus
;
20 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
21 import eu
.etaxonomy
.cdm
.api
.service
.exception
.DataChangeNoRollbackException
;
22 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
23 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
29 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
30 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
31 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
32 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
35 * <p>ChangeConceptToSynonymOperation class.</p>
42 public class ChangeConceptToSynonymOperation
extends
43 AbstractPostTaxonOperation
{
45 private Taxon concept
;
47 private HomotypicalGroup homotypicalGroup
;
49 private TaxonRelationship taxonRelationship
;
50 private TaxonRelationshipType oldRelationshipType
;
52 private SynonymRelationship newSynonymRelationship
;
55 * <p>Constructor for ChangeConceptToSynonymOperation.</p>
57 * @param label a {@link java.lang.String} object.
58 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
59 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
60 * @param concept a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
61 * @param homotypicalGroup a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object.
62 * @param editor a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
64 public ChangeConceptToSynonymOperation(String label
,
65 IUndoContext undoContext
, Taxon taxon
, Taxon concept
, HomotypicalGroup homotypicalGroup
,
66 IPostOperationEnabled editor
) {
67 super(label
, undoContext
, taxon
, editor
);
69 Set
<TaxonRelationship
> taxonRelationships
= taxon
.getTaxonRelations(concept
);
71 if(taxonRelationships
.size() > 1){
72 MessagingUtils
.warningDialog("Multiple relations between taxa", this, "There are multiple relations between the " +
73 "accepted and the related taxon. This case is not handled by the software yet");
77 this.taxonRelationship
= taxonRelationships
.iterator().next();
78 this.oldRelationshipType
= taxonRelationship
.getType();
80 this.concept
= concept
;
81 this.homotypicalGroup
= homotypicalGroup
!= null ? homotypicalGroup
: HomotypicalGroup
.NewInstance();
85 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
89 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
90 throws ExecutionException
{
92 // Create new synonym using concept name
93 TaxonNameBase
<?
, ?
> synonymName
= concept
.getName();
94 Synonym synonym
= null;
97 (Synonym
) CdmStore
.getService(ITaxonService
.class).changeRelatedTaxonToSynonym(concept
.getUuid(),
99 taxonRelationship
.getType(),
100 null).getCdmEntity();
101 } catch (DataChangeNoRollbackException e
) {
102 // TODO Auto-generated catch block
107 return postExecute(synonym
);
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 // TODO redo for change misapplied name ...
122 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
126 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
127 throws ExecutionException
{
128 // TODO undo for change misapplied name ...