Project

General

Profile

Download (2.38 KB) Statistics
| Branch: | Tag: | Revision:
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.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
	
34
	public DescriptionElementDragListener(DescriptiveViewPart part){
35
		this.part = part;
36
	}
37
	
38
	/**
39
	 * Method declared on DragSourceListener
40
	 */
41
	public void dragFinished(DragSourceEvent event) {
42
		if (!event.doit)
43
			return;
44
		// FIXME what to do here?
45
		if (event.detail != DND.DROP_NONE) {
46
			IStructuredSelection selection = (IStructuredSelection) part.getViewer()
47
					.getSelection();
48
			part.changed(null);
49
		}
50
	}
51
	
52
	/**
53
	 * Method declared on DragSourceListener
54
	 */
55
	public void dragSetData(DragSourceEvent event) {
56
		IStructuredSelection selection = (IStructuredSelection) part.getViewer()
57
				.getSelection();
58
		List<DescriptionElementBase> descriptionElements = new ArrayList<DescriptionElementBase>();
59
		for (Object object : selection.toList()){
60
			if(object instanceof DescriptionBase){
61
				descriptionElements.addAll(((DescriptionBase) object).getElements());
62
			}else if(object instanceof FeatureNodeContainer){
63
				descriptionElements.addAll(((FeatureNodeContainer) object).getDescriptionElements());
64
			}else if(object instanceof DescriptionElementBase){
65
				descriptionElements.add((DescriptionElementBase)object);
66
			}
67
			
68
		}
69
		if (DescriptionElementTransfer.getInstance().isSupportedType(
70
				event.dataType)) {
71
			event.data = descriptionElements.toArray(new DescriptionElementBase[descriptionElements.size()]);
72
		}
73
	}
74
	
75
	/**
76
	 * Method declared on DragSourceListener
77
	 */
78
	public void dragStart(DragSourceEvent event) {
79
		event.doit = !part.getViewer().getSelection().isEmpty();
80
	}
81
	
82
}
(1-1/7)