1 package org.simantics.browsing.ui.model.browsecontexts;
3 import java.util.ArrayList;
4 import java.util.Collection;
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;
16 public class ContributedActionBrowseContexts extends TernaryRead<Resource,Resource,String,Collection<Resource>> {
18 public ContributedActionBrowseContexts(Resource indexRoot, Resource context, String uiContext) {
19 super(indexRoot, context, uiContext);
23 public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
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);
31 if(!graph.isInstanceOf(parameter2, type)) continue;
33 Resource testResource = graph.getPossibleObject(contribution, VP.ActionBrowseContextContribution_HasTest);
34 if(testResource != null) {
35 Test test = graph.getPossibleAdapter(testResource, Test.class);
37 if(!test.test(graph, parameter2)) continue;
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))