]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural2/src/org/simantics/structural2/variables/AbstractVariableConnectionPointDescriptor.java
IConnectionPoint and canBeConnected-checking util to SCL
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / variables / AbstractVariableConnectionPointDescriptor.java
1 package org.simantics.structural2.variables;
2
3 import java.util.Collection;
4
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
7 import org.simantics.db.common.request.UnaryRead;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.layer0.request.PropertyInfo;
10 import org.simantics.db.layer0.request.PropertyInfoRequest;
11 import org.simantics.db.layer0.variable.Variable;
12 import org.simantics.db.layer0.variable.Variables;
13 import org.simantics.structural2.Functions;
14 import org.simantics.structural2.Functions.InterfaceResolution;
15
16 abstract public class AbstractVariableConnectionPointDescriptor implements VariableConnectionPointDescriptor {
17
18         static class ComputeInterfaceDescription extends UnaryRead<AbstractVariableConnectionPointDescriptor, Collection<InterfaceResolution>> {
19
20                 public ComputeInterfaceDescription(AbstractVariableConnectionPointDescriptor desc) {
21                         super(desc);
22                 }
23
24                 @Override
25                 public Collection<InterfaceResolution> perform(ReadGraph graph) throws DatabaseException {
26                         return Functions.computeInterfacePaths(graph, parameter.getVariable(graph).getParent(graph));
27                 }
28                 
29         }
30         
31         @Override
32         public Collection<InterfaceResolution> getInterfaceDescription(ReadGraph graph) throws DatabaseException {
33                 return graph.syncRequest(new ComputeInterfaceDescription(this), TransientCacheAsyncListener.<Collection<InterfaceResolution>>instance());
34         }
35         
36         @Override
37         public boolean isLeaf(ReadGraph graph) throws DatabaseException {
38                 
39                 Collection<InterfaceResolution> inf = getInterfaceDescription(graph);
40                 if(inf == null) return true;
41                 return inf.isEmpty();
42                 
43         }
44         
45         @Override
46         public boolean hasClassification(ReadGraph graph, String classification) throws DatabaseException {
47                 
48         PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(getConnectionPointResource(graph)), TransientCacheAsyncListener.<PropertyInfo>instance());
49         return info.hasClassification(classification);
50                 
51         }
52         
53         @Override
54         public String getRelativeRVI(ReadGraph graph, Variable base) throws DatabaseException {
55                 
56         String var = getURI(graph);
57         String baseURI = base.getURI(graph);
58         return Variables.getRelativeRVI(baseURI, var);
59
60         }
61
62 }