From 28436fab181e114382d85cd7f33a8b9af87f45c2 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Tue, 30 Oct 2018 11:05:32 +0200 Subject: [PATCH] Utility for creating NodeContext with NodeType from SCL gitlab #170 Change-Id: I88b163f6ca30d5dfebc42ff3aa590a7426614e48 --- .../ui/model/browsecontexts/BrowseContexts.java | 15 +++++++++++++-- .../scl/Simantics/Testing/BrowseContext.scl | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/browsecontexts/BrowseContexts.java b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/browsecontexts/BrowseContexts.java index 760f866e3..d8d02e014 100644 --- a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/browsecontexts/BrowseContexts.java +++ b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/browsecontexts/BrowseContexts.java @@ -5,10 +5,11 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -import org.simantics.browsing.ui.BuiltinKeys; import org.simantics.browsing.ui.NodeContext; import org.simantics.browsing.ui.common.NodeContextBuilder; import org.simantics.browsing.ui.model.actions.ActionBrowseContext; +import org.simantics.browsing.ui.model.nodetypes.EntityNodeType; +import org.simantics.browsing.ui.model.nodetypes.NodeType; import org.simantics.db.ReadGraph; import org.simantics.db.RequestProcessor; import org.simantics.db.Resource; @@ -69,7 +70,17 @@ public final class BrowseContexts { } public static NodeContext getNodeContextForResource(Resource resource) { - return NodeContextBuilder.buildWithData(BuiltinKeys.INPUT, resource); + return NodeContextBuilder.buildWithInput(resource); + } + + public static NodeContext getNodeContextWithTypeForResource(ReadGraph graph, Resource resource) { + try { + return NodeContextBuilder.buildWithData( + NodeType.KEY_SEQUENCE, + new Object[] { resource, EntityNodeType.getNodeTypeFor(graph, resource) }); + } catch (DatabaseException e) { + return NodeContextBuilder.buildWithInput(resource); + } } public static class URIsToBrowseContext extends UnaryRead, BrowseContext> { diff --git a/bundles/org.simantics.modeling.ui/scl/Simantics/Testing/BrowseContext.scl b/bundles/org.simantics.modeling.ui/scl/Simantics/Testing/BrowseContext.scl index 436557f31..106d93bb3 100644 --- a/bundles/org.simantics.modeling.ui/scl/Simantics/Testing/BrowseContext.scl +++ b/bundles/org.simantics.modeling.ui/scl/Simantics/Testing/BrowseContext.scl @@ -115,6 +115,7 @@ importJava "org.simantics.browsing.ui.content.Labeler$Modifier" where importJava "org.simantics.browsing.ui.model.browsecontexts.BrowseContexts" where toBrowseContextG :: Vector String -> BrowseContext getNodeContextForResource :: Resource -> NodeContext + getNodeContextWithTypeForResource :: Resource -> NodeContext """ Creates a new BrowseContext for the given Collection of Resources. -- 2.47.1