From 27486a61ad5a2df27c62edaff098926363a025b1 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Fri, 3 Nov 2017 08:50:24 +0200 Subject: [PATCH] DefaultMouseListener was added twice in GraphExplorerComposite 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 --- .../swt/widgets/GraphExplorerComposite.java | 1 - .../modeling/ui/ExpandNodeHandler.java | 23 +++++---------- .../workbench/action/ChooseActionRequest.java | 29 +++++-------------- 3 files changed, 16 insertions(+), 37 deletions(-) diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java index 249dad55c..f583d7e7f 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java @@ -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; diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/ExpandNodeHandler.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/ExpandNodeHandler.java index b0e75e538..9ad34737e 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/ExpandNodeHandler.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/ExpandNodeHandler.java @@ -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() { - @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() { diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/ChooseActionRequest.java b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/ChooseActionRequest.java index 210bdf911..dc8e5a67b 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/ChooseActionRequest.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/action/ChooseActionRequest.java @@ -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; } }); } -- 2.47.1