View | Details | Raw Unified | Return to bug 148402 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/gmf/internal/graphdef/codegen/ui/StandaloneGeneratorConfigAdapter.java (-1 / +1 lines)
Lines 13-19 Link Here
13
13
14
import org.eclipse.gmf.graphdef.codegen.StandaloneGenerator;
14
import org.eclipse.gmf.graphdef.codegen.StandaloneGenerator;
15
15
16
public class StandaloneGeneratorConfigAdapter implements StandaloneGenerator.Config {
16
public class StandaloneGeneratorConfigAdapter extends StandaloneGenerator.Config {
17
	private final ConverterSection mySection;
17
	private final ConverterSection mySection;
18
18
19
	public StandaloneGeneratorConfigAdapter(ConverterSection section){
19
	public StandaloneGeneratorConfigAdapter(ConverterSection section){
(-)src/org/eclipse/gmf/tests/gen/ShapePropertiesTest.java (-12 / +8 lines)
Lines 15-25 Link Here
15
import java.util.Iterator;
15
import java.util.Iterator;
16
16
17
import org.eclipse.gmf.gmfgraph.BasicFont;
17
import org.eclipse.gmf.gmfgraph.BasicFont;
18
import org.eclipse.gmf.gmfgraph.Color;
19
import org.eclipse.gmf.gmfgraph.ColorConstants;
18
import org.eclipse.gmf.gmfgraph.ColorConstants;
20
import org.eclipse.gmf.gmfgraph.CompoundBorder;
19
import org.eclipse.gmf.gmfgraph.CompoundBorder;
21
import org.eclipse.gmf.gmfgraph.ConstantColor;
22
import org.eclipse.gmf.gmfgraph.Dimension;
20
import org.eclipse.gmf.gmfgraph.Dimension;
21
import org.eclipse.gmf.gmfgraph.FontStyle;
23
import org.eclipse.gmf.gmfgraph.GMFGraphFactory;
22
import org.eclipse.gmf.gmfgraph.GMFGraphFactory;
24
import org.eclipse.gmf.gmfgraph.Insets;
23
import org.eclipse.gmf.gmfgraph.Insets;
25
import org.eclipse.gmf.gmfgraph.LineBorder;
24
import org.eclipse.gmf.gmfgraph.LineBorder;
Lines 53-58 Link Here
53
		shape.setName("Bold");
52
		shape.setName("Bold");
54
		performTests(shape);
53
		performTests(shape);
55
	}
54
	}
55
	
56
	public void testShapeFont(){
57
		Shape shape = GMFGraphFactory.eINSTANCE.createRoundedRectangle();
58
		shape.setName("WithArialFont");
59
		shape.setFont(createBasicFont("Arial", 10, FontStyle.NORMAL_LITERAL));
60
		performTests(shape);
61
	}
56
62
57
	public void testShapeInsets() {
63
	public void testShapeInsets() {
58
		Rectangle withInsets = GMFGraphFactory.eINSTANCE.createRectangle();
64
		Rectangle withInsets = GMFGraphFactory.eINSTANCE.createRectangle();
Lines 192-199 Link Here
192
		performTests(root);
198
		performTests(root);
193
	}
199
	}
194
	
200
	
195
	
196
	
197
	private Dimension createDimension(int x, int y){
201
	private Dimension createDimension(int x, int y){
198
		Dimension result = GMFGraphFactory.eINSTANCE.createDimension();
202
		Dimension result = GMFGraphFactory.eINSTANCE.createDimension();
199
		result.setDx(x);
203
		result.setDx(x);
Lines 201-212 Link Here
201
		return result;
205
		return result;
202
	}
206
	}
203
	
207
	
204
	private Color createConstantColor(ColorConstants constant) {
205
		ConstantColor result = GMFGraphFactory.eINSTANCE.createConstantColor();
206
		result.setValue(constant);
207
		return result;
208
	}
209
	
210
	
211
212
}
208
}
(-)src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java (+64 lines)
Lines 28-35 Link Here
28
import org.eclipse.gmf.gmfgraph.CustomFigure;
28
import org.eclipse.gmf.gmfgraph.CustomFigure;
29
import org.eclipse.gmf.gmfgraph.Dimension;
29
import org.eclipse.gmf.gmfgraph.Dimension;
30
import org.eclipse.gmf.gmfgraph.Figure;
30
import org.eclipse.gmf.gmfgraph.Figure;
31
import org.eclipse.gmf.gmfgraph.FontStyle;
31
import org.eclipse.gmf.gmfgraph.GMFGraphFactory;
32
import org.eclipse.gmf.gmfgraph.GMFGraphFactory;
32
import org.eclipse.gmf.gmfgraph.Insets;
33
import org.eclipse.gmf.gmfgraph.Insets;
34
import org.eclipse.gmf.gmfgraph.Label;
35
import org.eclipse.gmf.gmfgraph.LineBorder;
36
import org.eclipse.gmf.gmfgraph.Rectangle;
33
import org.eclipse.gmf.gmfgraph.util.RuntimeFQNSwitch;
37
import org.eclipse.gmf.gmfgraph.util.RuntimeFQNSwitch;
34
import org.eclipse.gmf.graphdef.codegen.FigureGenerator;
38
import org.eclipse.gmf.graphdef.codegen.FigureGenerator;
35
import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx;
39
import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx;
Lines 206-209 Link Here
206
		custom.setName(CodeGenUtil.getSimpleClassName(ScrollBar.class.getName()));
210
		custom.setName(CodeGenUtil.getSimpleClassName(ScrollBar.class.getName()));
207
		performTests(custom, CHECK_CAN_CREATE_INSTANCE);
211
		performTests(custom, CHECK_CAN_CREATE_INSTANCE);
208
	}
212
	}
213
	
214
	public void testFigureWithTwoBorderedChildren(){
215
		//check that border color static fields do not clash with each other 
216
		Figure root = GMFGraphFactory.eINSTANCE.createRectangle();
217
		root.setName("MultiBorderedRoot");
218
		
219
		Figure constantlyBordered = GMFGraphFactory.eINSTANCE.createRectangle();
220
		constantlyBordered.setName("WithRedConstantBorder");
221
		LineBorder constantRedBorder = GMFGraphFactory.eINSTANCE.createLineBorder();
222
		constantRedBorder.setColor(createConstantColor(ColorConstants.RED_LITERAL));
223
		constantRedBorder.setWidth(5);
224
		constantlyBordered.setBorder(constantRedBorder);
225
		root.getChildren().add(constantlyBordered);
226
		
227
		Figure rgbBordered = GMFGraphFactory.eINSTANCE.createRectangle();
228
		rgbBordered.setName("WithRedRGBBorder");
229
		LineBorder rgbRedBorder = GMFGraphFactory.eINSTANCE.createLineBorder();
230
		rgbRedBorder.setColor(createRGBColor(255, 0, 0));
231
		rgbRedBorder.setWidth(7);
232
		rgbBordered.setBorder(rgbRedBorder);
233
		root.getChildren().add(rgbBordered);
234
		
235
		performTests(root);
236
	}
237
	
238
	public void testFigureWithStaticFieldsForColorAndFonts(){
239
		Figure root = GMFGraphFactory.eINSTANCE.createEllipse();
240
		root.setName("FullOfColorsAndFonts");
241
		root.setFont(createBasicFont("Arial", 23, FontStyle.BOLD_LITERAL));
242
		root.setForegroundColor(createRGBColor(111, 111, 111));
243
		root.setBackgroundColor(createConstantColor(ColorConstants.GREEN_LITERAL));
244
		
245
		Label sansLabel = GMFGraphFactory.eINSTANCE.createLabel();
246
		sansLabel.setName("SansLabel");
247
		sansLabel.setFont(createBasicFont("Sans", 8, FontStyle.ITALIC_LITERAL));
248
		sansLabel.setForegroundColor(createRGBColor(112, 112, 112));
249
		root.getChildren().add(sansLabel);
250
		
251
		Label tahomaLabel = GMFGraphFactory.eINSTANCE.createLabel();
252
		tahomaLabel.setName("TahomaLabel");
253
		tahomaLabel.setFont(createBasicFont("Tahoma", 12, FontStyle.NORMAL_LITERAL));
254
		tahomaLabel.setForegroundColor(createRGBColor(113, 113, 113));
255
		root.getChildren().add(tahomaLabel);
256
		
257
		Rectangle deepLabelContainer = GMFGraphFactory.eINSTANCE.createRectangle();
258
		deepLabelContainer.setName("DeepLabelContainer");
259
		deepLabelContainer.setForegroundColor(createRGBColor(114, 114, 114));
260
		deepLabelContainer.setBackgroundColor(createRGBColor(114, 114, 114)); //the same
261
		root.getChildren().add(deepLabelContainer);
262
		
263
		Label defaultFontLabel = GMFGraphFactory.eINSTANCE.createLabel();
264
		defaultFontLabel.setName("DefaultFontLabel");
265
		defaultFontLabel.setFont(createBasicFont(null, 34, FontStyle.BOLD_LITERAL));
266
		defaultFontLabel.setForegroundColor(createRGBColor(114, 114, 114)); //again the same as above
267
		deepLabelContainer.getChildren().add(defaultFontLabel);
268
		
269
		//TODO: check that only 4 colors are instantiated (not trivial)
270
		performTests(root);
271
	}
272
	
209
}
273
}
(-)src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java (-14 / +28 lines)
Lines 33-38 Link Here
33
import org.eclipse.gmf.gmfgraph.Ellipse;
33
import org.eclipse.gmf.gmfgraph.Ellipse;
34
import org.eclipse.gmf.gmfgraph.Figure;
34
import org.eclipse.gmf.gmfgraph.Figure;
35
import org.eclipse.gmf.gmfgraph.FigureGallery;
35
import org.eclipse.gmf.gmfgraph.FigureGallery;
36
import org.eclipse.gmf.gmfgraph.Font;
36
import org.eclipse.gmf.gmfgraph.FontStyle;
37
import org.eclipse.gmf.gmfgraph.FontStyle;
37
import org.eclipse.gmf.gmfgraph.GMFGraphFactory;
38
import org.eclipse.gmf.gmfgraph.GMFGraphFactory;
38
import org.eclipse.gmf.gmfgraph.Label;
39
import org.eclipse.gmf.gmfgraph.Label;
Lines 41-46 Link Here
41
import org.eclipse.gmf.gmfgraph.Polygon;
42
import org.eclipse.gmf.gmfgraph.Polygon;
42
import org.eclipse.gmf.gmfgraph.PolygonDecoration;
43
import org.eclipse.gmf.gmfgraph.PolygonDecoration;
43
import org.eclipse.gmf.gmfgraph.PolylineConnection;
44
import org.eclipse.gmf.gmfgraph.PolylineConnection;
45
import org.eclipse.gmf.gmfgraph.RGBColor;
44
import org.eclipse.gmf.gmfgraph.Rectangle;
46
import org.eclipse.gmf.gmfgraph.Rectangle;
45
import org.eclipse.gmf.gmfgraph.RoundedRectangle;
47
import org.eclipse.gmf.gmfgraph.RoundedRectangle;
46
import org.eclipse.gmf.gmfgraph.util.RuntimeFQNSwitch;
48
import org.eclipse.gmf.gmfgraph.util.RuntimeFQNSwitch;
Lines 142-148 Link Here
142
		try {
144
		try {
143
			StandaloneGenerator generator = new StandaloneGenerator(new GalleryProcessor(gallery), config, new RuntimeFQNSwitch());
145
			StandaloneGenerator generator = new StandaloneGenerator(new GalleryProcessor(gallery), config, new RuntimeFQNSwitch());
144
			generator.run();
146
			generator.run();
145
			assertTrue(generator.getRunStatus().getSeverity() < IStatus.ERROR);
147
			assertTrue(generator.getRunStatus().toString(), generator.getRunStatus().getSeverity() < IStatus.ERROR);
146
			
148
			
147
			Bundle bundle = installPlugin(config.getPluginID());
149
			Bundle bundle = installPlugin(config.getPluginID());
148
			
150
			
Lines 210-231 Link Here
210
		Label l1 = GMFGraphFactory.eINSTANCE.createLabel();
212
		Label l1 = GMFGraphFactory.eINSTANCE.createLabel();
211
		l1.setText("aaaaa");
213
		l1.setText("aaaaa");
212
		l1.setName("L1");
214
		l1.setName("L1");
213
		BasicFont f1 = GMFGraphFactory.eINSTANCE.createBasicFont();
215
		l1.setFont(createBasicFont("Arial", 9, FontStyle.ITALIC_LITERAL));
214
		f1.setFaceName("Arial");
216
		l1.setForegroundColor(createConstantColor(ColorConstants.CYAN_LITERAL));
215
		f1.setHeight(9);
216
		f1.setStyle(FontStyle.ITALIC_LITERAL);
217
		l1.setFont(f1);
218
		ConstantColor c = GMFGraphFactory.eINSTANCE.createConstantColor();
219
		c.setValue(ColorConstants.CYAN_LITERAL);
220
		l1.setForegroundColor(c);
221
		Label l2 = GMFGraphFactory.eINSTANCE.createLabel();
217
		Label l2 = GMFGraphFactory.eINSTANCE.createLabel();
222
		l2.setText("bbbbb");
218
		l2.setText("bbbbb");
223
		l2.setName("L2");
219
		l2.setName("L2");
224
		BasicFont f2 = GMFGraphFactory.eINSTANCE.createBasicFont();
220
		l2.setFont(createBasicFont("Helvetica", 12, FontStyle.BOLD_LITERAL));
225
		f2.setFaceName("Helvetica");
226
		f2.setHeight(12);
227
		f2.setStyle(FontStyle.BOLD_LITERAL);
228
		l2.setFont(f2);
229
		r.getChildren().add(l1);
221
		r.getChildren().add(l1);
230
		r.getChildren().add(l2);
222
		r.getChildren().add(l2);
231
		return r;
223
		return r;
Lines 350-355 Link Here
350
		return combineChecks(new FigureCheck[] {first, second});
342
		return combineChecks(new FigureCheck[] {first, second});
351
	}
343
	}
352
	
344
	
345
	protected static final ConstantColor createConstantColor(ColorConstants constant) {
346
		ConstantColor result = GMFGraphFactory.eINSTANCE.createConstantColor();
347
		result.setValue(constant);
348
		return result;
349
	}
350
	
351
	protected static final RGBColor createRGBColor(int red, int green, int blue) {
352
		RGBColor result = GMFGraphFactory.eINSTANCE.createRGBColor();
353
		result.setRed(red);
354
		result.setGreen(green);
355
		result.setBlue(blue);
356
		return result;
357
	}
358
359
	protected static final Font createBasicFont(String name, int height, FontStyle style){
360
		BasicFont result = GMFGraphFactory.eINSTANCE.createBasicFont();
361
		result.setFaceName(name);
362
		result.setHeight(height);
363
		result.setStyle(style);
364
		return result;
365
	}
366
	
353
	protected static class GeneratedClassData {
367
	protected static class GeneratedClassData {
354
		private final Figure myFigureDef;
368
		private final Figure myFigureDef;
355
		private final Class myLoadedClass;
369
		private final Class myLoadedClass;
(-)src/org/eclipse/gmf/internal/common/codegen/Knowledge.java (+30 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2006 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Michael Golubev (Borland) - initial API and implementation
11
 */
12
13
package org.eclipse.gmf.internal.common.codegen;
14
15
public class Knowledge {
16
	/**
17
	 * This class name used in the GMFGraph codegeneration templates but the
18
	 * class itself is generated externally (either by
19
	 * org.eclipse.gmf.codegen.util.Generator or by
20
	 * org.eclipse.gmf.graphdef.codegen.StandaloneGenerator).
21
	 * 
22
	 * Thus we can not place this constant into the gmfgen model and allow user
23
	 * to tweak it.
24
	 * 
25
	 * The GMFGraph codegenerator assumes that the class with this name is
26
	 * always generated in the same package as Figure's code.
27
	 */
28
	public static final String LAZY_RESOURCE_REGISTRY_CLASS_NAME = "LazyResourceRegistry";
29
30
}
(-)templates/plugin/manifest.mfjet (+1 lines)
Lines 44-49 Link Here
44
allRequiredBundles.add("org.eclipse.draw2d");
44
allRequiredBundles.add("org.eclipse.draw2d");
45
allRequiredBundles.add("org.eclipse.osgi");
45
allRequiredBundles.add("org.eclipse.osgi");
46
allRequiredBundles.add("org.eclipse.core.runtime");
46
allRequiredBundles.add("org.eclipse.core.runtime");
47
allRequiredBundles.add("org.eclipse.jface");
47
allRequiredBundles.addAll(java.util.Arrays.asList(requiredBundles));
48
allRequiredBundles.addAll(java.util.Arrays.asList(requiredBundles));
48
if (config.needsMapMode()) {
49
if (config.needsMapMode()) {
49
	allRequiredBundles.add("org.eclipse.gmf.runtime.draw2d.ui");
50
	allRequiredBundles.add("org.eclipse.gmf.runtime.draw2d.ui");
(-)templates/plugin/Plugin.javajet (+33 lines)
Lines 30-35 Link Here
30
<%
30
<%
31
if (config.needsMapMode()){
31
if (config.needsMapMode()){
32
%>
32
%>
33
	/**
34
	 * @generated
35
	 */
33
	private IMapMode myMapMode = MapModeTypes.IDENTITY_MM;
36
	private IMapMode myMapMode = MapModeTypes.IDENTITY_MM;
34
<%
37
<%
35
}
38
}
Lines 38-43 Link Here
38
	/**
41
	/**
39
	 * @generated
42
	 * @generated
40
	 */
43
	 */
44
	private <%=importManager.getImportedName("org.eclipse.jface.resource.ColorRegistry")%> myColorRegistry;
45
46
	/**
47
	 * @generated
48
	 */
49
	private <%=importManager.getImportedName("org.eclipse.jface.resource.FontRegistry")%> myFontRegistry;
50
51
	/**
52
	 * @generated
53
	 */
41
	public static final String ID = "<%=config.getPluginID()%>"; //$NON-NLS-1$
54
	public static final String ID = "<%=config.getPluginID()%>"; //$NON-NLS-1$
42
55
43
	/**
56
	/**
Lines 100-105 Link Here
100
	/**
113
	/**
101
	 * @generated
114
	 * @generated
102
	 */
115
	 */
116
	public <%=importManager.getImportedName("org.eclipse.jface.resource.ColorRegistry")%> getColorRegistry() {
117
		if (myColorRegistry == null) {
118
			myColorRegistry = new <%=importManager.getImportedName("org.eclipse.jface.resource.ColorRegistry")%>();
119
		}
120
		return myColorRegistry;
121
	}
122
123
	/**
124
	 * @generated
125
	 */
126
	public <%=importManager.getImportedName("org.eclipse.jface.resource.FontRegistry")%> getFontRegistry() {
127
		if (myFontRegistry == null) {
128
			myFontRegistry = new <%=importManager.getImportedName("org.eclipse.jface.resource.FontRegistry")%>();
129
		}
130
		return myFontRegistry;
131
	}
132
133
	/**
134
	 * @generated
135
	 */
103
	public static <%=config.getPluginActivatorClassName()%> getDefault() {
136
	public static <%=config.getPluginActivatorClassName()%> getDefault() {
104
		return ourInstance;
137
		return ourInstance;
105
	}
138
	}
(-)templates/attr/Figure.javajet (-1 / +1 lines)
Lines 37-43 Link Here
37
			}
37
			}
38
		}
38
		}
39
		%>
39
		%>
40
		<%=figureVarName%>.setFont(new <%=importManager.getImportedName("org.eclipse.swt.graphics.Font")%>(<%=importManager.getImportedName("org.eclipse.swt.widgets.Display")%>.getCurrent(), "<%=fontName%>", <%=font.getHeight()%>, <%=importManager.getImportedName("org.eclipse.swt.SWT")%>.<%=font.getStyle().getLiteral()%>));
40
		<%=figureVarName%>.setFont(getLazyResourceRegistry().getFont("<%=fontName%>", <%=font.getHeight()%>, <%=importManager.getImportedName("org.eclipse.swt.SWT")%>.<%=font.getStyle().getLiteral()%>));
41
<%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Insets())) {
41
<%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Insets())) {
42
		Insets insets = figureInstance.getInsets();%>
42
		Insets insets = figureInstance.getInsets();%>
43
		<%=figureVarName%>.setBorder(new <%=importManager.getImportedName("org.eclipse.draw2d.MarginBorder")%>(<%=dispatcher.DPtoLP(insets.getTop())%>, <%=dispatcher.DPtoLP(insets.getLeft())%>, <%=dispatcher.DPtoLP(insets.getBottom())%>, <%=dispatcher.DPtoLP(insets.getRight())%>));
43
		<%=figureVarName%>.setBorder(new <%=importManager.getImportedName("org.eclipse.draw2d.MarginBorder")%>(<%=dispatcher.DPtoLP(insets.getTop())%>, <%=dispatcher.DPtoLP(insets.getLeft())%>, <%=dispatcher.DPtoLP(insets.getBottom())%>, <%=dispatcher.DPtoLP(insets.getRight())%>));
(-)src/org/eclipse/gmf/graphdef/codegen/templates/FigureAttrGenerator.java (-106 / +94 lines)
Lines 18-75 Link Here
18
  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
18
  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
19
  protected final String TEXT_1 = "\t\t";
19
  protected final String TEXT_1 = "\t\t";
20
  protected final String TEXT_2 = ".setForegroundColor(";
20
  protected final String TEXT_2 = ".setForegroundColor(";
21
  protected final String TEXT_3 = "new ";
21
  protected final String TEXT_3 = "getLazyResourceRegistry().getColor(";
22
  protected final String TEXT_4 = "(null, ";
22
  protected final String TEXT_4 = ", ";
23
  protected final String TEXT_5 = ", ";
23
  protected final String TEXT_5 = ", ";
24
  protected final String TEXT_6 = ", ";
24
  protected final String TEXT_6 = ")";
25
  protected final String TEXT_7 = ")";
25
  protected final String TEXT_7 = ".";
26
  protected final String TEXT_8 = ".";
26
  protected final String TEXT_8 = ");";
27
  protected final String TEXT_9 = ");";
27
  protected final String TEXT_9 = NL + "\t\t";
28
  protected final String TEXT_10 = NL + "\t\t";
28
  protected final String TEXT_10 = ".setBackgroundColor(";
29
  protected final String TEXT_11 = ".setBackgroundColor(";
29
  protected final String TEXT_11 = "getLazyResourceRegistry().getColor(";
30
  protected final String TEXT_12 = "new ";
30
  protected final String TEXT_12 = ", ";
31
  protected final String TEXT_13 = "(null, ";
31
  protected final String TEXT_13 = ", ";
32
  protected final String TEXT_14 = ", ";
32
  protected final String TEXT_14 = ")";
33
  protected final String TEXT_15 = ", ";
33
  protected final String TEXT_15 = ".";
34
  protected final String TEXT_16 = ")";
34
  protected final String TEXT_16 = ");";
35
  protected final String TEXT_17 = ".";
35
  protected final String TEXT_17 = NL + "\t\t";
36
  protected final String TEXT_18 = ");";
36
  protected final String TEXT_18 = ".setPreferredSize(";
37
  protected final String TEXT_19 = NL + "\t\t";
37
  protected final String TEXT_19 = ", ";
38
  protected final String TEXT_20 = ".setPreferredSize(";
38
  protected final String TEXT_20 = ");";
39
  protected final String TEXT_21 = ", ";
39
  protected final String TEXT_21 = NL + "\t\t";
40
  protected final String TEXT_22 = ");";
40
  protected final String TEXT_22 = ".setSize(";
41
  protected final String TEXT_23 = NL + "\t\t";
41
  protected final String TEXT_23 = ", ";
42
  protected final String TEXT_24 = ".setSize(";
42
  protected final String TEXT_24 = ");";
43
  protected final String TEXT_25 = ", ";
43
  protected final String TEXT_25 = NL + "\t\t";
44
  protected final String TEXT_26 = ");";
44
  protected final String TEXT_26 = ".setMaximumSize(new ";
45
  protected final String TEXT_27 = NL + "\t\t";
45
  protected final String TEXT_27 = "(";
46
  protected final String TEXT_28 = ".setMaximumSize(new ";
46
  protected final String TEXT_28 = ", ";
47
  protected final String TEXT_29 = "(";
47
  protected final String TEXT_29 = "));";
48
  protected final String TEXT_30 = ", ";
48
  protected final String TEXT_30 = NL + "\t\t";
49
  protected final String TEXT_31 = "));";
49
  protected final String TEXT_31 = ".setMinimumSize(new ";
50
  protected final String TEXT_32 = NL + "\t\t";
50
  protected final String TEXT_32 = "(";
51
  protected final String TEXT_33 = ".setMinimumSize(new ";
51
  protected final String TEXT_33 = ", ";
52
  protected final String TEXT_34 = "(";
52
  protected final String TEXT_34 = "));";
53
  protected final String TEXT_35 = ", ";
53
  protected final String TEXT_35 = NL + "\t\t";
54
  protected final String TEXT_36 = "));";
54
  protected final String TEXT_36 = ".setFont(getLazyResourceRegistry().getFont(\"";
55
  protected final String TEXT_37 = NL + "\t\t";
55
  protected final String TEXT_37 = "\", ";
56
  protected final String TEXT_38 = ".setFont(new ";
56
  protected final String TEXT_38 = ", ";
57
  protected final String TEXT_39 = "(";
57
  protected final String TEXT_39 = ".";
58
  protected final String TEXT_40 = ".getCurrent(), \"";
58
  protected final String TEXT_40 = "));";
59
  protected final String TEXT_41 = "\", ";
59
  protected final String TEXT_41 = NL + "\t\t";
60
  protected final String TEXT_42 = ", ";
60
  protected final String TEXT_42 = ".setBorder(new ";
61
  protected final String TEXT_43 = ".";
61
  protected final String TEXT_43 = "(";
62
  protected final String TEXT_44 = "));";
62
  protected final String TEXT_44 = ", ";
63
  protected final String TEXT_45 = NL + "\t\t";
63
  protected final String TEXT_45 = ", ";
64
  protected final String TEXT_46 = ".setBorder(new ";
64
  protected final String TEXT_46 = ", ";
65
  protected final String TEXT_47 = "(";
65
  protected final String TEXT_47 = "));";
66
  protected final String TEXT_48 = ", ";
66
  protected final String TEXT_48 = NL + "\t\t";
67
  protected final String TEXT_49 = ", ";
67
  protected final String TEXT_49 = ".setBorder(";
68
  protected final String TEXT_50 = ", ";
68
  protected final String TEXT_50 = ");";
69
  protected final String TEXT_51 = "));";
70
  protected final String TEXT_52 = NL + "\t\t";
71
  protected final String TEXT_53 = ".setBorder(";
72
  protected final String TEXT_54 = ");";
73
69
74
  public String generate(Object argument)
70
  public String generate(Object argument)
75
  {
71
  {
Lines 89-169 Link Here
89
    stringBuffer.append(TEXT_2);
85
    stringBuffer.append(TEXT_2);
90
    if (colorVal instanceof RGBColor) {
86
    if (colorVal instanceof RGBColor) {
91
    stringBuffer.append(TEXT_3);
87
    stringBuffer.append(TEXT_3);
92
    stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Color"));
93
    stringBuffer.append(TEXT_4);
94
    stringBuffer.append(((RGBColor) colorVal).getRed());
88
    stringBuffer.append(((RGBColor) colorVal).getRed());
95
    stringBuffer.append(TEXT_5);
89
    stringBuffer.append(TEXT_4);
96
    stringBuffer.append(((RGBColor) colorVal).getGreen());
90
    stringBuffer.append(((RGBColor) colorVal).getGreen());
97
    stringBuffer.append(TEXT_6);
91
    stringBuffer.append(TEXT_5);
98
    stringBuffer.append(((RGBColor) colorVal).getBlue());
92
    stringBuffer.append(((RGBColor) colorVal).getBlue());
99
    stringBuffer.append(TEXT_7);
93
    stringBuffer.append(TEXT_6);
100
    } else if (colorVal instanceof ConstantColor) {
94
    } else if (colorVal instanceof ConstantColor) {
101
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants"));
95
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants"));
102
    stringBuffer.append(TEXT_8);
96
    stringBuffer.append(TEXT_7);
103
    stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral());
97
    stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral());
104
    }
98
    }
105
    stringBuffer.append(TEXT_9);
99
    stringBuffer.append(TEXT_8);
106
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_BackgroundColor())) {
100
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_BackgroundColor())) {
107
		colorVal = figureInstance.getBackgroundColor();
101
		colorVal = figureInstance.getBackgroundColor();
108
    stringBuffer.append(TEXT_10);
102
    stringBuffer.append(TEXT_9);
109
    stringBuffer.append(figureVarName);
103
    stringBuffer.append(figureVarName);
110
    stringBuffer.append(TEXT_11);
104
    stringBuffer.append(TEXT_10);
111
    if (colorVal instanceof RGBColor) {
105
    if (colorVal instanceof RGBColor) {
112
    stringBuffer.append(TEXT_12);
106
    stringBuffer.append(TEXT_11);
113
    stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Color"));
114
    stringBuffer.append(TEXT_13);
115
    stringBuffer.append(((RGBColor) colorVal).getRed());
107
    stringBuffer.append(((RGBColor) colorVal).getRed());
116
    stringBuffer.append(TEXT_14);
108
    stringBuffer.append(TEXT_12);
117
    stringBuffer.append(((RGBColor) colorVal).getGreen());
109
    stringBuffer.append(((RGBColor) colorVal).getGreen());
118
    stringBuffer.append(TEXT_15);
110
    stringBuffer.append(TEXT_13);
119
    stringBuffer.append(((RGBColor) colorVal).getBlue());
111
    stringBuffer.append(((RGBColor) colorVal).getBlue());
120
    stringBuffer.append(TEXT_16);
112
    stringBuffer.append(TEXT_14);
121
    } else if (colorVal instanceof ConstantColor) {
113
    } else if (colorVal instanceof ConstantColor) {
122
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants"));
114
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants"));
123
    stringBuffer.append(TEXT_17);
115
    stringBuffer.append(TEXT_15);
124
    stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral());
116
    stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral());
125
    }
117
    }
126
    stringBuffer.append(TEXT_18);
118
    stringBuffer.append(TEXT_16);
127
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_PreferredSize())) {
119
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_PreferredSize())) {
128
		Dimension d = figureInstance.getPreferredSize();
120
		Dimension d = figureInstance.getPreferredSize();
129
    stringBuffer.append(TEXT_19);
121
    stringBuffer.append(TEXT_17);
130
    stringBuffer.append(figureVarName);
122
    stringBuffer.append(figureVarName);
131
    stringBuffer.append(TEXT_20);
123
    stringBuffer.append(TEXT_18);
132
    stringBuffer.append(dispatcher.DPtoLP(d.getDx()));
124
    stringBuffer.append(dispatcher.DPtoLP(d.getDx()));
133
    stringBuffer.append(TEXT_21);
125
    stringBuffer.append(TEXT_19);
134
    stringBuffer.append(dispatcher.DPtoLP(d.getDy()));
126
    stringBuffer.append(dispatcher.DPtoLP(d.getDy()));
135
    stringBuffer.append(TEXT_22);
127
    stringBuffer.append(TEXT_20);
136
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Size())) {
128
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Size())) {
137
		Point p = figureInstance.getSize();
129
		Point p = figureInstance.getSize();
138
    stringBuffer.append(TEXT_23);
130
    stringBuffer.append(TEXT_21);
139
    stringBuffer.append(figureVarName);
131
    stringBuffer.append(figureVarName);
140
    stringBuffer.append(TEXT_24);
132
    stringBuffer.append(TEXT_22);
141
    stringBuffer.append(dispatcher.DPtoLP(p.getX()));
133
    stringBuffer.append(dispatcher.DPtoLP(p.getX()));
142
    stringBuffer.append(TEXT_25);
134
    stringBuffer.append(TEXT_23);
143
    stringBuffer.append(dispatcher.DPtoLP(p.getY()));
135
    stringBuffer.append(dispatcher.DPtoLP(p.getY()));
144
    stringBuffer.append(TEXT_26);
136
    stringBuffer.append(TEXT_24);
145
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MaximumSize())) {
137
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MaximumSize())) {
146
		Dimension d = figureInstance.getMaximumSize();
138
		Dimension d = figureInstance.getMaximumSize();
147
    stringBuffer.append(TEXT_27);
139
    stringBuffer.append(TEXT_25);
148
    stringBuffer.append(figureVarName);
140
    stringBuffer.append(figureVarName);
149
    stringBuffer.append(TEXT_28);
141
    stringBuffer.append(TEXT_26);
150
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.geometry.Dimension"));
142
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.geometry.Dimension"));
151
    stringBuffer.append(TEXT_29);
143
    stringBuffer.append(TEXT_27);
152
    stringBuffer.append(dispatcher.DPtoLP(d.getDx()));
144
    stringBuffer.append(dispatcher.DPtoLP(d.getDx()));
153
    stringBuffer.append(TEXT_30);
145
    stringBuffer.append(TEXT_28);
154
    stringBuffer.append(dispatcher.DPtoLP(d.getDy()));
146
    stringBuffer.append(dispatcher.DPtoLP(d.getDy()));
155
    stringBuffer.append(TEXT_31);
147
    stringBuffer.append(TEXT_29);
156
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MinimumSize())) {
148
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MinimumSize())) {
157
		Dimension d = figureInstance.getMinimumSize();
149
		Dimension d = figureInstance.getMinimumSize();
158
    stringBuffer.append(TEXT_32);
150
    stringBuffer.append(TEXT_30);
159
    stringBuffer.append(figureVarName);
151
    stringBuffer.append(figureVarName);
160
    stringBuffer.append(TEXT_33);
152
    stringBuffer.append(TEXT_31);
161
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.geometry.Dimension"));
153
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.geometry.Dimension"));
162
    stringBuffer.append(TEXT_34);
154
    stringBuffer.append(TEXT_32);
163
    stringBuffer.append(dispatcher.DPtoLP(d.getDx()));
155
    stringBuffer.append(dispatcher.DPtoLP(d.getDx()));
164
    stringBuffer.append(TEXT_35);
156
    stringBuffer.append(TEXT_33);
165
    stringBuffer.append(dispatcher.DPtoLP(d.getDy()));
157
    stringBuffer.append(dispatcher.DPtoLP(d.getDy()));
166
    stringBuffer.append(TEXT_36);
158
    stringBuffer.append(TEXT_34);
167
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Font())) {
159
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Font())) {
168
		// XXX possible CCE when fonts other than Basic added to model 
160
		// XXX possible CCE when fonts other than Basic added to model 
169
		BasicFont font = (BasicFont) figureInstance.getFont();
161
		BasicFont font = (BasicFont) figureInstance.getFont();
Lines 175-217 Link Here
175
			}
167
			}
176
		}
168
		}
177
		
169
		
178
    stringBuffer.append(TEXT_37);
170
    stringBuffer.append(TEXT_35);
179
    stringBuffer.append(figureVarName);
171
    stringBuffer.append(figureVarName);
180
    stringBuffer.append(TEXT_38);
172
    stringBuffer.append(TEXT_36);
181
    stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Font"));
182
    stringBuffer.append(TEXT_39);
183
    stringBuffer.append(importManager.getImportedName("org.eclipse.swt.widgets.Display"));
184
    stringBuffer.append(TEXT_40);
185
    stringBuffer.append(fontName);
173
    stringBuffer.append(fontName);
186
    stringBuffer.append(TEXT_41);
174
    stringBuffer.append(TEXT_37);
187
    stringBuffer.append(font.getHeight());
175
    stringBuffer.append(font.getHeight());
188
    stringBuffer.append(TEXT_42);
176
    stringBuffer.append(TEXT_38);
189
    stringBuffer.append(importManager.getImportedName("org.eclipse.swt.SWT"));
177
    stringBuffer.append(importManager.getImportedName("org.eclipse.swt.SWT"));
190
    stringBuffer.append(TEXT_43);
178
    stringBuffer.append(TEXT_39);
191
    stringBuffer.append(font.getStyle().getLiteral());
179
    stringBuffer.append(font.getStyle().getLiteral());
192
    stringBuffer.append(TEXT_44);
180
    stringBuffer.append(TEXT_40);
193
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Insets())) {
181
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Insets())) {
194
		Insets insets = figureInstance.getInsets();
182
		Insets insets = figureInstance.getInsets();
195
    stringBuffer.append(TEXT_45);
183
    stringBuffer.append(TEXT_41);
196
    stringBuffer.append(figureVarName);
184
    stringBuffer.append(figureVarName);
197
    stringBuffer.append(TEXT_46);
185
    stringBuffer.append(TEXT_42);
198
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.MarginBorder"));
186
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.MarginBorder"));
199
    stringBuffer.append(TEXT_47);
187
    stringBuffer.append(TEXT_43);
200
    stringBuffer.append(dispatcher.DPtoLP(insets.getTop()));
188
    stringBuffer.append(dispatcher.DPtoLP(insets.getTop()));
201
    stringBuffer.append(TEXT_48);
189
    stringBuffer.append(TEXT_44);
202
    stringBuffer.append(dispatcher.DPtoLP(insets.getLeft()));
190
    stringBuffer.append(dispatcher.DPtoLP(insets.getLeft()));
203
    stringBuffer.append(TEXT_49);
191
    stringBuffer.append(TEXT_45);
204
    stringBuffer.append(dispatcher.DPtoLP(insets.getBottom()));
192
    stringBuffer.append(dispatcher.DPtoLP(insets.getBottom()));
205
    stringBuffer.append(TEXT_50);
193
    stringBuffer.append(TEXT_46);
206
    stringBuffer.append(dispatcher.DPtoLP(insets.getRight()));
194
    stringBuffer.append(dispatcher.DPtoLP(insets.getRight()));
207
    stringBuffer.append(TEXT_51);
195
    stringBuffer.append(TEXT_47);
208
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Border())) {
196
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Border())) {
209
		Border border = figureInstance.getBorder();
197
		Border border = figureInstance.getBorder();
210
    stringBuffer.append(TEXT_52);
198
    stringBuffer.append(TEXT_48);
211
    stringBuffer.append(figureVarName);
199
    stringBuffer.append(figureVarName);
212
    stringBuffer.append(TEXT_53);
200
    stringBuffer.append(TEXT_49);
213
    stringBuffer.append(dispatcher.dispatch(border, new Object[] {border, dispatcher}));
201
    stringBuffer.append(dispatcher.dispatch(border, new Object[] {border, dispatcher}));
214
    stringBuffer.append(TEXT_54);
202
    stringBuffer.append(TEXT_50);
215
    }
203
    }
216
    return stringBuffer.toString();
204
    return stringBuffer.toString();
217
  }
205
  }
(-)src/org/eclipse/gmf/graphdef/codegen/templates/NewLineBorderExpressionGenerator.java (-45 / +39 lines)
Lines 18-46 Link Here
18
  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
18
  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
19
  protected final String TEXT_1 = "new ";
19
  protected final String TEXT_1 = "new ";
20
  protected final String TEXT_2 = "(";
20
  protected final String TEXT_2 = "(";
21
  protected final String TEXT_3 = "new ";
21
  protected final String TEXT_3 = "getLazyResourceRegistry().getColor(";
22
  protected final String TEXT_4 = "(null, ";
22
  protected final String TEXT_4 = ", ";
23
  protected final String TEXT_5 = ", ";
23
  protected final String TEXT_5 = ", ";
24
  protected final String TEXT_6 = ", ";
24
  protected final String TEXT_6 = ")";
25
  protected final String TEXT_7 = ")";
25
  protected final String TEXT_7 = ".";
26
  protected final String TEXT_8 = ".";
26
  protected final String TEXT_8 = ", ";
27
  protected final String TEXT_9 = ", ";
27
  protected final String TEXT_9 = ")";
28
  protected final String TEXT_10 = ")";
28
  protected final String TEXT_10 = NL + "new ";
29
  protected final String TEXT_11 = NL + "new ";
29
  protected final String TEXT_11 = "(";
30
  protected final String TEXT_12 = "(";
30
  protected final String TEXT_12 = "getLazyResourceRegistry().getColor(";
31
  protected final String TEXT_13 = "new ";
31
  protected final String TEXT_13 = ", ";
32
  protected final String TEXT_14 = "(null, ";
32
  protected final String TEXT_14 = ", ";
33
  protected final String TEXT_15 = ", ";
33
  protected final String TEXT_15 = ")";
34
  protected final String TEXT_16 = ", ";
34
  protected final String TEXT_16 = ".";
35
  protected final String TEXT_17 = ")";
35
  protected final String TEXT_17 = ")";
36
  protected final String TEXT_18 = ".";
36
  protected final String TEXT_18 = NL + "new ";
37
  protected final String TEXT_19 = ")";
37
  protected final String TEXT_19 = "(";
38
  protected final String TEXT_20 = NL + "new ";
38
  protected final String TEXT_20 = ")";
39
  protected final String TEXT_21 = "(";
39
  protected final String TEXT_21 = NL + "new ";
40
  protected final String TEXT_22 = ")";
40
  protected final String TEXT_22 = "()";
41
  protected final String TEXT_23 = NL + "new ";
41
  protected final String TEXT_23 = NL;
42
  protected final String TEXT_24 = "()";
43
  protected final String TEXT_25 = NL;
44
42
45
  public String generate(Object argument)
43
  public String generate(Object argument)
46
  {
44
  {
Lines 66-127 Link Here
66
    stringBuffer.append(TEXT_2);
64
    stringBuffer.append(TEXT_2);
67
    if (colorVal instanceof RGBColor) {
65
    if (colorVal instanceof RGBColor) {
68
    stringBuffer.append(TEXT_3);
66
    stringBuffer.append(TEXT_3);
69
    stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Color"));
70
    stringBuffer.append(TEXT_4);
71
    stringBuffer.append(((RGBColor) colorVal).getRed());
67
    stringBuffer.append(((RGBColor) colorVal).getRed());
72
    stringBuffer.append(TEXT_5);
68
    stringBuffer.append(TEXT_4);
73
    stringBuffer.append(((RGBColor) colorVal).getGreen());
69
    stringBuffer.append(((RGBColor) colorVal).getGreen());
74
    stringBuffer.append(TEXT_6);
70
    stringBuffer.append(TEXT_5);
75
    stringBuffer.append(((RGBColor) colorVal).getBlue());
71
    stringBuffer.append(((RGBColor) colorVal).getBlue());
76
    stringBuffer.append(TEXT_7);
72
    stringBuffer.append(TEXT_6);
77
    } else if (colorVal instanceof ConstantColor) {
73
    } else if (colorVal instanceof ConstantColor) {
78
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants"));
74
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants"));
79
    stringBuffer.append(TEXT_8);
75
    stringBuffer.append(TEXT_7);
80
    stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral());
76
    stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral());
81
    }
77
    }
82
    stringBuffer.append(TEXT_9);
78
    stringBuffer.append(TEXT_8);
83
    stringBuffer.append(dispatcher.DPtoLP(border.getWidth()));
79
    stringBuffer.append(dispatcher.DPtoLP(border.getWidth()));
84
    stringBuffer.append(TEXT_10);
80
    stringBuffer.append(TEXT_9);
85
    
81
    
86
	} else if (hasColor && !hasWidth) {
82
	} else if (hasColor && !hasWidth) {
87
83
88
    stringBuffer.append(TEXT_11);
84
    stringBuffer.append(TEXT_10);
89
    stringBuffer.append(borderClazz);
85
    stringBuffer.append(borderClazz);
90
    stringBuffer.append(TEXT_12);
86
    stringBuffer.append(TEXT_11);
91
    if (colorVal instanceof RGBColor) {
87
    if (colorVal instanceof RGBColor) {
92
    stringBuffer.append(TEXT_13);
88
    stringBuffer.append(TEXT_12);
93
    stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Color"));
94
    stringBuffer.append(TEXT_14);
95
    stringBuffer.append(((RGBColor) colorVal).getRed());
89
    stringBuffer.append(((RGBColor) colorVal).getRed());
96
    stringBuffer.append(TEXT_15);
90
    stringBuffer.append(TEXT_13);
97
    stringBuffer.append(((RGBColor) colorVal).getGreen());
91
    stringBuffer.append(((RGBColor) colorVal).getGreen());
98
    stringBuffer.append(TEXT_16);
92
    stringBuffer.append(TEXT_14);
99
    stringBuffer.append(((RGBColor) colorVal).getBlue());
93
    stringBuffer.append(((RGBColor) colorVal).getBlue());
100
    stringBuffer.append(TEXT_17);
94
    stringBuffer.append(TEXT_15);
101
    } else if (colorVal instanceof ConstantColor) {
95
    } else if (colorVal instanceof ConstantColor) {
102
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants"));
96
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants"));
103
    stringBuffer.append(TEXT_18);
97
    stringBuffer.append(TEXT_16);
104
    stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral());
98
    stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral());
105
    }
99
    }
106
    stringBuffer.append(TEXT_19);
100
    stringBuffer.append(TEXT_17);
107
    
101
    
108
	} else if (!hasColor && hasWidth){
102
	} else if (!hasColor && hasWidth){
109
103
110
    stringBuffer.append(TEXT_20);
104
    stringBuffer.append(TEXT_18);
111
    stringBuffer.append(borderClazz);
105
    stringBuffer.append(borderClazz);
112
    stringBuffer.append(TEXT_21);
106
    stringBuffer.append(TEXT_19);
113
    stringBuffer.append(dispatcher.DPtoLP(border.getWidth()));
107
    stringBuffer.append(dispatcher.DPtoLP(border.getWidth()));
114
    stringBuffer.append(TEXT_22);
108
    stringBuffer.append(TEXT_20);
115
    
109
    
116
	} else {
110
	} else {
117
111
118
    stringBuffer.append(TEXT_23);
112
    stringBuffer.append(TEXT_21);
119
    stringBuffer.append(borderClazz);
113
    stringBuffer.append(borderClazz);
120
    stringBuffer.append(TEXT_24);
114
    stringBuffer.append(TEXT_22);
121
    
115
    
122
	} 
116
	} 
123
117
124
    stringBuffer.append(TEXT_25);
118
    stringBuffer.append(TEXT_23);
125
    return stringBuffer.toString();
119
    return stringBuffer.toString();
126
  }
120
  }
127
}
121
}
(-)src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java (-22 / +40 lines)
Lines 20-37 Link Here
20
  protected final String TEXT_1 = "";
20
  protected final String TEXT_1 = "";
21
  protected final String TEXT_2 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
21
  protected final String TEXT_2 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
22
  protected final String TEXT_3 = " extends ";
22
  protected final String TEXT_3 = " extends ";
23
  protected final String TEXT_4 = " {" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
23
  protected final String TEXT_4 = " {" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\t private final ";
24
  protected final String TEXT_5 = "() {";
24
  protected final String TEXT_5 = " fLazyResourceRegistry;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
25
  protected final String TEXT_6 = "\t" + NL + "\t\t";
25
  protected final String TEXT_6 = "() {" + NL + "\t\tthis(new ";
26
  protected final String TEXT_7 = NL + "\t\t";
26
  protected final String TEXT_7 = "());" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
27
  protected final String TEXT_8 = NL + "\t\tcreateContents();" + NL + "\t}" + NL;
27
  protected final String TEXT_8 = "(";
28
  protected final String TEXT_9 = NL;
28
  protected final String TEXT_9 = " lazyResourceRegistry) {" + NL + "\t\tfLazyResourceRegistry = lazyResourceRegistry;";
29
  protected final String TEXT_10 = NL;
29
  protected final String TEXT_10 = "\t" + NL + "\t\t";
30
  protected final String TEXT_11 = NL;
30
  protected final String TEXT_11 = NL + "\t\t";
31
  protected final String TEXT_12 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate boolean myUseLocalCoordinates = ";
31
  protected final String TEXT_12 = NL + "\t\tcreateContents();" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
32
  protected final String TEXT_13 = ";" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected boolean useLocalCoordinates() {" + NL + "\t\treturn myUseLocalCoordinates;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected void setUseLocalCoordinates(boolean useLocalCoordinates) {" + NL + "\t\tmyUseLocalCoordinates = useLocalCoordinates;" + NL + "\t}" + NL + "\t";
32
  protected final String TEXT_13 = " getLazyResourceRegistry(){" + NL + "\t\treturn fLazyResourceRegistry;" + NL + "\t}" + NL + "\t";
33
  protected final String TEXT_14 = NL + "}";
33
  protected final String TEXT_14 = NL;
34
  protected final String TEXT_15 = NL;
34
  protected final String TEXT_15 = NL;
35
  protected final String TEXT_16 = NL;
36
  protected final String TEXT_17 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate boolean myUseLocalCoordinates = ";
37
  protected final String TEXT_18 = ";" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected boolean useLocalCoordinates() {" + NL + "\t\treturn myUseLocalCoordinates;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected void setUseLocalCoordinates(boolean useLocalCoordinates) {" + NL + "\t\tmyUseLocalCoordinates = useLocalCoordinates;" + NL + "\t}" + NL + "\t";
38
  protected final String TEXT_19 = NL + "}";
39
  protected final String TEXT_20 = NL;
35
40
36
  public String generate(Object argument)
41
  public String generate(Object argument)
37
  {
42
  {
Lines 43-48 Link Here
43
final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2];
48
final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2];
44
final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3];
49
final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3];
45
50
51
//assuming the class with such name is in the same package -- no FQN
52
final String LAZY_RESOURCE_REGISTRY_CLASS = org.eclipse.gmf.internal.common.codegen.Knowledge.LAZY_RESOURCE_REGISTRY_CLASS_NAME;
53
46
    importManager.emitPackageStatement(stringBuffer);
54
    importManager.emitPackageStatement(stringBuffer);
47
    stringBuffer.append(TEXT_1);
55
    stringBuffer.append(TEXT_1);
48
    importManager.markImportLocation(stringBuffer);
56
    importManager.markImportLocation(stringBuffer);
Lines 51-71 Link Here
51
    stringBuffer.append(TEXT_3);
59
    stringBuffer.append(TEXT_3);
52
    stringBuffer.append(fqnSwitch.get(figure, importManager));
60
    stringBuffer.append(fqnSwitch.get(figure, importManager));
53
    stringBuffer.append(TEXT_4);
61
    stringBuffer.append(TEXT_4);
54
    stringBuffer.append(figure.getName());
62
    stringBuffer.append(LAZY_RESOURCE_REGISTRY_CLASS);
55
    stringBuffer.append(TEXT_5);
63
    stringBuffer.append(TEXT_5);
64
    stringBuffer.append(figure.getName());
65
    stringBuffer.append(TEXT_6);
66
    stringBuffer.append(LAZY_RESOURCE_REGISTRY_CLASS);
67
    stringBuffer.append(TEXT_7);
68
    stringBuffer.append(figure.getName());
69
    stringBuffer.append(TEXT_8);
70
    stringBuffer.append(LAZY_RESOURCE_REGISTRY_CLASS);
71
    stringBuffer.append(TEXT_9);
56
    
72
    
57
GraphDefDispatcher.LayoutArgs dispatcherArgs = dispatcher.createLayoutArgs(figure, "this", "myGenLayoutManager", null);
73
GraphDefDispatcher.LayoutArgs dispatcherArgs = dispatcher.createLayoutArgs(figure, "this", "myGenLayoutManager", null);
58
74
59
    stringBuffer.append(TEXT_6);
75
    stringBuffer.append(TEXT_10);
60
    stringBuffer.append(dispatcher.dispatch("createLayout", dispatcherArgs));
76
    stringBuffer.append(dispatcher.dispatch("createLayout", dispatcherArgs));
61
    stringBuffer.append(TEXT_7);
77
    stringBuffer.append(TEXT_11);
62
    stringBuffer.append(dispatcher.dispatch(figure, dispatcherArgs));
78
    stringBuffer.append(dispatcher.dispatch(figure, dispatcherArgs));
63
    stringBuffer.append(TEXT_8);
79
    stringBuffer.append(TEXT_12);
64
    stringBuffer.append(TEXT_9);
80
    stringBuffer.append(LAZY_RESOURCE_REGISTRY_CLASS);
81
    stringBuffer.append(TEXT_13);
82
    stringBuffer.append(TEXT_14);
65
    stringBuffer.append(dispatcher.dispatch("Children", dispatcherArgs));
83
    stringBuffer.append(dispatcher.dispatch("Children", dispatcherArgs));
66
    stringBuffer.append(TEXT_10);
84
    stringBuffer.append(TEXT_15);
67
    if (false == figure instanceof Polyline) {/*no much sense to define useLocalCoordinates for polyline and its descendants*/
85
    if (false == figure instanceof Polyline) {/*no much sense to define useLocalCoordinates for polyline and its descendants*/
68
    stringBuffer.append(TEXT_11);
86
    stringBuffer.append(TEXT_16);
69
    
87
    
70
// simple heuristic to detect need for local coordinates
88
// simple heuristic to detect need for local coordinates
71
boolean useLocalDefaultValue = false;
89
boolean useLocalDefaultValue = false;
Lines 76-88 Link Here
76
	}
94
	}
77
}
95
}
78
96
79
    stringBuffer.append(TEXT_12);
97
    stringBuffer.append(TEXT_17);
80
    stringBuffer.append(useLocalDefaultValue);
98
    stringBuffer.append(useLocalDefaultValue);
81
    stringBuffer.append(TEXT_13);
99
    stringBuffer.append(TEXT_18);
82
    }
100
    }
83
    stringBuffer.append(TEXT_14);
101
    stringBuffer.append(TEXT_19);
84
    importManager.emitSortedImports();
102
    importManager.emitSortedImports();
85
    stringBuffer.append(TEXT_15);
103
    stringBuffer.append(TEXT_20);
86
    return stringBuffer.toString();
104
    return stringBuffer.toString();
87
  }
105
  }
88
}
106
}
(-)src/org/eclipse/gmf/graphdef/codegen/standalone/templates/ManifestMFGenerator.java (+1 lines)
Lines 71-76 Link Here
71
allRequiredBundles.add("org.eclipse.draw2d");
71
allRequiredBundles.add("org.eclipse.draw2d");
72
allRequiredBundles.add("org.eclipse.osgi");
72
allRequiredBundles.add("org.eclipse.osgi");
73
allRequiredBundles.add("org.eclipse.core.runtime");
73
allRequiredBundles.add("org.eclipse.core.runtime");
74
allRequiredBundles.add("org.eclipse.jface");
74
allRequiredBundles.addAll(java.util.Arrays.asList(requiredBundles));
75
allRequiredBundles.addAll(java.util.Arrays.asList(requiredBundles));
75
if (config.needsMapMode()) {
76
if (config.needsMapMode()) {
76
	allRequiredBundles.add("org.eclipse.gmf.runtime.draw2d.ui");
77
	allRequiredBundles.add("org.eclipse.gmf.runtime.draw2d.ui");
(-)src/org/eclipse/gmf/graphdef/codegen/standalone/templates/PluginActivatorGenerator.java (-16 / +34 lines)
Lines 20-34 Link Here
20
  protected final String TEXT_3 = NL + NL + "import org.osgi.framework.BundleContext;";
20
  protected final String TEXT_3 = NL + NL + "import org.osgi.framework.BundleContext;";
21
  protected final String TEXT_4 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
21
  protected final String TEXT_4 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
22
  protected final String TEXT_5 = " extends Plugin {" + NL;
22
  protected final String TEXT_5 = " extends Plugin {" + NL;
23
  protected final String TEXT_6 = NL + "\tprivate IMapMode myMapMode = MapModeTypes.IDENTITY_MM;";
23
  protected final String TEXT_6 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate IMapMode myMapMode = MapModeTypes.IDENTITY_MM;";
24
  protected final String TEXT_7 = NL + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final String ID = \"";
24
  protected final String TEXT_7 = NL + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
25
  protected final String TEXT_8 = "\"; //$NON-NLS-1$" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static ";
25
  protected final String TEXT_8 = " myColorRegistry;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
26
  protected final String TEXT_9 = " ourInstance;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
26
  protected final String TEXT_9 = " myFontRegistry;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final String ID = \"";
27
  protected final String TEXT_10 = "() {" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void start(BundleContext context) throws Exception {" + NL + "\t\tsuper.start(context);" + NL + "\t\tif (ourInstance != null){" + NL + "\t\t\tthrow new IllegalStateException(\"Plugin: \" + ID + \" already started\");" + NL + "\t\t}" + NL + "\t\tourInstance = this;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void stop(BundleContext context) throws Exception {" + NL + "\t\tif (ourInstance == null){" + NL + "\t\t\tthrow new IllegalStateException(\"Plugin: \" + ID + \" is not started\");" + NL + "\t\t}" + NL + "\t\tourInstance = null;" + NL + "\t\tsuper.stop(context);" + NL + "\t}" + NL + "\t";
27
  protected final String TEXT_10 = "\"; //$NON-NLS-1$" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static ";
28
  protected final String TEXT_11 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void setMapMode(IMapMode mapMode) {" + NL + "\t\tmyMapMode = mapMode;" + NL + "\t\tif (myMapMode == null){" + NL + "\t\t\tmyMapMode = MapModeTypes.IDENTITY_MM;" + NL + "\t\t}" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic IMapMode getMapMode() {" + NL + "\t\treturn myMapMode;" + NL + "\t}" + NL;
28
  protected final String TEXT_11 = " ourInstance;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
29
  protected final String TEXT_12 = NL + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static ";
29
  protected final String TEXT_12 = "() {" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void start(BundleContext context) throws Exception {" + NL + "\t\tsuper.start(context);" + NL + "\t\tif (ourInstance != null){" + NL + "\t\t\tthrow new IllegalStateException(\"Plugin: \" + ID + \" already started\");" + NL + "\t\t}" + NL + "\t\tourInstance = this;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void stop(BundleContext context) throws Exception {" + NL + "\t\tif (ourInstance == null){" + NL + "\t\t\tthrow new IllegalStateException(\"Plugin: \" + ID + \" is not started\");" + NL + "\t\t}" + NL + "\t\tourInstance = null;" + NL + "\t\tsuper.stop(context);" + NL + "\t}" + NL + "\t";
30
  protected final String TEXT_13 = " getDefault() {" + NL + "\t\treturn ourInstance;" + NL + "\t}" + NL + "}";
30
  protected final String TEXT_13 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void setMapMode(IMapMode mapMode) {" + NL + "\t\tmyMapMode = mapMode;" + NL + "\t\tif (myMapMode == null){" + NL + "\t\t\tmyMapMode = MapModeTypes.IDENTITY_MM;" + NL + "\t\t}" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic IMapMode getMapMode() {" + NL + "\t\treturn myMapMode;" + NL + "\t}" + NL;
31
  protected final String TEXT_14 = NL;
31
  protected final String TEXT_14 = NL + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
32
  protected final String TEXT_15 = " getColorRegistry() {" + NL + "\t\tif (myColorRegistry == null) {" + NL + "\t\t\tmyColorRegistry = new ";
33
  protected final String TEXT_16 = "();" + NL + "\t\t}" + NL + "\t\treturn myColorRegistry;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
34
  protected final String TEXT_17 = " getFontRegistry() {" + NL + "\t\tif (myFontRegistry == null) {" + NL + "\t\t\tmyFontRegistry = new ";
35
  protected final String TEXT_18 = "();" + NL + "\t\t}" + NL + "\t\treturn myFontRegistry;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static ";
36
  protected final String TEXT_19 = " getDefault() {" + NL + "\t\treturn ourInstance;" + NL + "\t}" + NL + "}";
37
  protected final String TEXT_20 = NL;
32
38
33
  public String generate(Object argument)
39
  public String generate(Object argument)
34
  {
40
  {
Lines 61-84 Link Here
61
}
67
}
62
68
63
    stringBuffer.append(TEXT_7);
69
    stringBuffer.append(TEXT_7);
64
    stringBuffer.append(config.getPluginID());
70
    stringBuffer.append(importManager.getImportedName("org.eclipse.jface.resource.ColorRegistry"));
65
    stringBuffer.append(TEXT_8);
71
    stringBuffer.append(TEXT_8);
66
    stringBuffer.append(config.getPluginActivatorClassName());
72
    stringBuffer.append(importManager.getImportedName("org.eclipse.jface.resource.FontRegistry"));
67
    stringBuffer.append(TEXT_9);
73
    stringBuffer.append(TEXT_9);
68
    stringBuffer.append(config.getPluginActivatorClassName());
74
    stringBuffer.append(config.getPluginID());
69
    stringBuffer.append(TEXT_10);
75
    stringBuffer.append(TEXT_10);
76
    stringBuffer.append(config.getPluginActivatorClassName());
77
    stringBuffer.append(TEXT_11);
78
    stringBuffer.append(config.getPluginActivatorClassName());
79
    stringBuffer.append(TEXT_12);
70
    
80
    
71
if (config.needsMapMode()){
81
if (config.needsMapMode()){
72
82
73
    stringBuffer.append(TEXT_11);
83
    stringBuffer.append(TEXT_13);
74
    
84
    
75
}
85
}
76
86
77
    stringBuffer.append(TEXT_12);
87
    stringBuffer.append(TEXT_14);
88
    stringBuffer.append(importManager.getImportedName("org.eclipse.jface.resource.ColorRegistry"));
89
    stringBuffer.append(TEXT_15);
90
    stringBuffer.append(importManager.getImportedName("org.eclipse.jface.resource.ColorRegistry"));
91
    stringBuffer.append(TEXT_16);
92
    stringBuffer.append(importManager.getImportedName("org.eclipse.jface.resource.FontRegistry"));
93
    stringBuffer.append(TEXT_17);
94
    stringBuffer.append(importManager.getImportedName("org.eclipse.jface.resource.FontRegistry"));
95
    stringBuffer.append(TEXT_18);
78
    stringBuffer.append(config.getPluginActivatorClassName());
96
    stringBuffer.append(config.getPluginActivatorClassName());
79
    stringBuffer.append(TEXT_13);
97
    stringBuffer.append(TEXT_19);
80
    importManager.emitSortedImports();
98
    importManager.emitSortedImports();
81
    stringBuffer.append(TEXT_14);
99
    stringBuffer.append(TEXT_20);
82
    return stringBuffer.toString();
100
    return stringBuffer.toString();
83
  }
101
  }
84
}
102
}
(-)templates/top/Figure.javajet (-1 / +24 lines)
Lines 6-11 Link Here
6
final ImportAssistant importManager = (ImportAssistant) args[1];
6
final ImportAssistant importManager = (ImportAssistant) args[1];
7
final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2];
7
final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2];
8
final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3];
8
final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3];
9
10
//assuming the class with such name is in the same package -- no FQN
11
final String LAZY_RESOURCE_REGISTRY_CLASS = org.eclipse.gmf.internal.common.codegen.Knowledge.LAZY_RESOURCE_REGISTRY_CLASS_NAME;
9
%>
12
%>
10
<%importManager.emitPackageStatement(stringBuffer);%>
13
<%importManager.emitPackageStatement(stringBuffer);%>
11
14
Lines 19-25 Link Here
19
	/**
22
	/**
20
	 * @generated
23
	 * @generated
21
	 */
24
	 */
25
	 private final <%=LAZY_RESOURCE_REGISTRY_CLASS%> fLazyResourceRegistry;
26
27
	/**
28
	 * @generated
29
	 */
22
	public <%=figure.getName()%>() {
30
	public <%=figure.getName()%>() {
31
		this(new <%=LAZY_RESOURCE_REGISTRY_CLASS%>());
32
	}
33
34
	/**
35
	 * @generated
36
	 */
37
	public <%=figure.getName()%>(<%=LAZY_RESOURCE_REGISTRY_CLASS%> lazyResourceRegistry) {
38
		fLazyResourceRegistry = lazyResourceRegistry;
23
<%
39
<%
24
GraphDefDispatcher.LayoutArgs dispatcherArgs = dispatcher.createLayoutArgs(figure, "this", "myGenLayoutManager", null);
40
GraphDefDispatcher.LayoutArgs dispatcherArgs = dispatcher.createLayoutArgs(figure, "this", "myGenLayoutManager", null);
25
%>	
41
%>	
Lines 27-33 Link Here
27
		<%=dispatcher.dispatch(figure, dispatcherArgs)%>
43
		<%=dispatcher.dispatch(figure, dispatcherArgs)%>
28
		createContents();
44
		createContents();
29
	}
45
	}
30
46
	
47
	/**
48
	 * @generated
49
	 */
50
	private <%=LAZY_RESOURCE_REGISTRY_CLASS%> getLazyResourceRegistry(){
51
		return fLazyResourceRegistry;
52
	}
53
	
31
<%=dispatcher.dispatch("Children", dispatcherArgs)%>
54
<%=dispatcher.dispatch("Children", dispatcherArgs)%>
32
55
33
<%if (false == figure instanceof Polyline) {/*no much sense to define useLocalCoordinates for polyline and its descendants*/%>
56
<%if (false == figure instanceof Polyline) {/*no much sense to define useLocalCoordinates for polyline and its descendants*/%>
(-)src/org/eclipse/gmf/graphdef/codegen/StandaloneEmitters.java (-1 / +7 lines)
Lines 14-19 Link Here
14
import org.eclipse.core.runtime.Platform;
14
import org.eclipse.core.runtime.Platform;
15
import org.eclipse.gmf.common.UnexpectedBehaviourException;
15
import org.eclipse.gmf.common.UnexpectedBehaviourException;
16
import org.eclipse.gmf.graphdef.codegen.standalone.templates.BuildPropertiesGenerator;
16
import org.eclipse.gmf.graphdef.codegen.standalone.templates.BuildPropertiesGenerator;
17
import org.eclipse.gmf.graphdef.codegen.standalone.templates.LazyResourceRegistryGenerator;
17
import org.eclipse.gmf.graphdef.codegen.standalone.templates.ManifestMFGenerator;
18
import org.eclipse.gmf.graphdef.codegen.standalone.templates.ManifestMFGenerator;
18
import org.eclipse.gmf.graphdef.codegen.standalone.templates.PluginActivatorGenerator;
19
import org.eclipse.gmf.graphdef.codegen.standalone.templates.PluginActivatorGenerator;
19
import org.eclipse.gmf.graphdef.codegen.standalone.templates.PluginPropertiesGenerator;
20
import org.eclipse.gmf.graphdef.codegen.standalone.templates.PluginPropertiesGenerator;
Lines 45-50 Link Here
45
	public TextEmitter getPluginActivatorEmitter() throws UnexpectedBehaviourException {
46
	public TextEmitter getPluginActivatorEmitter() throws UnexpectedBehaviourException {
46
		return getRegistered(PluginActivatorGenerator.class);
47
		return getRegistered(PluginActivatorGenerator.class);
47
	}
48
	}
49
	
50
	public TextEmitter getLazyResourceRegistryEmitter() throws UnexpectedBehaviourException {
51
		return getRegistered(LazyResourceRegistryGenerator.class);
52
	}
48
53
49
	private TextEmitter getRegistered(Class key) throws UnexpectedBehaviourException {
54
	private TextEmitter getRegistered(Class key) throws UnexpectedBehaviourException {
50
		try {
55
		try {
Lines 64-70 Link Here
64
		registerTemplate(result, BuildPropertiesGenerator.class, "/plugin/build.propertiesjet");
69
		registerTemplate(result, BuildPropertiesGenerator.class, "/plugin/build.propertiesjet");
65
		registerTemplate(result, ManifestMFGenerator.class, "/plugin/manifest.mfjet");
70
		registerTemplate(result, ManifestMFGenerator.class, "/plugin/manifest.mfjet");
66
		registerTemplate(result, PluginPropertiesGenerator.class, "/plugin/plugin.propertiesjet");
71
		registerTemplate(result, PluginPropertiesGenerator.class, "/plugin/plugin.propertiesjet");
67
		registerTemplate(result, PluginActivatorGenerator.class, "/plugin/plugin.javajet");
72
		registerTemplate(result, PluginActivatorGenerator.class, "/plugin/Plugin.javajet");
73
		registerTemplate(result, LazyResourceRegistryGenerator.class, "/plugin/LazyResourceRegistry.javajet");
68
		return result;
74
		return result;
69
	}
75
	}
70
	
76
	
(-)src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java (-16 / +24 lines)
Lines 22-27 Link Here
22
import org.eclipse.gmf.internal.common.codegen.DelegateImportManager;
22
import org.eclipse.gmf.internal.common.codegen.DelegateImportManager;
23
import org.eclipse.gmf.internal.common.codegen.GeneratorBase;
23
import org.eclipse.gmf.internal.common.codegen.GeneratorBase;
24
import org.eclipse.gmf.internal.common.codegen.ImportUtil;
24
import org.eclipse.gmf.internal.common.codegen.ImportUtil;
25
import org.eclipse.gmf.internal.common.codegen.Knowledge;
25
26
26
public class StandaloneGenerator extends GeneratorBase {
27
public class StandaloneGenerator extends GeneratorBase {
27
	private final Config myArgs;
28
	private final Config myArgs;
Lines 32-50 Link Here
32
	private final FigureQualifiedNameSwitch myFigureNameSwitch;
33
	private final FigureQualifiedNameSwitch myFigureNameSwitch;
33
	private Processor myProcessor;
34
	private Processor myProcessor;
34
	
35
	
35
	public interface Config {
36
	public abstract static class Config {
36
		public String getPluginID();
37
		public abstract String getPluginID();
37
		public String getPluginFriendlyName();
38
		public abstract String getPluginFriendlyName();
38
		public String getPluginProviderName();
39
		public abstract String getPluginProviderName();
39
		public String getMainPackageName();
40
		public abstract String getMainPackageName();
40
41
41
		public String getPluginActivatorClassName();
42
		public abstract String getPluginActivatorClassName();
42
		public String getPluginActivatorPackageName();
43
		public abstract String getPluginActivatorPackageName();
44
		
45
		public abstract boolean needsMapMode();
43
46
44
		public boolean needsMapMode();
47
		public final String getPluginActivatorFullyQualifiedName() {
48
			String packageName = getPluginActivatorPackageName();
49
			String className = getPluginActivatorClassName();
50
			return composeFQN(packageName, className);
51
		}
52
		
45
	}
53
	}
46
54
47
	public static class ConfigImpl implements Config {
55
	public static class ConfigImpl extends Config {
48
		private final String myPluginId;
56
		private final String myPluginId;
49
		private final String myMainPackageName;
57
		private final String myMainPackageName;
50
		private final String myPluginFriendlyName;
58
		private final String myPluginFriendlyName;
Lines 120-126 Link Here
120
		myArgs = config;
128
		myArgs = config;
121
		myProcessor = p;
129
		myProcessor = p;
122
		myFigureNameSwitch = fqnSwitch;
130
		myFigureNameSwitch = fqnSwitch;
123
		String pluginActivatorFQN = composePluginActivatorClassFQN(config);
131
		String pluginActivatorFQN = config.getPluginActivatorFullyQualifiedName();
124
		MapModeCodeGenStrategy strategy;
132
		MapModeCodeGenStrategy strategy;
125
		if (config.needsMapMode()) {
133
		if (config.needsMapMode()) {
126
			myMapModeImportHack = new DelegateImportManager();
134
			myMapModeImportHack = new DelegateImportManager();
Lines 158-163 Link Here
158
		try {
166
		try {
159
			generatePluginActivator();
167
			generatePluginActivator();
160
			generateTopLevelFigures();
168
			generateTopLevelFigures();
169
			generateLazyResourceRegistry();
161
		} catch (IllegalStateException e){
170
		} catch (IllegalStateException e){
162
			throw new UnexpectedBehaviourException(e);
171
			throw new UnexpectedBehaviourException(e);
163
		}
172
		}
Lines 168-173 Link Here
168
		doGenerateJavaClass(myAuxiliaryGenerators.getPluginActivatorEmitter(), myArgs.getPluginActivatorPackageName(), myArgs.getPluginActivatorClassName(), new Object[] {args});		
177
		doGenerateJavaClass(myAuxiliaryGenerators.getPluginActivatorEmitter(), myArgs.getPluginActivatorPackageName(), myArgs.getPluginActivatorClassName(), new Object[] {args});		
169
	}
178
	}
170
	
179
	
180
	private void generateLazyResourceRegistry() throws UnexpectedBehaviourException, InterruptedException{
181
		Object[] args = new Object[] {myArgs, new ImportUtil(myArgs.getMainPackageName(), Knowledge.LAZY_RESOURCE_REGISTRY_CLASS_NAME)};
182
		doGenerateJavaClass(myAuxiliaryGenerators.getLazyResourceRegistryEmitter(), myArgs.getMainPackageName(), Knowledge.LAZY_RESOURCE_REGISTRY_CLASS_NAME, new Object[] {args});		
183
	}
184
171
	private void generatePluginStructure() throws UnexpectedBehaviourException, InterruptedException {
185
	private void generatePluginStructure() throws UnexpectedBehaviourException, InterruptedException {
172
		doGenerateFile(myAuxiliaryGenerators.getBuildPropertiesEmitter(), new Path("build.properties"), new Object[] { myArgs });
186
		doGenerateFile(myAuxiliaryGenerators.getBuildPropertiesEmitter(), new Path("build.properties"), new Object[] { myArgs });
173
		doGenerateFile(myAuxiliaryGenerators.getManifestMFEmitter(), new Path("META-INF/MANIFEST.MF"), new Object[] { new Object[] { myArgs, myProcessor.getRequiredBundles(myFigureNameSwitch) } });
187
		doGenerateFile(myAuxiliaryGenerators.getManifestMFEmitter(), new Path("META-INF/MANIFEST.MF"), new Object[] { new Object[] { myArgs, myProcessor.getRequiredBundles(myFigureNameSwitch) } });
Lines 196-207 Link Here
196
		return myArgs.getMainPackageName();
210
		return myArgs.getMainPackageName();
197
	}
211
	}
198
	
212
	
199
	private static String composePluginActivatorClassFQN(Config config) {
200
		String packageName = config.getPluginActivatorPackageName();
201
		String className = config.getPluginActivatorClassName();
202
		return composeFQN(packageName, className);
203
	}
204
205
	private static String composeFQN(String packageName, String className){
213
	private static String composeFQN(String packageName, String className){
206
		return packageName == null || "".equals(packageName) ? className : packageName + "." + className; 
214
		return packageName == null || "".equals(packageName) ? className : packageName + "." + className; 
207
	}
215
	}
(-)templates/Color.jetinc (-1 / +1 lines)
Line 1 Link Here
1
<%if (colorVal instanceof RGBColor) {%>new <%=importManager.getImportedName("org.eclipse.swt.graphics.Color")%>(null, <%=((RGBColor) colorVal).getRed()%>, <%=((RGBColor) colorVal).getGreen()%>, <%=((RGBColor) colorVal).getBlue()%>)<%} else if (colorVal instanceof ConstantColor) {%><%=importManager.getImportedName("org.eclipse.draw2d.ColorConstants")%>.<%=((ConstantColor) colorVal).getValue().getLiteral()%><%}%>
1
<%if (colorVal instanceof RGBColor) {%>getLazyResourceRegistry().getColor(<%=((RGBColor) colorVal).getRed()%>, <%=((RGBColor) colorVal).getGreen()%>, <%=((RGBColor) colorVal).getBlue()%>)<%} else if (colorVal instanceof ConstantColor) {%><%=importManager.getImportedName("org.eclipse.draw2d.ColorConstants")%>.<%=((ConstantColor) colorVal).getValue().getLiteral()%><%}%>
(-)src/org/eclipse/gmf/graphdef/codegen/standalone/templates/LazyResourceRegistryGenerator.java (+48 lines)
Added Link Here
1
package org.eclipse.gmf.graphdef.codegen.standalone.templates;
2
3
import org.eclipse.gmf.graphdef.codegen.*;
4
import org.eclipse.gmf.common.codegen.ImportAssistant;
5
6
public class LazyResourceRegistryGenerator
7
{
8
  protected static String nl;
9
  public static synchronized LazyResourceRegistryGenerator create(String lineSeparator)
10
  {
11
    nl = lineSeparator;
12
    LazyResourceRegistryGenerator result = new LazyResourceRegistryGenerator();
13
    nl = null;
14
    return result;
15
  }
16
17
  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
18
  protected final String TEXT_1 = NL + "import org.eclipse.jface.resource.ColorRegistry;" + NL + "import org.eclipse.jface.resource.FontRegistry;" + NL + "import org.eclipse.swt.graphics.Color;" + NL + "import org.eclipse.swt.graphics.Font;" + NL + "import org.eclipse.swt.graphics.FontData;" + NL + "import org.eclipse.swt.graphics.RGB;" + NL + "import org.eclipse.swt.widgets.Display;";
19
  protected final String TEXT_2 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
20
  protected final String TEXT_3 = " {" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static final String KEY_PREFIX = LazyResourceRegistry.class.getSimpleName();" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static final String COLOR_PREFIX = KEY_PREFIX + \":Color:\";" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static final String FONT_PREFIX = KEY_PREFIX + \":Font:\";" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate final ColorRegistry myColors;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate final FontRegistry myFonts;" + NL + "\t" + NL + "\t/**" + NL + "\t * All instances that do not provide concrete storage instances on" + NL + "\t * construction will share the common registries." + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic LazyResourceRegistry(){" + NL + "\t\tthis(";
21
  protected final String TEXT_4 = ".getDefault().getColorRegistry(), ";
22
  protected final String TEXT_5 = ".getDefault().getFontRegistry());" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic LazyResourceRegistry(ColorRegistry colorStorage, FontRegistry fontStorage){" + NL + "\t\tmyColors = colorStorage;" + NL + "\t\tmyFonts = fontStorage;" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Color getColor(int red, int green, int blue){" + NL + "\t\tString symbolicName = constructColorSymbolicName(red, green, blue);" + NL + "\t\tColor result = myColors.get(symbolicName);" + NL + "\t\tif (result == null){" + NL + "\t\t\tRGB rgb = new RGB(red, green, blue);" + NL + "\t\t\tmyColors.put(symbolicName, rgb);" + NL + "\t\t\tresult = myColors.get(symbolicName);" + NL + "\t\t}" + NL + "\t\treturn result;" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Font getFont(String name, int height, int style){" + NL + "\t\tString symbolicName = constructFontSymbolicName(name, height, style);" + NL + "\t\tFont result;" + NL + "\t\tif (myFonts.hasValueFor(symbolicName)){" + NL + "\t\t\tresult = myFonts.get(symbolicName);" + NL + "\t\t} else {" + NL + "\t\t\tFont font = new Font(Display.getCurrent(), name, height, style);" + NL + "\t\t\tFontData[] fontData = font.getFontData();" + NL + "\t\t\tmyFonts.put(symbolicName, fontData);" + NL + "\t\t\tfont.dispose();" + NL + "\t\t\tresult = myFonts.get(symbolicName);" + NL + "\t\t}" + NL + "\t\treturn result;" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate String constructColorSymbolicName(int red, int green, int blue){" + NL + "\t\treturn COLOR_PREFIX + red + \":\" + green + \":\" + blue;" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate String constructFontSymbolicName(String name, int height, int style){" + NL + "\t\treturn FONT_PREFIX + name + \":\" + height + \":\" + style;" + NL + "\t}" + NL + "}";
23
  protected final String TEXT_6 = NL;
24
25
  public String generate(Object argument)
26
  {
27
    final StringBuffer stringBuffer = new StringBuffer();
28
    
29
final Object[] passedArgs = (Object[]) argument;
30
final StandaloneGenerator.Config config = (StandaloneGenerator.Config) passedArgs[0];
31
final ImportAssistant importManager = (ImportAssistant) passedArgs[1];
32
33
importManager.emitPackageStatement(stringBuffer);
34
35
    stringBuffer.append(TEXT_1);
36
    importManager.markImportLocation(stringBuffer);
37
    stringBuffer.append(TEXT_2);
38
    stringBuffer.append(importManager.getCompilationUnitName());
39
    stringBuffer.append(TEXT_3);
40
    stringBuffer.append(importManager.getImportedName(config.getPluginActivatorFullyQualifiedName()));
41
    stringBuffer.append(TEXT_4);
42
    stringBuffer.append(importManager.getImportedName(config.getPluginActivatorFullyQualifiedName()));
43
    stringBuffer.append(TEXT_5);
44
    importManager.emitSortedImports();
45
    stringBuffer.append(TEXT_6);
46
    return stringBuffer.toString();
47
  }
48
}
(-)templates/plugin/LazyResourceRegistry.javajet (+112 lines)
Added Link Here
1
<%@ jet package="org.eclipse.gmf.graphdef.codegen.standalone.templates" class="LazyResourceRegistryGenerator"
2
	imports="org.eclipse.gmf.graphdef.codegen.* org.eclipse.gmf.common.codegen.ImportAssistant"%>
3
<%
4
final Object[] passedArgs = (Object[]) argument;
5
final StandaloneGenerator.Config config = (StandaloneGenerator.Config) passedArgs[0];
6
final ImportAssistant importManager = (ImportAssistant) passedArgs[1];
7
8
importManager.emitPackageStatement(stringBuffer);
9
%>
10
11
import org.eclipse.jface.resource.ColorRegistry;
12
import org.eclipse.jface.resource.FontRegistry;
13
import org.eclipse.swt.graphics.Color;
14
import org.eclipse.swt.graphics.Font;
15
import org.eclipse.swt.graphics.FontData;
16
import org.eclipse.swt.graphics.RGB;
17
import org.eclipse.swt.widgets.Display;
18
<%importManager.markImportLocation(stringBuffer);%>
19
20
/**
21
 * @generated
22
 */
23
public class <%=importManager.getCompilationUnitName()%> {
24
	/**
25
	 * @generated
26
	 */
27
	private static final String KEY_PREFIX = LazyResourceRegistry.class.getSimpleName();
28
29
	/**
30
	 * @generated
31
	 */
32
	private static final String COLOR_PREFIX = KEY_PREFIX + ":Color:";
33
34
	/**
35
	 * @generated
36
	 */
37
	private static final String FONT_PREFIX = KEY_PREFIX + ":Font:";
38
	
39
	/**
40
	 * @generated
41
	 */
42
	private final ColorRegistry myColors;
43
44
	/**
45
	 * @generated
46
	 */
47
	private final FontRegistry myFonts;
48
	
49
	/**
50
	 * All instances that do not provide concrete storage instances on
51
	 * construction will share the common registries.
52
	 * @generated
53
	 */
54
	public LazyResourceRegistry(){
55
		this(<%=importManager.getImportedName(config.getPluginActivatorFullyQualifiedName())%>.getDefault().getColorRegistry(), <%=importManager.getImportedName(config.getPluginActivatorFullyQualifiedName())%>.getDefault().getFontRegistry());
56
	}
57
	
58
	/**
59
	 * @generated
60
	 */
61
	public LazyResourceRegistry(ColorRegistry colorStorage, FontRegistry fontStorage){
62
		myColors = colorStorage;
63
		myFonts = fontStorage;
64
	}
65
	
66
	/**
67
	 * @generated
68
	 */
69
	public Color getColor(int red, int green, int blue){
70
		String symbolicName = constructColorSymbolicName(red, green, blue);
71
		Color result = myColors.get(symbolicName);
72
		if (result == null){
73
			RGB rgb = new RGB(red, green, blue);
74
			myColors.put(symbolicName, rgb);
75
			result = myColors.get(symbolicName);
76
		}
77
		return result;
78
	}
79
	
80
	/**
81
	 * @generated
82
	 */
83
	public Font getFont(String name, int height, int style){
84
		String symbolicName = constructFontSymbolicName(name, height, style);
85
		Font result;
86
		if (myFonts.hasValueFor(symbolicName)){
87
			result = myFonts.get(symbolicName);
88
		} else {
89
			Font font = new Font(Display.getCurrent(), name, height, style);
90
			FontData[] fontData = font.getFontData();
91
			myFonts.put(symbolicName, fontData);
92
			font.dispose();
93
			result = myFonts.get(symbolicName);
94
		}
95
		return result;
96
	}
97
	
98
	/**
99
	 * @generated
100
	 */
101
	private String constructColorSymbolicName(int red, int green, int blue){
102
		return COLOR_PREFIX + red + ":" + green + ":" + blue;
103
	}
104
	
105
	/**
106
	 * @generated
107
	 */
108
	private String constructFontSymbolicName(String name, int height, int style){
109
		return FONT_PREFIX + name + ":" + height + ":" + style;
110
	}
111
}
112
<%importManager.emitSortedImports();%>
(-)src/org/eclipse/gmf/internal/codegen/lite/Generator.java (+3 lines)
Lines 40-45 Link Here
40
import org.eclipse.gmf.common.UnexpectedBehaviourException;
40
import org.eclipse.gmf.common.UnexpectedBehaviourException;
41
import org.eclipse.gmf.internal.common.codegen.GeneratorBase;
41
import org.eclipse.gmf.internal.common.codegen.GeneratorBase;
42
import org.eclipse.gmf.internal.common.codegen.ImportUtil;
42
import org.eclipse.gmf.internal.common.codegen.ImportUtil;
43
import org.eclipse.gmf.internal.common.codegen.Knowledge;
43
import org.eclipse.gmf.internal.common.codegen.TextEmitter;
44
import org.eclipse.gmf.internal.common.codegen.TextEmitter;
44
45
45
/**
46
/**
Lines 106-111 Link Here
106
		internalGenerateJavaClass(myEmitters.getDiagramEditPartGenerator(), myDiagram.getEditPartQualifiedClassName(), myDiagram);
107
		internalGenerateJavaClass(myEmitters.getDiagramEditPartGenerator(), myDiagram.getEditPartQualifiedClassName(), myDiagram);
107
		internalGenerateJavaClass(myEmitters.getBendpointEditPolicyGenerator(), myDiagram.getEditPoliciesPackageName(), "BendpointEditPolicy", myDiagram);	//XXX: should be moved to a lite-runtime plugin
108
		internalGenerateJavaClass(myEmitters.getBendpointEditPolicyGenerator(), myDiagram.getEditPoliciesPackageName(), "BendpointEditPolicy", myDiagram);	//XXX: should be moved to a lite-runtime plugin
108
109
110
		internalGenerateJavaClass(myEmitters.getLazyResourceRegistryEmitter(), myDiagram.getEditPartsPackageName(), Knowledge.LAZY_RESOURCE_REGISTRY_CLASS_NAME, myDiagram);
111
		
109
		for (Iterator it = myDiagram.getAllNodes().iterator(); it.hasNext(); ) {
112
		for (Iterator it = myDiagram.getAllNodes().iterator(); it.hasNext(); ) {
110
			final GenNode next = (GenNode) it.next();
113
			final GenNode next = (GenNode) it.next();
111
			if (!(next instanceof GenChildLabelNode)) {
114
			if (!(next instanceof GenChildLabelNode)) {
(-)src/org/eclipse/gmf/internal/codegen/lite/CodegenEmitters.java (-9 / +14 lines)
Lines 16-29 Link Here
16
import org.eclipse.emf.codegen.jet.JETCompiler;
16
import org.eclipse.emf.codegen.jet.JETCompiler;
17
import org.eclipse.emf.codegen.jet.JETException;
17
import org.eclipse.emf.codegen.jet.JETException;
18
import org.eclipse.emf.common.util.URI;
18
import org.eclipse.emf.common.util.URI;
19
import org.eclipse.gmf.common.UnexpectedBehaviourException;
20
import org.eclipse.gmf.internal.codegen.dispatch.EmitterFactory;
21
import org.eclipse.gmf.internal.codegen.dispatch.NoSuchTemplateException;
22
import org.eclipse.gmf.internal.codegen.dispatch.StaticTemplateRegistry;
23
import org.eclipse.gmf.internal.common.codegen.GIFEmitter;
24
import org.eclipse.gmf.internal.common.codegen.JETEmitterAdapter;
25
import org.eclipse.gmf.internal.common.codegen.TextEmitter;
26
27
import org.eclipse.gmf.codegen.templates.lite.commands.CreateNotationalElementCommandGenerator;
19
import org.eclipse.gmf.codegen.templates.lite.commands.CreateNotationalElementCommandGenerator;
28
import org.eclipse.gmf.codegen.templates.lite.commands.RemoveNotationalElementCommandGenerator;
20
import org.eclipse.gmf.codegen.templates.lite.commands.RemoveNotationalElementCommandGenerator;
29
import org.eclipse.gmf.codegen.templates.lite.commands.ReplaceNotationalElementCommandGenerator;
21
import org.eclipse.gmf.codegen.templates.lite.commands.ReplaceNotationalElementCommandGenerator;
Lines 46-51 Link Here
46
import org.eclipse.gmf.codegen.templates.lite.parts.CompartmentEditPartGenerator;
38
import org.eclipse.gmf.codegen.templates.lite.parts.CompartmentEditPartGenerator;
47
import org.eclipse.gmf.codegen.templates.lite.parts.DiagramEditPartGenerator;
39
import org.eclipse.gmf.codegen.templates.lite.parts.DiagramEditPartGenerator;
48
import org.eclipse.gmf.codegen.templates.lite.parts.EditPartFactoryGenerator;
40
import org.eclipse.gmf.codegen.templates.lite.parts.EditPartFactoryGenerator;
41
import org.eclipse.gmf.codegen.templates.lite.parts.LazyResourceRegistryGenerator;
49
import org.eclipse.gmf.codegen.templates.lite.parts.LinkEditPartGenerator;
42
import org.eclipse.gmf.codegen.templates.lite.parts.LinkEditPartGenerator;
50
import org.eclipse.gmf.codegen.templates.lite.parts.LinkLabelEditPartGenerator;
43
import org.eclipse.gmf.codegen.templates.lite.parts.LinkLabelEditPartGenerator;
51
import org.eclipse.gmf.codegen.templates.lite.parts.NodeEditPartGenerator;
44
import org.eclipse.gmf.codegen.templates.lite.parts.NodeEditPartGenerator;
Lines 61-66 Link Here
61
import org.eclipse.gmf.codegen.templates.lite.providers.LinkViewFactoryGenerator;
54
import org.eclipse.gmf.codegen.templates.lite.providers.LinkViewFactoryGenerator;
62
import org.eclipse.gmf.codegen.templates.lite.providers.NodeViewFactoryGenerator;
55
import org.eclipse.gmf.codegen.templates.lite.providers.NodeViewFactoryGenerator;
63
import org.eclipse.gmf.codegen.templates.lite.providers.PropertySourceProviderGenerator;
56
import org.eclipse.gmf.codegen.templates.lite.providers.PropertySourceProviderGenerator;
57
import org.eclipse.gmf.common.UnexpectedBehaviourException;
58
import org.eclipse.gmf.internal.codegen.dispatch.EmitterFactory;
59
import org.eclipse.gmf.internal.codegen.dispatch.NoSuchTemplateException;
60
import org.eclipse.gmf.internal.codegen.dispatch.StaticTemplateRegistry;
61
import org.eclipse.gmf.internal.common.codegen.GIFEmitter;
62
import org.eclipse.gmf.internal.common.codegen.JETEmitterAdapter;
63
import org.eclipse.gmf.internal.common.codegen.TextEmitter;
64
import org.osgi.framework.Bundle;
64
import org.osgi.framework.Bundle;
65
65
66
/**
66
/**
Lines 95-100 Link Here
95
		put(tr, "/providers/LinkViewFactory.javajet", LinkViewFactoryGenerator.class);
95
		put(tr, "/providers/LinkViewFactory.javajet", LinkViewFactoryGenerator.class);
96
		put(tr, "/providers/NodeViewFactory.javajet", NodeViewFactoryGenerator.class);
96
		put(tr, "/providers/NodeViewFactory.javajet", NodeViewFactoryGenerator.class);
97
		put(tr, "/parts/CompartmentEditPart.javajet", CompartmentEditPartGenerator.class);
97
		put(tr, "/parts/CompartmentEditPart.javajet", CompartmentEditPartGenerator.class);
98
		put(tr, "/parts/LazyResourceRegistry.javajet", LazyResourceRegistryGenerator.class);
98
		put(tr, "/editor/CreationWizard.javajet", CreationWizardGenerator.class);
99
		put(tr, "/editor/CreationWizard.javajet", CreationWizardGenerator.class);
99
		put(tr, "/editor/CreationWizardPage.javajet", CreationWizardPageGenerator.class);
100
		put(tr, "/editor/CreationWizardPage.javajet", CreationWizardPageGenerator.class);
100
		put(tr, "/editor/DiagramEditorUtil.javajet", DiagramEditorUtilGenerator.class);
101
		put(tr, "/editor/DiagramEditorUtil.javajet", DiagramEditorUtilGenerator.class);
Lines 279-285 Link Here
279
	public TextEmitter getReplaceNotationalElementCommandGenerator() throws UnexpectedBehaviourException {
280
	public TextEmitter getReplaceNotationalElementCommandGenerator() throws UnexpectedBehaviourException {
280
		return retrieve(ReplaceNotationalElementCommandGenerator.class);
281
		return retrieve(ReplaceNotationalElementCommandGenerator.class);
281
	}
282
	}
282
283
	
284
	public TextEmitter getLazyResourceRegistryEmitter() throws UnexpectedBehaviourException {
285
		return retrieve(LazyResourceRegistryGenerator.class);
286
	}
287
	
283
	/**
288
	/**
284
	 * @see #retrieve(Class)
289
	 * @see #retrieve(Class)
285
	 */
290
	 */
(-)templates/parts/LazyResourceRegistry.javajet (+120 lines)
Added Link Here
1
<%@ jet package="org.eclipse.gmf.codegen.templates.lite.parts" class="LazyResourceRegistryGenerator"
2
  imports="org.eclipse.gmf.codegen.gmfgen.* org.eclipse.gmf.common.codegen.*"%>
3
<%
4
final GenDiagram genDiagram = (GenDiagram) ((Object[]) argument)[0];
5
final ImportAssistant importManager = (ImportAssistant) ((Object[]) argument)[1];
6
%>
7
<%@ include file="../copyright4java.jetinc"%>
8
<%importManager.emitPackageStatement(stringBuffer);%>
9
import org.eclipse.jface.resource.ColorRegistry;
10
import org.eclipse.jface.resource.FontRegistry;
11
import org.eclipse.swt.graphics.Color;
12
import org.eclipse.swt.graphics.Font;
13
import org.eclipse.swt.graphics.FontData;
14
import org.eclipse.swt.graphics.RGB;
15
import org.eclipse.swt.widgets.Display;
16
<%importManager.markImportLocation(stringBuffer);%>
17
18
/**
19
 * @generated
20
 */
21
public class <%=importManager.getCompilationUnitName()%> {
22
	/**
23
	 * @generated
24
	 */
25
	private static final ColorRegistry SHARED_COLORS = new ColorRegistry();
26
27
	/**
28
	 * @generated
29
	 */
30
	private static final FontRegistry SHARED_FONTS = new FontRegistry();
31
	
32
	/**
33
	 * @generated
34
	 */
35
	private static final String KEY_PREFIX = LazyResourceRegistry.class.getSimpleName();
36
37
	/**
38
	 * @generated
39
	 */
40
	private static final String COLOR_PREFIX = KEY_PREFIX + ":Color:";
41
42
	/**
43
	 * @generated
44
	 */
45
	private static final String FONT_PREFIX = KEY_PREFIX + ":Font:";
46
	
47
	/**
48
	 * @generated
49
	 */
50
	private final ColorRegistry myColors;
51
52
	/**
53
	 * @generated
54
	 */
55
	private final FontRegistry myFonts;
56
	
57
	/**
58
	 * All instances that do not provide concrete storage instances on
59
	 * construction will share the common registries.
60
	 * @generated
61
	 */
62
	public LazyResourceRegistry(){
63
		this(SHARED_COLORS, SHARED_FONTS);
64
	}
65
	
66
	/**
67
	 * @generated
68
	 */
69
	public LazyResourceRegistry(ColorRegistry colorStorage, FontRegistry fontStorage){
70
		myColors = colorStorage;
71
		myFonts = fontStorage;
72
	}
73
	
74
	/**
75
	 * @generated
76
	 */
77
	public Color getColor(int red, int green, int blue){
78
		String symbolicName = constructColorSymbolicName(red, green, blue);
79
		Color result = myColors.get(symbolicName);
80
		if (result == null){
81
			RGB rgb = new RGB(red, green, blue);
82
			myColors.put(symbolicName, rgb);
83
			result = myColors.get(symbolicName);
84
		}
85
		return result;
86
	}
87
	
88
	/**
89
	 * @generated
90
	 */
91
	public Font getFont(String name, int height, int style){
92
		String symbolicName = constructFontSymbolicName(name, height, style);
93
		Font result;
94
		if (myFonts.hasValueFor(symbolicName)){
95
			result = myFonts.get(symbolicName);
96
		} else {
97
			Font font = new Font(Display.getCurrent(), name, height, style);
98
			FontData[] fontData = font.getFontData();
99
			myFonts.put(symbolicName, fontData);
100
			font.dispose();
101
			result = myFonts.get(symbolicName);
102
		}
103
		return result;
104
	}
105
	
106
	/**
107
	 * @generated
108
	 */
109
	private String constructColorSymbolicName(int red, int green, int blue){
110
		return COLOR_PREFIX + red + ":" + green + ":" + blue;
111
	}
112
	
113
	/**
114
	 * @generated
115
	 */
116
	private String constructFontSymbolicName(String name, int height, int style){
117
		return FONT_PREFIX + name + ":" + height + ":" + style;
118
	}
119
}
120
<%importManager.emitSortedImports();%>
(-)src-templates/org/eclipse/gmf/codegen/templates/lite/parts/LazyResourceRegistryGenerator.java (+52 lines)
Added Link Here
1
package org.eclipse.gmf.codegen.templates.lite.parts;
2
3
import org.eclipse.gmf.codegen.gmfgen.*;
4
import org.eclipse.gmf.common.codegen.*;
5
6
public class LazyResourceRegistryGenerator
7
{
8
  protected static String nl;
9
  public static synchronized LazyResourceRegistryGenerator create(String lineSeparator)
10
  {
11
    nl = lineSeparator;
12
    LazyResourceRegistryGenerator result = new LazyResourceRegistryGenerator();
13
    nl = null;
14
    return result;
15
  }
16
17
  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
18
  protected final String TEXT_1 = "";
19
  protected final String TEXT_2 = NL + "/*" + NL + " * ";
20
  protected final String TEXT_3 = NL + " */";
21
  protected final String TEXT_4 = NL + "import org.eclipse.jface.resource.ColorRegistry;" + NL + "import org.eclipse.jface.resource.FontRegistry;" + NL + "import org.eclipse.swt.graphics.Color;" + NL + "import org.eclipse.swt.graphics.Font;" + NL + "import org.eclipse.swt.graphics.FontData;" + NL + "import org.eclipse.swt.graphics.RGB;" + NL + "import org.eclipse.swt.widgets.Display;";
22
  protected final String TEXT_5 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
23
  protected final String TEXT_6 = " {" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static final ColorRegistry SHARED_COLORS = new ColorRegistry();" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static final FontRegistry SHARED_FONTS = new FontRegistry();" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static final String KEY_PREFIX = LazyResourceRegistry.class.getSimpleName();" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static final String COLOR_PREFIX = KEY_PREFIX + \":Color:\";" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static final String FONT_PREFIX = KEY_PREFIX + \":Font:\";" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate final ColorRegistry myColors;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate final FontRegistry myFonts;" + NL + "\t" + NL + "\t/**" + NL + "\t * All instances that do not provide concrete storage instances on" + NL + "\t * construction will share the common registries." + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic LazyResourceRegistry(){" + NL + "\t\tthis(SHARED_COLORS, SHARED_FONTS);" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic LazyResourceRegistry(ColorRegistry colorStorage, FontRegistry fontStorage){" + NL + "\t\tmyColors = colorStorage;" + NL + "\t\tmyFonts = fontStorage;" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Color getColor(int red, int green, int blue){" + NL + "\t\tString symbolicName = constructColorSymbolicName(red, green, blue);" + NL + "\t\tColor result = myColors.get(symbolicName);" + NL + "\t\tif (result == null){" + NL + "\t\t\tRGB rgb = new RGB(red, green, blue);" + NL + "\t\t\tmyColors.put(symbolicName, rgb);" + NL + "\t\t\tresult = myColors.get(symbolicName);" + NL + "\t\t}" + NL + "\t\treturn result;" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Font getFont(String name, int height, int style){" + NL + "\t\tString symbolicName = constructFontSymbolicName(name, height, style);" + NL + "\t\tFont result;" + NL + "\t\tif (myFonts.hasValueFor(symbolicName)){" + NL + "\t\t\tresult = myFonts.get(symbolicName);" + NL + "\t\t} else {" + NL + "\t\t\tFont font = new Font(Display.getCurrent(), name, height, style);" + NL + "\t\t\tFontData[] fontData = font.getFontData();" + NL + "\t\t\tmyFonts.put(symbolicName, fontData);" + NL + "\t\t\tfont.dispose();" + NL + "\t\t\tresult = myFonts.get(symbolicName);" + NL + "\t\t}" + NL + "\t\treturn result;" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate String constructColorSymbolicName(int red, int green, int blue){" + NL + "\t\treturn COLOR_PREFIX + red + \":\" + green + \":\" + blue;" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate String constructFontSymbolicName(String name, int height, int style){" + NL + "\t\treturn FONT_PREFIX + name + \":\" + height + \":\" + style;" + NL + "\t}" + NL + "}";
24
  protected final String TEXT_7 = NL;
25
26
  public String generate(Object argument)
27
  {
28
    final StringBuffer stringBuffer = new StringBuffer();
29
    
30
final GenDiagram genDiagram = (GenDiagram) ((Object[]) argument)[0];
31
final ImportAssistant importManager = (ImportAssistant) ((Object[]) argument)[1];
32
33
    stringBuffer.append(TEXT_1);
34
    
35
String copyrightText = genDiagram.getEditorGen().getCopyrightText();
36
if (copyrightText != null && copyrightText.trim().length() > 0) {
37
38
    stringBuffer.append(TEXT_2);
39
    stringBuffer.append(copyrightText.replaceAll("\n", "\n * "));
40
    stringBuffer.append(TEXT_3);
41
    }
42
    importManager.emitPackageStatement(stringBuffer);
43
    stringBuffer.append(TEXT_4);
44
    importManager.markImportLocation(stringBuffer);
45
    stringBuffer.append(TEXT_5);
46
    stringBuffer.append(importManager.getCompilationUnitName());
47
    stringBuffer.append(TEXT_6);
48
    importManager.emitSortedImports();
49
    stringBuffer.append(TEXT_7);
50
    return stringBuffer.toString();
51
  }
52
}
(-)src/org/eclipse/gmf/internal/bridge/Knowledge.java (-2 / +1 lines)
Lines 20-27 Link Here
20
 * Handcoded decisions
20
 * Handcoded decisions
21
 * @author artem
21
 * @author artem
22
 */
22
 */
23
public class Knowledge {
23
public class Knowledge extends org.eclipse.gmf.internal.common.codegen.Knowledge {
24
25
	public static boolean isExternal(DiagramLabel diagramLabel) {
24
	public static boolean isExternal(DiagramLabel diagramLabel) {
26
		FigureHandle figure = diagramLabel.getFigure();
25
		FigureHandle figure = diagramLabel.getFigure();
27
		if (figure instanceof Figure) {
26
		if (figure instanceof Figure) {
(-)src/org/eclipse/gmf/codegen/util/Generator.java (-1 / +12 lines)
Lines 50-55 Link Here
50
import org.eclipse.gmf.internal.common.codegen.GeneratorBase;
50
import org.eclipse.gmf.internal.common.codegen.GeneratorBase;
51
import org.eclipse.gmf.internal.common.codegen.ImportUtil;
51
import org.eclipse.gmf.internal.common.codegen.ImportUtil;
52
import org.eclipse.gmf.internal.common.codegen.JETEmitterAdapter;
52
import org.eclipse.gmf.internal.common.codegen.JETEmitterAdapter;
53
import org.eclipse.gmf.internal.common.codegen.Knowledge;
53
54
54
/**
55
/**
55
 * Invokes JET templates to populate diagram editor project.
56
 * Invokes JET templates to populate diagram editor project.
Lines 98-103 Link Here
98
		generateBaseEditHelper();
99
		generateBaseEditHelper();
99
		
100
		
100
		// edit parts, edit policies and providers
101
		// edit parts, edit policies and providers
102
		generateLazyResourceRegistry();
101
		generateAbstractParser();
103
		generateAbstractParser();
102
		generateStructuralFeatureParser();
104
		generateStructuralFeatureParser();
103
		generateStructuralFeaturesParser();
105
		generateStructuralFeaturesParser();
Lines 301-309 Link Here
301
			genType
303
			genType
302
		);
304
		);
303
	}
305
	}
304
306
	
305
	// parts
307
	// parts
306
308
309
	private void generateLazyResourceRegistry() throws UnexpectedBehaviourException, InterruptedException {
310
		internalGenerateJavaClass(
311
			myEmitters.getLazyResourceRegistryEmitter(),
312
			myDiagram.getEditPartsPackageName(),
313
			Knowledge.LAZY_RESOURCE_REGISTRY_CLASS_NAME, //sic -- used in gmfgraph templates, can not be changed by user
314
			myDiagram
315
		);
316
	}
317
307
	private void generateDiagramEditPart() throws UnexpectedBehaviourException, InterruptedException {
318
	private void generateDiagramEditPart() throws UnexpectedBehaviourException, InterruptedException {
308
		internalGenerateJavaClass(
319
		internalGenerateJavaClass(
309
			myEmitters.getDiagramEditPartEmitter(),
320
			myEmitters.getDiagramEditPartEmitter(),
(-)src/org/eclipse/gmf/codegen/util/CodegenEmitters.java (+6 lines)
Lines 52-57 Link Here
52
import org.eclipse.gmf.codegen.templates.parts.DiagramExternalNodeLabelEditPartGenerator;
52
import org.eclipse.gmf.codegen.templates.parts.DiagramExternalNodeLabelEditPartGenerator;
53
import org.eclipse.gmf.codegen.templates.parts.EditPartFactoryGenerator;
53
import org.eclipse.gmf.codegen.templates.parts.EditPartFactoryGenerator;
54
import org.eclipse.gmf.codegen.templates.parts.ExternalNodeLabelEditPartGenerator;
54
import org.eclipse.gmf.codegen.templates.parts.ExternalNodeLabelEditPartGenerator;
55
import org.eclipse.gmf.codegen.templates.parts.LazyResourceRegistryGenerator;
55
import org.eclipse.gmf.codegen.templates.parts.LinkEditPartGenerator;
56
import org.eclipse.gmf.codegen.templates.parts.LinkEditPartGenerator;
56
import org.eclipse.gmf.codegen.templates.parts.LinkLabelEditPartGenerator;
57
import org.eclipse.gmf.codegen.templates.parts.LinkLabelEditPartGenerator;
57
import org.eclipse.gmf.codegen.templates.parts.NodeEditPartGenerator;
58
import org.eclipse.gmf.codegen.templates.parts.NodeEditPartGenerator;
Lines 144-149 Link Here
144
		put(tr, "/parts/LinkEditPart.javajet", LinkEditPartGenerator.class);
145
		put(tr, "/parts/LinkEditPart.javajet", LinkEditPartGenerator.class);
145
		put(tr, "/parts/LinkLabelEditPart.javajet", LinkLabelEditPartGenerator.class);
146
		put(tr, "/parts/LinkLabelEditPart.javajet", LinkLabelEditPartGenerator.class);
146
		put(tr, "/parts/EditPartFactory.javajet", EditPartFactoryGenerator.class);
147
		put(tr, "/parts/EditPartFactory.javajet", EditPartFactoryGenerator.class);
148
		put(tr, "/parts/LazyResourceRegistry.javajet", LazyResourceRegistryGenerator.class);
147
		put(tr, "/policies/ItemSemanticEditPolicy.javajet", ItemSemanticEditPolicyGenerator.class);
149
		put(tr, "/policies/ItemSemanticEditPolicy.javajet", ItemSemanticEditPolicyGenerator.class);
148
		put(tr, "/policies/GraphicalNodeEditPolicy.javajet", GraphicalNodeEditPolicyGenerator.class);
150
		put(tr, "/policies/GraphicalNodeEditPolicy.javajet", GraphicalNodeEditPolicyGenerator.class);
149
		put(tr, "/policies/ReferenceConnectionEditPolicy.javajet", ReferenceConnectionEditPolicyGenerator.class);
151
		put(tr, "/policies/ReferenceConnectionEditPolicy.javajet", ReferenceConnectionEditPolicyGenerator.class);
Lines 300-305 Link Here
300
		return retrieve(EditPartFactoryGenerator.class);
302
		return retrieve(EditPartFactoryGenerator.class);
301
	}
303
	}
302
	
304
	
305
	public JETEmitter getLazyResourceRegistryEmitter() throws UnexpectedBehaviourException {
306
		return retrieve(LazyResourceRegistryGenerator.class);
307
	}
308
	
303
	// policies
309
	// policies
304
310
305
	public JETEmitter getBaseItemSemanticEditPolicyEmitter() throws UnexpectedBehaviourException {
311
	public JETEmitter getBaseItemSemanticEditPolicyEmitter() throws UnexpectedBehaviourException {
(-)templates/parts/LazyResourceRegistry.javajet (+120 lines)
Added Link Here
1
<%@ jet package="org.eclipse.gmf.codegen.templates.parts" class="LazyResourceRegistryGenerator"
2
  imports="org.eclipse.gmf.codegen.gmfgen.* org.eclipse.gmf.common.codegen.*"%>
3
<%
4
final GenDiagram genDiagram = (GenDiagram) ((Object[]) argument)[0];
5
final ImportAssistant importManager = (ImportAssistant) ((Object[]) argument)[1];
6
%>
7
<%@ include file="../copyright4java.jetinc"%>
8
<%importManager.emitPackageStatement(stringBuffer);%>
9
import org.eclipse.jface.resource.ColorRegistry;
10
import org.eclipse.jface.resource.FontRegistry;
11
import org.eclipse.swt.graphics.Color;
12
import org.eclipse.swt.graphics.Font;
13
import org.eclipse.swt.graphics.FontData;
14
import org.eclipse.swt.graphics.RGB;
15
import org.eclipse.swt.widgets.Display;
16
<%importManager.markImportLocation(stringBuffer);%>
17
18
/**
19
 * @generated
20
 */
21
public class <%=importManager.getCompilationUnitName()%> {
22
	/**
23
	 * @generated
24
	 */
25
	private static final ColorRegistry SHARED_COLORS = new ColorRegistry();
26
27
	/**
28
	 * @generated
29
	 */
30
	private static final FontRegistry SHARED_FONTS = new FontRegistry();
31
	
32
	/**
33
	 * @generated
34
	 */
35
	private static final String KEY_PREFIX = LazyResourceRegistry.class.getSimpleName();
36
37
	/**
38
	 * @generated
39
	 */
40
	private static final String COLOR_PREFIX = KEY_PREFIX + ":Color:";
41
42
	/**
43
	 * @generated
44
	 */
45
	private static final String FONT_PREFIX = KEY_PREFIX + ":Font:";
46
	
47
	/**
48
	 * @generated
49
	 */
50
	private final ColorRegistry myColors;
51
52
	/**
53
	 * @generated
54
	 */
55
	private final FontRegistry myFonts;
56
	
57
	/**
58
	 * All instances that do not provide concrete storage instances on
59
	 * construction will share the common registries.
60
	 * @generated
61
	 */
62
	public LazyResourceRegistry(){
63
		this(SHARED_COLORS, SHARED_FONTS);
64
	}
65
	
66
	/**
67
	 * @generated
68
	 */
69
	public LazyResourceRegistry(ColorRegistry colorStorage, FontRegistry fontStorage){
70
		myColors = colorStorage;
71
		myFonts = fontStorage;
72
	}
73
	
74
	/**
75
	 * @generated
76
	 */
77
	public Color getColor(int red, int green, int blue){
78
		String symbolicName = constructColorSymbolicName(red, green, blue);
79
		Color result = myColors.get(symbolicName);
80
		if (result == null){
81
			RGB rgb = new RGB(red, green, blue);
82
			myColors.put(symbolicName, rgb);
83
			result = myColors.get(symbolicName);
84
		}
85
		return result;
86
	}
87
	
88
	/**
89
	 * @generated
90
	 */
91
	public Font getFont(String name, int height, int style){
92
		String symbolicName = constructFontSymbolicName(name, height, style);
93
		Font result;
94
		if (myFonts.hasValueFor(symbolicName)){
95
			result = myFonts.get(symbolicName);
96
		} else {
97
			Font font = new Font(Display.getCurrent(), name, height, style);
98
			FontData[] fontData = font.getFontData();
99
			myFonts.put(symbolicName, fontData);
100
			font.dispose();
101
			result = myFonts.get(symbolicName);
102
		}
103
		return result;
104
	}
105
	
106
	/**
107
	 * @generated
108
	 */
109
	private String constructColorSymbolicName(int red, int green, int blue){
110
		return COLOR_PREFIX + red + ":" + green + ":" + blue;
111
	}
112
	
113
	/**
114
	 * @generated
115
	 */
116
	private String constructFontSymbolicName(String name, int height, int style){
117
		return FONT_PREFIX + name + ":" + height + ":" + style;
118
	}
119
}
120
<%importManager.emitSortedImports();%>
(-)src-templates/org/eclipse/gmf/codegen/templates/parts/LazyResourceRegistryGenerator.java (+52 lines)
Added Link Here
1
package org.eclipse.gmf.codegen.templates.parts;
2
3
import org.eclipse.gmf.codegen.gmfgen.*;
4
import org.eclipse.gmf.common.codegen.*;
5
6
public class LazyResourceRegistryGenerator
7
{
8
  protected static String nl;
9
  public static synchronized LazyResourceRegistryGenerator create(String lineSeparator)
10
  {
11
    nl = lineSeparator;
12
    LazyResourceRegistryGenerator result = new LazyResourceRegistryGenerator();
13
    nl = null;
14
    return result;
15
  }
16
17
  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
18
  protected final String TEXT_1 = "";
19
  protected final String TEXT_2 = NL + "/*" + NL + " *";
20
  protected final String TEXT_3 = NL + " */";
21
  protected final String TEXT_4 = NL + "import org.eclipse.jface.resource.ColorRegistry;" + NL + "import org.eclipse.jface.resource.FontRegistry;" + NL + "import org.eclipse.swt.graphics.Color;" + NL + "import org.eclipse.swt.graphics.Font;" + NL + "import org.eclipse.swt.graphics.FontData;" + NL + "import org.eclipse.swt.graphics.RGB;" + NL + "import org.eclipse.swt.widgets.Display;";
22
  protected final String TEXT_5 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
23
  protected final String TEXT_6 = " {" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static final ColorRegistry SHARED_COLORS = new ColorRegistry();" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static final FontRegistry SHARED_FONTS = new FontRegistry();" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static final String KEY_PREFIX = LazyResourceRegistry.class.getSimpleName();" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static final String COLOR_PREFIX = KEY_PREFIX + \":Color:\";" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static final String FONT_PREFIX = KEY_PREFIX + \":Font:\";" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate final ColorRegistry myColors;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate final FontRegistry myFonts;" + NL + "\t" + NL + "\t/**" + NL + "\t * All instances that do not provide concrete storage instances on" + NL + "\t * construction will share the common registries." + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic LazyResourceRegistry(){" + NL + "\t\tthis(SHARED_COLORS, SHARED_FONTS);" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic LazyResourceRegistry(ColorRegistry colorStorage, FontRegistry fontStorage){" + NL + "\t\tmyColors = colorStorage;" + NL + "\t\tmyFonts = fontStorage;" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Color getColor(int red, int green, int blue){" + NL + "\t\tString symbolicName = constructColorSymbolicName(red, green, blue);" + NL + "\t\tColor result = myColors.get(symbolicName);" + NL + "\t\tif (result == null){" + NL + "\t\t\tRGB rgb = new RGB(red, green, blue);" + NL + "\t\t\tmyColors.put(symbolicName, rgb);" + NL + "\t\t\tresult = myColors.get(symbolicName);" + NL + "\t\t}" + NL + "\t\treturn result;" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Font getFont(String name, int height, int style){" + NL + "\t\tString symbolicName = constructFontSymbolicName(name, height, style);" + NL + "\t\tFont result;" + NL + "\t\tif (myFonts.hasValueFor(symbolicName)){" + NL + "\t\t\tresult = myFonts.get(symbolicName);" + NL + "\t\t} else {" + NL + "\t\t\tFont font = new Font(Display.getCurrent(), name, height, style);" + NL + "\t\t\tFontData[] fontData = font.getFontData();" + NL + "\t\t\tmyFonts.put(symbolicName, fontData);" + NL + "\t\t\tfont.dispose();" + NL + "\t\t\tresult = myFonts.get(symbolicName);" + NL + "\t\t}" + NL + "\t\treturn result;" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate String constructColorSymbolicName(int red, int green, int blue){" + NL + "\t\treturn COLOR_PREFIX + red + \":\" + green + \":\" + blue;" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate String constructFontSymbolicName(String name, int height, int style){" + NL + "\t\treturn FONT_PREFIX + name + \":\" + height + \":\" + style;" + NL + "\t}" + NL + "}";
24
  protected final String TEXT_7 = NL;
25
26
  public String generate(Object argument)
27
  {
28
    final StringBuffer stringBuffer = new StringBuffer();
29
    
30
final GenDiagram genDiagram = (GenDiagram) ((Object[]) argument)[0];
31
final ImportAssistant importManager = (ImportAssistant) ((Object[]) argument)[1];
32
33
    stringBuffer.append(TEXT_1);
34
    
35
String copyrightText = genDiagram.getEditorGen().getCopyrightText();
36
if (copyrightText != null && copyrightText.trim().length() > 0) {
37
38
    stringBuffer.append(TEXT_2);
39
    stringBuffer.append(copyrightText.replaceAll("\n", "\n *"));
40
    stringBuffer.append(TEXT_3);
41
    }
42
    importManager.emitPackageStatement(stringBuffer);
43
    stringBuffer.append(TEXT_4);
44
    importManager.markImportLocation(stringBuffer);
45
    stringBuffer.append(TEXT_5);
46
    stringBuffer.append(importManager.getCompilationUnitName());
47
    stringBuffer.append(TEXT_6);
48
    importManager.emitSortedImports();
49
    stringBuffer.append(TEXT_7);
50
    return stringBuffer.toString();
51
  }
52
}

Return to bug 148402