]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/CompositeTemplate.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / adapter / CompositeTemplate.java
diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/CompositeTemplate.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/CompositeTemplate.java
new file mode 100644 (file)
index 0000000..d437940
--- /dev/null
@@ -0,0 +1,248 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.spreadsheet.graph.adapter;\r
+\r
+import java.util.Map;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.Template;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.operation.Layer0X;\r
+import org.simantics.spreadsheet.resource.SpreadsheetResource;\r
+\r
+public class CompositeTemplate implements Template {\r
+\r
+    @Override\r
+    public void apply(WriteGraph graph, Map<String, Object> parameters) throws DatabaseException {\r
+\r
+        Layer0 l0 = Layer0.getInstance(graph);\r
+        Layer0X L0X = Layer0X.getInstance(graph);\r
+        SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);\r
+\r
+        Resource result = (Resource)parameters.get("");\r
+        Resource composite = (Resource)parameters.get("composite");\r
+        String name = (String)parameters.get("name");\r
+\r
+        if(name == null) {\r
+            name = GraphUtils.findFreshEscapedName(graph, "Sheet", composite, sr.HasSheet);\r
+        }\r
+        graph.claimLiteral(result, l0.HasName, name, Bindings.STRING);\r
+        graph.claim(composite, sr.HasSheet, result);\r
+        graph.claim(composite, L0X.IsRealized, result);\r
+        graph.claim(composite, l0.ConsistsOf, l0.PartOf, result);\r
+\r
+        //InstanceFactory sheetElementFactory = graph.adapt(sr.SpreadsheetElement, InstanceFactory.class);\r
+        //Map<String, Object> sheetElement = graph.syncRequest(sheetElementFactory.create(graph, ArrayMap.keys("").values("")));\r
+        //OrderedSetUtils.createExisting(graph, result, (Resource)sheetElement.get(""));\r
+        //graph.claim((Resource)sheetElement.get(""), sr.HasSheet, result);\r
+\r
+//        if (parameters.containsKey("exampleData")) {\r
+////            Resource rowResource0 = graph.newResource();\r
+////            graph.claim(rowResource0, b.InstanceOf, null, sr.Row);\r
+//            Resource rowResource1 = graph.newResource();\r
+//            graph.claim(rowResource1, l0.InstanceOf, null, sr.Row);\r
+//            Resource columnResource0 = graph.newResource();\r
+//            graph.claim(columnResource0, l0.InstanceOf, null, sr.Column);\r
+////            Resource columnResource1 = graph.newResource();\r
+////            graph.claim(columnResource1, b.InstanceOf, null, sr.Column);\r
+////            Resource columnResource2 = graph.newResource();\r
+////            graph.claim(columnResource2, b.InstanceOf, null, sr.Column);\r
+////            Resource columnResource3 = graph.newResource();\r
+////            graph.claim(columnResource3, b.InstanceOf, null, sr.Column);\r
+//\r
+////            graph.claim(result, sr.HasRows, OrderedSetUtils.create(graph, sr.Rows, rowResource0, rowResource1));\r
+////            graph.claim(result, sr.HasColumns, OrderedSetUtils.create(graph, sr.Columns, columnResource0, columnResource1, columnResource2, columnResource3));\r
+//            graph.claim(result, sr.HasRows, OrderedSetUtils.create(graph, sr.Rows, rowResource1));\r
+//            graph.claim(result, sr.HasColumns, OrderedSetUtils.create(graph, sr.Columns, columnResource0));\r
+//\r
+//            {\r
+//                Resource newCell = graph.newResource();\r
+//                graph.claim(newCell, l0.InstanceOf, null, sr.DimensionsCell);\r
+//                graph.addLiteral(newCell, l0.HasName, l0.NameOf, l0.String, "Dimensions", Bindings.STRING);\r
+//                graph.addValue(newCell, sr.FitColumns, sr.FitColumnsOf, l0.Boolean, true, Bindings.BOOLEAN);\r
+//                graph.addValue(newCell, sr.FitRows, sr.FitRowsOf, l0.Boolean, true, Bindings.BOOLEAN);\r
+//                graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);\r
+//            }\r
+//\r
+//            {\r
+//                Resource newCell = graph.newResource();\r
+//                graph.claim(newCell, l0.InstanceOf, null, sr.HeadersCell);\r
+//                graph.addLiteral(newCell, l0.HasName, l0.NameOf, l0.String, "Headers", Bindings.STRING);\r
+//                graph.addValue(newCell, sr.ColumnLabels, sr.ColumnLabelsOf, l0.StringArray, new String[] { "Diagram", "Name", "Length", "In Simulation" }, Bindings.getBindingUnchecked(String[].class));\r
+//                graph.addValue(newCell, sr.ColumnWidths, sr.ColumnCountOf, l0.IntegerArray, new int[] { 180, 180, 180, 180 }, Bindings.INT_ARRAY);\r
+//                graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);\r
+//            }\r
+//\r
+//\r
+////            {\r
+////                Resource newCell = graph.newResource();\r
+////                graph.claim(newCell, b.InstanceOf, null, sr.TextCell);\r
+////                String label = "Pipe name";\r
+////                graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);\r
+////                graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource0);\r
+////                graph.addValue(newCell, sr.Label, sr.LabelOf, b.String, label, StringJavaBinding.INSTANCE);\r
+////                graph.claim(result, b.ConsistsOf, b.PartOf, newCell);\r
+////            }\r
+////\r
+////            {\r
+////                Resource newCell = graph.newResource();\r
+////                graph.claim(newCell, b.InstanceOf, null, sr.TextCell);\r
+////                String label = "Pipe length";\r
+////                graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);\r
+////                graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource1);\r
+////                graph.addValue(newCell, sr.Label, sr.LabelOf, b.String, label, StringJavaBinding.INSTANCE);\r
+////                graph.claim(result, b.ConsistsOf, b.PartOf, newCell);\r
+////            }\r
+////\r
+////            {\r
+////                Resource newCell = graph.newResource();\r
+////                graph.claim(newCell, b.InstanceOf, null, sr.TextCell);\r
+////                String label = "Flow area";\r
+////                graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);\r
+////                graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource2);\r
+////                graph.addValue(newCell, sr.Label, sr.LabelOf, b.String, label, StringJavaBinding.INSTANCE);\r
+////                graph.claim(result, b.ConsistsOf, b.PartOf, newCell);\r
+////            }\r
+////\r
+////            {\r
+////                Resource newCell = graph.newResource();\r
+////                graph.claim(newCell, b.InstanceOf, null, sr.TextCell);\r
+////                String label = "In simulation";\r
+////                graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);\r
+////                graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource3);\r
+////                graph.addValue(newCell, sr.Label, sr.LabelOf, b.String, label, StringJavaBinding.INSTANCE);\r
+////                graph.claim(result, b.ConsistsOf, b.PartOf, newCell);\r
+////            }\r
+//\r
+//            {\r
+//                Resource newCell = graph.newResource();\r
+//                graph.claim(newCell, l0.InstanceOf, null, sr.ExpressionCell);\r
+//                graph.addLiteral(newCell, l0.HasName, l0.NameOf, l0.String, "Expression", Bindings.STRING);\r
+////                String label = "Attributes(Components('PIPE*'), '#Name', '#PI12_LENGTH', '#PI12_AREA', '#IncludedInSimulation')";\r
+//                String label = \r
+//                     "nameOf v = stringPropertyOf v \"HasName\"\n" +\r
+//                     "typeOf v = resourcePropertyOf v \"Type\"\n" +\r
+//                     "lengthOf v = doublePropertyOf v \"PI12_LENGTH\"\n" +\r
+//                     "module <- apply \"Components\" \"PIPE*\"\n" +\r
+//                     "composite = browseFrom module \".\"\n" +\r
+//                     "[(nameOf composite, nameOf module, lengthOf module)]\n";\r
+//                \r
+////                nameOf v = stringPropertyOf v "HasName"\r
+////                typeOf v = resourcePropertyOf v "Type"\r
+////                lengthOf v = doublePropertyOf v "PI12_LENGTH"\r
+////                module <- apply "Components" "PIPE*"\r
+////                composite = browseFrom module "."\r
+////                [(nameOf composite, nameOf module, lengthOf module)]\r
+//                \r
+//                   \r
+//                graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource1);\r
+//                graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource0);\r
+//                graph.addValue(newCell, sr.Expression, sr.ExpressionOf, l0.String, label, Bindings.STRING);\r
+//                graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);\r
+//            }\r
+//\r
+//        } else if (parameters.containsKey("StreamPropertyTable")) {\r
+//\r
+//            Resource rowResource0 = graph.newResource();\r
+//            graph.claim(rowResource0, l0.InstanceOf, null, sr.Row);\r
+//            Resource columnResource0 = graph.newResource();\r
+//            graph.claim(columnResource0, l0.InstanceOf, null, sr.Column);\r
+//\r
+//            graph.claim(result, sr.HasRows, OrderedSetUtils.create(graph, sr.Rows, rowResource0));\r
+//            graph.claim(result, sr.HasColumns, OrderedSetUtils.create(graph, sr.Columns, columnResource0));\r
+//\r
+//            {\r
+//                Resource newCell = graph.newResource();\r
+//                graph.claim(newCell, l0.InstanceOf, null, sr.DimensionsCell);\r
+//                graph.addValue(newCell, sr.FitColumns, sr.FitColumnsOf, l0.Boolean, true, Bindings.BOOLEAN);\r
+//                graph.addValue(newCell, sr.FitRows, sr.FitRowsOf, l0.Boolean, true, Bindings.BOOLEAN);\r
+//                graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);\r
+//            }\r
+//\r
+//            {\r
+//                Resource newCell = graph.newResource();\r
+//                graph.claim(newCell, l0.InstanceOf, null, sr.HeadersCell);\r
+//                graph.addValue(newCell, sr.ColumnLabels, sr.ColumnLabelsOf, l0.StringArray, new String[] { "Stream", "Property", "Value", "Source" }, Bindings.getBindingUnchecked(String[].class));\r
+//                graph.addValue(newCell, sr.ColumnWidths, sr.ColumnCountOf, l0.IntegerArray, new int[] { 180, 180, 180 }, Bindings.INT_ARRAY);\r
+//                graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);\r
+//            }\r
+//\r
+//            {\r
+//                Resource newCell = graph.newResource();\r
+//                graph.claim(newCell, l0.InstanceOf, null, sr.ExpressionCell);\r
+//                String label = "PropertyTable(Properties(Streams()), '.#HasName', 'HasName', '', 'HasSource')";\r
+//                graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);\r
+//                graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource0);\r
+//                graph.addValue(newCell, sr.Expression, sr.ExpressionOf, l0.String, label, Bindings.STRING);\r
+//                graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);\r
+//            }\r
+//\r
+//        } else if (parameters.containsKey("ActiveModulePropertyTable")) {\r
+//\r
+//            Resource rowResource0 = graph.newResource();\r
+//            graph.claim(rowResource0, l0.InstanceOf, null, sr.Row);\r
+//            Resource columnResource0 = graph.newResource();\r
+//            graph.claim(columnResource0, l0.InstanceOf, null, sr.Column);\r
+//\r
+//            graph.claim(result, sr.HasRows, OrderedSetUtils.create(graph, sr.Rows, rowResource0));\r
+//            graph.claim(result, sr.HasColumns, OrderedSetUtils.create(graph, sr.Columns, columnResource0));\r
+//\r
+//            {\r
+//                Resource newCell = graph.newResource();\r
+//                graph.claim(newCell, l0.InstanceOf, null, sr.DimensionsCell);\r
+//                graph.addValue(newCell, sr.FitColumns, sr.FitColumnsOf, l0.Boolean, true, Bindings.BOOLEAN);\r
+//                graph.addValue(newCell, sr.FitRows, sr.FitRowsOf, l0.Boolean, true, Bindings.BOOLEAN);\r
+//                graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);\r
+//            }\r
+//\r
+//            {\r
+//                Resource newCell = graph.newResource();\r
+//                graph.claim(newCell, l0.InstanceOf, null, sr.HeadersCell);\r
+//                graph.addValue(newCell, sr.ColumnLabels, sr.ColumnLabelsOf, l0.StringArray, new String[] { "Unit", "Property", "Value", "Source" }, Bindings.getBindingUnchecked(String[].class));\r
+//                graph.addValue(newCell, sr.ColumnWidths, sr.ColumnCountOf, l0.IntegerArray, new int[] { 180, 180, 180 }, Bindings.INT_ARRAY);\r
+//                graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);\r
+//            }\r
+//\r
+//            {\r
+//                Resource newCell = graph.newResource();\r
+//                graph.claim(newCell, l0.InstanceOf, null, sr.ExpressionCell);\r
+//                String label = "PropertyTable(Parameters(ActiveModules()), '..#HasName', 'HasName', '', 'HasSource')";\r
+//                graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);\r
+//                graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource0);\r
+//                graph.addValue(newCell, sr.Expression, sr.ExpressionOf, l0.String, label, Bindings.STRING);\r
+//                graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);\r
+//            }\r
+//\r
+//        } else {\r
+//\r
+//            graph.claim(result, sr.HasRows, OrderedSetUtils.create(graph, sr.Rows));\r
+//            graph.claim(result, sr.HasColumns, OrderedSetUtils.create(graph, sr.Columns));\r
+//\r
+//            {\r
+//                Resource newCell = graph.newResource();\r
+//                graph.claim(newCell, l0.InstanceOf, null, sr.DimensionsCell);\r
+//                graph.addValue(newCell, sr.ColumnCount, sr.ColumnCountOf, l0.Integer, 10, Bindings.INTEGER);\r
+//                graph.addValue(newCell, sr.RowCount, sr.RowCountOf, l0.Integer, 10, Bindings.INTEGER);\r
+//                graph.addValue(newCell, sr.FitColumns, sr.FitColumnsOf, l0.Boolean, false, Bindings.BOOLEAN);\r
+//                graph.addValue(newCell, sr.FitRows, sr.FitRowsOf, l0.Boolean, false, Bindings.BOOLEAN);\r
+//                graph.claim(result, l0.ConsistsOf, l0.PartOf, newCell);\r
+//            }\r
+//\r
+//        }\r
+\r
+    }\r
+\r
+}\r