Skip to main content
summaryrefslogtreecommitdiffstats
blob: c19d1bc927049631752883b09f38b5d68ebdbade (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
 *                                                                            
 *  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.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»'''

	
}

Back to the top