1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.editor.name.dnd;
|
5
|
|
6
|
import org.eclipse.core.runtime.Assert;
|
7
|
import org.eclipse.swt.dnd.DND;
|
8
|
import org.eclipse.swt.dnd.DropTargetAdapter;
|
9
|
import org.eclipse.swt.dnd.DropTargetEvent;
|
10
|
|
11
|
import eu.etaxonomy.cdm.model.common.ICdmBase;
|
12
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
13
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
14
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
15
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
16
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
17
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
18
|
import eu.etaxonomy.taxeditor.editor.IDropTargetable;
|
19
|
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
|
20
|
import eu.etaxonomy.taxeditor.editor.name.container.AbstractHomotypicalGroupContainer;
|
21
|
import eu.etaxonomy.taxeditor.editor.name.container.HomotypicalSynonymGroup;
|
22
|
import eu.etaxonomy.taxeditor.editor.name.container.MisappliedGroup;
|
23
|
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptRelationshipTypeOperation;
|
24
|
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation;
|
25
|
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation;
|
26
|
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToMisapplicationOperation;
|
27
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
28
|
|
29
|
/**
|
30
|
* <p>NameEditorDropTargetListener class.</p>
|
31
|
*
|
32
|
* @author n.hoffmann
|
33
|
* @version $Id: $
|
34
|
*/
|
35
|
public class NameEditorDropTargetListener extends DropTargetAdapter {
|
36
|
|
37
|
private IDropTargetable target;
|
38
|
|
39
|
/**
|
40
|
* <p>Constructor for NameEditorDropTargetListener.</p>
|
41
|
*
|
42
|
* @param target a {@link eu.etaxonomy.taxeditor.editor.IDropTargetable} object.
|
43
|
*/
|
44
|
public NameEditorDropTargetListener(IDropTargetable target){
|
45
|
this.target = target;
|
46
|
}
|
47
|
|
48
|
/** {@inheritDoc} */
|
49
|
public void dragEnter(DropTargetEvent dropTargetEvent) {
|
50
|
target.dragEntered();
|
51
|
|
52
|
// if(! EditorUtil.getActiveMultiPageTaxonEditor().equals(editor.getMultiPageTaxonEditor())){
|
53
|
// editor.getMultiPageTaxonEditor().setFocus();
|
54
|
// }
|
55
|
}
|
56
|
|
57
|
/** {@inheritDoc} */
|
58
|
public void dragLeave(DropTargetEvent dropTargetEvent) {
|
59
|
target.dragLeft();
|
60
|
}
|
61
|
|
62
|
/** {@inheritDoc} */
|
63
|
public void drop(DropTargetEvent dropTargetEvent) {
|
64
|
|
65
|
TaxonBase taxonBase = getDroppedTaxonBase(dropTargetEvent);
|
66
|
|
67
|
Assert.isNotNull(taxonBase);
|
68
|
|
69
|
if(taxonBase.getHomotypicGroup().equals(getHomotypicalGroup())){
|
70
|
// do nothing when dragged to the same group
|
71
|
dropTargetEvent.detail = DND.DROP_NONE;
|
72
|
return;
|
73
|
}
|
74
|
|
75
|
// Execute operations at end of drag event
|
76
|
AbstractPostOperation operation = createOperation(taxonBase);
|
77
|
|
78
|
// Execute operation if it has been initiated
|
79
|
if (operation == null) {
|
80
|
EditorUtil.warn(getClass(), "User unsuccessfully tried to drop: " + taxonBase.getClass() +
|
81
|
". Target: " + target);
|
82
|
dropTargetEvent.detail = DND.DROP_NONE;
|
83
|
} else {
|
84
|
EditorUtil.executeOperation(operation);
|
85
|
}
|
86
|
}
|
87
|
|
88
|
private AbstractPostOperation createOperation(TaxonBase taxonBase) {
|
89
|
|
90
|
if(taxonBase instanceof Synonym){
|
91
|
Synonym synonym = (Synonym) taxonBase;
|
92
|
|
93
|
if(target instanceof AbstractHomotypicalGroupContainer){
|
94
|
HomotypicalGroup homotypicalGroup = ((AbstractHomotypicalGroupContainer) target).getGroup();
|
95
|
|
96
|
return new ChangeHomotypicGroupOperation("Change Homotypical Group", getEditor().getUndoContext(),
|
97
|
getEditor().getTaxon(), synonym, homotypicalGroup, target);
|
98
|
}
|
99
|
else if(target instanceof MisappliedGroup){
|
100
|
return new ChangeSynonymToMisapplicationOperation("Change Synonym to Misapplication", getEditor().getUndoContext(),
|
101
|
getEditor().getTaxon(), synonym, target);
|
102
|
}
|
103
|
else if(target instanceof TaxonNameEditor){
|
104
|
return new ChangeHomotypicGroupOperation("Change Homotypical Group", getEditor().getUndoContext(),
|
105
|
getEditor().getTaxon(), synonym, null, target);
|
106
|
}
|
107
|
|
108
|
}else if(taxonBase instanceof Taxon){
|
109
|
Taxon concept = (Taxon) taxonBase;
|
110
|
|
111
|
if(target instanceof AbstractHomotypicalGroupContainer){
|
112
|
HomotypicalGroup homotypicalGroup = ((AbstractHomotypicalGroupContainer) target).getGroup();
|
113
|
|
114
|
return new ChangeConceptToSynonymOperation("Change to Synonym", getEditor().getUndoContext(),
|
115
|
getEditor().getTaxon(), concept, homotypicalGroup, target);
|
116
|
}
|
117
|
else if(target instanceof MisappliedGroup ){
|
118
|
return new ChangeConceptRelationshipTypeOperation("Change", getEditor().getUndoContext(),
|
119
|
getEditor().getTaxon(), concept, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), target);
|
120
|
}
|
121
|
}
|
122
|
|
123
|
|
124
|
return null;
|
125
|
}
|
126
|
|
127
|
/** {@inheritDoc} */
|
128
|
@Override
|
129
|
public void dropAccept(DropTargetEvent event) {
|
130
|
// pass
|
131
|
}
|
132
|
|
133
|
|
134
|
private HomotypicalGroup getHomotypicalGroup() {
|
135
|
if(target instanceof AbstractHomotypicalGroupContainer){
|
136
|
return ((AbstractHomotypicalGroupContainer) target).getGroup();
|
137
|
}
|
138
|
return null;
|
139
|
}
|
140
|
|
141
|
private TaxonBase getDroppedTaxonBase(DropTargetEvent dropTargetEvent){
|
142
|
if(dropTargetEvent.data instanceof ICdmBase[]){
|
143
|
|
144
|
ICdmBase[] cdmBaseObjects = (ICdmBase[]) dropTargetEvent.data;
|
145
|
|
146
|
if(cdmBaseObjects[0] instanceof TaxonBase){
|
147
|
return (TaxonBase) cdmBaseObjects[0];
|
148
|
}
|
149
|
}
|
150
|
return null;
|
151
|
}
|
152
|
|
153
|
/**
|
154
|
* @return
|
155
|
*
|
156
|
*/
|
157
|
private TaxonNameEditor getEditor() {
|
158
|
return target.getEditor();
|
159
|
}
|
160
|
}
|