From e3a908eaf0d1625c6b8c2e58b710e37da05602e8 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Mon, 22 Oct 2018 14:56:44 +0300 Subject: [PATCH] Possible variable browse without URI gitlab #154 Change-Id: I394bac9a1aa74abeb5f261fa77cd08cbdf0b90ea --- .../variable/StandardGraphChildVariable.java | 2 +- .../db/layer0/variable/VariableUtils.java | 5 +++- .../db/layer0/variable/Variables.java | 24 ++++++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java index 78fff71c2..b784754bf 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java @@ -107,7 +107,7 @@ public class StandardGraphChildVariable extends AbstractChildVariable { return node.support.manager.getName(node.node); } String unescapedName = graph.getPossibleRelatedValue(resource, graph.getService(Layer0.class).HasName, Bindings.STRING); - if(unescapedName == null) return "r" + resource.getResourceId(); + if(unescapedName == null) return VariableUtils.unnamedResourceName(resource); return unescapedName; } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableUtils.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableUtils.java index 1ee4cec1b..46803b5e0 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableUtils.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableUtils.java @@ -109,5 +109,8 @@ public class VariableUtils { } }; - + + public static String unnamedResourceName(Resource resource) { + return "r" + resource.getResourceId(); + } } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java index 610e0013c..341a496a4 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java @@ -18,6 +18,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.simantics.databoard.Bindings; import org.simantics.databoard.Databoard; import org.simantics.databoard.binding.Binding; import org.simantics.databoard.binding.mutable.Variant; @@ -30,6 +31,7 @@ import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.common.request.TernaryRead; +import org.simantics.db.common.utils.CommonDBUtils; import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.exception.InvalidVariableException; @@ -158,7 +160,27 @@ final public class Variables { public static Variable getPossibleVariable(ReadGraph graph, Resource resource) throws DatabaseException { String uri = graph.getPossibleURI(resource); - return uri != null ? getPossibleVariable(graph, uri) : null; + if (uri != null) + return getPossibleVariable(graph, uri); + Resource parent = CommonDBUtils.getPossibleOwner(graph, resource); + if (parent == null) + return null; + Variable possibleVariable = getPossibleVariable(graph, parent); + if (possibleVariable == null) + return null; + String possibleName = graph.getPossibleRelatedValue(resource, Layer0.getInstance(graph).HasName, Bindings.STRING); + if (possibleName == null) + possibleName = VariableUtils.unnamedResourceName(resource); + Variable possibleChild = possibleVariable.getPossibleChild(graph, possibleName); + if (possibleChild != null) + return possibleChild; + for (Variable v : possibleVariable.getChildren(graph)) { + Resource vr = v.getPossibleRepresents(graph); + if (vr != null && vr.equals(resource)) { + return v; + } + } + return null; } public static Variable getPossibleVariable(ReadGraph graph, String uri) throws DatabaseException { -- 2.47.1