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
.store
.operations
;
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
.model
.reference
.ReferenceBase
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
22 import eu
.etaxonomy
.taxeditor
.store
.model
.TaxonUtil
;
25 * Deletes a relation between two taxa.
27 * TODO we assume that there is only one kind of relation between two taxa.
28 * If there are more, this operation breaks
35 public class DeleteConceptRelationOperation
extends AbstractPostOperation
{
37 private Taxon relatedTaxon
;
38 private TaxonRelationshipType relationshipType
;
39 private ReferenceBase
<?
> citation
;
40 private String microcitation
;
41 private TaxonRelationship relationship
;
43 public DeleteConceptRelationOperation(String label
,
44 IUndoContext undoContext
, Taxon taxon
, Taxon relatedTaxon
,
45 IPostOperationEnabled postOperationEnabled
) {
46 super(label
, undoContext
, taxon
, postOperationEnabled
);
48 this.relatedTaxon
= relatedTaxon
;
50 relationship
= TaxonUtil
.getRelationshipBetweenTwoTaxa(relatedTaxon
, taxon
);
52 relationshipType
= relationship
.getType();
54 citation
= relationship
.getCitation();
55 microcitation
= relationship
.getCitationMicroReference();
59 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
62 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
63 throws ExecutionException
{
65 // Find relation, save citation information
66 for (TaxonRelationship relationship
: taxon
.getTaxonRelations()) {
67 if (relationship
.getType().equals(relationshipType
)
68 && relationship
.getFromTaxon().equals(relatedTaxon
)) {
69 citation
= relationship
.getCitation();
70 microcitation
= relationship
.getCitationMicroReference();
71 this.relationship
= relationship
;
75 // Remove relation from taxon
76 taxon
.removeTaxonRelation(relationship
);
78 return postExecute(taxon
);
82 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
85 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
86 throws ExecutionException
{
87 return execute(monitor
, info
);
91 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
94 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
95 throws ExecutionException
{
97 // relatedTaxon.addTaxonRelation(relationship); // don't do nothin'
98 taxon
.addTaxonRelation(relatedTaxon
, relationshipType
, citation
, microcitation
);
100 return postExecute(relatedTaxon
);