]> gerrit.simantics Code Review - simantics/platform.git/blob
8f0a9fdd4eb263cc1e4430edfb4cffdffd2e8618
[simantics/platform.git] /
1 package org.simantics.selectionview;
2
3 import java.util.Collection;
4
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;
11
12 abstract public class AbstractResourceTabContribution implements TabContribution<Resource> {
13
14         final protected Resource configuration;
15
16         public AbstractResourceTabContribution(ReadGraph graph, Resource configuration) throws DatabaseException {
17                 this.configuration = configuration;
18         }
19
20         public abstract void getContributors(ReadGraph graph, Resource resource, Integer priority, String label, Collection<ComparableTabContributor> result) throws DatabaseException;
21         
22         @Override
23         public boolean accept(ReadGraph graph, Object input) throws DatabaseException {
24
25                 if (!(input instanceof Resource))
26                         return false;
27                 Resource resource = (Resource) input;
28
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;
33                 }
34                 
35                 return true;
36                 
37         }
38         
39         @Override
40         final public void contribute(ReadGraph graph, final Resource resource, Collection<ComparableTabContributor> result) throws DatabaseException {
41
42                 Layer0 L0 = Layer0.getInstance(graph);
43                 SelectionViewResources SEL = SelectionViewResources.getInstance(graph);
44
45                 Integer priority = graph.getPossibleRelatedValue(configuration, SEL.AbstractResourceTabContribution_HasPriority, Bindings.INTEGER);
46                 String label = graph.getPossibleRelatedValue(configuration, L0.HasLabel);
47
48                 getContributors(graph, resource, priority, label, result);
49
50         }
51
52 }