]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/CompositeTemplate.java
Bumped master version to 1.38.0
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / adapter / CompositeTemplate.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.spreadsheet.graph.adapter;
13
14 import java.util.Map;
15
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;
25
26 public class CompositeTemplate implements Template {
27
28     @Override
29     public void apply(WriteGraph graph, Map<String, Object> parameters) throws DatabaseException {
30
31         Layer0 l0 = Layer0.getInstance(graph);
32         Layer0X L0X = Layer0X.getInstance(graph);
33         SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);
34
35         Resource result = (Resource)parameters.get("");
36         Resource composite = (Resource)parameters.get("composite");
37         String name = (String)parameters.get("name");
38
39         if(name == null) {
40             name = GraphUtils.findFreshEscapedName(graph, "Sheet", composite, sr.HasSheet);
41         }
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);
46
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);
51
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);
65 //
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));
70 //
71 //            {
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);
78 //            }
79 //
80 //            {
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);
87 //            }
88 //
89 //
90 ////            {
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);
98 ////            }
99 ////
100 ////            {
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);
108 ////            }
109 ////
110 ////            {
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);
118 ////            }
119 ////
120 ////            {
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);
128 ////            }
129 //
130 //            {
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')";
135 //                String label = 
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";
142 //                
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)]
149 //                
150 //                   
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);
155 //            }
156 //
157 //        } else if (parameters.containsKey("StreamPropertyTable")) {
158 //
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);
163 //
164 //            graph.claim(result, sr.HasRows, OrderedSetUtils.create(graph, sr.Rows, rowResource0));
165 //            graph.claim(result, sr.HasColumns, OrderedSetUtils.create(graph, sr.Columns, columnResource0));
166 //
167 //            {
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);
173 //            }
174 //
175 //            {
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);
181 //            }
182 //
183 //            {
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);
191 //            }
192 //
193 //        } else if (parameters.containsKey("ActiveModulePropertyTable")) {
194 //
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);
199 //
200 //            graph.claim(result, sr.HasRows, OrderedSetUtils.create(graph, sr.Rows, rowResource0));
201 //            graph.claim(result, sr.HasColumns, OrderedSetUtils.create(graph, sr.Columns, columnResource0));
202 //
203 //            {
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);
209 //            }
210 //
211 //            {
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);
217 //            }
218 //
219 //            {
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);
227 //            }
228 //
229 //        } else {
230 //
231 //            graph.claim(result, sr.HasRows, OrderedSetUtils.create(graph, sr.Rows));
232 //            graph.claim(result, sr.HasColumns, OrderedSetUtils.create(graph, sr.Columns));
233 //
234 //            {
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);
242 //            }
243 //
244 //        }
245
246     }
247
248 }