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
|
|
10
|
package eu.etaxonomy.taxeditor.editor.view.descriptive;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
|
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;
|
19
|
|
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;
|
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 FactualDataPartE4 part;
|
34
|
private DescriptionBase description;
|
35
|
|
36
|
public DescriptionElementDragListener(FactualDataPartE4 part){
|
37
|
this.part = part;
|
38
|
}
|
39
|
|
40
|
/**
|
41
|
* Method declared on DragSourceListener
|
42
|
*/
|
43
|
@Override
|
44
|
public void dragFinished(DragSourceEvent event) {
|
45
|
if (!event.doit) {
|
46
|
return;
|
47
|
}
|
48
|
// FIXME what to do here?
|
49
|
if (event.detail != DND.DROP_NONE) {
|
50
|
//IStructuredSelection selection = (IStructuredSelection) part.getViewer().getSelection();
|
51
|
part.getViewer().refresh();
|
52
|
|
53
|
part.changed(null);
|
54
|
}
|
55
|
}
|
56
|
|
57
|
/**
|
58
|
* Method declared on DragSourceListener
|
59
|
*/
|
60
|
@Override
|
61
|
public void dragSetData(DragSourceEvent event) {
|
62
|
IStructuredSelection selection = (IStructuredSelection) part.getViewer()
|
63
|
.getSelection();
|
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());
|
69
|
}
|
70
|
description = HibernateProxyHelper.deproxy(object, DescriptionBase.class);
|
71
|
|
72
|
}else if(object instanceof FeatureNodeContainer){
|
73
|
descriptionElements.addAll(((FeatureNodeContainer) object).getDescriptionElements());
|
74
|
}else if(object instanceof DescriptionElementBase){
|
75
|
descriptionElements.add((DescriptionElementBase)object);
|
76
|
}
|
77
|
|
78
|
}
|
79
|
if (DescriptionElementTransfer.getInstance().isSupportedType(
|
80
|
event.dataType)) {
|
81
|
if (!descriptionElements.isEmpty()){
|
82
|
event.data = descriptionElements.toArray(new DescriptionElementBase[descriptionElements.size()]);
|
83
|
}
|
84
|
|
85
|
}
|
86
|
|
87
|
}
|
88
|
|
89
|
/**
|
90
|
* Method declared on DragSourceListener
|
91
|
*/
|
92
|
@Override
|
93
|
public void dragStart(DragSourceEvent event) {
|
94
|
event.doit = !part.getViewer().getSelection().isEmpty();
|
95
|
}
|
96
|
|
97
|
}
|