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