4 package eu
.etaxonomy
.taxeditor
.editor
.name
;
6 import org
.apache
.log4j
.Logger
;
7 import org
.eclipse
.core
.runtime
.Assert
;
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
.taxon
.Synonym
;
15 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
16 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
17 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
18 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
19 import eu
.etaxonomy
.taxeditor
.editor
.IDropTargetable
;
20 import eu
.etaxonomy
.taxeditor
.operations
.AbstractPostOperation
;
21 import eu
.etaxonomy
.taxeditor
.operations
.ChangeConceptRelationshipTypeOperation
;
22 import eu
.etaxonomy
.taxeditor
.operations
.ChangeConceptToSynonymOperation
;
23 import eu
.etaxonomy
.taxeditor
.operations
.ChangeHomotypicGroupOperation
;
24 import eu
.etaxonomy
.taxeditor
.operations
.ChangeSynonymToMisapplicationOperation
;
27 * <p>NameEditorDropTargetListener class.</p>
32 public class NameEditorDropTargetListener
extends DropTargetAdapter
{
34 private static final Logger logger
= Logger
.getLogger(NameEditorDropTargetListener
.class);
36 private TaxonNameEditor editor
;
38 private IDropTargetable target
;
41 * <p>Constructor for NameEditorDropTargetListener.</p>
43 * @param target a {@link eu.etaxonomy.taxeditor.editor.IDropTargetable} object.
45 public NameEditorDropTargetListener(IDropTargetable target
){
47 editor
= target
.getNameEditor();
51 public void dragEnter(DropTargetEvent dropTargetEvent
) {
54 // if(! EditorUtil.getActiveMultiPageTaxonEditor().equals(editor.getMultiPageTaxonEditor())){
55 // editor.getMultiPageTaxonEditor().setFocus();
60 public void dragLeave(DropTargetEvent dropTargetEvent
) {
65 public void drop(DropTargetEvent dropTargetEvent
) {
67 TaxonBase taxonBase
= getDroppedTaxonBase(dropTargetEvent
);
69 Assert
.isNotNull(taxonBase
);
71 if(taxonBase
.getHomotypicGroup().equals(getHomotypicalGroup())){
72 // do nothing when dragged to the same group
73 dropTargetEvent
.detail
= DND
.DROP_NONE
;
77 // Execute operations at end of drag event
78 AbstractPostOperation operation
= createOperation(taxonBase
);
80 // Execute operation if it has been initiated
81 if (operation
== null) {
82 logger
.warn("User unsuccessfully tried to drop: " + taxonBase
.getClass() +
83 ". Target: " + target
);
84 dropTargetEvent
.detail
= DND
.DROP_NONE
;
86 EditorUtil
.executeOperation(operation
);
90 private AbstractPostOperation
createOperation(TaxonBase taxonBase
) {
92 if(taxonBase
instanceof Synonym
){
93 Synonym synonym
= (Synonym
) taxonBase
;
95 if(target
instanceof HomotypicalSynonymGroup
){
96 HomotypicalGroup homotypicalGroup
= ((HomotypicalSynonymGroup
) target
).getGroup();
98 return new ChangeHomotypicGroupOperation("Change Homotypical Group", editor
.getUndoContext(),
99 editor
.getTaxon(), synonym
, homotypicalGroup
, target
);
101 else if(target
instanceof MisappliedGroup
){
102 return new ChangeSynonymToMisapplicationOperation("Change Synonym to Misapplication", editor
.getUndoContext(),
103 editor
.getTaxon(), synonym
, target
);
105 else if(target
instanceof TaxonNameEditor
){
106 return new ChangeHomotypicGroupOperation("Change Homotypical Group", editor
.getUndoContext(),
107 editor
.getTaxon(), synonym
, null, target
);
110 }else if(taxonBase
instanceof Taxon
){
111 Taxon concept
= (Taxon
) taxonBase
;
113 if(target
instanceof HomotypicalSynonymGroup
){
114 HomotypicalGroup homotypicalGroup
= ((HomotypicalSynonymGroup
) target
).getGroup();
116 return new ChangeConceptToSynonymOperation("Change to Synonym", editor
.getUndoContext(),
117 editor
.getTaxon(), concept
, homotypicalGroup
, target
);
119 else if(target
instanceof MisappliedGroup
){
120 return new ChangeConceptRelationshipTypeOperation("Change", editor
.getUndoContext(),
121 editor
.getTaxon(), concept
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR(), target
);
131 public void dropAccept(DropTargetEvent event
) {
136 private HomotypicalGroup
getHomotypicalGroup() {
137 if(target
instanceof HomotypicalSynonymGroup
){
138 return ((HomotypicalSynonymGroup
) target
).getGroup();
143 private TaxonBase
getDroppedTaxonBase(DropTargetEvent dropTargetEvent
){
144 if(dropTargetEvent
.data
instanceof ICdmBase
[]){
146 ICdmBase
[] cdmBaseObjects
= (ICdmBase
[]) dropTargetEvent
.data
;
148 if(cdmBaseObjects
[0] instanceof TaxonBase
){
149 return (TaxonBase
) cdmBaseObjects
[0];