| /** |
| * |
| * 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 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| * |
| * This copyright notice shows up in the generated Java code |
| * |
| */ |
| |
| package org.eclipse.osbp.xtext.strategy.jvmmodel |
| |
| import javax.inject.Inject |
| import org.eclipse.osbp.ecview.^extension.api.IFocusingEnhancer |
| import org.eclipse.osbp.ecview.^extension.model.YStrategyLayout |
| import org.eclipse.osbp.utils.annotation.CommonUtils |
| import org.eclipse.osbp.xtext.strategy.FocusingEnhancer |
| import org.eclipse.osbp.xtext.strategy.StrategyPackage |
| import org.eclipse.osbp.xtext.strategy.constants.StrategyConstants |
| import org.eclipse.xtext.common.types.JvmGenericType |
| import org.eclipse.xtext.common.types.JvmVisibility |
| import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor |
| import org.eclipse.xtext.xbase.jvmmodel.JvmAnnotationReferenceBuilder |
| import org.eclipse.xtext.xbase.jvmmodel.JvmTypeReferenceBuilder |
| import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder |
| import org.osgi.service.component.annotations.Component |
| |
| class StrategyDSLFocusingEnhancerCreator { |
| @Inject extension JvmTypesBuilder |
| @Inject extension StrategyConstants |
| @Inject extension CommonUtils |
| |
| private JvmAnnotationReferenceBuilder _annotationTypesBuilder; |
| private JvmTypeReferenceBuilder _typeReferenceBuilder; |
| |
| def void createFocusingEnhancer(StrategyPackage pckg, FocusingEnhancer focusingEnhancer, IJvmDeclaredTypeAcceptor acceptor, JvmAnnotationReferenceBuilder annotationTypesBuilder, JvmTypeReferenceBuilder typeReferenceBuilder){ |
| pckg.createFocusingEnhancer(focusingEnhancer, acceptor, annotationTypesBuilder, typeReferenceBuilder, false) |
| } |
| |
| def void createFocusingEnhancer(StrategyPackage pckg, FocusingEnhancer focusingEnhancer, IJvmDeclaredTypeAcceptor acceptor, JvmAnnotationReferenceBuilder annotationTypesBuilder, JvmTypeReferenceBuilder typeReferenceBuilder, boolean osdefault){ |
| _annotationTypesBuilder = annotationTypesBuilder |
| _typeReferenceBuilder = typeReferenceBuilder |
| // creation of the IFocusingEnhancer implementation |
| var clsStrategy = focusingEnhancer.toClass('''«pckg.name».«focusingEnhancer.getStrategyClassName(osdefault)»''') |
| clsStrategy.getSuperTypes().add(_typeReferenceBuilder.typeRef(typeof(IFocusingEnhancer))) |
| acceptor.accept(clsStrategy, |
| [ |
| var annotationRef = _annotationTypesBuilder.annotationRef(typeof(Component)) |
| val propContent = '''ecview.focusing.enhancer.id=«focusingEnhancer.getStrategyClassName(osdefault)»''' |
| if (osdefault){ |
| var String[] propContents = newArrayOfSize(2) |
| propContents.set(0,propContent) |
| propContents.set(1,"ecview.focusing.enhancer.default=true") |
| annotationRef.addAnnAttrArr(focusingEnhancer, "property", propContents) |
| } else { |
| annotationRef.addAnnAttr(focusingEnhancer, "property", propContent) |
| } |
| annotations += annotationRef |
| it.toOperations(focusingEnhancer) |
| ]) |
| |
| } |
| |
| // Strategy Methods |
| def void toOperations(JvmGenericType type, FocusingEnhancer focusingEnhancer){ |
| // create enhanceFocusing |
| type.members += focusingEnhancer.toMethod("enhanceFocusing", _typeReferenceBuilder.typeRef(Void::TYPE), |
| [ |
| annotations += _annotationTypesBuilder.annotationRef(typeof(Override)) |
| visibility = JvmVisibility.PUBLIC |
| parameters += focusingEnhancer.toParameter("yLayout", _typeReferenceBuilder.typeRef(YStrategyLayout)) |
| body = [append(focusingEnhancer.enhanceFocusingBody)] |
| ]) |
| } |
| |
| def String getEnhanceFocusingBody(FocusingEnhancer focusingEnhancer){ |
| var body = '''yLayout.getFocusingStrategies().clear();''' |
| var idx = 1 |
| for (focusingStrategy : focusingEnhancer.focusingStrategies){ |
| body = ''' |
| «body» |
| YDelegatingFocusingStrategy yStgy«idx» = YECviewFactory.eINSTANCE.createYDelegatingFocusingStrategy(); |
| yStgy«idx».setDelegateStrategyId("«focusingStrategy.ecviewFocusingId»"); |
| yLayout.getFocusingStrategies().add(yStgy«idx»);''' |
| idx++ |
| } |
| return body |
| } |
| |
| // Helper Methods |
| def String getStrategyClassName(FocusingEnhancer focusingEnhancer, boolean osdefault) { |
| var focusingEnhancerClassName = focusingEnhancer.notDefaultStrategyClassName |
| if (osdefault){ |
| focusingEnhancerClassName = defaultStrategyClassName |
| } |
| return '''«focusingEnhancerClassName»''' |
| } |
| |
| def getNotDefaultStrategyClassName(FocusingEnhancer focusingEnhancer)'''«focusingEnhancer.name»«FOCUSING_ENHANCER_PREFIX»''' |
| def getDefaultStrategyClassName()'''Default«FOCUSING_ENHANCER_PREFIX»''' |
| |
| |
| } |