1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.spreadsheet.graph.adapter;
\r
14 import java.util.Map;
\r
16 import org.simantics.databoard.Bindings;
\r
17 import org.simantics.db.Resource;
\r
18 import org.simantics.db.WriteGraph;
\r
19 import org.simantics.db.exception.DatabaseException;
\r
20 import org.simantics.db.layer0.adapter.Template;
\r
21 import org.simantics.layer0.Layer0;
\r
22 import org.simantics.layer0.utils.direct.GraphUtils;
\r
23 import org.simantics.operation.Layer0X;
\r
24 import org.simantics.spreadsheet.resource.SpreadsheetResource;
\r
26 public class CompositeTemplate implements Template {
\r
29 public void apply(WriteGraph graph, Map<String, Object> parameters) throws DatabaseException {
\r
31 Layer0 l0 = Layer0.getInstance(graph);
\r
32 Layer0X L0X = Layer0X.getInstance(graph);
\r
33 SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);
\r
35 Resource result = (Resource)parameters.get("");
\r
36 Resource composite = (Resource)parameters.get("composite");
\r
37 String name = (String)parameters.get("name");
\r
40 name = GraphUtils.findFreshEscapedName(graph, "Sheet", composite, sr.HasSheet);
\r
42 graph.claimLiteral(result, l0.HasName, name, Bindings.STRING);
\r
43 graph.claim(composite, sr.HasSheet, result);
\r
44 graph.claim(composite, L0X.IsRealized, result);
\r
45 graph.claim(composite, l0.ConsistsOf, l0.PartOf, result);
\r
47 //InstanceFactory sheetElementFactory = graph.adapt(sr.SpreadsheetElement, InstanceFactory.class);
\r
48 //Map<String, Object> sheetElement = graph.syncRequest(sheetElementFactory.create(graph, ArrayMap.keys("").values("")));
\r
49 //OrderedSetUtils.createExisting(graph, result, (Resource)sheetElement.get(""));
\r
50 //graph.claim((Resource)sheetElement.get(""), sr.HasSheet, result);
\r
52 // if (parameters.containsKey("exampleData")) {
\r
53 //// Resource rowResource0 = graph.newResource();
\r
54 //// graph.claim(rowResource0, b.InstanceOf, null, sr.Row);
\r
55 // Resource rowResource1 = graph.newResource();
\r
56 // graph.claim(rowResource1, l0.InstanceOf, null, sr.Row);
\r
57 // Resource columnResource0 = graph.newResource();
\r
58 // graph.claim(columnResource0, l0.InstanceOf, null, sr.Column);
\r
59 //// Resource columnResource1 = graph.newResource();
\r
60 //// graph.claim(columnResource1, b.InstanceOf, null, sr.Column);
\r
61 //// Resource columnResource2 = graph.newResource();
\r
62 //// graph.claim(columnResource2, b.InstanceOf, null, sr.Column);
\r
63 //// Resource columnResource3 = graph.newResource();
\r
64 //// graph.claim(columnResource3, b.InstanceOf, null, sr.Column);
\r
66 //// graph.claim(result, sr.HasRows, OrderedSetUtils.create(graph, sr.Rows, rowResource0, rowResource1));
\r
67 //// graph.claim(result, sr.HasColumns, OrderedSetUtils.create(graph, sr.Columns, columnResource0, columnResource1, columnResource2, columnResource3));
\r
68 // graph.claim(result, sr.HasRows, OrderedSetUtils.create(graph, sr.Rows, rowResource1));
\r
69 // graph.claim(result, sr.HasColumns, OrderedSetUtils.create(graph, sr.Columns, columnResource0));
\r
72 // Resource newCell = graph.newResource();
\r
73 // graph.claim(newCell, l0.InstanceOf, null, sr.DimensionsCell);
\r
74 // graph.addLiteral(newCell, l0.HasName, l0.NameOf, l0.String, "Dimensions", Bindings.STRING);
\r
75 // graph.addValue(newCell, sr.FitColumns, sr.FitColumnsOf, l0.Boolean, true, Bindings.BOOLEAN);
\r
76 // graph.addValue(newCell, sr.FitRows, sr.FitRowsOf, l0.Boolean, true, Bindings.BOOLEAN);
\r
77 // graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);
\r
81 // Resource newCell = graph.newResource();
\r
82 // graph.claim(newCell, l0.InstanceOf, null, sr.HeadersCell);
\r
83 // graph.addLiteral(newCell, l0.HasName, l0.NameOf, l0.String, "Headers", Bindings.STRING);
\r
84 // graph.addValue(newCell, sr.ColumnLabels, sr.ColumnLabelsOf, l0.StringArray, new String[] { "Diagram", "Name", "Length", "In Simulation" }, Bindings.getBindingUnchecked(String[].class));
\r
85 // graph.addValue(newCell, sr.ColumnWidths, sr.ColumnCountOf, l0.IntegerArray, new int[] { 180, 180, 180, 180 }, Bindings.INT_ARRAY);
\r
86 // graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);
\r
91 //// Resource newCell = graph.newResource();
\r
92 //// graph.claim(newCell, b.InstanceOf, null, sr.TextCell);
\r
93 //// String label = "Pipe name";
\r
94 //// graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);
\r
95 //// graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource0);
\r
96 //// graph.addValue(newCell, sr.Label, sr.LabelOf, b.String, label, StringJavaBinding.INSTANCE);
\r
97 //// graph.claim(result, b.ConsistsOf, b.PartOf, newCell);
\r
101 //// Resource newCell = graph.newResource();
\r
102 //// graph.claim(newCell, b.InstanceOf, null, sr.TextCell);
\r
103 //// String label = "Pipe length";
\r
104 //// graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);
\r
105 //// graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource1);
\r
106 //// graph.addValue(newCell, sr.Label, sr.LabelOf, b.String, label, StringJavaBinding.INSTANCE);
\r
107 //// graph.claim(result, b.ConsistsOf, b.PartOf, newCell);
\r
111 //// Resource newCell = graph.newResource();
\r
112 //// graph.claim(newCell, b.InstanceOf, null, sr.TextCell);
\r
113 //// String label = "Flow area";
\r
114 //// graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);
\r
115 //// graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource2);
\r
116 //// graph.addValue(newCell, sr.Label, sr.LabelOf, b.String, label, StringJavaBinding.INSTANCE);
\r
117 //// graph.claim(result, b.ConsistsOf, b.PartOf, newCell);
\r
121 //// Resource newCell = graph.newResource();
\r
122 //// graph.claim(newCell, b.InstanceOf, null, sr.TextCell);
\r
123 //// String label = "In simulation";
\r
124 //// graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);
\r
125 //// graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource3);
\r
126 //// graph.addValue(newCell, sr.Label, sr.LabelOf, b.String, label, StringJavaBinding.INSTANCE);
\r
127 //// graph.claim(result, b.ConsistsOf, b.PartOf, newCell);
\r
131 // Resource newCell = graph.newResource();
\r
132 // graph.claim(newCell, l0.InstanceOf, null, sr.ExpressionCell);
\r
133 // graph.addLiteral(newCell, l0.HasName, l0.NameOf, l0.String, "Expression", Bindings.STRING);
\r
134 //// String label = "Attributes(Components('PIPE*'), '#Name', '#PI12_LENGTH', '#PI12_AREA', '#IncludedInSimulation')";
\r
136 // "nameOf v = stringPropertyOf v \"HasName\"\n" +
\r
137 // "typeOf v = resourcePropertyOf v \"Type\"\n" +
\r
138 // "lengthOf v = doublePropertyOf v \"PI12_LENGTH\"\n" +
\r
139 // "module <- apply \"Components\" \"PIPE*\"\n" +
\r
140 // "composite = browseFrom module \".\"\n" +
\r
141 // "[(nameOf composite, nameOf module, lengthOf module)]\n";
\r
143 //// nameOf v = stringPropertyOf v "HasName"
\r
144 //// typeOf v = resourcePropertyOf v "Type"
\r
145 //// lengthOf v = doublePropertyOf v "PI12_LENGTH"
\r
146 //// module <- apply "Components" "PIPE*"
\r
147 //// composite = browseFrom module "."
\r
148 //// [(nameOf composite, nameOf module, lengthOf module)]
\r
151 // graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource1);
\r
152 // graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource0);
\r
153 // graph.addValue(newCell, sr.Expression, sr.ExpressionOf, l0.String, label, Bindings.STRING);
\r
154 // graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);
\r
157 // } else if (parameters.containsKey("StreamPropertyTable")) {
\r
159 // Resource rowResource0 = graph.newResource();
\r
160 // graph.claim(rowResource0, l0.InstanceOf, null, sr.Row);
\r
161 // Resource columnResource0 = graph.newResource();
\r
162 // graph.claim(columnResource0, l0.InstanceOf, null, sr.Column);
\r
164 // graph.claim(result, sr.HasRows, OrderedSetUtils.create(graph, sr.Rows, rowResource0));
\r
165 // graph.claim(result, sr.HasColumns, OrderedSetUtils.create(graph, sr.Columns, columnResource0));
\r
168 // Resource newCell = graph.newResource();
\r
169 // graph.claim(newCell, l0.InstanceOf, null, sr.DimensionsCell);
\r
170 // graph.addValue(newCell, sr.FitColumns, sr.FitColumnsOf, l0.Boolean, true, Bindings.BOOLEAN);
\r
171 // graph.addValue(newCell, sr.FitRows, sr.FitRowsOf, l0.Boolean, true, Bindings.BOOLEAN);
\r
172 // graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);
\r
176 // Resource newCell = graph.newResource();
\r
177 // graph.claim(newCell, l0.InstanceOf, null, sr.HeadersCell);
\r
178 // graph.addValue(newCell, sr.ColumnLabels, sr.ColumnLabelsOf, l0.StringArray, new String[] { "Stream", "Property", "Value", "Source" }, Bindings.getBindingUnchecked(String[].class));
\r
179 // graph.addValue(newCell, sr.ColumnWidths, sr.ColumnCountOf, l0.IntegerArray, new int[] { 180, 180, 180 }, Bindings.INT_ARRAY);
\r
180 // graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);
\r
184 // Resource newCell = graph.newResource();
\r
185 // graph.claim(newCell, l0.InstanceOf, null, sr.ExpressionCell);
\r
186 // String label = "PropertyTable(Properties(Streams()), '.#HasName', 'HasName', '', 'HasSource')";
\r
187 // graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);
\r
188 // graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource0);
\r
189 // graph.addValue(newCell, sr.Expression, sr.ExpressionOf, l0.String, label, Bindings.STRING);
\r
190 // graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);
\r
193 // } else if (parameters.containsKey("ActiveModulePropertyTable")) {
\r
195 // Resource rowResource0 = graph.newResource();
\r
196 // graph.claim(rowResource0, l0.InstanceOf, null, sr.Row);
\r
197 // Resource columnResource0 = graph.newResource();
\r
198 // graph.claim(columnResource0, l0.InstanceOf, null, sr.Column);
\r
200 // graph.claim(result, sr.HasRows, OrderedSetUtils.create(graph, sr.Rows, rowResource0));
\r
201 // graph.claim(result, sr.HasColumns, OrderedSetUtils.create(graph, sr.Columns, columnResource0));
\r
204 // Resource newCell = graph.newResource();
\r
205 // graph.claim(newCell, l0.InstanceOf, null, sr.DimensionsCell);
\r
206 // graph.addValue(newCell, sr.FitColumns, sr.FitColumnsOf, l0.Boolean, true, Bindings.BOOLEAN);
\r
207 // graph.addValue(newCell, sr.FitRows, sr.FitRowsOf, l0.Boolean, true, Bindings.BOOLEAN);
\r
208 // graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);
\r
212 // Resource newCell = graph.newResource();
\r
213 // graph.claim(newCell, l0.InstanceOf, null, sr.HeadersCell);
\r
214 // graph.addValue(newCell, sr.ColumnLabels, sr.ColumnLabelsOf, l0.StringArray, new String[] { "Unit", "Property", "Value", "Source" }, Bindings.getBindingUnchecked(String[].class));
\r
215 // graph.addValue(newCell, sr.ColumnWidths, sr.ColumnCountOf, l0.IntegerArray, new int[] { 180, 180, 180 }, Bindings.INT_ARRAY);
\r
216 // graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);
\r
220 // Resource newCell = graph.newResource();
\r
221 // graph.claim(newCell, l0.InstanceOf, null, sr.ExpressionCell);
\r
222 // String label = "PropertyTable(Parameters(ActiveModules()), '..#HasName', 'HasName', '', 'HasSource')";
\r
223 // graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);
\r
224 // graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource0);
\r
225 // graph.addValue(newCell, sr.Expression, sr.ExpressionOf, l0.String, label, Bindings.STRING);
\r
226 // graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);
\r
231 // graph.claim(result, sr.HasRows, OrderedSetUtils.create(graph, sr.Rows));
\r
232 // graph.claim(result, sr.HasColumns, OrderedSetUtils.create(graph, sr.Columns));
\r
235 // Resource newCell = graph.newResource();
\r
236 // graph.claim(newCell, l0.InstanceOf, null, sr.DimensionsCell);
\r
237 // graph.addValue(newCell, sr.ColumnCount, sr.ColumnCountOf, l0.Integer, 10, Bindings.INTEGER);
\r
238 // graph.addValue(newCell, sr.RowCount, sr.RowCountOf, l0.Integer, 10, Bindings.INTEGER);
\r
239 // graph.addValue(newCell, sr.FitColumns, sr.FitColumnsOf, l0.Boolean, false, Bindings.BOOLEAN);
\r
240 // graph.addValue(newCell, sr.FitRows, sr.FitRowsOf, l0.Boolean, false, Bindings.BOOLEAN);
\r
241 // graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);
\r