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
.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
.l10n
.Messages
;
18 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.IDropTargetableE4
;
19 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
20 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.container
.AbstractHomotypicalGroupContainerE4
;
21 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.container
.MisappliedGroupE4
;
22 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.operation
.MoveSynonymToAnotherAcceptedTaxonOperationE4
;
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
.event
.EventUtility
;
28 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
29 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
30 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
38 public class NameEditorDropTargetListenerE4
extends DropTargetAdapter
{
40 private IDropTargetableE4 target
;
42 public NameEditorDropTargetListenerE4(IDropTargetableE4 target
){
48 public void dragEnter(DropTargetEvent dropTargetEvent
) {
54 public void dragLeave(DropTargetEvent dropTargetEvent
) {
60 public void drop(DropTargetEvent dropTargetEvent
) {
62 TaxonBase taxonBase
= getDroppedTaxonBase(dropTargetEvent
);
64 Assert
.isNotNull(taxonBase
);
66 if(taxonBase
.getHomotypicGroup().equals(getHomotypicalGroup())){
67 // do nothing when dragged to the same group
68 dropTargetEvent
.detail
= DND
.DROP_NONE
;
72 // Execute operations at end of drag event
73 AbstractPostOperation operation
= createOperation(taxonBase
);
75 // Execute operation if it has been initiated
76 if (operation
== null) {
77 MessagingUtils
.warn(getClass(), String
.format(Messages
.NameEditorDropTargetListener_UNSUCCESSFULL_DROP
, taxonBase
.getClass(), target
));
78 dropTargetEvent
.detail
= DND
.DROP_NONE
;
80 AbstractUtility
.executeOperation(operation
);
82 target
.getEditor().getConversationHolder().commit();
83 if (!target
.equals(EventUtility
.getEditor())){
84 ((TaxonNameEditorE4
)EventUtility
.getEditor()).redraw();
85 ((TaxonNameEditorE4
)EventUtility
.getEditor()).getConversationHolder().commit();
88 target
.getEditor().redraw();
92 private AbstractPostOperation
createOperation(TaxonBase taxonBase
) {
94 if(taxonBase
instanceof Synonym
){
95 Synonym synonym
= (Synonym
) taxonBase
;
97 if(target
instanceof AbstractHomotypicalGroupContainerE4
){
98 HomotypicalGroup homotypicalGroup
= ((AbstractHomotypicalGroupContainerE4
) target
).getGroup();
100 return new ChangeHomotypicGroupOperation(Messages
.NameEditorDropTargetListener_CHANGE_HOMOTYPICAL_GROUP
, getEditor().getUndoContext(),
101 getEditor().getTaxon(), synonym
, homotypicalGroup
, target
);
103 else if(target
instanceof MisappliedGroupE4
){
104 return new ChangeSynonymToMisapplicationOperation(Messages
.NameEditorDropTargetListener_CHANGE_SYNONYM_TO_MISAPP
, getEditor().getUndoContext(),
105 getEditor().getTaxon(), synonym
, target
);
107 else if(target
instanceof TaxonNameEditorE4
){
108 if (target
.equals(getEditor())){
109 return new ChangeHomotypicGroupOperation(Messages
.NameEditorDropTargetListener_CHANGE_HOMOTYPICAL_GROUP
, getEditor().getUndoContext(),
110 getEditor().getTaxon(), synonym
, null, target
);
112 getEditor().getConversationHolder().commit();
113 ((TaxonNameEditorE4
) target
).getConversationHolder().commit();
115 return new MoveSynonymToAnotherAcceptedTaxonOperationE4(Messages
.NameEditorDropTargetListener_CHANGE_ACC_TAXON
, getEditor().getUndoContext(), synonym
.getUuid(), ((TaxonNameEditorE4
) target
).getTaxon(), (TaxonNameEditorE4
) target
, (TaxonNameEditorE4
) target
);
120 }else if(taxonBase
instanceof Taxon
){
121 Taxon concept
= (Taxon
) taxonBase
;
123 if(target
instanceof AbstractHomotypicalGroupContainerE4
){
124 HomotypicalGroup homotypicalGroup
= ((AbstractHomotypicalGroupContainerE4
) target
).getGroup();
126 return new ChangeConceptToSynonymOperation(Messages
.NameEditorDropTargetListener_CHANGE_SYNONYM
, getEditor().getUndoContext(),
127 getEditor().getTaxon(), concept
, homotypicalGroup
, target
);
129 else if(target
instanceof MisappliedGroupE4
){
130 return new ChangeConceptRelationshipTypeOperation(Messages
.NameEditorDropTargetListener_CHANGE
, getEditor().getUndoContext(),
131 getEditor().getTaxon(), concept
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR(), target
);
141 public void dropAccept(DropTargetEvent event
) {
146 private HomotypicalGroup
getHomotypicalGroup() {
147 if(target
instanceof AbstractHomotypicalGroupContainerE4
){
148 return ((AbstractHomotypicalGroupContainerE4
) target
).getGroup();
153 private TaxonBase
getDroppedTaxonBase(DropTargetEvent dropTargetEvent
){
154 if(dropTargetEvent
.data
instanceof ICdmBase
[]){
156 ICdmBase
[] cdmBaseObjects
= (ICdmBase
[]) dropTargetEvent
.data
;
158 if(cdmBaseObjects
[0] instanceof TaxonBase
){
159 return (TaxonBase
) cdmBaseObjects
[0];
165 private TaxonNameEditorE4
getEditor() {
166 return (TaxonNameEditorE4
) EventUtility
.getEditor();