commit 739cbae5d4fdf061701b3755b7febc443a42a09f
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Wed Dec 20 08:53:44 2017 +0100

    ref #7086 Allow drag and drop for taxon filter from taxon navigator

diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/TaxonNodeDropAdapter.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/TaxonNodeDropAdapter.java
new file mode 100644
index 000000000..2b6c16682
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/TaxonNodeDropAdapter.java
@@ -0,0 +1,73 @@
+/**
+* Copyright (C) 2017 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.editor.workingSet;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.jface.util.LocalSelectionTransfer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerDropAdapter;
+import org.eclipse.swt.dnd.TransferData;
+
+import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
+
+/**
+ * @author pplitzner
+ * @since Dec 19, 2017
+ *
+ */
+public class TaxonNodeDropAdapter extends ViewerDropAdapter {
+
+    private WorkingSetEditor workingSetEditor;
+
+    public TaxonNodeDropAdapter(WorkingSetEditor workingSetEditor) {
+        super(workingSetEditor.getTaxonTreeViewer());
+        this.workingSetEditor = workingSetEditor;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean performDrop(Object data) {
+        ITaxonTreeNode treeNode= (ITaxonTreeNode) ((ITreeSelection) data).getFirstElement();
+        Viewer taxonTreeViewer = workingSetEditor.getTaxonTreeViewer();
+        Object input = taxonTreeViewer.getInput();
+        Collection<ITaxonTreeNode> treeNodes;
+        if(input==null){
+            treeNodes = new ArrayList<>();
+        }
+        else{
+            treeNodes = (Collection<ITaxonTreeNode>) input;
+        }
+        treeNodes.add(treeNode);
+        taxonTreeViewer.setInput(treeNodes);
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean validateDrop(Object target, int operation, TransferData transferType) {
+        ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
+        if(selection instanceof ITreeSelection
+                && ((IStructuredSelection) selection).size()==1
+                && ((IStructuredSelection) selection).getFirstElement() instanceof ITaxonTreeNode){
+            return true;
+        }
+        return false;
+    }
+
+
+}
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/WorkingSetComposite.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/WorkingSetComposite.java
index 05c4af0ec..7a8123d1b 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/WorkingSetComposite.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/WorkingSetComposite.java
@@ -8,10 +8,6 @@
  */
 package eu.etaxonomy.taxeditor.editor.workingSet;
 
-import java.util.List;
-
-import org.eclipse.jface.viewers.ITreeSelection;
-import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.GridData;
@@ -21,15 +17,11 @@ import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.swt.widgets.Tree;
 
-import eu.etaxonomy.cdm.api.service.IClassificationService;
 import eu.etaxonomy.cdm.model.common.TermType;
 import eu.etaxonomy.cdm.model.description.FeatureTree;
 import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.cdm.model.name.Rank;
-import eu.etaxonomy.cdm.model.taxon.Classification;
-import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditorComposite;
-import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.combo.TermUuidComboViewer;
 import eu.etaxonomy.taxeditor.util.TaxonTreeNodeContentProvider;
 import eu.etaxonomy.taxeditor.util.TaxonTreeNodeLabelProvider;
@@ -51,8 +43,6 @@ public class WorkingSetComposite extends Composite {
     public WorkingSetComposite(Composite parent, int style) {
         super(parent, style);
 
-        List<Classification> list = CdmStore.getService(IClassificationService.class).list(Classification.class, null, null, null, null);
-
         setLayout(new GridLayout(3, false));
 
         Label lblNewLabel = new Label(this, SWT.NONE);
@@ -78,7 +68,6 @@ public class WorkingSetComposite extends Composite {
 
         taxonNodeTree.setContentProvider(new TaxonTreeNodeContentProvider());
         taxonNodeTree.setLabelProvider(new TaxonTreeNodeLabelProvider());
-        taxonNodeTree.setInput(list);
 
         Label lblNewLabel_3 = new Label(this, SWT.NONE);
         lblNewLabel_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
@@ -134,15 +123,8 @@ public class WorkingSetComposite extends Composite {
         featureTreeEditorComposite.setSelectedTree(characters, null);
     }
 
-    public TaxonNode getTaxonNode(){
-        ITreeSelection selection = (ITreeSelection) taxonNodeTree.getSelection();
-        if(selection!=null && selection.getFirstElement() instanceof TaxonNode){
-            return (TaxonNode) selection.getFirstElement();
-        }
-        return null;
-    }
-    public void setTaxonNode(TaxonNode taxonNode){
-        taxonNodeTree.setSelection(new StructuredSelection(taxonNode), true);
+    public TreeViewer getTaxonNodeTree() {
+        return taxonNodeTree;
     }
 
     public NamedArea getArea(){
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/WorkingSetEditor.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/WorkingSetEditor.java
index d8eac201c..56aa97258 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/WorkingSetEditor.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/WorkingSetEditor.java
@@ -25,12 +25,15 @@ import org.eclipse.e4.ui.di.Focus;
 import org.eclipse.e4.ui.di.Persist;
 import org.eclipse.e4.ui.model.application.ui.MDirtyable;
 import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.util.LocalSelectionTransfer;
+import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.Transfer;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Shell;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
@@ -44,6 +47,7 @@ import eu.etaxonomy.cdm.model.description.WorkingSet;
 import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.cdm.model.name.Rank;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -64,11 +68,11 @@ public class WorkingSetEditor implements IE4SavablePart{
 
     private WorkingSet workingSet;
 
+    private final int dndOperations = DND.DROP_MOVE;
+
     @Inject
     private MDirtyable dirty;
 
-    private Listener nameAreaSelectionListener;
-
     private ModifyListener labelModifyListener;
 
     @PostConstruct
@@ -100,6 +104,11 @@ public class WorkingSetEditor implements IE4SavablePart{
             }
             dirty.setDirty(true);
         });
+
+        //add drag'n'drop support
+        Transfer[] transfers = new Transfer[] {LocalSelectionTransfer.getTransfer()};
+        composite.getTaxonNodeTree().addDropSupport(dndOperations, transfers, new TaxonNodeDropAdapter(this));
+
     }
 
     public void init(UUID workingSetUuid) {
@@ -137,15 +146,24 @@ public class WorkingSetEditor implements IE4SavablePart{
         if(area!=null){
             areas.add(area);
         }
-        TaxonNode taxonNode = composite.getTaxonNode();
-        Set<NamedArea> descriptions;
-        if(taxonNode!=null && taxonNode.getTaxon()!=null){
-            Taxon taxon = HibernateProxyHelper.deproxy(taxonNode.getTaxon(), Taxon.class);
-            Collection<SpecimenOrObservationBase> specimens = CdmStore.getService(IOccurrenceService.class).listByAssociatedTaxon(SpecimenOrObservationBase.class, null, taxon, null, null, null, null, null);
-            for (SpecimenOrObservationBase specimen : specimens) {
-                Set<SpecimenDescription> specimenDescriptions = specimen.getSpecimenDescriptions();
-                for (SpecimenDescription specimenDescription : specimenDescriptions) {
-                    workingSet.addDescription(specimenDescription);
+        Object input = composite.getTaxonNodeTree().getInput();
+        if(input!=null){
+            Collection<ITaxonTreeNode> taxonNodes = (Collection<ITaxonTreeNode>) input;
+            for (ITaxonTreeNode taxonTreeNode : taxonNodes) {
+                if(taxonTreeNode instanceof TaxonNode){
+                    TaxonNode taxonNode = (TaxonNode)taxonTreeNode;
+                    workingSet.addTaxonSubtree(taxonNode);
+                    Set<NamedArea> descriptions;
+                    if(taxonNode!=null && taxonNode.getTaxon()!=null){
+                        Taxon taxon = HibernateProxyHelper.deproxy(taxonNode.getTaxon(), Taxon.class);
+                        Collection<SpecimenOrObservationBase> specimens = CdmStore.getService(IOccurrenceService.class).listByAssociatedTaxon(SpecimenOrObservationBase.class, null, taxon, null, null, null, null, null);
+                        for (SpecimenOrObservationBase specimen : specimens) {
+                            Set<SpecimenDescription> specimenDescriptions = specimen.getSpecimenDescriptions();
+                            for (SpecimenDescription specimenDescription : specimenDescriptions) {
+                                workingSet.addDescription(specimenDescription);
+                            }
+                        }
+                    }
                 }
             }
         }
@@ -164,7 +182,6 @@ public class WorkingSetEditor implements IE4SavablePart{
         workingSet.setMaxRank(rankMax);
         workingSet.setMinRank(rankMin);
         workingSet.setDescriptiveSystem(characters);
-        workingSet.addTaxonSubtree(taxonNode);
         workingSet.setGeoFilter(areas);
 
         conversation.commit();
@@ -188,4 +205,8 @@ public class WorkingSetEditor implements IE4SavablePart{
         }
     }
 
+    public Viewer getTaxonTreeViewer() {
+        return composite.getTaxonNodeTree();
+    }
+
 }
