ref #6190 removing svn property place holder in first line of code - java files
[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
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.model.FeatureNodeContainer;
24
25 /**
26 * @author n.hoffmann
27 * @created Feb 8, 2011
28 * @version 1.0
29 */
30 public class DescriptionElementDragListener extends DragSourceAdapter {
31
32 private DescriptiveViewPart part;
33 private DescriptionBase description;
34
35 public DescriptionElementDragListener(DescriptiveViewPart part){
36 this.part = part;
37 }
38
39 /**
40 * Method declared on DragSourceListener
41 */
42 public void dragFinished(DragSourceEvent event) {
43 if (!event.doit)
44 return;
45 // FIXME what to do here?
46 if (event.detail != DND.DROP_NONE) {
47 //IStructuredSelection selection = (IStructuredSelection) part.getViewer().getSelection();
48 part.getViewer().refresh();
49
50 part.changed(null);
51 }
52 }
53
54 /**
55 * Method declared on DragSourceListener
56 */
57 public void dragSetData(DragSourceEvent event) {
58 IStructuredSelection selection = (IStructuredSelection) part.getViewer()
59 .getSelection();
60 List<DescriptionElementBase> descriptionElements = new ArrayList<DescriptionElementBase>();
61 for (Object object : selection.toList()){
62 if(object instanceof DescriptionBase){
63 if (!((DescriptionBase) object).getElements().isEmpty()){
64 descriptionElements.addAll(((DescriptionBase) object).getElements());
65 }
66 description = HibernateProxyHelper.deproxy(object, DescriptionBase.class);
67
68 }else if(object instanceof FeatureNodeContainer){
69 descriptionElements.addAll(((FeatureNodeContainer) object).getDescriptionElements());
70 }else if(object instanceof DescriptionElementBase){
71 descriptionElements.add((DescriptionElementBase)object);
72 }
73
74 }
75 if (DescriptionElementTransfer.getInstance().isSupportedType(
76 event.dataType)) {
77 if (!descriptionElements.isEmpty()){
78 event.data = descriptionElements.toArray(new DescriptionElementBase[descriptionElements.size()]);
79 }
80
81 }
82
83 }
84
85 /**
86 * Method declared on DragSourceListener
87 */
88 public void dragStart(DragSourceEvent event) {
89 event.doit = !part.getViewer().getSelection().isEmpty();
90 }
91
92 }