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
.hibernate
.HibernateProxyHelper
;
13 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
14 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
15 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
16 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
17 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
18 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
22 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
23 import eu
.etaxonomy
.taxeditor
.editor
.IDropTargetable
;
24 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
25 import eu
.etaxonomy
.taxeditor
.editor
.name
.container
.AbstractHomotypicalGroupContainer
;
26 import eu
.etaxonomy
.taxeditor
.editor
.name
.container
.HomotypicalSynonymGroup
;
27 import eu
.etaxonomy
.taxeditor
.editor
.name
.container
.MisappliedGroup
;
28 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeConceptRelationshipTypeOperation
;
29 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeConceptToSynonymOperation
;
30 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeHomotypicGroupOperation
;
31 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeSynonymToMisapplicationOperation
;
32 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.MoveSynonymToAnotherAcceptedTaxonOperation
;
33 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
34 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
37 * <p>NameEditorDropTargetListener class.</p>
42 public class NameEditorDropTargetListener
extends DropTargetAdapter
{
44 private IDropTargetable target
;
48 * <p>Constructor for NameEditorDropTargetListener.</p>
50 * @param target a {@link eu.etaxonomy.taxeditor.editor.IDropTargetable} object.
52 public NameEditorDropTargetListener(IDropTargetable target
){
57 public void dragEnter(DropTargetEvent dropTargetEvent
) {
60 // if(! EditorUtil.getActiveMultiPageTaxonEditor().equals(editor.getMultiPageTaxonEditor())){
61 // editor.getMultiPageTaxonEditor().setFocus();
66 public void dragLeave(DropTargetEvent dropTargetEvent
) {
71 public void drop(DropTargetEvent dropTargetEvent
) {
72 if (!EditorUtil
.forceUserSave(target
.getEditor(), dropTargetEvent
.display
.getActiveShell())){
75 TaxonBase taxonBase
= getDroppedTaxonBase(dropTargetEvent
);
77 Assert
.isNotNull(taxonBase
);
79 if(taxonBase
.getHomotypicGroup().equals(getHomotypicalGroup())){
80 // do nothing when dragged to the same group
81 dropTargetEvent
.detail
= DND
.DROP_NONE
;
85 // Execute operations at end of drag event
86 AbstractPostOperation operation
= createOperation(taxonBase
);
88 // Execute operation if it has been initiated
89 if (operation
== null) {
90 MessagingUtils
.warn(getClass(), "User unsuccessfully tried to drop: " + taxonBase
.getClass() +
91 ". Target: " + target
);
92 dropTargetEvent
.detail
= DND
.DROP_NONE
;
94 EditorUtil
.executeOperation(operation
);
96 target
.getEditor().getConversationHolder().commit();
97 if (!target
.equals(EditorUtil
.getActiveMultiPageTaxonEditor().getActiveEditor())){
98 ((TaxonNameEditor
)EditorUtil
.getActiveMultiPageTaxonEditor().getActiveEditor()).redraw();
99 ((TaxonNameEditor
)EditorUtil
.getActiveMultiPageTaxonEditor().getActiveEditor()).getConversationHolder().commit();
102 target
.getEditor().redraw();
106 private AbstractPostOperation
createOperation(TaxonBase taxonBase
) {
109 if(taxonBase
instanceof Synonym
){
110 Synonym synonym
= (Synonym
) taxonBase
;
112 if(target
instanceof AbstractHomotypicalGroupContainer
){
113 HomotypicalGroup homotypicalGroup
= ((AbstractHomotypicalGroupContainer
) target
).getGroup();
115 return new ChangeHomotypicGroupOperation("Change Homotypical Group", getEditor().getUndoContext(),
116 getEditor().getTaxon(), synonym
, homotypicalGroup
, target
);
118 else if(target
instanceof MisappliedGroup
){
119 return new ChangeSynonymToMisapplicationOperation("Change Synonym to Misapplication", getEditor().getUndoContext(),
120 getEditor().getTaxon(), synonym
, target
);
122 else if(target
instanceof TaxonNameEditor
){
123 if (target
.equals(getEditor())){
124 return new ChangeHomotypicGroupOperation("Change Homotypical Group", getEditor().getUndoContext(),
125 getEditor().getTaxon(), synonym
, null, target
);
127 getEditor().getConversationHolder().commit();
128 ((TaxonNameEditor
) target
).getConversationHolder().commit();
130 return new MoveSynonymToAnotherAcceptedTaxonOperation("Change accepted Taxon", getEditor().getUndoContext(), getEditor().getTaxon().getUuid(), synonym
.getUuid(), ((TaxonNameEditor
) target
).getTaxon(), null );
135 }else if(taxonBase
instanceof Taxon
){
136 Taxon concept
= (Taxon
) taxonBase
;
138 if(target
instanceof AbstractHomotypicalGroupContainer
){
139 HomotypicalGroup homotypicalGroup
= ((AbstractHomotypicalGroupContainer
) target
).getGroup();
141 return new ChangeConceptToSynonymOperation("Change to Synonym", getEditor().getUndoContext(),
142 getEditor().getTaxon(), concept
, homotypicalGroup
, target
);
144 else if(target
instanceof MisappliedGroup
){
145 return new ChangeConceptRelationshipTypeOperation("Change", getEditor().getUndoContext(),
146 getEditor().getTaxon(), concept
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR(), target
);
156 public void dropAccept(DropTargetEvent event
) {
161 private HomotypicalGroup
getHomotypicalGroup() {
162 if(target
instanceof AbstractHomotypicalGroupContainer
){
163 return ((AbstractHomotypicalGroupContainer
) target
).getGroup();
168 private TaxonBase
getDroppedTaxonBase(DropTargetEvent dropTargetEvent
){
169 if(dropTargetEvent
.data
instanceof ICdmBase
[]){
171 ICdmBase
[] cdmBaseObjects
= (ICdmBase
[]) dropTargetEvent
.data
;
173 if(cdmBaseObjects
[0] instanceof TaxonBase
){
174 return (TaxonBase
) cdmBaseObjects
[0];
184 private TaxonNameEditor
getEditor() {
185 return (TaxonNameEditor
) EditorUtil
.getActiveMultiPageTaxonEditor().getActiveEditor();