]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/flag/IOTablesInfo.java
Ensure GetElementClassRequest is not constructed without elementFactory
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / flag / IOTablesInfo.java
1 package org.simantics.diagram.flag;\r
2 \r
3 import java.util.ArrayList;\r
4 \r
5 import org.simantics.databoard.Bindings;\r
6 import org.simantics.db.Resource;\r
7 import org.simantics.db.WriteGraph;\r
8 import org.simantics.db.exception.DatabaseException;\r
9 import org.simantics.diagram.stubs.DiagramResource;\r
10 import org.simantics.scl.runtime.tuple.Tuple2;\r
11 \r
12 public class IOTablesInfo {\r
13     public static final IOTablesInfo EMPTY = new IOTablesInfo();\r
14     \r
15     ArrayList<IOTableInfo> tables = new ArrayList<IOTableInfo>();\r
16 \r
17     public Tuple2 getBindingRef(double x, double y) {\r
18         for(IOTableInfo table : tables) {\r
19             if(x < table.x || x > table.x + table.width)\r
20                 continue;\r
21             return new Tuple2(table.name, (int)((y-table.y)/table.rowHeight));\r
22         }\r
23         return null;\r
24     }\r
25 \r
26     public boolean updateBinding(WriteGraph graph, DiagramResource DIA, Resource flagResource, double flagX, double flagY) throws DatabaseException {\r
27         Tuple2 bindingRef = getBindingRef(flagX, flagY);\r
28         \r
29         if(bindingRef != null) {\r
30             graph.claimLiteral(flagResource, DIA.Flag_HasIOTableBinding, (String)bindingRef.c0, Bindings.STRING);\r
31             graph.claimLiteral(flagResource, DIA.Flag_HasIOTableRowIndex, (Integer)bindingRef.c1, Bindings.INTEGER);\r
32             return true;\r
33         }\r
34         else {\r
35             String currentBinding = graph.getPossibleRelatedValue(flagResource,  DIA.Flag_HasIOTableBinding);\r
36             if(currentBinding != null && !currentBinding.isEmpty()) {\r
37                 graph.claimLiteral(flagResource, DIA.Flag_HasIOTableBinding, "", Bindings.STRING);\r
38                 double[] transform = graph.getRelatedValue(flagResource, DIA.HasTransform, Bindings.DOUBLE_ARRAY);\r
39                 transform[4] = flagX;\r
40                 transform[5] = flagY;\r
41                 graph.claimLiteral(flagResource, DIA.HasTransform, transform);\r
42                 return true;\r
43             }\r
44             return false;\r
45         }\r
46     } \r
47 }\r