Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.osbp.xtext.table/src/org/eclipse/osbp/xtext/table/generator/TableGridSourceGenerator.xtend')
-rw-r--r--org.eclipse.osbp.xtext.table/src/org/eclipse/osbp/xtext/table/generator/TableGridSourceGenerator.xtend103
1 files changed, 103 insertions, 0 deletions
diff --git a/org.eclipse.osbp.xtext.table/src/org/eclipse/osbp/xtext/table/generator/TableGridSourceGenerator.xtend b/org.eclipse.osbp.xtext.table/src/org/eclipse/osbp/xtext/table/generator/TableGridSourceGenerator.xtend
new file mode 100644
index 0000000..7c1c028
--- /dev/null
+++ b/org.eclipse.osbp.xtext.table/src/org/eclipse/osbp/xtext/table/generator/TableGridSourceGenerator.xtend
@@ -0,0 +1,103 @@
+/**
+ *
+ * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
+ *
+ *
+ * This copyright notice shows up in the generated Java code
+ *
+ */
+
+package org.eclipse.osbp.xtext.table.generator
+
+import java.io.StringWriter
+import java.io.Writer
+import org.eclipse.emf.ecore.resource.Resource
+import org.eclipse.emf.ecore.util.EcoreUtil
+import org.eclipse.emf.ecore.xmi.XMLResource
+import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl
+import org.eclipse.osbp.dsl.semantic.common.types.LPackage
+import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridPropPriceStyle
+import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridPropQuantityStyle
+import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridPropStyle
+import org.eclipse.osbp.xtext.table.TableGrid
+import org.eclipse.osbp.xtext.table.TableModel
+import org.eclipse.xtext.generator.IFileSystemAccess
+import org.eclipse.xtext.generator.IGenerator
+
+import static extension org.eclipse.osbp.infogrid.model.gridsource.util.Util.*
+
+/**
+ * Generates code from your model files on save.
+ *
+ * see http://www.eclipse.org/Xtext/documentation.html#TutorialCodeGeneration
+ */
+class TableGridSourceGenerator implements IGenerator {
+
+ override void doGenerate(Resource resource, IFileSystemAccess fsa) {
+ resource.toBinary(fsa)
+ }
+
+ def toBinary(Resource input, IFileSystemAccess fsa) {
+ val TableModel lModel = input.contents.get(0) as TableModel
+
+ lModel.packages.forEach [
+ val packageName = it.name
+ it.tables.forEach [
+ val tableName = it.name
+ if (it.tabletype instanceof TableGrid) {
+ generateXMI(it.tabletype as TableGrid, packageName, tableName, fsa);
+ }
+ ]
+ ]
+ }
+
+ def generateXMI(TableGrid grid, String packageName, String tableName, IFileSystemAccess fsa) {
+ val XMLResource outputRes = new XMLResourceImpl
+
+ val ds = grid.source
+
+ ds.id = packageName + "." + tableName + "Grid"
+
+ // set required inputs using the dto defined in the grid table
+ ds.rootTypeFQN = '''«(ds.dtoSource.eContainer as LPackage).name».«ds.dtoSource.name»'''
+
+ // set required properties
+ for (prop : ds.properties) {
+ prop.dotPath = prop.calcDotPath
+
+ // prepare dot path in styles
+ prop.style.prepare
+ }
+
+ val copy = EcoreUtil.copy(ds)
+ outputRes.contents += copy
+
+ // create a writer
+ val Writer writer = new StringWriter
+ outputRes.save(writer, null)
+
+ fsa.generateFile(ds.id + ".gridsource_xmi", "xmi", writer.toString)
+ }
+
+ def dispatch void prepare(CxGridPropStyle style) {
+ }
+
+ def dispatch void prepare(CxGridPropPriceStyle style) {
+ style.valuePropertyDotPath = style.valuePropertyPath.calcDotPath
+ style.currencyPropertyDotPath = style.currencyPropertyPath.calcDotPath
+ }
+
+ def dispatch void prepare(CxGridPropQuantityStyle style) {
+ style.valuePropertyDotPath = style.valuePropertyPath.calcDotPath
+ style.uomPropertyDotPath = style.uomPropertyPath.calcDotPath
+ }
+
+}

Back to the top