X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Fqueries%2FStructuralChildMapOfResource.java;fp=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Fqueries%2FStructuralChildMapOfResource.java;h=4243c1d634fa094c8feba83231ba829bffb99547;hb=0db0b69c4abedc90b366631582c57e13f2f110b7;hp=0000000000000000000000000000000000000000;hpb=512d469c3e490cdfc9a10fbbd6efe92ae6c0358a;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/queries/StructuralChildMapOfResource.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/queries/StructuralChildMapOfResource.java new file mode 100644 index 000000000..4243c1d63 --- /dev/null +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/queries/StructuralChildMapOfResource.java @@ -0,0 +1,34 @@ +package org.simantics.structural2.queries; + +import java.util.Map; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.common.uri.UnescapedChildMapOfResource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.structural.stubs.StructuralResource2; + +public class StructuralChildMapOfResource extends ResourceRead> { + + public StructuralChildMapOfResource(Resource resource) { + super(resource); + } + + @Override + public Map perform(ReadGraph graph) throws DatabaseException { + StructuralResource2 STR = StructuralResource2.getInstance(graph); + Resource type = graph.getPossibleType(resource, STR.Component); + if(type != null) { + Resource definition = graph.getPossibleObject(type, STR.IsDefinedBy); + if(definition != null) { + Map map = graph.syncRequest(new UnescapedChildMapOfResource(definition)); + if (!map.isEmpty()) + return map; + } + } + Map directChildren = graph.syncRequest(new UnescapedChildMapOfResource(resource)); + return directChildren; + } + +} \ No newline at end of file