2 * Copyright (C) 2017 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.
9 package eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
.character
;
11 import java
.util
.Collection
;
13 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
14 import org
.eclipse
.jface
.viewers
.TreeSelection
;
15 import org
.eclipse
.jface
.viewers
.TreeViewer
;
16 import org
.eclipse
.swt
.dnd
.DragSourceEvent
;
18 import eu
.etaxonomy
.cdm
.model
.description
.Character
;
19 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
20 import eu
.etaxonomy
.taxeditor
.featuretree
.CharacterTransfer
;
21 import eu
.etaxonomy
.taxeditor
.featuretree
.e4
.FeatureNodeDragListener
;
28 public class CharacterDragListener
extends FeatureNodeDragListener
{
30 private TreeViewer structureViewer
;
31 private TreeViewer propertyViewer
;
33 public CharacterDragListener(TreeViewer structureViewer
, TreeViewer propertyViewer
) {
34 super(propertyViewer
);
35 this.structureViewer
= structureViewer
;
36 this.propertyViewer
= propertyViewer
;
40 public void dragSetData(DragSourceEvent event
) {
41 TreeSelection structureSelection
= (TreeSelection
) structureViewer
.getSelection();
42 TreeSelection propertySelection
= (TreeSelection
) propertyViewer
.getSelection();
43 if(structureSelection
!=null && propertySelection
!=null
44 && !structureSelection
.isEmpty() && !propertySelection
.isEmpty()){
45 //create all possible characters
46 Collection
<Character
> characters
= CharacterEditor
.createCharacters(structureSelection
, propertySelection
);
48 if (CharacterTransfer
.getInstance().isSupportedType(event
.dataType
)) {
49 event
.data
= characters
;
55 * Method declared on DragSourceListener
58 public void dragStart(DragSourceEvent event
) {
60 !structureViewer
.getSelection().isEmpty()
61 && !propertyViewer
.getSelection().isEmpty()
62 && ((IStructuredSelection
) structureViewer
.getSelection()).toList()
63 .stream().allMatch(element
-> element
instanceof FeatureNode
)
64 && ((IStructuredSelection
) propertyViewer
.getSelection()).toList()
65 .stream().allMatch(element
-> element
instanceof FeatureNode
);