4 package eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.dnd
;
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
;
11 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
12 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
13 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
14 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
15 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
16 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
17 import eu
.etaxonomy
.taxeditor
.editor
.name
.container
.AbstractHomotypicalGroupContainer
;
18 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.IDropTargetableE4
;
19 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
20 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
21 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
22 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
30 public class NameEditorDropTargetListenerE4
extends DropTargetAdapter
{
32 private IDropTargetableE4 target
;
34 public NameEditorDropTargetListenerE4(IDropTargetableE4 target
){
40 public void dragEnter(DropTargetEvent dropTargetEvent
) {
46 public void dragLeave(DropTargetEvent dropTargetEvent
) {
52 public void drop(DropTargetEvent dropTargetEvent
) {
54 TaxonBase taxonBase
= getDroppedTaxonBase(dropTargetEvent
);
56 Assert
.isNotNull(taxonBase
);
58 if(taxonBase
.getHomotypicGroup().equals(getHomotypicalGroup())){
59 // do nothing when dragged to the same group
60 dropTargetEvent
.detail
= DND
.DROP_NONE
;
64 // Execute operations at end of drag event
65 AbstractPostOperation operation
= createOperation(taxonBase
);
67 // Execute operation if it has been initiated
68 if (operation
== null) {
69 MessagingUtils
.warn(getClass(), String
.format(Messages
.NameEditorDropTargetListener_UNSUCCESSFULL_DROP
, taxonBase
.getClass(), target
));
70 dropTargetEvent
.detail
= DND
.DROP_NONE
;
72 AbstractUtility
.executeOperation(operation
);
74 target
.getEditor().getConversationHolder().commit();
75 if (!target
.equals(EditorUtil
.getActiveMultiPageTaxonEditor().getActiveEditor())){
76 ((TaxonNameEditor
)EditorUtil
.getActiveMultiPageTaxonEditor().getActiveEditor()).redraw();
77 ((TaxonNameEditor
)EditorUtil
.getActiveMultiPageTaxonEditor().getActiveEditor()).getConversationHolder().commit();
80 target
.getEditor().redraw();
84 private AbstractPostOperation
createOperation(TaxonBase taxonBase
) {
86 //FIXME E4 migrate dnd
88 // if(taxonBase instanceof Synonym){
89 // Synonym synonym = (Synonym) taxonBase;
91 // if(target instanceof AbstractHomotypicalGroupContainer){
92 // HomotypicalGroup homotypicalGroup = ((AbstractHomotypicalGroupContainer) target).getGroup();
94 // return new ChangeHomotypicGroupOperation(Messages.NameEditorDropTargetListener_CHANGE_HOMOTYPICAL_GROUP, getEditor().getUndoContext(),
95 // getEditor().getTaxon(), synonym, homotypicalGroup, target);
97 // else if(target instanceof MisappliedGroup){
98 // return new ChangeSynonymToMisapplicationOperation(Messages.NameEditorDropTargetListener_CHANGE_SYNONYM_TO_MISAPP, getEditor().getUndoContext(),
99 // getEditor().getTaxon(), synonym, target);
101 // else if(target instanceof TaxonNameEditor){
102 // if (target.equals(getEditor())){
103 // return new ChangeHomotypicGroupOperation(Messages.NameEditorDropTargetListener_CHANGE_HOMOTYPICAL_GROUP, getEditor().getUndoContext(),
104 // getEditor().getTaxon(), synonym, null, target);
106 // getEditor().getConversationHolder().commit();
107 // ((TaxonNameEditor) target).getConversationHolder().commit();
109 // return new MoveSynonymToAnotherAcceptedTaxonOperation(Messages.NameEditorDropTargetListener_CHANGE_ACC_TAXON, getEditor().getUndoContext(), getEditor().getTaxon().getUuid(), synonym.getUuid(), ((TaxonNameEditor) target).getTaxon(), null );
114 // }else if(taxonBase instanceof Taxon){
115 // Taxon concept = (Taxon) taxonBase;
117 // if(target instanceof AbstractHomotypicalGroupContainer){
118 // HomotypicalGroup homotypicalGroup = ((AbstractHomotypicalGroupContainer) target).getGroup();
120 // return new ChangeConceptToSynonymOperation(Messages.NameEditorDropTargetListener_CHANGE_SYNONYM, getEditor().getUndoContext(),
121 // getEditor().getTaxon(), concept, homotypicalGroup, target);
123 // else if(target instanceof MisappliedGroup ){
124 // return new ChangeConceptRelationshipTypeOperation(Messages.NameEditorDropTargetListener_CHANGE, getEditor().getUndoContext(),
125 // getEditor().getTaxon(), concept, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), target);
135 public void dropAccept(DropTargetEvent event
) {
140 private HomotypicalGroup
getHomotypicalGroup() {
141 if(target
instanceof AbstractHomotypicalGroupContainer
){
142 return ((AbstractHomotypicalGroupContainer
) target
).getGroup();
147 private TaxonBase
getDroppedTaxonBase(DropTargetEvent dropTargetEvent
){
148 if(dropTargetEvent
.data
instanceof ICdmBase
[]){
150 ICdmBase
[] cdmBaseObjects
= (ICdmBase
[]) dropTargetEvent
.data
;
152 if(cdmBaseObjects
[0] instanceof TaxonBase
){
153 return (TaxonBase
) cdmBaseObjects
[0];
159 private TaxonNameEditorE4
getEditor() {
160 return (TaxonNameEditorE4
) EditorUtil
.getActiveMultiPageTaxonEditor().getActiveEditor();