blob: dee068c53e3edeab7665018bf42ce8f183a7eb44 [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.organizationdsl.scoping
import javax.inject.Inject
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.EReference
import org.eclipse.osbp.xtext.datamartdsl.DatamartDSLPackage
import org.eclipse.osbp.xtext.datamartdsl.EventBrokerDataMart
import org.eclipse.osbp.xtext.datamartdsl.jvmmodel.DatamartDSLJvmModelInferrer
import org.eclipse.osbp.xtext.datamartdsl.util.EventBrokerDatamartUtils
import org.eclipse.osbp.xtext.organizationdsl.Organization
import org.eclipse.osbp.xtext.organizationdsl.OrganizationPosition
import org.eclipse.osbp.xtext.organizationdsl.OrganizationSuperior
import org.eclipse.osbp.xtext.organizationdsl.OrganizationDSLPackage
import org.eclipse.osbp.xtext.organizationdsl.OrganizationDslUtils
import org.eclipse.xtext.scoping.IScope
import org.eclipse.xtext.scoping.Scopes
import org.eclipse.xtext.xbase.annotations.typesystem.XbaseWithAnnotationsBatchScopeProvider
/**
* This class contains custom scoping description.
*
* see : http://www.eclipse.org/Xtext/documentation.html#scoping
* on how and when to use it
*
*/
class OrganizationDslScopeProvider extends XbaseWithAnnotationsBatchScopeProvider {
@Inject extension DatamartDSLJvmModelInferrer datamartInferrer
@Inject extension OrganizationDslUtils orgUtils
@Inject extension EventBrokerDatamartUtils
@Override
override IScope getScope(EObject context, EReference reference) {
if (reference == OrganizationDSLPackage.Literals.ORGANIZATION_SUPERIOR__SUPERIOR_POS_VALUE) {
return getScope_Organization_Superior_Superior(context as OrganizationSuperior)
} else if (reference == OrganizationDSLPackage.Literals.ORGANIZATION__SUPERIOR_POS_VALUE) {
return getScope_Organization_SuperiorPosValue(context as Organization)
} else if (reference == DatamartDSLPackage.Literals.EVENT_BROKER_DATA_MART__DATAMART_DEF && (context as EventBrokerDataMart).checkSubOrg) {
return getScope_Organization_Datamart_DatamartDef(context as EventBrokerDataMart)
} else if (reference == OrganizationDSLPackage.Literals.ORGANIZATION__SUB_ORGANIZATIONS) {
return getScope_Organization_Datamart_DatamartDef(context as EventBrokerDataMart)
// } else if (reference == OrganizationDslPackage.Literals.CC_ORGANIZATION_DATA_MART__FILTER) {
// return getScope_Organization_DataMart_Filter(context as OrganizationDataMart)
} else {
return super.getScope(context, reference)
}
}
def getScope_Organization_SuperiorPosValue(Organization organization) {
var result = <EObject>newArrayList
var eObj = organization.eContainer()
while (!(eObj instanceof Organization)) {
eObj = eObj.eContainer()
}
if (eObj != null) {
for (OrganizationPosition pos : (eObj as Organization).getOrganizationPositions) {
result.add(pos)
}
return Scopes.scopeFor(result)
}
}
def getScope_Organization_Superior_Superior(OrganizationSuperior orgSup) {
var result = <EObject>newArrayList
var OrganizationPosition orgSupPosition
var eObj = orgSup.eContainer()
while (!(eObj instanceof Organization)) {
if (eObj instanceof OrganizationPosition){
orgSupPosition = (eObj as OrganizationPosition)
}
eObj = eObj.eContainer()
}
if (eObj != null) {
for (OrganizationPosition pos : (eObj as Organization).getOrganizationPositions) {
if (pos.name!=null && orgSupPosition!=null && !pos.name.equals(orgSupPosition.name))
result.add(pos)
}
return Scopes.scopeFor(result)
}
}
def getScope_Organization_Datamart_DatamartDef(EventBrokerDataMart orgDatamart) {
var result = <EObject>newArrayList
// not the inmediate organization of this datamart but the superior organization
// var eObj = orgDatamart.eContainer().eContainer()
var eObj = orgDatamart.eContainer()
// as long as the root node is not reached
while ((eObj != null) && (!(eObj instanceof Organization) || ((eObj instanceof Organization) && (eObj as Organization).superiorPosValue!=null))) {
eObj = eObj.eContainer()
}
if (eObj != null) {
var usedDatamartsFilterMap = ((eObj as Organization).datamarts).getUsedFilterMap()
usedDatamartsFilterMap = (eObj as Organization).getRemainingFilters(usedDatamartsFilterMap)
((eObj as Organization).datamarts).fillResultWithFilter(usedDatamartsFilterMap, result)
}
return Scopes.scopeFor(result)
}
// def getScope_Organization_DataMart_Filter(OrganizationDataMart datamart) {
// var result = <IEObjectDescription>newArrayList
// var filterIdList = <String>newArrayList
// datamartInferrer.createFilterMap(datamart.datamartDef, filterIdList)
// for (filter : filterIdList){
// var filterArray = filter.split(Pattern.quote( "." ))
// var filterTemp = filterArray.get(filterArray.size-1)
// result.add(EObjectDescription.create(filterTemp, datamart))
// }
// return MapBasedScope.createScope(IScope.NULLSCOPE, result)
// }
def private boolean checkSubOrg(EventBrokerDataMart datamart){
// Suborg-Check
var eObj = datamart.eContainer()
while (!(eObj instanceof Organization)) {
eObj = eObj.eContainer()
}
// In case of a suborg
if ((eObj as Organization).superiorPosValue!=null) {
return true
}
return false
}
}