1 package org.simantics.diagram.flag;
\r
3 import java.util.ArrayList;
\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
12 public class IOTablesInfo {
\r
13 public static final IOTablesInfo EMPTY = new IOTablesInfo();
\r
15 ArrayList<IOTableInfo> tables = new ArrayList<IOTableInfo>();
\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
21 return new Tuple2(table.name, (int)((y-table.y)/table.rowHeight));
\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
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
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