Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0328bf2294e242b94342bbf2cd91e562df71c17b (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
/*
 * Copyright (c) 2007 Borland Software Corporation
 * 
 * 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
 */

«IMPORT "http://www.eclipse.org/gmf/2005/GenModel/2.0"»
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
«IMPORT "http://www.eclipse.org/emf/2002/GenModel"»
«EXTENSION xpt::GenModelUtils»

«DEFINE ElementTypes FOR gmfgen::GenDiagram-»
«EXPAND xpt::Common::copyright FOR editorGen-»
package «providersPackageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «elementTypesClassName» {

	«EXPAND constructor-»
	
	«EXPAND attributes-»
	
	«EXPAND getImageRegistry-»

	«EXPAND getImageRegistryKey-»

	«EXPAND getProvidedImageDescriptor-»

	«EXPAND getNamedElementImageDescriptor-»

	«EXPAND getNamedElementImage-»

	«EXPAND additions-»
}
«ENDDEFINE»

«DEFINE constructor FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
private «elementTypesClassName»() {
}
«ENDDEFINE»

«DEFINE attributes FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
private static org.eclipse.jface.resource.ImageRegistry imageRegistry;
«ENDDEFINE»


«DEFINE getImageRegistry FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
private static org.eclipse.jface.resource.ImageRegistry getImageRegistry() {
	if (imageRegistry == null) {
		imageRegistry = new org.eclipse.jface.resource.ImageRegistry();
	}
	return imageRegistry;
}
«ENDDEFINE»

«DEFINE getImageRegistryKey FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
private static String getImageRegistryKey(org.eclipse.emf.ecore.ENamedElement element) {
	return element.getName();
}
«ENDDEFINE»

«DEFINE getProvidedImageDescriptor FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
private static org.eclipse.jface.resource.ImageDescriptor getProvidedImageDescriptor(org.eclipse.emf.ecore.ENamedElement element) {
	if (element instanceof org.eclipse.emf.ecore.EStructuralFeature) {
		org.eclipse.emf.ecore.EStructuralFeature feature = ((org.eclipse.emf.ecore.EStructuralFeature) element);
		org.eclipse.emf.ecore.EClass eContainingClass = feature.getEContainingClass();
		org.eclipse.emf.ecore.EClassifier eType = feature.getEType();
		if (eContainingClass != null && !eContainingClass.isAbstract()){
			element = eContainingClass;
		} else if (eType instanceof org.eclipse.emf.ecore.EClass && !((org.eclipse.emf.ecore.EClass)eType).isAbstract()){
			element = eType;
		}
	}
	if (element instanceof org.eclipse.emf.ecore.EClass) {
		org.eclipse.emf.ecore.EClass eClass = (org.eclipse.emf.ecore.EClass) element;
		if (!eClass.isAbstract()) {
			return «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().getItemImageDescriptor(
				eClass.getEPackage().getEFactoryInstance().create(eClass));
		}
	}
	// TODO : support structural features
	return null;
}
«ENDDEFINE»

«DEFINE getNamedElementImageDescriptor FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
public static org.eclipse.jface.resource.ImageDescriptor getImageDescriptor(org.eclipse.emf.ecore.ENamedElement element) {
	String key = getImageRegistryKey(element);
	org.eclipse.jface.resource.ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key);
	if (imageDescriptor == null) {
		«EXPAND loadProvidedImageDescriptor-»
	}
	return imageDescriptor;
}
«ENDDEFINE»

«DEFINE loadProvidedImageDescriptor FOR gmfgen::GenDiagram-»
imageDescriptor = getProvidedImageDescriptor(element);
if (imageDescriptor == null) {
	imageDescriptor = org.eclipse.jface.resource.ImageDescriptor.getMissingImageDescriptor();
}
getImageRegistry().put(key, imageDescriptor);
«ENDDEFINE»

«DEFINE getNamedElementImage FOR gmfgen::GenDiagram-»
	«EXPAND xpt::Common::generatedMemberComment»
public static org.eclipse.swt.graphics.Image getImage(org.eclipse.emf.ecore.ENamedElement element) {
	String key = getImageRegistryKey(element);
	org.eclipse.swt.graphics.Image image = getImageRegistry().get(key);
	if (image == null) {
		org.eclipse.jface.resource.ImageDescriptor «EXPAND loadProvidedImageDescriptor-»
		image = getImageRegistry().get(key);
	}
	return image;
}
«ENDDEFINE»

«DEFINE additions FOR gmfgen::GenDiagram-»
«ENDDEFINE»

Back to the top