blob: 7f9128b5f24ca3ad8cd5c0cad11f57e95ff542e0 [file] [log] [blame]
/**
*
* 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.chart.scoping
import java.util.ArrayList
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.EReference
import org.eclipse.osbp.xtext.chart.ChartDSLPackage
import org.eclipse.osbp.xtext.chart.ChartDatamart
import org.eclipse.osbp.xtext.datamartdsl.AxisEnum
import org.eclipse.osbp.xtext.datamartdsl.DatamartCube
import org.eclipse.osbp.xtext.datamartdsl.DatamartCubeAxis
import org.eclipse.osbp.xtext.datamartdsl.DatamartEntity
import org.eclipse.osbp.xtext.datamartdsl.DatamartMember
import org.eclipse.osbp.xtext.datamartdsl.DatamartOwner
import org.eclipse.osbp.xtext.datamartdsl.DatamartTask
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
class ChartDSLScopeProvider extends AbstractChartDSLScopeProvider {
@Override
override IScope getScope(EObject context, EReference reference) {
if (reference == ChartDSLPackage.Literals.CHART_AXIS__AXIS) {
return getScope_Chart_Axis_axis(context)
}
return super.getScope(context, reference)
}
def IScope getScope_Chart_Axis_axis(EObject object) {
var result = <IEObjectDescription>newArrayList
var eObj = object
while (!(eObj instanceof ChartDatamart)) {
eObj = eObj.eContainer
}
if (eObj !== null) {
var datamart = (eObj as ChartDatamart).datamartRef
if (datamart !== null && datamart.source !== null) {
if (datamart.source instanceof DatamartCube) {
for (axis : (datamart.source as DatamartCube).axisslicer) {
if (axis instanceof DatamartCubeAxis) {
var literal = (axis as DatamartCubeAxis).axis.name.literal
result.add(EObjectDescription.create(literal, (axis as DatamartCubeAxis).axis))
}
}
} else if (datamart.source instanceof DatamartEntity) {
getEntityAxes(datamart.source as DatamartEntity, result)
} 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 (attribute : (navigation as DatamartMember).datamartEntity.attributes) {
result.add(EObjectDescription.create(attribute.axis.name.literal, attribute.axis))
}
}
if (navigation instanceof DatamartOwner) {
(navigation as DatamartOwner).datamartEntity.getEntityAxes(result)
for (attribute : (navigation as DatamartOwner).datamartEntity.attributes) {
result.add(EObjectDescription.create(attribute.axis.name.literal, attribute.axis))
}
}
}
for (attribute : entity.attributes) {
if (attribute.axis !== null) {
result.add(EObjectDescription.create(attribute.axis.name.literal, attribute.axis))
} else {
result.add(EObjectDescription.create(attribute.axis.name.literal, attribute.axis))
}
}
}
}