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
.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
.operation
.AbstractPostOperation
;
25 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
26 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
29 * Deletes a relation between two taxa.
31 * TODO we assume that there is only one kind of relation between two taxa.
32 * If there are more, this operation breaks
39 public class DeleteConceptRelationOperation
extends AbstractPostOperation
{
41 private Taxon relatedTaxon
;
42 private TaxonRelationshipType relationshipType
;
43 private Reference
<?
> citation
;
44 private String microcitation
;
45 private TaxonRelationship taxonRelationship
;
48 * <p>Constructor for DeleteConceptRelationOperation.</p>
50 * @param label a {@link java.lang.String} object.
51 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
52 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
53 * @param relatedTaxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
54 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
56 public DeleteConceptRelationOperation(String label
,
57 IUndoContext undoContext
, Taxon taxon
, Taxon relatedTaxon
,
58 IPostOperationEnabled postOperationEnabled
) {
59 super(label
, undoContext
, taxon
, postOperationEnabled
);
61 this.relatedTaxon
= relatedTaxon
;
63 Set
<TaxonRelationship
> taxonRelationships
= taxon
.getTaxonRelations(relatedTaxon
);
65 if(taxonRelationships
.size() > 1){
66 StoreUtil
.warningDialog("Multiple relations between taxa", this, "There are multiple relations between the " +
67 "accepted and the related taxon. This case is not handled by the software yet");
71 taxonRelationship
= taxonRelationships
.iterator().next();
73 relationshipType
= taxonRelationship
.getType();
75 citation
= taxonRelationship
.getCitation();
76 microcitation
= taxonRelationship
.getCitationMicroReference();
80 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
84 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
85 throws ExecutionException
{
87 // Find relation, save citation information
88 for (TaxonRelationship relationship
: taxon
.getTaxonRelations()) {
89 if (relationship
.getType().equals(relationshipType
)
90 && relationship
.getFromTaxon().equals(relatedTaxon
)) {
91 citation
= relationship
.getCitation();
92 microcitation
= relationship
.getCitationMicroReference();
93 taxonRelationship
= relationship
;
98 // Remove relation from taxon
99 taxon
.removeTaxonRelation(taxonRelationship
);
102 return postExecute(taxon
);
106 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
110 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
111 throws ExecutionException
{
112 return execute(monitor
, info
);
116 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
120 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
121 throws ExecutionException
{
123 // relatedTaxon.addTaxonRelation(relationship); // don't do nothin'
124 taxon
.addTaxonRelation(relatedTaxon
, relationshipType
, citation
, microcitation
);
126 return postExecute(relatedTaxon
);