]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Possible variable browse without URI 48/2348/2
authorjsimomaa <jani.simomaa@gmail.com>
Mon, 22 Oct 2018 11:56:44 +0000 (14:56 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Mon, 22 Oct 2018 12:08:57 +0000 (15:08 +0300)
gitlab #154

Change-Id: I394bac9a1aa74abeb5f261fa77cd08cbdf0b90ea

bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableUtils.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java

index 78fff71c2d44a31696332c96d1c90097aa6a7078..b784754bfa69ce8187999cb78af598506552c45d 100644 (file)
@@ -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;
        }
 
index 1ee4cec1bd9d40e5a58c7e8d62e5833e45e5fe23..46803b5e082e74743b564c991406d8ae8c0974c0 100644 (file)
@@ -109,5 +109,8 @@ public class VariableUtils {
                }
                
        };
-       
+
+    public static String unnamedResourceName(Resource resource) {
+        return "r" + resource.getResourceId();
+    }
 }
index 610e0013c8cedb57cc118b73bebc5e2a6b4763aa..341a496a4ff2778a3e9972cb2c0c998dbe9f6114 100644 (file)
@@ -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 {