X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.graph%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Frepresentation%2FTransferableGraphUtils.java;h=9873f8f1eef88ce338129a110e5e1e61d2ab2a9d;hp=b0690532b85d584969526609181ba6fc712b5ba5;hb=6bd970eba63ff08a122fdf819e428adaf80cfcef;hpb=da0a902de6b2b4c7b4b635d11b397f663db8ecd9 diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java b/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java index b0690532b..9873f8f1e 100644 --- a/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java +++ b/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java @@ -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 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 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; @@ -112,25 +156,27 @@ public class TransferableGraphUtils { } Identity consistsOf = findExternal(tg, "http://www.simantics.org/Layer0-1.1/ConsistsOf"); Identity hasName = findExternal(tg, "http://www.simantics.org/Layer0-1.1/HasName"); - for (int i = 0; i < tg.statements.length; i += 4) { - if (tg.statements[i] == parentResource) { - if (tg.statements[i + 1] == consistsOf.resource) { - Identity identity = getIdentity(tg, tg.statements[i + 3]); - if (identity != null) { - if (identity.definition instanceof Internal) { - Internal internal = (Internal) identity.definition; - result.put(internal.name, identity); - } - } else { - int possibleNameResource = getPossibleObject2(tg, tg.statements[i + 3], hasName); - if (possibleNameResource != NOT_FOUND) { - Value value = findValue(tg, possibleNameResource); - if (value != null) { - try { - String name = (String) value.value.getValue(Bindings.STRING); - result.put(name, new Identity(tg.statements[i + 3], new Internal(tg.statements[i], name))); - } catch (AdaptException e) { - e.printStackTrace(); + if(consistsOf != null && hasName != null) { + for (int i = 0; i < tg.statements.length; i += 4) { + if (tg.statements[i] == parentResource) { + if (tg.statements[i + 1] == consistsOf.resource) { + Identity identity = getIdentity(tg, tg.statements[i + 3]); + if (identity != null) { + if (identity.definition instanceof Internal) { + Internal internal = (Internal) identity.definition; + result.put(internal.name, identity); + } + } else { + int possibleNameResource = getPossibleObject2(tg, tg.statements[i + 3], hasName); + if (possibleNameResource != NOT_FOUND) { + Value value = findValue(tg, possibleNameResource); + if (value != null) { + try { + String name = (String) value.value.getValue(Bindings.STRING); + result.put(name, new Identity(tg.statements[i + 3], new Internal(tg.statements[i], name))); + } catch (AdaptException e) { + e.printStackTrace(); + } } } }