Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6e28d18da21ad8afcb32379c05e511bbd2145071 (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
/**
 * Copyright (c) 2006, 2014 Borland Software Corporation, 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:
 *    Dmitry Stadnik (Borland) - initial API and implementation
 *    Michael Golubev (Montages) - #386838 - migrate to Xtend2
 *    Christian W. Damus - bug 451230
 */
package aspects.xpt.providers

import aspects.xpt.CodeStyle
import com.google.inject.Inject
import com.google.inject.Singleton
import org.eclipse.gmf.codegen.gmfgen.GenCommonBase
import org.eclipse.gmf.codegen.gmfgen.GenDiagram
import xpt.Common
import xpt.diagram.Utils_qvto

@Singleton class ElementTypes extends xpt.providers.ElementTypes {
	@Inject extension Common;
	@Inject extension Utils_qvto;

	@Inject CodeStyle xptCodeStyle;

	override def getElement(GenDiagram it) '''
		«generatedMemberComment('Returns \'type\' of the ecore object associated with the hint.\n')»
		public static synchronized org.eclipse.emf.ecore.ENamedElement getElement(org.eclipse.core.runtime.IAdaptable hint) {
			Object type = hint.getAdapter(org.eclipse.gmf.runtime.emf.type.core.IElementType.class);
			if (elements == null) {
				elements = new java.util.IdentityHashMap<org.eclipse.gmf.runtime.emf.type.core.IElementType, org.eclipse.emf.ecore.ENamedElement>();
				«IF domainDiagramElement != null»«bindUniqueIdentifierToNamedElement(domainDiagramElement, getUniqueIdentifier())»«ENDIF»
				«FOR node : getAllNodes()»
					«IF node.modelFacet != null»«bindUniqueIdentifierToNamedElement(node.modelFacet, node.getUniqueIdentifier())»«ENDIF»
				«ENDFOR»
				«FOR link : it.links»
					«IF link.modelFacet != null»«bindUniqueIdentifierToNamedElement(link.modelFacet, link.getUniqueIdentifier())»«ENDIF»
				«ENDFOR»
			}
			return elements.get(type);
		}
	'''
	
	override def isKnownElementType(GenDiagram it) '''
		«generatedMemberComment»
		public static synchronized boolean isKnownElementType(org.eclipse.gmf.runtime.emf.type.core.IElementType elementType) {
			if (KNOWN_ELEMENT_TYPES == null) {
				KNOWN_ELEMENT_TYPES = new java.util.HashSet<org.eclipse.gmf.runtime.emf.type.core.IElementType>();
				«FOR e : it.getAllTypedElements()»
					«addKnownElementType(e)»
				«ENDFOR»
			}

		    boolean result = KNOWN_ELEMENT_TYPES.contains(elementType);

		    if (!result) {
		        org.eclipse.gmf.runtime.emf.type.core.IElementType[] supertypes = elementType.getAllSuperTypes();
		        for (int i = 0; !result && (i < supertypes.length); i++) {
		            result = KNOWN_ELEMENT_TYPES.contains(supertypes[i]);
		        }
		    }
		    
		    return result;
		}
	'''

    override def additions(GenDiagram it) '''
        «super.additions(it)»
        
        «generatedMemberComment»
        public static boolean isKindOf(org.eclipse.gmf.runtime.emf.type.core.IElementType subtype, org.eclipse.gmf.runtime.emf.type.core.IElementType supertype) {
            boolean result = subtype == supertype;

            if (!result) {
                org.eclipse.gmf.runtime.emf.type.core.IElementType[] supertypes = subtype.getAllSuperTypes();
                for (int i = 0; !result && (i < supertypes.length); i++) {
                    result = supertype == supertypes[i];
                }
            }

            return result;
        }
    '''

	override def getElementTypeByVisualID(GenDiagram it) '''
		«generatedMemberComment»
		public static org.eclipse.gmf.runtime.emf.type.core.IElementType getElementType(String visualID) {
			if (visualID != null) {
				switch (visualID) {
					«FOR e : it.getAllTypedElements().filter[el|el.elementType != null]»
						«caseElementType(e)»
					«ENDFOR»
				}
			}
			return null;
		}
	'''

	override def getElementType(GenDiagram it) '''
		«generatedMemberComment»
		private static org.eclipse.gmf.runtime.emf.type.core.IElementType getElementTypeByUniqueId(String id) {
			return org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry.getInstance().getType(id);
		}
	'''

	override def elementTypeField(GenCommonBase it) '''
		«IF null != elementType»
			«generatedMemberComment»
			public static final org.eclipse.gmf.runtime.emf.type.core.IElementType «getUniqueIdentifier()» = getElementTypeByUniqueId("«elementType.
			uniqueIdentifier»"); «nonNLS(1)»
		«ENDIF»
	'''

	override def typedInstance(GenDiagram it) '''
		«generatedClassComment»
		public static final org.eclipse.papyrus.infra.gmfdiag.common.providers.DiagramElementTypes TYPED_INSTANCE 
			= new org.eclipse.papyrus.infra.gmfdiag.common.providers.DiagramElementTypes(elementTypeImages) {
			
			«generatedMemberComment»
			«xptCodeStyle.overrideC(it)»
			public boolean isKnownElementType(org.eclipse.gmf.runtime.emf.type.core.IElementType elementType) {
				return «qualifiedClassName(it)».isKnownElementType(elementType);
			}
			
			«generatedMemberComment»
			«xptCodeStyle.overrideC(it)»
			public org.eclipse.gmf.runtime.emf.type.core.IElementType getElementTypeForVisualId(String visualID) {
				return «qualifiedClassName(it)».getElementType(visualID);
			}
			
			«generatedMemberComment»
			«xptCodeStyle.overrideC(it)»
			public org.eclipse.emf.ecore.ENamedElement getDefiningNamedElement(org.eclipse.core.runtime.IAdaptable elementTypeAdapter) {
				return «qualifiedClassName(it)».getElement(elementTypeAdapter);
			}
		}; 
	'''
}

Back to the top