Project

General

Profile

Revision a901ba1e

IDa901ba1ea2dac142ca2f6f0937b1c92d1a025f8e
Parent 5671f445
Child fa44b721

Added by Patrick Plitzner about 3 years ago

ref #6805 Avoid dragging of non term objects

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermDragListener.java
1
/**
2
* Copyright (C) 2009 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
package eu.etaxonomy.taxeditor.editor.definedterm;
10

  
11
import java.util.ArrayList;
12
import java.util.List;
13

  
14
import org.eclipse.jface.viewers.IStructuredSelection;
15
import org.eclipse.jface.viewers.Viewer;
16
import org.eclipse.swt.dnd.DragSourceAdapter;
17
import org.eclipse.swt.dnd.DragSourceEvent;
18

  
19
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
20

  
21
/**
22
 * @author l.morris
23
 * @date 10 Jan 2012
24
 *
25
 */
26
public class DefinedTermDragListener extends DragSourceAdapter {
27
	
28
	private Viewer viewer;
29

  
30
	public DefinedTermDragListener(Viewer viewer) {
31
		this.viewer = viewer;
32
	}
33

  
34
	@Override
35
	public void dragStart(DragSourceEvent event) {
36
		
37
		event.doit = true;// set to false if needed - default is true
38
	}
39
	}
40

  
41
	@Override
42
	public void dragSetData(DragSourceEvent event) {
43
		
44
		IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
45
		List<DefinedTermBase> definedTerms = new ArrayList<DefinedTermBase>();
46
		
47
		for (Object object : selection.toList()){
48
				definedTerms.add((DefinedTermBase)object);
49
			}
50
			
51
		if (TermTransfer.getInstance().isSupportedType(
52
				event.dataType)) {
53
			event.data = definedTerms.toArray(new DefinedTermBase[definedTerms.size()]);
54
		}
55
	}
56
	
57
	
58

  
59
}
1
/**
2
* Copyright (C) 2009 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
package eu.etaxonomy.taxeditor.editor.definedterm;
10

  
11
import java.util.ArrayList;
12
import java.util.List;
13

  
14
import org.eclipse.jface.viewers.IStructuredSelection;
15
import org.eclipse.jface.viewers.Viewer;
16
import org.eclipse.swt.dnd.DragSourceAdapter;
17
import org.eclipse.swt.dnd.DragSourceEvent;
18

  
19
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
20

  
21
/**
22
 * @author l.morris
23
 * @date 10 Jan 2012
24
 *
25
 */
26
public class DefinedTermDragListener extends DragSourceAdapter {
27

  
28
	private Viewer viewer;
29

  
30
	public DefinedTermDragListener(Viewer viewer) {
31
		this.viewer = viewer;
32
	}
33

  
34
	@Override
35
	public void dragStart(DragSourceEvent event) {
36
	    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
37
	    List list = selection.toList();
38
	    for (Object object : list) {
39
            if(!(object instanceof DefinedTermBase)){
40
                event.doit = false;
41
                return;
42
            }
43
        }
44
		event.doit = true;
45
	}
46

  
47
	@Override
48
	public void dragSetData(DragSourceEvent event) {
49

  
50
		IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
51
		List<DefinedTermBase> definedTerms = new ArrayList<DefinedTermBase>();
52

  
53
		for (Object object : selection.toList()){
54
				definedTerms.add((DefinedTermBase)object);
55
			}
56

  
57
		if (TermTransfer.getInstance().isSupportedType(
58
				event.dataType)) {
59
			event.data = definedTerms.toArray(new DefinedTermBase[definedTerms.size()]);
60
		}
61
	}
62

  
63
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)