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
.reference
.Reference
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
24 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
27 * Deletes a relation between two taxa.
29 * TODO we assume that there is only one kind of relation between two taxa.
30 * If there are more, this operation breaks
37 public class DeleteConceptRelationOperation
extends AbstractPostOperation
{
39 private Taxon relatedTaxon
;
40 private TaxonRelationshipType relationshipType
;
41 private Reference
<?
> citation
;
42 private String microcitation
;
43 private TaxonRelationship taxonRelationship
;
46 * <p>Constructor for DeleteConceptRelationOperation.</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 postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
54 public DeleteConceptRelationOperation(String label
,
55 IUndoContext undoContext
, Taxon taxon
, Taxon relatedTaxon
,
56 IPostOperationEnabled postOperationEnabled
) {
57 super(label
, undoContext
, taxon
, postOperationEnabled
);
59 this.relatedTaxon
= relatedTaxon
;
61 Set
<TaxonRelationship
> taxonRelationships
= taxon
.getTaxonRelations(relatedTaxon
);
63 if(taxonRelationships
.size() > 1){
64 StoreUtil
.warningDialog("Multiple relations between taxa", this, "There are multiple relations between the " +
65 "accepted and the related taxon. This case is not handled by the software yet");
69 taxonRelationship
= taxonRelationships
.iterator().next();
71 relationshipType
= taxonRelationship
.getType();
73 citation
= taxonRelationship
.getCitation();
74 microcitation
= taxonRelationship
.getCitationMicroReference();
78 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
82 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
83 throws ExecutionException
{
85 // Find relation, save citation information
86 for (TaxonRelationship relationship
: taxon
.getTaxonRelations()) {
87 if (relationship
.getType().equals(relationshipType
)
88 && relationship
.getFromTaxon().equals(relatedTaxon
)) {
89 citation
= relationship
.getCitation();
90 microcitation
= relationship
.getCitationMicroReference();
91 taxonRelationship
= relationship
;
96 // Remove relation from taxon
97 taxon
.removeTaxonRelation(taxonRelationship
);
100 return postExecute(taxon
);
104 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
108 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
109 throws ExecutionException
{
110 return execute(monitor
, info
);
114 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
118 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
119 throws ExecutionException
{
121 // relatedTaxon.addTaxonRelation(relationship); // don't do nothin'
122 taxon
.addTaxonRelation(relatedTaxon
, relationshipType
, citation
, microcitation
);
124 return postExecute(relatedTaxon
);