3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
;
13 import java
.util
.ArrayList
;
14 import java
.util
.List
;
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
;
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
;
28 * @created Feb 8, 2011
31 public class DescriptionElementDragListener
extends DragSourceAdapter
{
33 private DescriptiveViewPart part
;
34 private DescriptionBase description
;
36 public DescriptionElementDragListener(DescriptiveViewPart part
){
41 * Method declared on DragSourceListener
43 public void dragFinished(DragSourceEvent event
) {
46 // FIXME what to do here?
47 if (event
.detail
!= DND
.DROP_NONE
) {
48 //IStructuredSelection selection = (IStructuredSelection) part.getViewer().getSelection();
49 part
.getViewer().refresh();
56 * Method declared on DragSourceListener
58 public void dragSetData(DragSourceEvent event
) {
59 IStructuredSelection selection
= (IStructuredSelection
) part
.getViewer()
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());
67 description
= HibernateProxyHelper
.deproxy(object
, DescriptionBase
.class);
69 }else if(object
instanceof FeatureNodeContainer
){
70 descriptionElements
.addAll(((FeatureNodeContainer
) object
).getDescriptionElements());
71 }else if(object
instanceof DescriptionElementBase
){
72 descriptionElements
.add((DescriptionElementBase
)object
);
76 if (DescriptionElementTransfer
.getInstance().isSupportedType(
78 if (!descriptionElements
.isEmpty()){
79 event
.data
= descriptionElements
.toArray(new DescriptionElementBase
[descriptionElements
.size()]);
87 * Method declared on DragSourceListener
89 public void dragStart(DragSourceEvent event
) {
90 event
.doit
= !part
.getViewer().getSelection().isEmpty();