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
.name
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.commands
.ExecutionException
;
14 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
15 import org
.eclipse
.core
.runtime
.IAdaptable
;
16 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
17 import org
.eclipse
.core
.runtime
.IStatus
;
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
.operations
.AbstractEditorOperation
;
29 public class ChangeConceptRelationOperation
extends AbstractEditorOperation
{
32 private static final Logger logger
= Logger
33 .getLogger(ChangeConceptRelationOperation
.class);
34 private Taxon relatedTaxon
;
35 private TaxonRelationshipType oldRelationshipType
;
36 private TaxonRelationshipType newRelationshipType
;
38 public ChangeConceptRelationOperation(String label
,
39 IUndoContext undoContext
, Taxon taxon
, Taxon relatedTaxon
, TaxonRelationshipType type
) {
40 super(label
, undoContext
, taxon
);
41 this.relatedTaxon
= relatedTaxon
;
42 this.newRelationshipType
= type
;
46 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
49 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
50 throws ExecutionException
{
52 // Remove relatedTaxon and old relationship
53 TaxonRelationship relationship
= getTaxonRelationship(taxon
, relatedTaxon
);
54 taxon
.removeTaxonRelation(relationship
);
55 oldRelationshipType
= relationship
.getType();
57 // Add new relationship
58 // TODO add microcitation for misapplied name to property sheet
59 relatedTaxon
.addTaxonRelation(taxon
, newRelationshipType
, null, null);
61 return redrawOpenEditor();
65 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
68 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
69 throws ExecutionException
{
70 return execute(monitor
, info
);
74 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
77 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
78 throws ExecutionException
{
79 TaxonRelationship relationship
= getTaxonRelationship(taxon
, relatedTaxon
);
80 taxon
.removeTaxonRelation(relationship
);
82 // Add new relationship
83 // TODO add microcitation for misapplied name to property sheet
84 relatedTaxon
.addTaxonRelation(taxon
, oldRelationshipType
, null, null);
86 return redrawOpenEditor();
89 private TaxonRelationship
getTaxonRelationship(Taxon taxon1
, Taxon taxon2
) {
90 for (TaxonRelationship relationship
: taxon1
.getTaxonRelations()) {
91 if ((relationship
.getToTaxon().equals(taxon1
)
92 && relationship
.getFromTaxon().equals(taxon2
))
94 (relationship
.getFromTaxon().equals(taxon1
)
95 && relationship
.getToTaxon().equals(taxon2
))) {