4 package eu
.etaxonomy
.taxeditor
.editor
.name
.dnd
;
6 import org
.eclipse
.core
.runtime
.Assert
;
7 import org
.eclipse
.swt
.SWTException
;
8 import org
.eclipse
.swt
.dnd
.DND
;
9 import org
.eclipse
.swt
.dnd
.DropTargetAdapter
;
10 import org
.eclipse
.swt
.dnd
.DropTargetEvent
;
12 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
13 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
14 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
15 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
16 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
17 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
18 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
21 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
22 import eu
.etaxonomy
.taxeditor
.editor
.IDropTargetable
;
23 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
24 import eu
.etaxonomy
.taxeditor
.editor
.name
.container
.AbstractHomotypicalGroupContainer
;
25 import eu
.etaxonomy
.taxeditor
.editor
.name
.container
.HomotypicalSynonymGroup
;
26 import eu
.etaxonomy
.taxeditor
.editor
.name
.container
.MisappliedGroup
;
27 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeConceptRelationshipTypeOperation
;
28 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeConceptToSynonymOperation
;
29 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeHomotypicGroupOperation
;
30 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeSynonymToMisapplicationOperation
;
31 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.MoveSynonymToAnotherAcceptedTaxonOperation
;
32 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
33 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
36 * <p>NameEditorDropTargetListener class.</p>
41 public class NameEditorDropTargetListener
extends DropTargetAdapter
{
43 private IDropTargetable target
;
47 * <p>Constructor for NameEditorDropTargetListener.</p>
49 * @param target a {@link eu.etaxonomy.taxeditor.editor.IDropTargetable} object.
51 public NameEditorDropTargetListener(IDropTargetable target
){
56 public void dragEnter(DropTargetEvent dropTargetEvent
) {
59 // if(! EditorUtil.getActiveMultiPageTaxonEditor().equals(editor.getMultiPageTaxonEditor())){
60 // editor.getMultiPageTaxonEditor().setFocus();
65 public void dragLeave(DropTargetEvent dropTargetEvent
) {
70 public void drop(DropTargetEvent dropTargetEvent
) {
72 TaxonBase taxonBase
= getDroppedTaxonBase(dropTargetEvent
);
74 Assert
.isNotNull(taxonBase
);
76 if(taxonBase
.getHomotypicGroup().equals(getHomotypicalGroup())){
77 // do nothing when dragged to the same group
78 dropTargetEvent
.detail
= DND
.DROP_NONE
;
82 // Execute operations at end of drag event
83 AbstractPostOperation operation
= createOperation(taxonBase
);
85 // Execute operation if it has been initiated
86 if (operation
== null) {
87 MessagingUtils
.warn(getClass(), "User unsuccessfully tried to drop: " + taxonBase
.getClass() +
88 ". Target: " + target
);
89 dropTargetEvent
.detail
= DND
.DROP_NONE
;
91 EditorUtil
.executeOperation(operation
);
93 target
.getEditor().getConversationHolder().commit();
94 if (!target
.equals(EditorUtil
.getActiveMultiPageTaxonEditor().getActiveEditor())){
95 ((TaxonNameEditor
)EditorUtil
.getActiveMultiPageTaxonEditor().getActiveEditor()).redraw();
96 ((TaxonNameEditor
)EditorUtil
.getActiveMultiPageTaxonEditor().getActiveEditor()).getConversationHolder().commit();
99 target
.getEditor().redraw();
103 private AbstractPostOperation
createOperation(TaxonBase taxonBase
) {
105 if(taxonBase
instanceof Synonym
){
106 Synonym synonym
= (Synonym
) taxonBase
;
108 if(target
instanceof AbstractHomotypicalGroupContainer
){
109 HomotypicalGroup homotypicalGroup
= ((AbstractHomotypicalGroupContainer
) target
).getGroup();
111 return new ChangeHomotypicGroupOperation("Change Homotypical Group", getEditor().getUndoContext(),
112 getEditor().getTaxon(), synonym
, homotypicalGroup
, target
);
114 else if(target
instanceof MisappliedGroup
){
115 return new ChangeSynonymToMisapplicationOperation("Change Synonym to Misapplication", getEditor().getUndoContext(),
116 getEditor().getTaxon(), synonym
, target
);
118 else if(target
instanceof TaxonNameEditor
){
119 if (target
.equals(getEditor())){
120 return new ChangeHomotypicGroupOperation("Change Homotypical Group", getEditor().getUndoContext(),
121 getEditor().getTaxon(), synonym
, null, target
);
123 getEditor().getConversationHolder().commit();
124 ((TaxonNameEditor
) target
).getConversationHolder().commit();
126 return new MoveSynonymToAnotherAcceptedTaxonOperation("Change accepted Taxon", getEditor().getUndoContext(), getEditor().getTaxon().getUuid(), synonym
.getUuid(), ((TaxonNameEditor
) target
).getTaxon(), null );
131 }else if(taxonBase
instanceof Taxon
){
132 Taxon concept
= (Taxon
) taxonBase
;
134 if(target
instanceof AbstractHomotypicalGroupContainer
){
135 HomotypicalGroup homotypicalGroup
= ((AbstractHomotypicalGroupContainer
) target
).getGroup();
137 return new ChangeConceptToSynonymOperation("Change to Synonym", getEditor().getUndoContext(),
138 getEditor().getTaxon(), concept
, homotypicalGroup
, target
);
140 else if(target
instanceof MisappliedGroup
){
141 return new ChangeConceptRelationshipTypeOperation("Change", getEditor().getUndoContext(),
142 getEditor().getTaxon(), concept
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR(), target
);
152 public void dropAccept(DropTargetEvent event
) {
157 private HomotypicalGroup
getHomotypicalGroup() {
158 if(target
instanceof AbstractHomotypicalGroupContainer
){
159 return ((AbstractHomotypicalGroupContainer
) target
).getGroup();
164 private TaxonBase
getDroppedTaxonBase(DropTargetEvent dropTargetEvent
){
165 if(dropTargetEvent
.data
instanceof ICdmBase
[]){
167 ICdmBase
[] cdmBaseObjects
= (ICdmBase
[]) dropTargetEvent
.data
;
169 if(cdmBaseObjects
[0] instanceof TaxonBase
){
170 return (TaxonBase
) cdmBaseObjects
[0];
180 private TaxonNameEditor
getEditor() {
181 return (TaxonNameEditor
) EditorUtil
.getActiveMultiPageTaxonEditor().getActiveEditor();