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
.operations
;
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
.store
.StoreUtil
;
26 * <p>ChangeConceptRelationshipTypeOperation class.</p>
32 public class ChangeConceptRelationshipTypeOperation
extends AbstractPostOperation
{
34 private Taxon relatedTaxon
;
36 private TaxonRelationship taxonRelationship
;
38 private TaxonRelationshipType oldRelationshipType
;
40 private TaxonRelationshipType newRelationshipType
;
43 * <p>Constructor for ChangeConceptRelationshipTypeOperation.</p>
45 * @param label a {@link java.lang.String} object.
46 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
47 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
48 * @param relatedTaxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
49 * @param type a {@link eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType} object.
50 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
52 public ChangeConceptRelationshipTypeOperation(String label
,
53 IUndoContext undoContext
, Taxon taxon
, Taxon relatedTaxon
, TaxonRelationshipType type
, IPostOperationEnabled postOperationEnabled
) {
54 super(label
, undoContext
, taxon
, postOperationEnabled
);
55 this.relatedTaxon
= relatedTaxon
;
57 Set
<TaxonRelationship
> taxonRelationships
= taxon
.getTaxonRelations(relatedTaxon
);
59 if(taxonRelationships
.size() > 1){
60 StoreUtil
.warningDialog("Multiple relations between taxa", this, "There are multiple relations between the " +
61 "accepted and the related taxon. This case is not handled by the software yet");
65 this.taxonRelationship
= taxonRelationships
.iterator().next();
66 this.oldRelationshipType
= taxonRelationship
.getType();
67 this.newRelationshipType
= type
;
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
{
78 // Remove relatedTaxon and old relationship
79 // FIXME since taxon relationships come in a set, which relationships are we going to delete here?
80 taxon
.removeTaxon(relatedTaxon
, oldRelationshipType
);
83 // Add new relationship
84 // TODO add microcitation for misapplied name to property sheet
85 relatedTaxon
.addTaxonRelation(taxon
, newRelationshipType
, null, null);
88 return postExecute(relatedTaxon
);
92 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
96 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
97 throws ExecutionException
{
98 return execute(monitor
, info
);
102 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
106 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
107 throws ExecutionException
{
108 // see FIXME in execute()
109 StoreUtil
.warn(this.getClass(), "Not implemented yet. See developer documentation for details");