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;
@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) {
}
}
- private IPriorityAction expandAction(final GraphExplorer explorer, final NodeContext node) {
+ private IPriorityAction expandAction(GraphExplorer explorer, NodeContext node) {
return new PriorityAction(100) {
@Override
public void run() {
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;
}
});
}