X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FExpandNodeHandler.java;h=b0e75e538d79af65483881b0c9133d2adc4144cd;hp=c5553a2a20828e7be5bbf822bd3659f88873c40c;hb=fa806341cc06b72051d5e8d709674eb9d5c2bf00;hpb=969bd23cab98a79ca9101af33334000879fb60c5 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 c5553a2a2..b0e75e538 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,74 +1,74 @@ -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; -import org.simantics.ui.IDoubleClickAction; -import org.simantics.ui.workbench.action.IWorkbenchActionHints; -import org.simantics.ui.workbench.editor.EditorAdapter; -import org.simantics.ui.workbench.editor.EditorRegistry; -import org.simantics.utils.ui.ISelectionUtils; -import org.simantics.utils.ui.action.IPriorityAction; -import org.simantics.utils.ui.action.PriorityAction; - -/** - * @author Tuukka Lehtonen - */ -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); - if (node == null) - return; - - Object widget = e.getHintContext().getHint(IWorkbenchActionHints.KEY_WIDGET); - if (!(widget instanceof GraphExplorer)) - return; - final 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()); - } - }); - - // If editor selection is unanimous, use the editor. Otherwise just expand/collapse the clicked node. - if (editorAdapters.length == 0) { - e.add(expandAction(explorer, node)); - e.consume(); - } else if (editorAdapters.length > 1 && editorAdapters[0].getPriority() == editorAdapters[1].getPriority()) { - e.add(expandAction(explorer, node)); - e.consume(); - } - } - - private IPriorityAction expandAction(final GraphExplorer explorer, final NodeContext node) { - return new PriorityAction(100) { - @Override - public void run() { - PrimitiveQueryProcessor pqp = explorer.getPrimitiveProcessor(BuiltinKeys.IS_EXPANDED); - if (pqp instanceof IsExpandedProcessor) { - IsExpandedProcessor iep = (IsExpandedProcessor) pqp; - boolean expanded = iep.getExpanded(node); - iep.replaceExpanded(node, !expanded); - } - } - }; - } - -} +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; +import org.simantics.ui.IDoubleClickAction; +import org.simantics.ui.workbench.action.IWorkbenchActionHints; +import org.simantics.ui.workbench.editor.EditorAdapter; +import org.simantics.ui.workbench.editor.EditorRegistry; +import org.simantics.utils.ui.ISelectionUtils; +import org.simantics.utils.ui.action.IPriorityAction; +import org.simantics.utils.ui.action.PriorityAction; + +/** + * @author Tuukka Lehtonen + */ +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); + if (node == null) + return; + + Object widget = e.getHintContext().getHint(IWorkbenchActionHints.KEY_WIDGET); + if (!(widget instanceof GraphExplorer)) + return; + final 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()); + } + }); + + // If editor selection is unanimous, use the editor. Otherwise just expand/collapse the clicked node. + if (editorAdapters.length == 0) { + e.add(expandAction(explorer, node)); + e.consume(); + } else if (editorAdapters.length > 1 && editorAdapters[0].getPriority() == editorAdapters[1].getPriority()) { + e.add(expandAction(explorer, node)); + e.consume(); + } + } + + private IPriorityAction expandAction(final GraphExplorer explorer, final NodeContext node) { + return new PriorityAction(100) { + @Override + public void run() { + PrimitiveQueryProcessor pqp = explorer.getPrimitiveProcessor(BuiltinKeys.IS_EXPANDED); + if (pqp instanceof IsExpandedProcessor) { + IsExpandedProcessor iep = (IsExpandedProcessor) pqp; + boolean expanded = iep.getExpanded(node); + iep.replaceExpanded(node, !expanded); + } + } + }; + } + +}