Merge branch 'hotfix/5.45.1'
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / descriptive / DescriptionElementDragListener.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.editor.view.descriptive;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import org.eclipse.jface.viewers.IStructuredSelection;
15 import org.eclipse.swt.dnd.DND;
16 import org.eclipse.swt.dnd.DragSourceAdapter;
17 import org.eclipse.swt.dnd.DragSourceEvent;
18
19 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
20 import eu.etaxonomy.cdm.model.description.DescriptionBase;
21 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
22 import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
23 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
24
25 /**
26 * @author n.hoffmann
27 * @created Feb 8, 2011
28 */
29 public class DescriptionElementDragListener extends DragSourceAdapter {
30
31 private FactualDataPartE4 part;
32 private DescriptionBase<?> description;
33
34 public DescriptionElementDragListener(FactualDataPartE4 part){
35 this.part = part;
36 }
37
38 /**
39 * Method declared on DragSourceListener
40 */
41 @Override
42 public void dragFinished(DragSourceEvent event) {
43 if (!event.doit) {
44 return;
45 }
46 // FIXME what to do here?
47 if (event.detail != DND.DROP_NONE) {
48 //IStructuredSelection selection = (IStructuredSelection) part.getViewer().getSelection();
49 part.getViewer().refresh();
50
51 part.changed(null);
52 }
53 }
54
55 /**
56 * Method declared on DragSourceListener
57 */
58 @Override
59 public void dragSetData(DragSourceEvent event) {
60 IStructuredSelection selection = (IStructuredSelection) part.getViewer()
61 .getSelection();
62 List<DescriptionElementBase> descriptionElements = new ArrayList<DescriptionElementBase>();
63 for (Object object : selection.toList()){
64 if(object instanceof DescriptionBase){
65 if (!((DescriptionBase) object).getElements().isEmpty()){
66 descriptionElements.addAll(((DescriptionBase) object).getElements());
67 }
68 description = HibernateProxyHelper.deproxy(object, DescriptionBase.class);
69
70 }else if(object instanceof FeatureNodeContainer){
71 descriptionElements.addAll(((FeatureNodeContainer) object).getDescriptionElements());
72 }else if(object instanceof DescriptionElementBase){
73 descriptionElements.add((DescriptionElementBase)object);
74 }
75
76 }
77 if (DescriptionElementTransfer.getInstance().isSupportedType(
78 event.dataType)) {
79 if (!descriptionElements.isEmpty()){
80 event.data = descriptionElements.toArray(new DescriptionElementBase[descriptionElements.size()]);
81 }
82
83 }
84 }
85
86 /**
87 * Method declared on DragSourceListener
88 */
89 @Override
90 public void dragStart(DragSourceEvent event) {
91 event.doit = !part.getViewer().getSelection().isEmpty();
92 }
93 }