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