]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java
Fix graph.tg hardcoded in CompilePGraphs code
[simantics/platform.git] / bundles / org.simantics.graph / src / org / simantics / graph / representation / TransferableGraphUtils.java
index b0690532b85d584969526609181ba6fc712b5ba5..f2321dce9515b2819af7c51ddc146f324c5b4b1a 100644 (file)
@@ -78,7 +78,51 @@ public class TransferableGraphUtils {
         return identity;
         
     }
-    
+
+    /**
+     * Provided a tg and a resource uri, returns the identity of the tg if the uri_ matches the tg exactly
+     * @param tg
+     * @param uri_
+     * @return
+     */
+    public static Identity getIdentity2(TransferableGraph1 tg, String uri_) {
+        Collection<Identity> identities = TransferableGraphUtils.getRoots(tg);
+        for (Identity i : identities) {
+            Identity id = getIdentity2(tg, uri_, i);
+            if (id != null) {
+                return id;
+            }
+        }
+        return null;
+    }
+
+    /**
+     *
+     * @param tg
+     * @param uri_
+     * @param id
+     * @return
+     */
+    public static Identity getIdentity2(TransferableGraph1 tg, String uri_, Identity id) {
+        String uri = TransferableGraphUtils.getURI(tg, id.resource);
+
+        if (uri_.equals(uri)) {
+            return id;
+        }
+
+        if (uri_.startsWith(uri)) {
+            Collection<Identity> childIdentitiesOfRoot = TransferableGraphUtils.getChildren2(tg, id);
+            for (Identity i2 : childIdentitiesOfRoot) {
+                Identity id2 = getIdentity2(tg, uri_, i2);
+                if (id2 != null) {
+                    return id2;
+                }
+            }
+        }
+
+        return null;
+    }
+
     public static Identity getIdentity(TransferableGraph1 tg, int resource) {
         for(Identity id : tg.identities) {
             if(id.resource == resource) return id;