Merge branch 'develop' into featureTreeEditor
authorPatrick Plitzner <p.plitzner@bgbm.org>
Sun, 18 Jun 2017 19:28:14 +0000 (21:28 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Sun, 18 Jun 2017 19:28:14 +0000 (21:28 +0200)
12 files changed:
eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.editor/fragment.e4xmi
eu.etaxonomy.taxeditor.editor/icons/Ontology.xml [new file with mode: 0644]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/CharacterDragListener.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/CharacterDropAdapter.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/FeatureTreeBuilderViewPart.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/StructureContentProvider.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/StructureLabelProvider.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/FeatureNodeDragListener.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/FeatureNodeDropAdapter.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/FeatureTreeLabelProvider.java

index f10e87bf421fb1fbfcae1ff14edf63450862a144..ff33a16d6412ed3fe5146a0ab4cb338658c0492f 100644 (file)
@@ -35,7 +35,8 @@ Require-Bundle: org.eclipse.ui,
  org.eclipse.e4.ui.di
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-ActivationPolicy: lazy
-Import-Package: javax.inject;version="1.0.0",
+Import-Package: javax.annotation;version="1.0.0";resolution:=optional,
+ javax.inject;version="1.0.0",
  org.eclipse.core.databinding.beans,
  org.eclipse.core.databinding.observable.list,
  org.eclipse.core.databinding.observable.map,
index 85719aa92f22e108a8e302e204f3efcda724eb58..4fdda3da52d74309572523073e3be33e6b4340be 100644 (file)
@@ -54,6 +54,7 @@
         <children xsi:type="menu:HandledMenuItem" xmi:id="_wg0-oDulEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.commandlabel54" label="%command.label.54" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.editor/icons/deep-delete-16x16-32.png" command="_fKT-wDulEeeOtqC_3qh40A"/>
       </menus>
     </elements>
+    <elements xsi:type="basic:PartDescriptor" xmi:id="_R7vxEECaEeeL5JDzMOYK6g" elementId="eu.etaxonomy.taxeditor.editor.workingSet.FeatureTreeBuilderViewPart" label="Character Editor" closeable="true" dirtyable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.workingSet.FeatureTreeBuilderViewPart"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="__mwtMDVpEee_b7RlBzTDRw" featurename="commands" parentElementId="xpath:/">
     <elements xsi:type="commands:Command" xmi:id="_BjF3ADVqEee_b7RlBzTDRw" elementId="eu.etaxonomy.taxeditor.editor.command.specimeneditor.create_field_unit" commandName="%command.commandname.1"/>
@@ -71,4 +72,9 @@
     <elements xsi:type="commands:Command" xmi:id="_N0wLsDumEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.derivative.copySingleReadToClipBoard" commandName="%command.name.COPY_SINGLE_READ_TO_CLIPBOARD"/>
     <elements xsi:type="commands:Command" xmi:id="_YPp1wDvREeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.derivate.delete" commandName="Delete"/>
   </fragments>
+  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_pZmusEalEeeXMc6kSYO7Xg" featurename="children" parentElementId="eu.etaxonomy.taxeditor.menu.showView">
+    <elements xsi:type="menu:HandledMenuItem" xmi:id="_tvph4EalEeeXMc6kSYO7Xg" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.featuretreeeditor" label="Character Editor" command="_WPjpoDSnEeek0dKsFNy--Q">
+      <parameters xmi:id="_wJkmoEalEeeXMc6kSYO7Xg" elementId="eu.etaxonomy.taxeditor.editor.parameter.0" name="eu.etaxonomy.taxeditor.workbench.commandparameter.partName" value="eu.etaxonomy.taxeditor.editor.workingSet.FeatureTreeBuilderViewPart"/>
+    </elements>
+  </fragments>
 </fragment:ModelFragments>
diff --git a/eu.etaxonomy.taxeditor.editor/icons/Ontology.xml b/eu.etaxonomy.taxeditor.editor/icons/Ontology.xml
new file mode 100644 (file)
index 0000000..5266690
Binary files /dev/null and b/eu.etaxonomy.taxeditor.editor/icons/Ontology.xml differ
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/CharacterDragListener.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/CharacterDragListener.java
new file mode 100644 (file)
index 0000000..7b127f6
--- /dev/null
@@ -0,0 +1,53 @@
+/**
+* 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 org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.dnd.DragSourceEvent;
+
+import eu.etaxonomy.cdm.model.description.FeatureNode;
+import eu.etaxonomy.taxeditor.featuretree.FeatureNodeDragListener;
+import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
+
+/**
+ * @author pplitzner
+ * @since Jun 2, 2017
+ *
+ */
+public class CharacterDragListener extends FeatureNodeDragListener {
+
+    private TreeViewer structureViewer;
+    private TreeViewer propertyViewer;
+
+    /**
+     * @param propertyViewer
+     */
+    public CharacterDragListener(TreeViewer structureViewer, TreeViewer propertyViewer) {
+        super(propertyViewer);
+        this.structureViewer = structureViewer;
+        this.propertyViewer = propertyViewer;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void dragSetData(DragSourceEvent event) {
+        FeatureNode structure = (FeatureNode) ((IStructuredSelection) structureViewer.getSelection()).getFirstElement();
+        FeatureNode property = (FeatureNode) ((IStructuredSelection) propertyViewer.getSelection()).getFirstElement();
+        FeatureNode[] character = new FeatureNode[2];
+        character[0] = structure;
+        character[1] = property;
+        if (FeatureNodeTransfer.getInstance().isSupportedType(event.dataType)) {
+            event.data = character;
+        }
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/CharacterDropAdapter.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/CharacterDropAdapter.java
new file mode 100644 (file)
index 0000000..14f2562
--- /dev/null
@@ -0,0 +1,71 @@
+/**
+* Copyright (C) 2009 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 org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerDropAdapter;
+import org.eclipse.swt.dnd.TransferData;
+
+import eu.etaxonomy.cdm.model.description.Character;
+import eu.etaxonomy.cdm.model.description.FeatureNode;
+import eu.etaxonomy.cdm.model.description.FeatureTree;
+import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
+
+/**
+ *
+ * @author pplitzner
+ * @date Jun 1, 2017
+ *
+ */
+public class CharacterDropAdapter extends ViewerDropAdapter {
+
+       protected CharacterDropAdapter(Viewer viewer) {
+           super(viewer);
+       }
+
+       @Override
+       public boolean performDrop(Object data) {
+
+           FeatureNode target = (FeatureNode) getCurrentTarget();
+               int currentLocation = getCurrentLocation();
+               Object[] characterData = (Object[]) data;
+
+               //create new Character
+               if(characterData.length==2){
+                   FeatureNode structureNode = (FeatureNode) characterData[0];
+                   FeatureNode propertyNode = (FeatureNode) characterData[1];
+                   String label = structureNode.getFeature().toString()+" "+propertyNode.getFeature().toString();
+                   Character character = Character.NewInstance(structureNode, propertyNode, null, label, label);
+                   FeatureNode characterNode = FeatureNode.NewInstance(character);
+
+                   if(getViewer().getInput()==null){
+                       //create new feature tree
+                       FeatureTree featureTree = FeatureTree.NewInstance();
+                       getViewer().setInput(featureTree);
+                   }
+            if(target==null){
+                FeatureNode root = ((FeatureTree)getViewer().getInput()).getRoot();
+                root.addChild(characterNode);
+            }
+            else{
+                target.addChild(characterNode);
+            }
+               }
+               getViewer().refresh();
+               return true;
+       }
+
+       @Override
+       public boolean validateDrop(Object target, int operation,
+                       TransferData transferType) {
+               boolean transferDataIsSupported = FeatureNodeTransfer.getInstance().isSupportedType(transferType);
+               return transferDataIsSupported;
+       }
+
+}
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/FeatureTreeBuilderViewPart.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/FeatureTreeBuilderViewPart.java
new file mode 100644 (file)
index 0000000..e618c4c
--- /dev/null
@@ -0,0 +1,119 @@
+// $Id$
+/**
+* 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.UUID;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Named;
+
+import org.eclipse.e4.ui.di.Focus;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
+import eu.etaxonomy.cdm.model.description.FeatureTree;
+import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
+import eu.etaxonomy.taxeditor.featuretree.FeatureTreeContentProvider;
+import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider;
+import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author pplitzner
+ * @date 24.05.2017
+ *
+ */
+public class FeatureTreeBuilderViewPart {
+
+
+    private TreeViewer treeViewerCharacters;
+    private TreeViewer treeViewerProperties;
+    private TreeViewer treeViewerStructures;
+    private FeatureTreeEditor editor;
+    private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
+
+    public FeatureTreeBuilderViewPart() {
+    }
+
+    /**
+     * Create contents of the view part.
+     */
+    @PostConstruct
+    public void createControls(Composite parent, @Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
+        parent.setLayout(new GridLayout(1, false));
+
+        SashForm sashForm = new SashForm(parent, SWT.NONE);
+        sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+        formToolkit.adapt(sashForm);
+        formToolkit.paintBordersFor(sashForm);
+
+        treeViewerStructures = new TreeViewer(sashForm, SWT.BORDER);
+
+        treeViewerProperties = new TreeViewer(sashForm, SWT.BORDER);
+
+//                editor = new FeatureTreeEditor(shell);
+//                editor.createControl(sashForm, shell);
+                treeViewerCharacters = new TreeViewer(sashForm, SWT.BORDER);
+        sashForm.setWeights(new int[] {1, 1, 1});
+
+        init();
+    }
+
+    private void init(){
+        int dndOperations = DND.DROP_COPY | DND.DROP_MOVE;
+        Transfer[] transfers = new Transfer[] { FeatureNodeTransfer.getInstance() };
+
+        FeatureTree structureFeatureTree = CdmStore.getService(IFeatureTreeService.class).load(UUID.fromString("546e9c1e-d186-4e3b-838d-7e44586d1b39"));
+        treeViewerStructures.setContentProvider(new FeatureTreeContentProvider());
+        treeViewerStructures.setLabelProvider(new FeatureTreeLabelProvider());
+        treeViewerStructures.setInput(structureFeatureTree);
+
+        FeatureTree propertiesFeatureTree = CdmStore.getService(IFeatureTreeService.class).load(UUID.fromString("07543f00-1572-4ba8-b633-4fdb83fb32dd"));
+        treeViewerProperties.setContentProvider(new FeatureTreeContentProvider());
+        treeViewerProperties.setLabelProvider(new FeatureTreeLabelProvider());
+        treeViewerProperties.addDragSupport(dndOperations, transfers, new CharacterDragListener(treeViewerStructures, treeViewerProperties));
+        treeViewerProperties.setInput(propertiesFeatureTree);
+
+        treeViewerCharacters.setContentProvider(new FeatureTreeContentProvider());
+        treeViewerCharacters.setLabelProvider(new FeatureTreeLabelProvider());
+        treeViewerCharacters.addDropSupport(dndOperations, transfers, new CharacterDropAdapter(treeViewerCharacters));
+    }
+
+    @PreDestroy
+    public void dispose() {
+    }
+
+    @Focus
+    public void setFocus() {
+    }
+
+    public TreeViewer getTreeViewerCharacters() {
+        return treeViewerCharacters;
+    }
+    public TreeViewer getTreeViewerProperties() {
+        return treeViewerProperties;
+    }
+    public TreeViewer getTreeViewerStructures() {
+        return treeViewerStructures;
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/StructureContentProvider.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/StructureContentProvider.java
new file mode 100644 (file)
index 0000000..ce6b01e
--- /dev/null
@@ -0,0 +1,62 @@
+// $Id$
+/**
+* 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.Collections;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+
+import eu.etaxonomy.cdm.model.description.FeatureNode;
+import eu.etaxonomy.cdm.model.description.FeatureTree;
+
+/**
+ * @author pplitzner
+ * @date 24.05.2017
+ *
+ */
+public class StructureContentProvider implements ITreeContentProvider {
+
+    public StructureContentProvider() {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Object[] getElements(Object inputElement) {
+        FeatureTree featureTree = (FeatureTree)inputElement;
+        return Collections.singleton(featureTree.getRoot()).toArray();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Object[] getChildren(Object parentElement) {
+        return ((FeatureNode)parentElement).getChildNodes().toArray();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Object getParent(Object element) {
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean hasChildren(Object element) {
+        return ((FeatureNode)element).getChildCount()>0;
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/StructureLabelProvider.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/StructureLabelProvider.java
new file mode 100644 (file)
index 0000000..9314bbb
--- /dev/null
@@ -0,0 +1,34 @@
+// $Id$
+/**
+* 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 org.eclipse.jface.viewers.ColumnLabelProvider;
+
+import eu.etaxonomy.cdm.model.description.FeatureNode;
+
+/**
+ * @author pplitzner
+ * @date 24.05.2017
+ *
+ */
+public class StructureLabelProvider extends ColumnLabelProvider {
+
+
+    public StructureLabelProvider() {
+    }
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getText(Object element) {
+
+        return ((FeatureNode)element).getFeature().getLabel();
+    }
+}
index ce3d5489275b41616fbbacc8796c5e5e3be9c53b..de4a8932b1f0d3ad37c13a824ff0dbd067dc2c13 100644 (file)
@@ -15,6 +15,7 @@ Export-Package: eu.etaxonomy.cdm,
  eu.etaxonomy.taxeditor.editor.definedterm,
  eu.etaxonomy.taxeditor.editor.definedterm.input,
  eu.etaxonomy.taxeditor.featuretree,
+ eu.etaxonomy.taxeditor.featuretree.e4,
  eu.etaxonomy.taxeditor.handler,
  eu.etaxonomy.taxeditor.handler.defaultHandler,
  eu.etaxonomy.taxeditor.io,
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/FeatureNodeDragListener.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/FeatureNodeDragListener.java
new file mode 100644 (file)
index 0000000..048d298
--- /dev/null
@@ -0,0 +1,68 @@
+/**
+* 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.featuretree;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DragSourceAdapter;
+import org.eclipse.swt.dnd.DragSourceEvent;
+
+import eu.etaxonomy.cdm.model.description.FeatureNode;
+
+/**
+ * @author pplitzner
+ * @since Jun 2, 2017
+ *
+ */
+public class FeatureNodeDragListener extends DragSourceAdapter {
+
+    private final TreeViewer viewer;
+
+    public FeatureNodeDragListener(TreeViewer viewer) {
+        this.viewer = viewer;
+    }
+
+    /**
+     * Method declared on DragSourceListener
+     */
+    @Override
+    public void dragFinished(DragSourceEvent event) {
+        if (!event.doit) {
+            return;
+        }
+        if (event.detail == DND.DROP_MOVE) {
+            viewer.refresh();
+        }
+    }
+
+    /**
+     * Method declared on DragSourceListener
+     */
+    @Override
+    public void dragSetData(DragSourceEvent event) {
+        IStructuredSelection selection = (IStructuredSelection) viewer
+                .getSelection();
+        FeatureNode[] featureNodes = (FeatureNode[]) selection.toList()
+                .toArray(new FeatureNode[selection.size()]);
+        if (FeatureNodeTransfer.getInstance().isSupportedType(
+                event.dataType)) {
+            event.data = featureNodes;
+        }
+    }
+
+    /**
+     * Method declared on DragSourceListener
+     */
+    @Override
+    public void dragStart(DragSourceEvent event) {
+        event.doit = !viewer.getSelection().isEmpty();
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/FeatureNodeDropAdapter.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/FeatureNodeDropAdapter.java
new file mode 100644 (file)
index 0000000..a3f7c71
--- /dev/null
@@ -0,0 +1,89 @@
+/**
+* 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.featuretree;
+
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerDropAdapter;
+import org.eclipse.swt.dnd.TransferData;
+
+import eu.etaxonomy.cdm.model.description.FeatureNode;
+import eu.etaxonomy.cdm.model.description.FeatureTree;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+
+/**
+ * @author pplitzner
+ * @since Jun 2, 2017
+ *
+ */
+public class FeatureNodeDropAdapter extends ViewerDropAdapter {
+
+    public FeatureNodeDropAdapter(Viewer viewer) {
+        super(viewer);
+    }
+
+    @Override
+    public boolean performDrop(Object data) {
+        FeatureNode target = (FeatureNode) getCurrentTarget();
+        int position = 0;
+
+        if (target != null) {
+            int location = getCurrentLocation();
+            FeatureNode parent = target.getParent();
+            if (location == LOCATION_BEFORE) {
+                position = Math.max(0, parent.getIndex(target) - 1);
+                target = parent;
+            }
+
+            if (location == LOCATION_AFTER) {
+                position = parent.getIndex(target);
+                target = parent;
+            }
+        }
+
+        // set target to root node if there is no target specified
+        if (target == null) {
+            FeatureTree featureTree = (FeatureTree) getViewer().getInput();
+            target = featureTree.getRoot();
+        }
+
+        Object[] droppedObjects = (Object[]) data;
+        TreeViewer viewer = (TreeViewer) getViewer();
+
+        // cannot drop a feature node onto itself
+        for (Object droppedObject : droppedObjects) {
+            if (droppedObject == null) {
+                MessagingUtils.warningDialog(
+                                "Operation not supported yet",
+                                this,
+                                "We are currently unable to change the order of freshly created "
+                                        + "feature trees nodes. Please close and reopen the dialog to change the order of features.");
+                return false;
+            }
+            if (droppedObject.equals(target)) {
+                return false;
+            }
+        }
+        for (Object droppedObject : droppedObjects) {
+            FeatureNode droppedNode = (FeatureNode) droppedObject;
+            target.addChild(droppedNode, position);
+            viewer.add(target, droppedNode);
+            viewer.reveal(droppedNode);
+        }
+        return true;
+    }
+
+    @Override
+    public boolean validateDrop(Object target, int operation,
+            TransferData transferData) {
+        return FeatureNodeTransfer.getInstance().isSupportedType(
+                transferData);
+    }
+
+}
\ No newline at end of file
index 1f2f7131c8bf05ee00f1796adb82575e9fff1f80..5ff277ceff752d9366347454f712b16b13ac149b 100644 (file)
@@ -1,8 +1,8 @@
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* 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.
 */
@@ -16,37 +16,26 @@ import eu.etaxonomy.cdm.model.description.FeatureNode;
 import eu.etaxonomy.cdm.model.description.FeatureTree;
 
 /**
- * <p>FeatureTreeLabelProvider class.</p>
  *
  * @author n.hoffmann
  * @created Aug 5, 2010
  * @version 1.0
  */
 public class FeatureTreeLabelProvider extends LabelProvider {
-       
-       private Feature feature;
-               
+
        /** {@inheritDoc} */
        @Override
        public String getText(Object element) {
                if(element instanceof FeatureTree){
                        return ((FeatureTree) element).getTitleCache();
                }else if(element instanceof FeatureNode){
-                       feature = ((FeatureNode) element).getFeature();
-                       
-                       if(feature != null)
-                               return feature.getTitleCache();
-                       
+                   Feature feature = ((FeatureNode) element).getFeature();
+                       if(feature != null) {
+                return feature.getTitleCache();
+            }
+
                }
                return "No label provided";
        }
-       
-       /**
-        * <p>Getter for the field <code>feature</code>.</p>
-        *
-        * @return a {@link eu.etaxonomy.cdm.model.description.Feature} object.
-        */
-       public Feature getFeature(){
-               return feature;
-       }
+
 }