2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
15 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
16 import org
.eclipse
.swt
.dnd
.DND
;
17 import org
.eclipse
.swt
.dnd
.DragSourceAdapter
;
18 import org
.eclipse
.swt
.dnd
.DragSourceEvent
;
20 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
21 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
22 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
23 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.e4
.FactualDataPartE4
;
24 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
28 * @created Feb 8, 2011
31 public class DescriptionElementDragListener
extends DragSourceAdapter
{
33 private FactualDataPartE4 part
;
34 private DescriptionBase description
;
36 public DescriptionElementDragListener(FactualDataPartE4 part
){
41 * Method declared on DragSourceListener
44 public void dragFinished(DragSourceEvent event
) {
48 // FIXME what to do here?
49 if (event
.detail
!= DND
.DROP_NONE
) {
50 //IStructuredSelection selection = (IStructuredSelection) part.getViewer().getSelection();
51 part
.getViewer().refresh();
58 * Method declared on DragSourceListener
61 public void dragSetData(DragSourceEvent event
) {
62 IStructuredSelection selection
= (IStructuredSelection
) part
.getViewer()
64 List
<DescriptionElementBase
> descriptionElements
= new ArrayList
<DescriptionElementBase
>();
65 for (Object object
: selection
.toList()){
66 if(object
instanceof DescriptionBase
){
67 if (!((DescriptionBase
) object
).getElements().isEmpty()){
68 descriptionElements
.addAll(((DescriptionBase
) object
).getElements());
70 description
= HibernateProxyHelper
.deproxy(object
, DescriptionBase
.class);
72 }else if(object
instanceof FeatureNodeContainer
){
73 descriptionElements
.addAll(((FeatureNodeContainer
) object
).getDescriptionElements());
74 }else if(object
instanceof DescriptionElementBase
){
75 descriptionElements
.add((DescriptionElementBase
)object
);
79 if (DescriptionElementTransfer
.getInstance().isSupportedType(
81 if (!descriptionElements
.isEmpty()){
82 event
.data
= descriptionElements
.toArray(new DescriptionElementBase
[descriptionElements
.size()]);
90 * Method declared on DragSourceListener
93 public void dragStart(DragSourceEvent event
) {
94 event
.doit
= !part
.getViewer().getSelection().isEmpty();