]> gerrit.simantics Code Review - simantics/platform.git/blob
51affb5faf7c3e5525833d8feae06ee3c6cf9a96
[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 ContributedActionBrowseContexts extends TernaryRead<Resource,Resource,String,Collection<Resource>> {
16
17     public ContributedActionBrowseContexts(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.ActionBrowseContextContribution, Instances.class);
26         Collection<Resource> result = new ArrayList<Resource>();
27         for(Resource contribution : query.find(graph, parameter)) {
28             Resource type = graph.getPossibleObject(contribution, VP.ActionBrowseContextContribution_HasType);
29             if(type == null) continue;
30             if(graph.isInstanceOf(parameter2, type)) {
31                 Resource context = graph.getPossibleObject(contribution, VP.ActionBrowseContextContribution_HasActionBrowseContext);
32                 if(context == null) continue;
33                 String[] allowedContexts = graph.getPossibleRelatedValue(contribution, VP.ActionBrowseContextContribution_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 }