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
.operation
.AbstractPostTaxonOperation
;
24 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
25 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
28 * <p>ChangeConceptRelationshipTypeOperation class.</p>
34 public class ChangeConceptRelationshipTypeOperation
extends AbstractPostTaxonOperation
{
36 private Taxon relatedTaxon
;
38 private TaxonRelationship taxonRelationship
;
40 private TaxonRelationshipType oldRelationshipType
;
42 private TaxonRelationshipType newRelationshipType
;
45 * <p>Constructor for ChangeConceptRelationshipTypeOperation.</p>
47 * @param label a {@link java.lang.String} object.
48 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
49 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
50 * @param relatedTaxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
51 * @param type a {@link eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType} object.
52 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
54 public ChangeConceptRelationshipTypeOperation(String label
,
55 IUndoContext undoContext
, Taxon taxon
, Taxon relatedTaxon
, TaxonRelationshipType type
, IPostOperationEnabled postOperationEnabled
) {
56 super(label
, undoContext
, taxon
, postOperationEnabled
);
57 this.relatedTaxon
= relatedTaxon
;
59 Set
<TaxonRelationship
> taxonRelationships
= taxon
.getTaxonRelations(relatedTaxon
);
61 if(taxonRelationships
.size() > 1){
62 StoreUtil
.warningDialog("Multiple relations between taxa", this, "There are multiple relations between the " +
63 "accepted and the related taxon. This case is not handled by the software yet");
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 StoreUtil
.warn(this.getClass(), "Not implemented yet. See developer documentation for details");