]> gerrit.simantics Code Review - simantics/platform.git/blob
f2015257f1fb33997425b174a3c3c1a3f10ff025
[simantics/platform.git] /
1 package org.simantics.browsing.ui.model.browsecontexts;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5
6 import org.simantics.databoard.Bindings;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.request.TernaryRead;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.adapter.Instances;
12 import org.simantics.utils.datastructures.Arrays;
13 import org.simantics.viewpoint.ontology.ViewpointResource;
14
15 public class ContributedBrowseContexts extends TernaryRead<Resource,Resource,String,Collection<Resource>> {
16
17     public ContributedBrowseContexts(Resource indexRoot, Resource context, String uiContext) {
18         super(indexRoot, context, uiContext);
19     }
20
21     @Override
22     public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
23         
24         ViewpointResource VP = ViewpointResource.getInstance(graph);
25         Instances query = graph.adapt(VP.BrowseContextContribution, Instances.class);
26         Collection<Resource> result = new ArrayList<Resource>();
27         for(Resource contribution : query.find(graph, parameter)) {
28             Resource type = graph.getPossibleObject(contribution, VP.BrowseContextContribution_HasType);
29             if(type == null) continue;
30             if(graph.isInstanceOf(parameter2, type)) {
31                 Resource context = graph.getPossibleObject(contribution, VP.BrowseContextContribution_HasBrowseContext);
32                 if(context == null) continue;
33                 String[] allowedContexts = graph.getPossibleRelatedValue(contribution, VP.BrowseContextContribution_allowedUIContexts, Bindings.STRING_ARRAY);
34                 if(allowedContexts != null)
35                         if(!Arrays.contains(allowedContexts, parameter3))
36                                 continue;
37                 result.add(context);
38             }
39         }
40         return result;
41         
42     }
43
44 }