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
.model
.taxon
.Taxon
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
23 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
24 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
25 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
26 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
29 * <p>ChangeConceptRelationshipTypeOperation class.</p>
35 public class ChangeConceptRelationshipTypeOperation
extends AbstractPostTaxonOperation
{
37 private Taxon relatedTaxon
;
39 private TaxonRelationship taxonRelationship
;
41 private TaxonRelationshipType oldRelationshipType
;
43 private TaxonRelationshipType newRelationshipType
;
46 * <p>Constructor for ChangeConceptRelationshipTypeOperation.</p>
48 * @param label a {@link java.lang.String} object.
49 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
50 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
51 * @param relatedTaxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
52 * @param type a {@link eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType} object.
53 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
55 public ChangeConceptRelationshipTypeOperation(String label
,
56 IUndoContext undoContext
, Taxon taxon
, Taxon relatedTaxon
, TaxonRelationshipType type
, IPostOperationEnabled postOperationEnabled
) {
57 super(label
, undoContext
, taxon
, postOperationEnabled
);
58 this.relatedTaxon
= relatedTaxon
;
60 Set
<TaxonRelationship
> taxonRelationships
= taxon
.getTaxonRelations(relatedTaxon
);
62 if(taxonRelationships
.size() > 1){
63 MessagingUtils
.warningDialog(ChangeConceptToSynonymOperation
.CHANGE_CONCEPT_TO_SYNONYM_OPERATION_MULTI_REPS
, this, ChangeConceptToSynonymOperation
.CHANGE_CONCEPT_TO_SYNONYM_OPERATION_MULTI_REPS_MESSAGE
);
67 this.taxonRelationship
= taxonRelationships
.iterator().next();
68 this.oldRelationshipType
= taxonRelationship
.getType();
69 this.newRelationshipType
= type
;
73 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
77 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
78 throws ExecutionException
{
80 // Remove relatedTaxon and old relationship
81 // FIXME since taxon relationships come in a set, which relationships are we going to delete here?
82 element
.removeTaxon(relatedTaxon
, oldRelationshipType
);
85 // Add new relationship
86 // TODO add microcitation for misapplied name to property sheet
87 relatedTaxon
.addTaxonRelation(element
, newRelationshipType
, null, null);
90 return postExecute(relatedTaxon
);
94 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
98 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
99 throws ExecutionException
{
100 return execute(monitor
, info
);
104 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
108 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
109 throws ExecutionException
{
110 // see FIXME in execute()
111 MessagingUtils
.warn(this.getClass(), Messages
.ChangeConceptRelationshipTypeOperation_NOT_IMPLEMENTED
);