Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a8597c8c1027b828cf153a4daddd4cde28138994 (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
/*****************************************************************************
 * Copyright (c) 2015 Christian W. Damus 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:
 *   Christian W. Damus - Initial API and implementation
 *   
 *****************************************************************************/

package aspects.xpt.providers

import javax.inject.Inject
import javax.inject.Singleton
import org.eclipse.gmf.codegen.gmfgen.GenDiagram
import org.eclipse.papyrus.papyrusgmfgenextension.GenVisualTypeProvider
import xpt.CodeStyle
import xpt.Common
import xpt.editor.VisualIDRegistry
import xpt.providers.ElementTypes

/**
 * Template for the class that plugs in knowledge of the Visual IDs of this diagram
 * into the {@code VisualTypeService}.
 */
@Singleton class VisualTypeProvider {
	
	@Inject extension Common
	@Inject extension CodeStyle
	@Inject VisualIDRegistry visualIDs
	@Inject ElementTypes elementTypes
	
	def getPackageName(GenDiagram it) '''«it.providersPackageName»'''
	
	def getClassName(GenDiagram it) '''«GenVisualTypeProvider.getClassName(it)»'''
	
	def getQualifiedClassName(GenDiagram it) '''«packageName».«className»'''
	
	protected def constructor(GenDiagram it) '''
		«generatedMemberComment»
		public «it.className»() {
			super();
		}
	'''

	protected def getElementType_(GenDiagram it) '''
		«generatedMemberComment»
		«overrideI»
		public org.eclipse.gmf.runtime.emf.type.core.IElementType getElementType(org.eclipse.gmf.runtime.notation.Diagram diagram, String viewType) {
			org.eclipse.gmf.runtime.emf.type.core.IElementType result = null;
			
			try {
				result = «elementTypes.qualifiedClassName(it)».getElementType(Integer.parseInt(viewType));
			} catch (NumberFormatException e) {
				// Not supported by this diagram
			}
			
			return result;
		}
	'''

	protected def getNodeType(GenDiagram it) '''
		«generatedMemberComment»
		«overrideI»
		public String getNodeType(View parentView, EObject element) {
			int result = «visualIDs.getNodeVisualIDMethodCall(it)»(parentView, element);
			return (result < 0) ? null : Integer.toString(result);
		}
	'''

	protected def getLinkType(GenDiagram it) '''
		«generatedMemberComment»
		«overrideI»
		public String getLinkType(Diagram diagram, EObject element) {
			int result = «visualIDs.getLinkWithClassVisualIDMethodCall(it)»(element);
			return (result < 0) ? null : Integer.toString(result);
		}
	'''

	public def VisualTypeProvider(GenDiagram it) '''
		«editorGen.copyright»
		package «packageName»;
		
		«generatedClassComment»
		public class «className» extends org.eclipse.papyrus.infra.gmfdiag.common.service.visualtype.AbstractVisualTypeProvider {
		
			«constructor»
			
			«getElementType_»
			
			«getNodeType»
			
			«getLinkType»
			
		}
	'''
}

Back to the top