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 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;
|
17
|
|
18
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
19
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
20
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
21
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
22
|
import eu.etaxonomy.cdm.model.taxon.SynonymType;
|
23
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
24
|
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
|
25
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
26
|
|
27
|
/**
|
28
|
* Change the homotypical group of a given synonym.
|
29
|
*
|
30
|
* @author n.hoffmann
|
31
|
* @created 19.01.2009
|
32
|
*/
|
33
|
public class ChangeHomotypicGroupOperation extends AbstractPostTaxonOperation {
|
34
|
|
35
|
/**
|
36
|
* The synonym to be moved.
|
37
|
*/
|
38
|
private final Synonym synonym;
|
39
|
/**
|
40
|
* The former homotypical group the synonym belonged to
|
41
|
*/
|
42
|
private HomotypicalGroup oldHomotypicalGroup;
|
43
|
/**
|
44
|
* The homotypical group the synonym is to be moved to
|
45
|
*/
|
46
|
private HomotypicalGroup newHomotypicalGroup;
|
47
|
|
48
|
/**
|
49
|
* <p>Constructor for ChangeHomotypicGroupOperation.</p>
|
50
|
*
|
51
|
* @param label a {@link java.lang.String} object.
|
52
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
53
|
* @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
54
|
* @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
|
55
|
* @param newHomotypicalGroup a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object.
|
56
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
57
|
*/
|
58
|
public ChangeHomotypicGroupOperation(String label, IUndoContext undoContext,
|
59
|
Taxon taxon, Synonym synonym, HomotypicalGroup newHomotypicalGroup, IPostOperationEnabled postOperationEnabled) {
|
60
|
super(label, undoContext, taxon, postOperationEnabled);
|
61
|
|
62
|
this.synonym = synonym;
|
63
|
if(synonym == null){
|
64
|
throw new IllegalArgumentException(
|
65
|
"A null synonym was provided."); //$NON-NLS-1$
|
66
|
}
|
67
|
|
68
|
this.oldHomotypicalGroup = synonym.getHomotypicGroup();
|
69
|
this.newHomotypicalGroup = newHomotypicalGroup != null ? newHomotypicalGroup : HomotypicalGroup.NewInstance();
|
70
|
}
|
71
|
|
72
|
@Override
|
73
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
74
|
throws ExecutionException {
|
75
|
|
76
|
// Get synonym name
|
77
|
TaxonName synonymName = synonym.getName();
|
78
|
monitor.worked(20);
|
79
|
|
80
|
// TODO pass in homotypical group's taxon in case we are dragging from one editor to another
|
81
|
|
82
|
// Switch groups
|
83
|
oldHomotypicalGroup.removeTypifiedName(synonymName, false);
|
84
|
monitor.worked(40);
|
85
|
newHomotypicalGroup = HibernateProxyHelper.deproxy(newHomotypicalGroup, HomotypicalGroup.class);
|
86
|
newHomotypicalGroup.addTypifiedName(synonymName);
|
87
|
|
88
|
Taxon acc = synonym.getAcceptedTaxon();
|
89
|
if(acc == null || !acc.equals(element)){
|
90
|
if(acc != null){
|
91
|
acc.removeSynonym(synonym);
|
92
|
}
|
93
|
|
94
|
SynonymType type = SynonymType.HETEROTYPIC_SYNONYM_OF();
|
95
|
if(newHomotypicalGroup.getTypifiedNames().contains(element.getName())){
|
96
|
type = SynonymType.HOMOTYPIC_SYNONYM_OF();
|
97
|
}
|
98
|
|
99
|
element.addSynonym(synonym, type);
|
100
|
}
|
101
|
|
102
|
// Redraw editor if it exists
|
103
|
return postExecute(synonym);
|
104
|
}
|
105
|
|
106
|
@Override
|
107
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
108
|
throws ExecutionException {
|
109
|
return execute(monitor, info);
|
110
|
}
|
111
|
|
112
|
@Override
|
113
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
114
|
throws ExecutionException {
|
115
|
|
116
|
// Get synonym name
|
117
|
TaxonName synonymName = this.synonym.getName();
|
118
|
if(synonymName == null){
|
119
|
// TODO
|
120
|
}
|
121
|
|
122
|
// TODO pass in homotypical group's taxon in case we are dragging from one editor to another
|
123
|
|
124
|
// Switch groups
|
125
|
newHomotypicalGroup.removeTypifiedName(synonymName, false);
|
126
|
oldHomotypicalGroup.addTypifiedName(synonymName);
|
127
|
|
128
|
// Redraw editor if it exists
|
129
|
return postExecute(synonym);
|
130
|
}
|
131
|
}
|