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