]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/scl/imports/SCLModulesQuery.java
Merge "Define ConnectionRelationType to make searching of instances possible"
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / scl / imports / SCLModulesQuery.java
1 package org.simantics.modeling.ui.scl.imports;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.Resource;
8 import org.simantics.db.common.request.UnaryRead;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.layer0.Layer0;
11
12 public class SCLModulesQuery extends UnaryRead<Resource, Collection<String>> {
13
14     public SCLModulesQuery(Resource parameter) {
15         super(parameter);
16     }
17
18     @Override
19     public Collection<String> perform(ReadGraph graph) throws DatabaseException {
20         ArrayList<String> result = new ArrayList<String>(); 
21         
22         Layer0 L0 = Layer0.getInstance(graph);
23         browse(graph, L0, parameter, result);
24         
25         return result;
26     }
27
28     private static void browse(ReadGraph graph, Layer0 L0, Resource current,
29             ArrayList<String> result) throws DatabaseException {
30         if(graph.isInstanceOf(current, L0.SCLModule))
31             result.add(graph.getURI(current));
32         else if(graph.isInstanceOf(current, L0.Library)
33                 || graph.isInstanceOf(current, L0.IndexRoot)) {
34             for(Resource child : graph.getObjects(current, L0.ConsistsOf))
35                 browse(graph, L0, child, result);
36         }
37     }
38
39 }