Skip to main content
summaryrefslogtreecommitdiffstats
blob: b799fa7b3c353fd0170fb2c6b2db6d6c2f5db0a2 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
 * Copyright (c) 2007, 2010, 2013 Borland Software Corporation and others
 * 
 * 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:
 *    Alexander Shatalin (Borland) - initial API and implementation
 * 	  Michael Golubev (Montages) - #372479, #386838
 */
package aspects.xpt.editor

import com.google.inject.Inject
import com.google.inject.Singleton
import metamodel.MetaModel
import org.eclipse.emf.codegen.ecore.genmodel.GenClass
import org.eclipse.gmf.codegen.gmfgen.GenCommonBase
import org.eclipse.gmf.codegen.gmfgen.GenDiagram
import org.eclipse.gmf.codegen.gmfgen.GenExpressionInterpreter
import org.eclipse.gmf.codegen.gmfgen.GenJavaExpressionProvider
import org.eclipse.gmf.codegen.gmfgen.GenLink
import org.eclipse.gmf.codegen.gmfgen.TypeModelFacet
import org.eclipse.gmf.codegen.gmfgen.ValueExpression
import xpt.CodeStyle
import xpt.Common
import xpt.expressions.getExpression
import org.eclipse.gmf.codegen.gmfgen.GenConstraint

//XXX: [MG] decide what to do with @MetaDef methods
@Singleton class VisualIDRegistry extends xpt.editor.VisualIDRegistry {

	@Inject extension MetaModel
	@Inject extension Common
	@Inject CodeStyle xptCodeStyle;
	@Inject getExpression xptGetExpression;

	override getDiagramVisualID(GenDiagram it) '''
		«generatedMemberComment()»
		public static int «getDiagramVisualIDMethodName(it)»(org.eclipse.emf.ecore.EObject domainElement) {
			if (domainElement == null) {
				«unrecognizedVID(it)»
			}
			return «visualID»;
		}
	'''

	/**
	 * Support for extra contstraints to check about model element.
	 * Includes expression fields for interpreted constrains (like ocl or regexp).
	 * For each model element that has an associated constraint, there's a method is<DomainElement>_<UID>()
	 * that performs extra specification as defined by value expression
	 * 
	 * FIXME don't use static fields, replace with instance/separate cache (e.g. accessible from Activator)
	 */
		override constraintMethods(GenDiagram it) '''
			«IF null != editorGen.expressionProviders»
				«FOR topNode : topLevelNodes.filter[n|!n.sansDomain].filter[n|n.modelFacet.modelElementSelector != null]»«constraintMethod(
				topNode)»«ENDFOR»
				«FOR childNode : childNodes.filter[n|!n.sansDomain].filter[n|n.modelFacet.modelElementSelector != null]»«constraintMethod(
				childNode)»«ENDFOR»
				«FOR link : links.filter[n|!n.sansDomain]»«constraintMethod(link.modelFacet, link)»«ENDFOR»
			«ENDIF»
		'''
	//[ExtendedConstraint] Model selector constraint
	override checkDomainElementConstraints(TypeModelFacet it, GenCommonBase commonBase) '''
«««		«IF null != modelElementSelector»
«««		//«it.eContainer»
«««		//->«modelElementSelector»
«««		«ENDIF»
		«««	 [ExtendedConstraint] START Testing the kind of ModelFacet (GenLink or Default case)
		«IF null != modelElementSelector»
			«IF commonBase instanceof GenLink || !(modelElementSelector.provider instanceof GenJavaExpressionProvider)»
				«««	[ExtendedConstraint] END   Testing the kind of ModelFacet (GenLink or Default case)
				 && «domainElementConstraintMethodName(commonBase)»(«CastEObject(metaClass,'domainElement')»)
				«««	[ExtendedConstraint] START Testing the kind of ModelFacet (GenLink or Default case) 
			«ELSE»
				 && «domainElementConstraintMethodName(commonBase)»(containerView, «CastEObject(metaClass, 'domainElement')»)
		«ENDIF»
		«ENDIF»
		«««	[ExtendedConstraint] END   Testing the kind of ModelFacet (GenLink or Default case)
	'''

//	override dispatch domainElementConstraintMethod(GenExpressionInterpreter it, GenCommonBase diagramElement,
//		ValueExpression expression, GenClass context) '''
//		«generatedMemberComment()»
//		«IF diagramElement instanceof GenLink»
//		
//		«ELSE»
//		private static boolean «domainElementConstraintMethodName(diagramElement)»(«QualifiedClassName(context)» domainElement) {
//			Object result = «xptGetExpression.getExpression(it, expression, context)».evaluate(domainElement);
//			return result instanceof Boolean && ((Boolean)result).booleanValue();
//		}			
//		«ENDIF»
//		
//	'''

	//	[ExtendedConstraint] Model selector constraint
	override dispatch domainElementConstraintMethod(GenJavaExpressionProvider it, GenCommonBase diagramElement,
		ValueExpression expression, GenClass context) '''
		«generatedMemberComment»
		«««	[ExtendedConstraint] START Testing the kind of ModelFacet (GenLink or Default case)
		«IF diagramElement instanceof GenLink»
			««« [ExtendedConstraint] END   Testing the kind of ModelFacet (GenLink or Default case)
		private static boolean «domainElementConstraintMethodName(diagramElement)»(«QualifiedClassName(context)» domainElement) {
		««« [ExtendedConstraint] START Testing the kind of ModelFacet (GenLink or Default case)
		«ELSE»
		private static boolean «domainElementConstraintMethodName(diagramElement)»(org.eclipse.gmf.runtime.notation.View containerView, «QualifiedClassName(
		context)» domainElement) {
		«ENDIF»
		««« [ExtendedConstraint] END   Testing the kind of ModelFacet (GenLink or Default case)
		«IF injectExpressionBody && (expression.body != null && expression.body.length() != 0)»
			«expression.body»
		«ELSEIF throwException || (injectExpressionBody && (expression.body == null || expression.body.length() == 0))»
			// FIXME: implement this method 
			// Ensure that you remove @generated or mark it @generated NOT
			throw new java.lang.UnsupportedOperationException("No java implementation provided in '« domainElementConstraintMethodName(diagramElement)»' operation");«nonNLS»
		«ELSE»
			return false;
		«ENDIF»
	}
	'''

	override runtimeTypedInstance(GenDiagram it) '''
		«generatedClassComment()»
		public static final org.eclipse.gmf.tooling.runtime.structure.DiagramStructure «runtimeTypedInstanceName(it)» = new org.eclipse.gmf.tooling.runtime.structure.DiagramStructure() {
			«generatedMemberComment()»
			«xptCodeStyle.overrideC(it)»
			public int «getVisualIdMethodName(it)»(org.eclipse.gmf.runtime.notation.View view) {
				return «getVisualIDMethodCall(it)»(view);
			}
			
			«generatedMemberComment()»
			«xptCodeStyle.overrideC(it)»
			public String «getModelIDMethodName(it)»(org.eclipse.gmf.runtime.notation.View view) {
				return «getModelIDMethodCall(it)»(view);
			}
			
			«generatedMemberComment()»
			«xptCodeStyle.overrideC(it)»
			public int «getNodeVisualIDMethodName(it)»(org.eclipse.gmf.runtime.notation.View containerView, org.eclipse.emf.ecore.EObject domainElement) {
				return «getNodeVisualIDMethodCall(it)»(containerView, domainElement);
			}
			
			«generatedMemberComment()»
			«xptCodeStyle.overrideC(it)»
			public boolean «checkNodeVisualIDMethodName(it)»(org.eclipse.gmf.runtime.notation.View containerView, org.eclipse.emf.ecore.EObject domainElement, int candidate) {
				return «checkNodeVisualIDMethodCall(it)»(containerView, domainElement, candidate);
			}
			
			«generatedMemberComment()»
			«xptCodeStyle.overrideC(it)»
			public boolean «isCompartmentVisualIDMethodName(it)»(int visualID) {
				return «isCompartmentVisualIDMethodCall(it)»(visualID);
			}
			
			«generatedMemberComment()»
			«xptCodeStyle.overrideC(it)»
			public boolean «isSemanticLeafVisualIDMethodName(it)»(int visualID) {
				return «isSemanticLeafVisualIDMethodCall(it)»(visualID);
			}
		};
	'''

	override getModelID(GenDiagram it) '''
		«generatedMemberComment()»
		public static String «getModelIDMethodName(it)»(org.eclipse.gmf.runtime.notation.View view) {
			org.eclipse.gmf.runtime.notation.View diagram = view.getDiagram();
			while (view != diagram) {
				org.eclipse.emf.ecore.EAnnotation annotation = view.getEAnnotation("Shortcut"); «nonNLS(1)»
				if (annotation != null) {
					return annotation.getDetails().get("modelID"); «nonNLS(1)»
				}
				view = (org.eclipse.gmf.runtime.notation.View) view.eContainer();
			}
			return diagram != null ? diagram.getType() : null;
		}
	'''
}

Back to the top