Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.osbp.xtext.table/src/org/eclipse/osbp/xtext/table/scoping/TableDSLScopeProvider.xtend')
-rw-r--r--org.eclipse.osbp.xtext.table/src/org/eclipse/osbp/xtext/table/scoping/TableDSLScopeProvider.xtend424
1 files changed, 424 insertions, 0 deletions
diff --git a/org.eclipse.osbp.xtext.table/src/org/eclipse/osbp/xtext/table/scoping/TableDSLScopeProvider.xtend b/org.eclipse.osbp.xtext.table/src/org/eclipse/osbp/xtext/table/scoping/TableDSLScopeProvider.xtend
new file mode 100644
index 0000000..4e5a9cc
--- /dev/null
+++ b/org.eclipse.osbp.xtext.table/src/org/eclipse/osbp/xtext/table/scoping/TableDSLScopeProvider.xtend
@@ -0,0 +1,424 @@
+/**
+ *
+ * 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.scoping
+
+import java.util.ArrayList
+import javax.inject.Inject
+import org.eclipse.emf.ecore.EObject
+import org.eclipse.emf.ecore.EReference
+import org.eclipse.osbp.dsl.common.xtext.extensions.ModelExtensions
+import org.eclipse.osbp.dsl.entity.xtext.extensions.EntityTypesBuilder
+import org.eclipse.osbp.dsl.semantic.common.types.LReference
+import org.eclipse.osbp.infogrid.model.gridsource.CxGridSourcePackage
+import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridStylePackage
+import org.eclipse.osbp.xtext.cubedsl.CubeDimensionEntity
+import org.eclipse.osbp.xtext.cubedsl.CubeHierarchy
+import org.eclipse.osbp.xtext.cubedsl.CubeLevel
+import org.eclipse.osbp.xtext.datamartdsl.AxisEnum
+import org.eclipse.osbp.xtext.datamartdsl.DatamartAxis
+import org.eclipse.osbp.xtext.datamartdsl.DatamartCube
+import org.eclipse.osbp.xtext.datamartdsl.DatamartDerivedMeasure
+import org.eclipse.osbp.xtext.datamartdsl.DatamartEntity
+import org.eclipse.osbp.xtext.datamartdsl.DatamartHierarchy
+import org.eclipse.osbp.xtext.datamartdsl.DatamartMeasure
+import org.eclipse.osbp.xtext.datamartdsl.DatamartMember
+import org.eclipse.osbp.xtext.datamartdsl.DatamartOwner
+import org.eclipse.osbp.xtext.datamartdsl.DatamartProperty
+import org.eclipse.osbp.xtext.datamartdsl.DatamartSetAggregation
+import org.eclipse.osbp.xtext.datamartdsl.DatamartSetAggregationFunction
+import org.eclipse.osbp.xtext.datamartdsl.DatamartTask
+import org.eclipse.osbp.xtext.datamartdsl.jvmmodel.DatamartDSLJvmModelInferrer
+import org.eclipse.osbp.xtext.datamartdsl.scoping.DatamartDSLScopeProvider
+import org.eclipse.osbp.xtext.gridsource.scoping.GridSourceScopeProvider
+import org.eclipse.osbp.xtext.table.TableAxis
+import org.eclipse.osbp.xtext.table.TableBrokerDatamart
+import org.eclipse.osbp.xtext.table.TableDSLPackage
+import org.eclipse.osbp.xtext.table.TableDatamart
+import org.eclipse.xtext.resource.EObjectDescription
+import org.eclipse.xtext.resource.IEObjectDescription
+import org.eclipse.xtext.scoping.IScope
+import org.eclipse.xtext.scoping.impl.MapBasedScope
+import org.eclipse.xtext.xbase.annotations.typesystem.XbaseWithAnnotationsBatchScopeProvider
+
+class TableScopeProvider extends XbaseWithAnnotationsBatchScopeProvider {
+ @Inject extension ModelExtensions
+ @Inject extension EntityTypesBuilder
+ @Inject extension DatamartDSLScopeProvider datamartScopeProvider
+ @Inject extension DatamartDSLJvmModelInferrer datamartInferrer
+ @Inject GridSourceScopeProvider gridScopeProvider
+
+ @Override
+ override IScope getScope(EObject context, EReference reference) {
+
+ // if context is part of the grid source semantic model
+ if (context.eClass.EPackage == CxGridSourcePackage.eINSTANCE ||
+ context.eClass.EPackage == CxGridStylePackage.eINSTANCE) {
+ return gridScopeProvider.getScope(context, reference)
+ }
+
+ if (reference == TableDSLPackage.Literals.TABLE_AXIS__AXIS) {
+ return getScope_Table_Axis_axis(context)
+ } else if (reference == TableDSLPackage.Literals.TABLE_MEASURE__VALUE_REF ||
+ reference == TableDSLPackage.Literals.TABLE_DERIVED__VALUE_REF ||
+ reference == TableDSLPackage.Literals.TABLE_PROPERTY__VALUE_REF ||
+ reference == TableDSLPackage.Literals.TABLE_COLUMN__VALUE_REF ||
+ reference == TableDSLPackage.Literals.TABLE_HIERARCHY__VALUE_REF) {
+ return getScope_Table_valueRef(context, reference)
+ } else if (reference == TableDSLPackage.Literals.TABLE_AGGREGATION__VALUE_REF) {
+ return getScope_Table_Aggregation_valueRef(context)
+ } else if (reference == TableDSLPackage.Literals.TABLE_BROKER_DATAMART__REFERENCE) {
+ return getScope_Table_Broker_reference(context)
+ } else {
+ return super.getScope(context, reference)
+ }
+ }
+
+ def getScope_Table_Broker_reference(EObject object) {
+ var result = <IEObjectDescription>newArrayList
+ if (object instanceof TableBrokerDatamart) {
+ var datamart = (object as TableBrokerDatamart).datamartDef
+ if (datamart.source instanceof DatamartEntity) {
+ var entity = (datamart.source as DatamartEntity).entityRef
+ for (f : entity.features) {
+ if (f instanceof LReference && !(f as LReference).toMany) {
+ result.add(EObjectDescription.create((f as LReference).name, (f as LReference)))
+ }
+ }
+ }
+ }
+ return MapBasedScope.createScope(IScope.NULLSCOPE, result)
+ }
+
+ def IScope getScope_Table_Axis_axis(EObject object) {
+ var result = <IEObjectDescription>newArrayList
+ var eObj = object
+ while (!(eObj instanceof TableDatamart)) {
+ eObj = eObj.eContainer
+ }
+ if (eObj != null) {
+ var datamart = (eObj as TableDatamart).datamartRef
+ if (datamart != null && datamart.source != null) {
+ if (datamart.source instanceof DatamartCube) {
+ for (axis : (datamart.source as DatamartCube).axisslicer) {
+ if (axis instanceof DatamartAxis) {
+ var literal = (axis as DatamartAxis).name.literal
+ result.add(EObjectDescription.create(literal, (axis as DatamartAxis)))
+ }
+ }
+ } else if (datamart.source instanceof DatamartEntity) {
+ getEntityAxes(datamart.source as DatamartEntity, result)
+
+ // user must not supply any axes, but we need it with tables
+ if (!result.containsName(AxisEnum.COLUMNS.literal)) {
+ result.add(
+ EObjectDescription.create(AxisEnum.COLUMNS.literal, (datamart.source as DatamartEntity)))
+ }
+ if (!result.containsName(AxisEnum.ROWS.literal)) {
+ result.add(
+ EObjectDescription.create(AxisEnum.ROWS.literal, (datamart.source as DatamartEntity)))
+ }
+ } else if (datamart.source instanceof DatamartTask) {
+ result.add(EObjectDescription.create(AxisEnum.COLUMNS.literal, (datamart.source as DatamartTask)))
+ result.add(EObjectDescription.create(AxisEnum.ROWS.literal, (datamart.source as DatamartTask)))
+ }
+ }
+ }
+ return MapBasedScope.createScope(IScope.NULLSCOPE, result)
+ }
+
+ def void getEntityAxes(DatamartEntity entity, ArrayList<IEObjectDescription> result) {
+ for (navigation : entity.navigations) {
+ if (navigation instanceof DatamartMember) {
+ (navigation as DatamartMember).datamartEntity.getEntityAxes(result)
+ for (property : (navigation as DatamartMember).datamartEntity.properties) {
+ if (!result.containsName(property.axis.literal)) {
+ result.add(EObjectDescription.create(property.axis.literal, property as DatamartAxis))
+ }
+ }
+ }
+ if (navigation instanceof DatamartOwner) {
+ (navigation as DatamartOwner).datamartEntity.getEntityAxes(result)
+ for (property : (navigation as DatamartOwner).datamartEntity.properties) {
+ if (!result.containsName(property.axis.literal)) {
+ result.add(EObjectDescription.create(property.axis.literal, property as DatamartAxis))
+ }
+ }
+ }
+ }
+ for (property : entity.properties) {
+ if (property.axis != null) {
+ if (!result.containsName(property.axis.literal)) {
+ result.add(EObjectDescription.create(property.axis.literal, property as DatamartAxis))
+ }
+ } else {
+ if (!result.containsName(property.axis.literal)) {
+ result.add(EObjectDescription.create(property.axis.literal, property as DatamartAxis))
+ }
+ }
+ }
+ }
+
+ def boolean containsName(ArrayList<IEObjectDescription> list, String name) {
+ for (obj : list) {
+ var oname = obj.name.toString
+ if (oname.equals(name)) {
+ return true
+ }
+ }
+ return false
+ }
+
+ def void getEntityProperties(DatamartEntity entity, ArrayList<IEObjectDescription> result,
+ String requestedAxisName) {
+ for (navigation : entity.navigations) {
+ if (navigation instanceof DatamartMember) {
+ (navigation as DatamartMember).datamartEntity.getEntityProperties(result, requestedAxisName)
+ for (property : (navigation as DatamartMember).datamartEntity.properties) {
+ if (property.axis.literal.equals(requestedAxisName)) {
+ result.add(
+ EObjectDescription.create(datamartInferrer.getPropertyName(property),
+ property as DatamartProperty))
+ }
+ }
+ }
+ if (navigation instanceof DatamartOwner) {
+ (navigation as DatamartOwner).datamartEntity.getEntityProperties(result, requestedAxisName)
+ for (property : (navigation as DatamartOwner).datamartEntity.properties) {
+ if (property.axis.literal.equals(requestedAxisName)) {
+ result.add(
+ EObjectDescription.create(datamartInferrer.getPropertyName(property),
+ property as DatamartProperty))
+ }
+ }
+ }
+ }
+ for (property : entity.properties) {
+ if (property.axis != null) {
+ if (property.axis.literal.equals(requestedAxisName)) {
+ result.add(
+ EObjectDescription.create(datamartInferrer.getPropertyName(property),
+ property as DatamartProperty))
+ }
+ } else {
+ result.add(
+ EObjectDescription.create(datamartInferrer.getPropertyName(property),
+ property as DatamartProperty))
+
+ }
+ }
+ }
+
+ def void getTaskColumns(DatamartTask task, ArrayList<IEObjectDescription> result, String requestedAxisName) {
+ for (column : task.columns) {
+ if (AxisEnum.COLUMNS.literal.equals(requestedAxisName)) {
+ result.add(EObjectDescription.create(column.columnRef.literal, column))
+ }
+ }
+ }
+
+ def IScope getScope_Table_valueRef(EObject object, EReference reference) {
+ var result = <IEObjectDescription>newArrayList
+ var eObj = object
+ var requestedAxisName = ""
+ while (!(eObj instanceof TableDatamart)) {
+ eObj = eObj.eContainer
+ if (eObj instanceof TableAxis) {
+ requestedAxisName = (eObj as TableAxis).axis.literal
+ }
+ }
+ if (eObj != null) {
+ var datamart = (eObj as TableDatamart).datamartRef
+ if (datamart != null && datamart.source != null) {
+ if (datamart.source instanceof DatamartCube) {
+ for (axis : (datamart.source as DatamartCube).axisslicer) {
+ if (axis instanceof DatamartAxis) {
+ if ((axis as DatamartAxis).name.literal.equals(requestedAxisName)) {
+ var hasMeasures = false
+ var hasHierarchy = false
+ var hasAggregation = false
+ var isCrossjoined = false
+ for (element : (axis as DatamartAxis).elements) {
+ if (element instanceof DatamartMeasure ||
+ element instanceof DatamartDerivedMeasure) {
+ hasMeasures = true
+ }
+ }
+ for (element : (axis as DatamartAxis).elements) {
+ if (element instanceof DatamartHierarchy) {
+ if (hasHierarchy) {
+ isCrossjoined = true
+ } else {
+ hasHierarchy = true
+ }
+ }
+ if (element instanceof DatamartSetAggregation) {
+ if (hasAggregation) {
+ isCrossjoined = true
+ } else {
+ hasAggregation = true
+ }
+ hasAggregation = true
+ }
+ }
+ if (hasMeasures && (hasHierarchy || hasAggregation)) {
+ isCrossjoined = true
+ }
+ if (/*!isCrossjoined*/1 == 1) {
+ for (element : (axis as DatamartAxis).elements) {
+ if (element instanceof DatamartMeasure &&
+ reference == TableDSLPackage.Literals.TABLE_MEASURE__VALUE_REF) {
+ if ((element as DatamartMeasure).measureRef != null) {
+ result.add(
+ EObjectDescription.create(
+ (element as DatamartMeasure).measureRef.name,
+ element))
+ }
+ }
+ if (element instanceof DatamartDerivedMeasure &&
+ reference == TableDSLPackage.Literals.TABLE_DERIVED__VALUE_REF) {
+ if ((element as DatamartDerivedMeasure).derivedRef != null) {
+ result.add(
+ EObjectDescription.create(
+ (element as DatamartDerivedMeasure).derivedRef.name,
+ element))
+ }
+ }
+ if (element instanceof DatamartHierarchy && !hasMeasures &&
+ reference == TableDSLPackage.Literals.TABLE_HIERARCHY__VALUE_REF) {
+ if ((element as DatamartHierarchy).hierarchyRef != null) {
+ var hierarchy = element as DatamartHierarchy
+ if (hierarchy.levelRef != null) {
+ if (hierarchy.all) { // detailed was modeled - we must add the complete hierarchy
+ var dimEntity = (hierarchy.levelRef as CubeLevel).eContainer as CubeDimensionEntity
+ for (cubeLevel : dimEntity.hierarchLevels) {
+ result.add(
+ EObjectDescription.create(cubeLevel.name,
+ cubeLevel))
+ }
+ } else {
+ result.add(
+ EObjectDescription.create(hierarchy.levelRef.name,
+ (hierarchy.levelRef as CubeLevel)))
+ }
+
+ } else if ((hierarchy.hierarchyRef as CubeHierarchy).allMemberName) {
+ result.add(
+ EObjectDescription.create(
+ (hierarchy.hierarchyRef as CubeHierarchy).
+ allMemberNameValue.toString,
+ (hierarchy.hierarchyRef as CubeHierarchy)))
+ } else if ((hierarchy.defaultMember)) {
+ result.add(
+ EObjectDescription.create(
+ (hierarchy.hierarchyRef as CubeHierarchy).
+ defaultMemberValue.toString,
+ (hierarchy.hierarchyRef as CubeHierarchy)))
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ } else if (datamart.source instanceof DatamartEntity) {
+ getEntityProperties(datamart.source as DatamartEntity, result, requestedAxisName)
+ } else if (datamart.source instanceof DatamartTask) {
+ getTaskColumns(datamart.source as DatamartTask, result, requestedAxisName)
+ }
+ }
+
+ }
+ return MapBasedScope.createScope(IScope.NULLSCOPE, result)
+ }
+
+ def IScope getScope_Table_Aggregation_valueRef(EObject object) {
+ var result = <IEObjectDescription>newArrayList
+ var requestedAxisName = ""
+ var eObj = object
+ while (!(eObj instanceof TableDatamart)) {
+ eObj = eObj.eContainer
+ if (eObj instanceof TableAxis) {
+ requestedAxisName = (eObj as TableAxis).axis.literal
+ }
+ }
+ if (eObj != null) {
+ var datamart = (eObj as TableDatamart).datamartRef
+ if (datamart != null && datamart.source != null) {
+ if (datamart.source instanceof DatamartCube) {
+ for (axis : (datamart.source as DatamartCube).axisslicer) {
+ if (axis instanceof DatamartAxis) {
+ if ((axis as DatamartAxis).name.literal.equals(requestedAxisName)) {
+ var hasMeasures = false
+ var hasHierarchy = false
+ var hasAggregation = false
+ var isCrossjoined = false
+ for (element : (axis as DatamartAxis).elements) {
+ if (element instanceof DatamartMeasure ||
+ element instanceof DatamartDerivedMeasure) {
+ hasMeasures = true
+ }
+ }
+ for (element : (axis as DatamartAxis).elements) {
+ if (element instanceof DatamartHierarchy) {
+ if (hasHierarchy) {
+ isCrossjoined = true
+ } else {
+ hasHierarchy = true
+ }
+ }
+ if (element instanceof DatamartSetAggregation) {
+ if (hasAggregation) {
+ isCrossjoined = true
+ } else {
+ hasAggregation = true
+ }
+ hasAggregation = true
+ }
+ }
+ if (hasMeasures && (hasHierarchy || hasAggregation)) {
+ isCrossjoined = true
+ }
+ if (!hasMeasures && !isCrossjoined) {
+ for (element : (axis as DatamartAxis).elements) {
+ if (element instanceof DatamartSetAggregation) {
+ if ((element as DatamartSetAggregation).left != null) {
+ if ((element as DatamartSetAggregation).left.aggregation != null) {
+ var aggregation = ((element as DatamartSetAggregation).left.
+ aggregation) as DatamartSetAggregationFunction
+
+ // with EObjectDescription.create, we use our own name computation for scoping - it must return a created scope
+ result.add(
+ EObjectDescription.create(aggregation.aggregation.literal,
+ aggregation))
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // with EObjectDescription.create, we use our own name computation for scoping - it must return a created scope
+ return MapBasedScope.createScope(IScope.NULLSCOPE, result)
+ }
+}

Back to the top