1 package org.simantics.selectionview;
3 import java.util.Collection;
5 import org.simantics.databoard.Bindings;
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.Resource;
8 import org.simantics.db.common.utils.Functions;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.layer0.Layer0;
12 abstract public class AbstractResourceTabContribution implements TabContribution<Resource> {
14 final protected Resource configuration;
16 public AbstractResourceTabContribution(ReadGraph graph, Resource configuration) throws DatabaseException {
17 this.configuration = configuration;
20 public abstract void getContributors(ReadGraph graph, Resource resource, Integer priority, String label, Collection<ComparableTabContributor> result) throws DatabaseException;
23 public boolean accept(ReadGraph graph, Object input) throws DatabaseException {
25 if (!(input instanceof Resource))
27 Resource resource = (Resource) input;
29 SelectionViewResources SEL = SelectionViewResources.getInstance(graph);
30 for(Resource r : graph.getObjects(configuration, SEL.AbstractResourceTabContribution_HasTest)) {
31 Boolean pass = Functions.exec(graph, r, graph, resource);
32 if(!pass) return false;
40 final public void contribute(ReadGraph graph, final Resource resource, Collection<ComparableTabContributor> result) throws DatabaseException {
42 Layer0 L0 = Layer0.getInstance(graph);
43 SelectionViewResources SEL = SelectionViewResources.getInstance(graph);
45 Integer priority = graph.getPossibleRelatedValue(configuration, SEL.AbstractResourceTabContribution_HasPriority, Bindings.INTEGER);
46 String label = graph.getPossibleRelatedValue(configuration, L0.HasLabel);
48 getContributors(graph, resource, priority, label, result);