]> gerrit.simantics Code Review - simantics/platform.git/blob
dd3fba2c750f068b7835445429452d1905fdc356
[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.browsing.ui.model.tests.Test;
7 import org.simantics.databoard.Bindings;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.common.request.TernaryRead;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.layer0.adapter.Instances;
13 import org.simantics.utils.datastructures.Arrays;
14 import org.simantics.viewpoint.ontology.ViewpointResource;
15
16 public class ContributedActionBrowseContexts extends TernaryRead<Resource,Resource,String,Collection<Resource>> {
17
18     public ContributedActionBrowseContexts(Resource indexRoot, Resource context, String uiContext) {
19         super(indexRoot, context, uiContext);
20     }
21
22     @Override
23     public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
24         
25         ViewpointResource VP = ViewpointResource.getInstance(graph);
26         Instances query = graph.adapt(VP.ActionBrowseContextContribution, Instances.class);
27         Collection<Resource> result = new ArrayList<Resource>();
28         for(Resource contribution : query.find(graph, parameter)) {
29             Resource type = graph.getPossibleObject(contribution, VP.ActionBrowseContextContribution_HasType);
30             if(type != null) {
31                     if(!graph.isInstanceOf(parameter2, type)) continue;
32             }
33             Resource testResource = graph.getPossibleObject(contribution, VP.ActionBrowseContextContribution_HasTest);
34             if(testResource != null) {
35                 Test test = graph.getPossibleAdapter(testResource, Test.class);
36                 if(test != null) {
37                         if(!test.test(graph, parameter2)) continue;
38                 }
39             }
40                         
41             Resource context = graph.getPossibleObject(contribution, VP.ActionBrowseContextContribution_HasActionBrowseContext);
42             if(context == null) continue;
43             String[] allowedContexts = graph.getPossibleRelatedValue(contribution, VP.ActionBrowseContextContribution_allowedUIContexts, Bindings.STRING_ARRAY);
44             if(allowedContexts != null)
45                 if(!Arrays.contains(allowedContexts, parameter3))
46                         continue;
47             result.add(context);
48             
49         }
50         return result;
51         
52     }
53
54 }