- fixed bug when creating another DescriptionElement
authorPatric Plitzner <p.plitzner@bgbm.org>
Mon, 16 Dec 2013 07:52:56 +0000 (07:52 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Mon, 16 Dec 2013 07:52:56 +0000 (07:52 +0000)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/CreateDescriptionElementHandler.java

index 7d95201d924dda3490106a723b33273651786f02..d8b1bf94b9f529c23c2bbc1ae8f0cfbebcfdb9e5 100644 (file)
@@ -16,6 +16,8 @@ import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.common.NotDefinedException;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.TreePath;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.handlers.HandlerUtil;
@@ -55,11 +57,16 @@ public class CreateDescriptionElementHandler extends AbstractHandler {
         DescriptionBase<?> description = null;
 
         ISelection selection = HandlerUtil.getCurrentSelection(event);
-        if (selection instanceof IStructuredSelection) {
-            Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
-            if (selectedElement instanceof DescriptionBase<?>) {
-                description = (DescriptionBase<?>) selectedElement;
-            }
+        Object selectedElement = null;
+        if (selection instanceof ITreeSelection) {
+            TreePath[] paths = ((ITreeSelection) selection).getPaths();
+            selectedElement = paths[0].getFirstSegment();
+        }
+        else if (selection instanceof IStructuredSelection) {
+            selectedElement = ((IStructuredSelection) selection).getFirstElement();
+        }
+        if (selectedElement instanceof DescriptionBase<?>) {
+            description = (DescriptionBase<?>) selectedElement;
         }
 
         if (description != null) {