]> gerrit.simantics Code Review - simantics/platform.git/blob
741cbd39674c5eb64d34c78e546d7fd94a8ea5af
[simantics/platform.git] /
1 package org.simantics.selectionview;
2
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.Resource;
5 import org.simantics.db.exception.DatabaseException;
6 import org.simantics.db.layer0.variable.Variable;
7
8 abstract public class AbstractTypedVariableTabContribution extends AbstractVariableTabContribution {
9
10         public AbstractTypedVariableTabContribution(ReadGraph graph, Resource configuration) throws DatabaseException {
11                 super(graph, configuration);
12         }
13
14         @Override
15         public boolean accept(ReadGraph graph, Variable variable, Object selection) throws DatabaseException {
16
17                 SelectionViewResources SEL = SelectionViewResources.getInstance(graph);
18
19                 Resource type = graph.getPossibleObject(configuration, SEL.AbstractTypedVariableTabContribution_HasType);
20                 if(type == null) throw new DatabaseException("No type for " + graph.getPossibleURI(configuration));
21
22                 Resource resource = variable.getPossibleRepresents(graph);
23                 if(resource == null) return false;
24                 
25                 if(!graph.isInstanceOf(resource, type)) return false;
26                 
27                 return super.accept(graph, variable, selection);
28                 
29         }
30         
31 }