1 package org.simantics.browsing.ui.model.browsecontexts;
3 import java.util.ArrayList;
4 import java.util.Collection;
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;
15 public class ContributedBrowseContexts extends TernaryRead<Resource,Resource,String,Collection<Resource>> {
17 public ContributedBrowseContexts(Resource indexRoot, Resource context, String uiContext) {
18 super(indexRoot, context, uiContext);
22 public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
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))