1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.editor.name.operation;
|
11
|
|
12
|
import java.util.Set;
|
13
|
|
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;
|
19
|
|
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.model.MessagingUtils;
|
24
|
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
|
25
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
26
|
|
27
|
/**
|
28
|
* <p>ChangeConceptRelationshipTypeOperation class.</p>
|
29
|
*
|
30
|
* @author n.hoffmann
|
31
|
* @created 03.02.2009
|
32
|
* @version 1.0
|
33
|
*/
|
34
|
public class ChangeConceptRelationshipTypeOperation extends AbstractPostTaxonOperation {
|
35
|
|
36
|
private Taxon relatedTaxon;
|
37
|
|
38
|
private TaxonRelationship taxonRelationship;
|
39
|
|
40
|
private TaxonRelationshipType oldRelationshipType;
|
41
|
|
42
|
private TaxonRelationshipType newRelationshipType;
|
43
|
|
44
|
/**
|
45
|
* <p>Constructor for ChangeConceptRelationshipTypeOperation.</p>
|
46
|
*
|
47
|
* @param label a {@link java.lang.String} object.
|
48
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
49
|
* @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
50
|
* @param relatedTaxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
51
|
* @param type a {@link eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType} object.
|
52
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
53
|
*/
|
54
|
public ChangeConceptRelationshipTypeOperation(String label,
|
55
|
IUndoContext undoContext, Taxon taxon, Taxon relatedTaxon, TaxonRelationshipType type, IPostOperationEnabled postOperationEnabled) {
|
56
|
super(label, undoContext, taxon, postOperationEnabled);
|
57
|
this.relatedTaxon = relatedTaxon;
|
58
|
|
59
|
Set<TaxonRelationship> taxonRelationships = taxon.getTaxonRelations(relatedTaxon);
|
60
|
|
61
|
if(taxonRelationships.size() > 1){
|
62
|
MessagingUtils.warningDialog("Multiple relations between taxa", this, "There are multiple relations between the " +
|
63
|
"accepted and the related taxon. This case is not handled by the software yet");
|
64
|
return;
|
65
|
}
|
66
|
|
67
|
this.taxonRelationship = taxonRelationships.iterator().next();
|
68
|
this.oldRelationshipType = taxonRelationship.getType();
|
69
|
this.newRelationshipType = type;
|
70
|
}
|
71
|
|
72
|
/* (non-Javadoc)
|
73
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
74
|
*/
|
75
|
/** {@inheritDoc} */
|
76
|
@Override
|
77
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
78
|
throws ExecutionException {
|
79
|
|
80
|
// Remove relatedTaxon and old relationship
|
81
|
// FIXME since taxon relationships come in a set, which relationships are we going to delete here?
|
82
|
element.removeTaxon(relatedTaxon, oldRelationshipType);
|
83
|
monitor.worked(20);
|
84
|
|
85
|
// Add new relationship
|
86
|
// TODO add microcitation for misapplied name to property sheet
|
87
|
relatedTaxon.addTaxonRelation(element, newRelationshipType, null, null);
|
88
|
monitor.worked(40);
|
89
|
|
90
|
return postExecute(relatedTaxon);
|
91
|
}
|
92
|
|
93
|
/* (non-Javadoc)
|
94
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
95
|
*/
|
96
|
/** {@inheritDoc} */
|
97
|
@Override
|
98
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
99
|
throws ExecutionException {
|
100
|
return execute(monitor, info);
|
101
|
}
|
102
|
|
103
|
/* (non-Javadoc)
|
104
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
105
|
*/
|
106
|
/** {@inheritDoc} */
|
107
|
@Override
|
108
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
109
|
throws ExecutionException {
|
110
|
// see FIXME in execute()
|
111
|
MessagingUtils.warn(this.getClass(), "Not implemented yet. See developer documentation for details");
|
112
|
return null;
|
113
|
}
|
114
|
}
|