]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
DefaultMouseListener was added twice in GraphExplorerComposite 86/1186/3
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 3 Nov 2017 06:50:24 +0000 (08:50 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 3 Nov 2017 07:06:49 +0000 (09:06 +0200)
Changed ExpandNodeHandler double click action to perform its search for
editor adapters based on the input object provided in the double click
event instead of the NodeContext potentially contained by the input
object. This makes it use the same logic as OpenDefaultEditor adapter.

refs #7434

Change-Id: Ic22bbd98406f61df55817e76e5b2feabe0aedd5e

bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/ExpandNodeHandler.java
bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/ChooseActionRequest.java

index 249dad55ccc7c921e01fbff3e1a7730c97eab0ae..f583d7e7f1df374f0466232cf40d786a4b14cf2b 100644 (file)
@@ -373,7 +373,6 @@ public class GraphExplorerComposite extends Composite implements Widget, IAdapta
         } else {
                explorer = createExplorerControl(explorerComposite, maxChildren);
         }
-        explorer.addListener(new DefaultMouseListener(explorer));
         
         if (args.containsKey("useNodeBrowseContexts") && Boolean.TRUE.equals(args.get("useNodeBrowseContexts"))) {
                useNodeBrowseContexts = true;
index b0e75e538d79af65483881b0c9133d2adc4144cd..9ad34737ebed0bbd4c87de96eea83b139f5367cb 100644 (file)
@@ -1,14 +1,12 @@
 package org.simantics.modeling.ui;
 
 import java.util.Arrays;
-import java.util.Comparator;
 
 import org.simantics.browsing.ui.BuiltinKeys;
 import org.simantics.browsing.ui.GraphExplorer;
 import org.simantics.browsing.ui.NodeContext;
 import org.simantics.browsing.ui.PrimitiveQueryProcessor;
 import org.simantics.browsing.ui.common.processors.IsExpandedProcessor;
-import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.SelectionHints;
 import org.simantics.ui.DoubleClickEvent;
@@ -27,25 +25,20 @@ public class ExpandNodeHandler implements IDoubleClickAction {
 
     @Override
     public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException {
-        ReadGraph g = e.getGraph();
-        final NodeContext node = ISelectionUtils.getSinglePossibleKey(e.getResource(), SelectionHints.KEY_MAIN, NodeContext.class);
+        Object selection = e.getResource();
+        NodeContext node = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, NodeContext.class);
         if (node == null)
             return;
 
         Object widget = e.getHintContext().getHint(IWorkbenchActionHints.KEY_WIDGET);
         if (!(widget instanceof GraphExplorer))
             return;
-        final GraphExplorer explorer = (GraphExplorer) widget;
+        GraphExplorer explorer = (GraphExplorer) widget;
 
-        EditorAdapter[] editorAdapters = EditorRegistry.getInstance().getAdaptersFor(g, node);
-
-        Arrays.sort(editorAdapters, new Comparator<EditorAdapter>() {
-            @Override
-            public int compare(EditorAdapter o1, EditorAdapter o2) {
-                // Sort in descending priority order
-                return -(o1.getPriority() - o2.getPriority());
-            }
-        });
+        // Get adapters in descending priority order
+        EditorAdapter[] editorAdapters = EditorRegistry.getInstance().getAdaptersFor(e.getGraph(), selection);
+        if (editorAdapters.length > 1)
+            Arrays.sort(editorAdapters, (o1,o2) -> -(o1.getPriority() - o2.getPriority()));
 
         // If editor selection is unanimous, use the editor. Otherwise just expand/collapse the clicked node.
         if (editorAdapters.length == 0) {
@@ -57,7 +50,7 @@ public class ExpandNodeHandler implements IDoubleClickAction {
         }
     }
 
-    private IPriorityAction expandAction(final GraphExplorer explorer, final NodeContext node) {
+    private IPriorityAction expandAction(GraphExplorer explorer, NodeContext node) {
         return new PriorityAction(100) {
             @Override
             public void run() {
index 210bdf91107d1a8fc276a982a4a397148f28cf3f..dc8e5a67bf7079c6557035bc8fc2760afb5fbb40 100644 (file)
@@ -141,27 +141,14 @@ public class ChooseActionRequest extends ReadRequest {
                 return;
             }
         } else {
-            parent.getDisplay().asyncExec(new Runnable() {
-                @Override
-                public void run() {
-                    if (parent.isDisposed())
-                        return;
-
-//                    System.out.println("ACTIONS: " + Arrays.toString(actions));
-                    IAction action = chooseAction(parent, actions, resourceName, neverPromptForAction);
-                    if (action != null) {
-                        action.run();
-                        return;
-                    }
-
-// // 2. No actions ran, thus just open/close the tree
-// // node.
-// if (viewer.getExpandedState(singleSelection)) {
-// viewer.collapseToLevel(singleSelection, 1);
-// } else {
-// viewer.expandToLevel(singleSelection, 1);
-// }
-
+            parent.getDisplay().asyncExec(() -> {
+                if (parent.isDisposed())
+                    return;
+//                System.out.println("ACTIONS: " + Arrays.toString(actions));
+                IAction action = chooseAction(parent, actions, resourceName, neverPromptForAction);
+                if (action != null) {
+                    action.run();
+                    return;
                 }
             });
         }