| /** |
| * |
| * 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 javax.inject.Inject |
| import org.eclipse.emf.ecore.EObject |
| import org.eclipse.emf.ecore.EReference |
| import org.eclipse.osbp.xtext.chart.ChartDatamart |
| import org.eclipse.osbp.xtext.chart.ChartDSLPackage |
| 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.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.osbp.xtext.datamartdsl.jvmmodel.DatamartDSLJvmModelInferrer |
| 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 ChartScopeProvider extends XbaseWithAnnotationsBatchScopeProvider { |
| |
| @Inject extension DatamartDSLJvmModelInferrer datamartInferrer |
| |
| @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 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) |
| } 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) { |
| result.add(EObjectDescription.create(property.axis.literal, property)) |
| } |
| } |
| if (navigation instanceof DatamartOwner) { |
| (navigation as DatamartOwner).datamartEntity.getEntityAxes(result) |
| for (property : (navigation as DatamartOwner).datamartEntity.properties) { |
| result.add(EObjectDescription.create(property.axis.literal, property)) |
| } |
| } |
| } |
| for (property : entity.properties) { |
| if (property.axis != null) { |
| result.add(EObjectDescription.create(property.axis.literal, property)) |
| } else { |
| result.add(EObjectDescription.create(property.axis.literal, property)) |
| } |
| } |
| } |
| |
| 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(property.getPropertyName(null), property.propertyRef)) |
| } |
| } |
| } |
| 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(property.getPropertyName(null), property.propertyRef)) |
| } |
| } |
| } |
| } |
| for (property : entity.properties) { |
| if (property.axis != null) { |
| if (property.axis.literal.equals(requestedAxisName)) { |
| result.add(EObjectDescription.create(property.getPropertyName(null), property.propertyRef)) |
| } |
| } else { |
| result.add(EObjectDescription.create(property.getPropertyName(null), property.propertyRef)) |
| } |
| } |
| } |
| } |
| |