View | Details | Raw Unified | Return to bug 134249
Collapse All | Expand All

(-)src/org/eclipse/gmf/tests/gen/GenericFigureCheck.java (-31 / +155 lines)
Lines 12-35 Link Here
12
12
13
package org.eclipse.gmf.tests.gen;
13
package org.eclipse.gmf.tests.gen;
14
14
15
import java.lang.reflect.Field;
15
import java.util.Iterator;
16
import java.util.Iterator;
16
import java.util.List;
17
import java.util.List;
17
18
19
import org.eclipse.draw2d.Graphics;
18
import org.eclipse.draw2d.IFigure;
20
import org.eclipse.draw2d.IFigure;
19
import org.eclipse.draw2d.geometry.PointList;
21
import org.eclipse.draw2d.geometry.PointList;
20
import org.eclipse.gmf.gmfgraph.BasicFont;
22
import org.eclipse.gmf.gmfgraph.BasicFont;
23
import org.eclipse.gmf.gmfgraph.Border;
21
import org.eclipse.gmf.gmfgraph.Color;
24
import org.eclipse.gmf.gmfgraph.Color;
22
import org.eclipse.gmf.gmfgraph.ColorConstants;
25
import org.eclipse.gmf.gmfgraph.CompoundBorder;
23
import org.eclipse.gmf.gmfgraph.ConstantColor;
26
import org.eclipse.gmf.gmfgraph.ConstantColor;
24
import org.eclipse.gmf.gmfgraph.Dimension;
27
import org.eclipse.gmf.gmfgraph.Dimension;
25
import org.eclipse.gmf.gmfgraph.Figure;
28
import org.eclipse.gmf.gmfgraph.Figure;
26
import org.eclipse.gmf.gmfgraph.Font;
29
import org.eclipse.gmf.gmfgraph.Font;
27
import org.eclipse.gmf.gmfgraph.FontStyle;
30
import org.eclipse.gmf.gmfgraph.FontStyle;
28
import org.eclipse.gmf.gmfgraph.GMFGraphPackage;
31
import org.eclipse.gmf.gmfgraph.GMFGraphPackage;
32
import org.eclipse.gmf.gmfgraph.Insets;
29
import org.eclipse.gmf.gmfgraph.Label;
33
import org.eclipse.gmf.gmfgraph.Label;
34
import org.eclipse.gmf.gmfgraph.LineBorder;
35
import org.eclipse.gmf.gmfgraph.LineKind;
36
import org.eclipse.gmf.gmfgraph.MarginBorder;
30
import org.eclipse.gmf.gmfgraph.Point;
37
import org.eclipse.gmf.gmfgraph.Point;
31
import org.eclipse.gmf.gmfgraph.Polyline;
38
import org.eclipse.gmf.gmfgraph.Polyline;
32
import org.eclipse.gmf.gmfgraph.RGBColor;
39
import org.eclipse.gmf.gmfgraph.RGBColor;
40
import org.eclipse.gmf.gmfgraph.Shape;
33
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.graphics.FontData;
42
import org.eclipse.swt.graphics.FontData;
35
import org.eclipse.swt.graphics.RGB;
43
import org.eclipse.swt.graphics.RGB;
Lines 46-57 Link Here
46
		checkFigure(myGMFRootFigure, figure);
54
		checkFigure(myGMFRootFigure, figure);
47
	}
55
	}
48
	
56
	
49
	private void checkFigure(Figure gmfFigure, IFigure d2dFigure){
57
	protected void checkFigure(Figure gmfFigure, IFigure d2dFigure){
50
		checkFigureItself(gmfFigure, d2dFigure);
58
		checkFigureItself(gmfFigure, d2dFigure);
51
		checkFigureChildren(gmfFigure, d2dFigure);
59
		checkFigureChildren(gmfFigure, d2dFigure);
52
	}
60
	}
53
	
61
	
54
	private void checkFigureChildren(Figure gmfFigure, IFigure d2dFigure){
62
	protected void checkFigureChildren(Figure gmfFigure, IFigure d2dFigure){
55
		List gmfChildren = gmfFigure.getChildren();
63
		List gmfChildren = gmfFigure.getChildren();
56
		List d2dChildren = d2dFigure.getChildren();
64
		List d2dChildren = d2dFigure.getChildren();
57
		assertNotNull(gmfChildren);
65
		assertNotNull(gmfChildren);
Lines 68-84 Link Here
68
		}
76
		}
69
	}
77
	}
70
	
78
	
71
	private void checkFigureItself(Figure gmfFigure, IFigure d2dFigure){
79
	protected void checkFigureItself(Figure gmfFigure, IFigure d2dFigure){
72
		checkSize(gmfFigure, d2dFigure);
80
		checkSize(gmfFigure, d2dFigure);
81
		//XXX: checkLocation(gmfFigure, d2dFigure);
82
		checkMaximumSize(gmfFigure, d2dFigure);
83
		checkMinimumSize(gmfFigure, d2dFigure);
73
		checkPreferredSize(gmfFigure, d2dFigure);
84
		checkPreferredSize(gmfFigure, d2dFigure);
74
		checkFont(gmfFigure, d2dFigure);
85
		checkFont(gmfFigure, d2dFigure);
75
		checkForeground(gmfFigure, d2dFigure);
86
		checkForeground(gmfFigure, d2dFigure);
76
		checkBackgroud(gmfFigure, d2dFigure);
87
		checkBackgroud(gmfFigure, d2dFigure);
88
		checkInsets(gmfFigure, d2dFigure);
89
		checkBorder(gmfFigure, d2dFigure);
90
		checkShapeProperties(gmfFigure, d2dFigure);
77
		checkLabelText(gmfFigure, d2dFigure);
91
		checkLabelText(gmfFigure, d2dFigure);
78
		checkPolylinePoints(gmfFigure, d2dFigure);
92
		checkPolylinePoints(gmfFigure, d2dFigure);
79
	}
93
	}
94
95
	private void checkShapeProperties(Figure gmfFigure, IFigure figure) {
96
		if (gmfFigure instanceof Shape){
97
			Shape eShape = (Shape)gmfFigure; 
98
			assertTrue(figure instanceof org.eclipse.draw2d.Shape);
99
			org.eclipse.draw2d.Shape d2dShape = (org.eclipse.draw2d.Shape)figure;
100
			checkLineKind(eShape, d2dShape);
101
			checkLineWidth(eShape, d2dShape);
102
		}
103
	}
104
105
	protected void checkLineWidth(Shape eShape, org.eclipse.draw2d.Shape d2dShape) {
106
		if (eShape.eIsSet(GMFGraphPackage.eINSTANCE.getShape_LineWidth())){
107
			int expected = eShape.getLineWidth();
108
			assertEquals(expected, d2dShape.getLineWidth());
109
		}
110
	}
111
112
	protected void checkLineKind(Shape eShape, org.eclipse.draw2d.Shape d2dShape) {
113
		if (eShape.eIsSet(GMFGraphPackage.eINSTANCE.getShape_LineKind())){
114
			LineKind expected = eShape.getLineKind();
115
			assertEquals(transformLineKind(expected), d2dShape.getLineStyle());
116
		}
117
	}
80
	
118
	
81
	private void checkPolylinePoints(Figure gmfFigure, IFigure d2dFigure) {
119
	private int transformLineKind(LineKind kind){
120
		Object d2dValue = getStaticFieldValue("Unknown LineKind: " + kind, Graphics.class, kind.getName());
121
		assertTrue(d2dValue instanceof Integer);
122
		return ((Integer)d2dValue).intValue();
123
	}
124
125
	protected final void checkDimension(Dimension eDimension, org.eclipse.draw2d.geometry.Dimension d2dDimension){
126
		assertEquals(new org.eclipse.draw2d.geometry.Dimension(eDimension.getDx(), eDimension.getDy()), d2dDimension);		
127
	}
128
129
	protected void checkPolylinePoints(Figure gmfFigure, IFigure d2dFigure) {
82
		if (gmfFigure instanceof Polyline && gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getPolyline_Template())){
130
		if (gmfFigure instanceof Polyline && gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getPolyline_Template())){
83
			Polyline gmfPolyline = (Polyline)gmfFigure;
131
			Polyline gmfPolyline = (Polyline)gmfFigure;
84
			assertTrue(d2dFigure instanceof org.eclipse.draw2d.Polyline);
132
			assertTrue(d2dFigure instanceof org.eclipse.draw2d.Polyline);
Lines 98-104 Link Here
98
		
146
		
99
	}
147
	}
100
148
101
	private void checkLabelText(Figure gmfFigure, IFigure d2dFigure) {
149
	protected void checkLabelText(Figure gmfFigure, IFigure d2dFigure) {
102
		if (gmfFigure instanceof Label && gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getLabel_Text())){
150
		if (gmfFigure instanceof Label && gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getLabel_Text())){
103
			assertTrue(d2dFigure instanceof org.eclipse.draw2d.Label);
151
			assertTrue(d2dFigure instanceof org.eclipse.draw2d.Label);
104
			org.eclipse.draw2d.Label d2dLabel = (org.eclipse.draw2d.Label)d2dFigure;
152
			org.eclipse.draw2d.Label d2dLabel = (org.eclipse.draw2d.Label)d2dFigure;
Lines 107-125 Link Here
107
		}
155
		}
108
	}
156
	}
109
157
110
	private void checkBackgroud(Figure gmfFigure, IFigure figure) {
158
	protected void checkBackgroud(Figure gmfFigure, IFigure figure) {
111
		if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_BackgroundColor())){
159
		if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_BackgroundColor())){
112
			checkColor(gmfFigure.getBackgroundColor(), figure.getBackgroundColor());
160
			checkColor(gmfFigure.getBackgroundColor(), figure.getBackgroundColor());
113
		}
161
		}
114
	}
162
	}
115
163
116
	private void checkForeground(Figure gmfFigure, IFigure figure) {
164
	protected void checkForeground(Figure gmfFigure, IFigure figure) {
117
		if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_ForegroundColor())){
165
		if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_ForegroundColor())){
118
			checkColor(gmfFigure.getForegroundColor(), figure.getForegroundColor());
166
			checkColor(gmfFigure.getForegroundColor(), figure.getForegroundColor());
119
		}
167
		}
120
	}
168
	}
121
169
122
	private void checkColor(Color eColor, org.eclipse.swt.graphics.Color swtColor){
170
	protected final void checkColor(Color eColor, org.eclipse.swt.graphics.Color swtColor){
123
		assertNotNull(swtColor);
171
		assertNotNull(swtColor);
124
		assertNotNull(eColor);
172
		assertNotNull(eColor);
125
		
173
		
Lines 134-147 Link Here
134
		assertEquals(expectedRGB, swtColor.getRGB());
182
		assertEquals(expectedRGB, swtColor.getRGB());
135
	}
183
	}
136
	
184
	
137
	private void checkFont(Figure gmfFigure, IFigure figure) {
185
	protected void checkFont(Figure gmfFigure, IFigure figure) {
138
		if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Font())){
186
		if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Font())){
139
			Font eFont = gmfFigure.getFont();
187
			Font eFont = gmfFigure.getFont();
140
			checkFont(eFont, figure.getFont());
188
			checkFont(eFont, figure.getFont());
141
		}
189
		}
142
	}
190
	}
143
	
191
	
144
	private void checkFont(Font gmfFont, org.eclipse.swt.graphics.Font actual){
192
	protected final void checkFont(Font gmfFont, org.eclipse.swt.graphics.Font actual){
145
		assertNotNull(actual);
193
		assertNotNull(actual);
146
		if (gmfFont instanceof BasicFont && actual.getFontData().length == 1){
194
		if (gmfFont instanceof BasicFont && actual.getFontData().length == 1){
147
			BasicFont expected = (BasicFont)gmfFont;
195
			BasicFont expected = (BasicFont)gmfFont;
Lines 164-186 Link Here
164
	}
212
	}
165
213
166
	private org.eclipse.swt.graphics.Color transformConstantColor(ConstantColor color) {
214
	private org.eclipse.swt.graphics.Color transformConstantColor(ConstantColor color) {
167
		switch(color.getValue().getValue()){
215
		Class d2dClass = org.eclipse.draw2d.ColorConstants.class;
168
			case ColorConstants.BLACK : return org.eclipse.draw2d.ColorConstants.black;
216
		Object d2dValue = getStaticFieldValue("Unknown color: " + color, d2dClass, color.getValue().getLiteral());
169
			case ColorConstants.BLUE : return org.eclipse.draw2d.ColorConstants.blue;
217
		assertTrue(d2dValue instanceof org.eclipse.swt.graphics.Color);
170
			case ColorConstants.CYAN : return org.eclipse.draw2d.ColorConstants.cyan;
218
		return (org.eclipse.swt.graphics.Color)d2dValue;
171
			case ColorConstants.DARK_BLUE : return org.eclipse.draw2d.ColorConstants.darkBlue;
219
	}
172
			case ColorConstants.DARK_GRAY: return org.eclipse.draw2d.ColorConstants.darkGray;
220
	
173
			case ColorConstants.DARK_GREEN: return org.eclipse.draw2d.ColorConstants.darkGreen;
221
	private Object getStaticFieldValue(String failureMessage, Class clazz, String fieldName){
174
			case ColorConstants.GRAY: return org.eclipse.draw2d.ColorConstants.gray;
222
		try {
175
			case ColorConstants.GREEN: return org.eclipse.draw2d.ColorConstants.green;
223
			Field constant = clazz.getField(fieldName);
176
			case ColorConstants.LIGHT_BLUE: return org.eclipse.draw2d.ColorConstants.lightBlue;
224
			assertNotNull(failureMessage, constant);
177
			case ColorConstants.LIGHT_GRAY: return org.eclipse.draw2d.ColorConstants.lightGray;
225
			Object value = constant.get(null);
178
			case ColorConstants.LIGHT_GREEN: return org.eclipse.draw2d.ColorConstants.lightGreen;
226
			assertNotNull(failureMessage, value);
179
			case ColorConstants.ORANGE: return org.eclipse.draw2d.ColorConstants.orange;
227
			return value;
180
			case ColorConstants.RED: return org.eclipse.draw2d.ColorConstants.red;
228
		} catch (Exception e) {
181
			case ColorConstants.WHITE: return org.eclipse.draw2d.ColorConstants.white;
229
			fail(failureMessage + "\n" + e.toString());
182
			case ColorConstants.YELLOW: return org.eclipse.draw2d.ColorConstants.yellow;
230
			throw new InternalError("Unreachable");
183
			default: throw new IllegalArgumentException("Unknown Color: " + color);
184
		}
231
		}
185
	}
232
	}
186
233
Lines 188-205 Link Here
188
		return new RGB(color.getRed(), color.getGreen(), color.getBlue());
235
		return new RGB(color.getRed(), color.getGreen(), color.getBlue());
189
	}
236
	}
190
237
191
	private void checkPreferredSize(Figure gmfFigure, IFigure figure) {
238
	protected void checkPreferredSize(Figure gmfFigure, IFigure figure) {
192
		if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_PreferredSize())){
239
		if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_PreferredSize())){
193
			Dimension ePreferredSize = gmfFigure.getPreferredSize();
240
			Dimension ePreferredSize = gmfFigure.getPreferredSize();
194
			assertEquals(new org.eclipse.draw2d.geometry.Dimension(ePreferredSize.getDx(), ePreferredSize.getDy()), figure.getPreferredSize());
241
			checkDimension(ePreferredSize, figure.getPreferredSize());
195
		}
242
		}
196
	}
243
	}
197
244
198
	private void checkSize(Figure gmfFigure, IFigure figure) {
245
	protected void checkSize(Figure gmfFigure, IFigure figure) {
199
		if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Size())){
246
		if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Size())){
200
			Point eSize = gmfFigure.getSize();
247
			Point eSize = gmfFigure.getSize();
201
			assertEquals(new org.eclipse.draw2d.geometry.Dimension(eSize.getX(), eSize.getY()), figure.getSize());
248
			assertEquals(new org.eclipse.draw2d.geometry.Dimension(eSize.getX(), eSize.getY()), figure.getSize());
202
		}
249
		}
203
	}
250
	}
251
	
252
	protected void checkMaximumSize(Figure gmfFigure, IFigure figure) {
253
		if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MaximumSize())){
254
			Dimension eSize = gmfFigure.getMaximumSize();
255
			checkDimension(eSize, figure.getMaximumSize());
256
		}
257
	}
258
	
259
	protected void checkMinimumSize(Figure gmfFigure, IFigure figure) {
260
		if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MinimumSize())){
261
			Dimension eSize = gmfFigure.getMinimumSize();
262
			checkDimension(eSize, figure.getMinimumSize());
263
		}
264
	}
265
	
266
	
267
	protected void checkBorder(Figure gmfFigure, IFigure figure) {
268
		if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Border())){
269
			Border eBorder = gmfFigure.getBorder();
270
			checkBorder(eBorder, figure.getBorder(), figure);
271
		}
272
	}
273
	
274
	protected final void checkBorder(Border eBorder, org.eclipse.draw2d.Border d2dBorder, IFigure mainD2DFigure){
275
		assertNotNull(eBorder);
276
		assertNotNull(d2dBorder);
277
		if (eBorder instanceof LineBorder){
278
			checkLineBorder((LineBorder)eBorder, d2dBorder);
279
		} else if (eBorder instanceof CompoundBorder){
280
			checkCompoundBorder((CompoundBorder)eBorder, d2dBorder, mainD2DFigure);
281
		} else if (eBorder instanceof MarginBorder){
282
			checkMarginBorder((MarginBorder)eBorder, d2dBorder, mainD2DFigure);
283
		}
284
	}
285
	
286
	protected final void checkMarginBorder(MarginBorder eBorder, org.eclipse.draw2d.Border d2dBorder, IFigure mainD2DFigure) {
287
		assertTrue(d2dBorder instanceof org.eclipse.draw2d.MarginBorder);
288
		org.eclipse.draw2d.MarginBorder actual = (org.eclipse.draw2d.MarginBorder)d2dBorder;
289
		if (eBorder.eIsSet(GMFGraphPackage.eINSTANCE.getMarginBorder_Insets())){
290
			Insets eInsets = eBorder.getInsets();
291
			checkInsets(eInsets, actual.getInsets(mainD2DFigure));
292
		}
293
	}
294
295
	protected final void checkCompoundBorder(CompoundBorder eBorder, org.eclipse.draw2d.Border d2dBorder, IFigure mainD2DFigure){
296
		assertTrue(d2dBorder instanceof org.eclipse.draw2d.CompoundBorder);
297
		org.eclipse.draw2d.CompoundBorder actual = (org.eclipse.draw2d.CompoundBorder)d2dBorder;
298
		if (eBorder.eIsSet(GMFGraphPackage.eINSTANCE.getCompoundBorder_Inner())){
299
			checkBorder(eBorder.getInner(), actual.getInnerBorder(), mainD2DFigure);
300
		}
301
		if (eBorder.eIsSet(GMFGraphPackage.eINSTANCE.getCompoundBorder_Outer())){
302
			checkBorder(eBorder.getOuter(), actual.getOuterBorder(), mainD2DFigure);
303
		}
304
	}
305
	
306
	protected final void checkLineBorder(LineBorder eBorder, org.eclipse.draw2d.Border d2dBorder){
307
		assertTrue(d2dBorder instanceof org.eclipse.draw2d.LineBorder);
308
		org.eclipse.draw2d.LineBorder actual = (org.eclipse.draw2d.LineBorder)d2dBorder;
309
		//intentionally always checked, there is a default value mathcing default value in d2d
310
		assertEquals(eBorder.getWidth(), actual.getWidth());
311
		 
312
		if (eBorder.eIsSet(GMFGraphPackage.eINSTANCE.getLineBorder_Color())){
313
			checkColor(eBorder.getColor(), actual.getColor());
314
		}
315
	}
316
317
	protected void checkInsets(Figure gmfFigure, IFigure figure) {
318
		if (gmfFigure.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Insets())){
319
			checkInsets(gmfFigure.getInsets(), figure.getInsets());
320
		}
321
	}
322
	
323
	protected final void checkInsets(Insets eInsets, org.eclipse.draw2d.geometry.Insets d2dInsets){
324
		assertNotNull(d2dInsets);
325
		assertNotNull(eInsets);
326
		assertEquals(new org.eclipse.draw2d.geometry.Insets(eInsets.getTop(), eInsets.getLeft(), eInsets.getBottom(), eInsets.getRight()), d2dInsets);
327
	}
204
328
205
}
329
}
(-)src/org/eclipse/gmf/tests/AllTests.java (+2 lines)
Lines 29-34 Link Here
29
import org.eclipse.gmf.tests.gen.HandcodedImplTest;
29
import org.eclipse.gmf.tests.gen.HandcodedImplTest;
30
import org.eclipse.gmf.tests.gen.MapModeStrategyTest;
30
import org.eclipse.gmf.tests.gen.MapModeStrategyTest;
31
import org.eclipse.gmf.tests.gen.RTFigureTest;
31
import org.eclipse.gmf.tests.gen.RTFigureTest;
32
import org.eclipse.gmf.tests.gen.ShapePropertiesTest;
32
import org.eclipse.gmf.tests.gen.StandaloneMapModeTest;
33
import org.eclipse.gmf.tests.gen.StandaloneMapModeTest;
33
import org.eclipse.gmf.tests.gen.ToolDefHandocodedImplTest;
34
import org.eclipse.gmf.tests.gen.ToolDefHandocodedImplTest;
34
import org.eclipse.gmf.tests.gen.ViewmapProducersTest;
35
import org.eclipse.gmf.tests.gen.ViewmapProducersTest;
Lines 62-67 Link Here
62
		suite.addTestSuite(HistoryTest.class);
63
		suite.addTestSuite(HistoryTest.class);
63
		
64
		
64
		suite.addTestSuite(FigureCodegenTest.class);
65
		suite.addTestSuite(FigureCodegenTest.class);
66
		suite.addTestSuite(ShapePropertiesTest.class);
65
		suite.addTestSuite(FigureLayoutTest.class);
67
		suite.addTestSuite(FigureLayoutTest.class);
66
		suite.addTestSuite(StandaloneMapModeTest.class);
68
		suite.addTestSuite(StandaloneMapModeTest.class);
67
		suite.addTestSuite(RTFigureTest.class);
69
		suite.addTestSuite(RTFigureTest.class);
(-)src/org/eclipse/gmf/tests/gen/ShapePropertiesTest.java (+188 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.tests.gen;
14
15
import java.util.Iterator;
16
17
import org.eclipse.gmf.gmfgraph.Color;
18
import org.eclipse.gmf.gmfgraph.ColorConstants;
19
import org.eclipse.gmf.gmfgraph.CompoundBorder;
20
import org.eclipse.gmf.gmfgraph.ConstantColor;
21
import org.eclipse.gmf.gmfgraph.Dimension;
22
import org.eclipse.gmf.gmfgraph.GMFGraphFactory;
23
import org.eclipse.gmf.gmfgraph.Insets;
24
import org.eclipse.gmf.gmfgraph.LineBorder;
25
import org.eclipse.gmf.gmfgraph.LineKind;
26
import org.eclipse.gmf.gmfgraph.MarginBorder;
27
import org.eclipse.gmf.gmfgraph.Rectangle;
28
import org.eclipse.gmf.gmfgraph.RoundedRectangle;
29
import org.eclipse.gmf.gmfgraph.Shape;
30
31
public class ShapePropertiesTest extends FigureCodegenTestBase {
32
	public ShapePropertiesTest(String name) {
33
		super(name);
34
	}
35
36
	public void testShapeLineStyle() {
37
		Rectangle container = GMFGraphFactory.eINSTANCE.createRectangle();
38
		container.setName("Container");
39
		for (Iterator kinds = LineKind.VALUES.iterator(); kinds.hasNext(); ) {
40
			LineKind next = (LineKind) kinds.next();
41
			Shape shape = GMFGraphFactory.eINSTANCE.createEllipse();
42
			shape.setName("Ellipse_" + next.getLiteral());
43
			shape.setLineKind(next);
44
			container.getChildren().add(shape);
45
		}
46
		performTests(container);
47
	}
48
49
	public void testShapeLineWidth() {
50
		Shape shape = GMFGraphFactory.eINSTANCE.createRoundedRectangle();
51
		shape.setLineWidth(23);
52
		shape.setName("Bold");
53
		performTests(shape);
54
	}
55
56
	public void testShapeInsets() {
57
		Rectangle withInsets = GMFGraphFactory.eINSTANCE.createRectangle();
58
		withInsets.setName("WithInsets");
59
		Insets insets = GMFGraphFactory.eINSTANCE.createInsets();
60
		insets.setBottom(23);
61
		insets.setTop(34);
62
		insets.setRight(45);
63
		insets.setLeft(56);
64
		withInsets.setInsets(insets);
65
66
		performTests(withInsets);
67
	}
68
69
	public void testLineBorder() {
70
		Rectangle container = GMFGraphFactory.eINSTANCE.createRectangle();
71
		container.setName("Root");
72
73
		Rectangle colorAndWidth = GMFGraphFactory.eINSTANCE.createRectangle();
74
		colorAndWidth.setName("ColorAndWidth");
75
		LineBorder colorAndWidthBorder = GMFGraphFactory.eINSTANCE.createLineBorder();
76
		colorAndWidthBorder.setColor(createConstantColor(ColorConstants.CYAN_LITERAL));
77
		colorAndWidthBorder.setWidth(23);
78
		colorAndWidth.setBorder(colorAndWidthBorder);
79
80
		Rectangle onlyColor = GMFGraphFactory.eINSTANCE.createRectangle();
81
		onlyColor.setName("OnlyColor");
82
		LineBorder onlyColorBorder = GMFGraphFactory.eINSTANCE.createLineBorder();
83
		onlyColorBorder.setColor(createConstantColor(ColorConstants.CYAN_LITERAL));
84
		onlyColor.setBorder(onlyColorBorder);
85
86
		Rectangle onlyWidth = GMFGraphFactory.eINSTANCE.createRectangle();
87
		onlyWidth.setName("OnlyWidth");
88
		LineBorder onlyWidthBorder = GMFGraphFactory.eINSTANCE.createLineBorder();
89
		onlyWidthBorder.setWidth(34);
90
		onlyWidth.setBorder(onlyWidthBorder);
91
92
		Rectangle empty = GMFGraphFactory.eINSTANCE.createRectangle();
93
		empty.setName("Empty");
94
		LineBorder emptyBorder = GMFGraphFactory.eINSTANCE.createLineBorder();
95
		empty.setBorder(emptyBorder);
96
		
97
		container.getChildren().add(colorAndWidth);
98
		container.getChildren().add(onlyColor);
99
		container.getChildren().add(onlyWidth);
100
		container.getChildren().add(empty);
101
		
102
		performTests(container);
103
	}
104
	
105
	public void testCompoundBorder(){
106
		LineBorder outerOuter = GMFGraphFactory.eINSTANCE.createLineBorder();
107
		outerOuter.setColor(createConstantColor(ColorConstants.BLUE_LITERAL));
108
		outerOuter.setWidth(22);
109
		
110
		MarginBorder outerInner = GMFGraphFactory.eINSTANCE.createMarginBorder();
111
		outerInner.setInsets(GMFGraphFactory.eINSTANCE.createInsets());
112
		outerInner.getInsets().setBottom(23);
113
		outerInner.getInsets().setTop(34);
114
		//sic! outerInner.getInsets().setRight(45);
115
		//sic! outerInner.getInsets().setLeft(56);
116
		
117
		CompoundBorder outer = GMFGraphFactory.eINSTANCE.createCompoundBorder();
118
		outer.setOuter(outerOuter);
119
		outer.setInner(outerInner);
120
		
121
		CompoundBorder innerEmpty = GMFGraphFactory.eINSTANCE.createCompoundBorder();
122
		//sic!
123
		innerEmpty.setInner(null);
124
		innerEmpty.setOuter(null);
125
		
126
		CompoundBorder result = GMFGraphFactory.eINSTANCE.createCompoundBorder();
127
		result.setOuter(outer);
128
		result.setInner(innerEmpty);
129
		
130
		Rectangle tester = GMFGraphFactory.eINSTANCE.createRectangle();
131
		tester.setBorder(result);
132
		tester.setName("Tester");
133
		
134
		performTests(tester);
135
	}
136
	
137
	public void testMarginBorder(){
138
		MarginBorder border = GMFGraphFactory.eINSTANCE.createMarginBorder();
139
		border.setInsets(GMFGraphFactory.eINSTANCE.createInsets());
140
		border.getInsets().setBottom(23);
141
		border.getInsets().setTop(34);
142
		border.getInsets().setRight(45);
143
		border.getInsets().setLeft(56);
144
		
145
		Shape marginTester = GMFGraphFactory.eINSTANCE.createEllipse();
146
		marginTester.setBorder(border);
147
		marginTester.setName("MarginTester");
148
		
149
		performTests(marginTester);
150
	}
151
	
152
	public void testConstantColors(){
153
		Rectangle rainbow = GMFGraphFactory.eINSTANCE.createRectangle();
154
		rainbow.setName("Rainbow");
155
		for (Iterator colors = ColorConstants.VALUES.iterator(); colors.hasNext();){
156
			ColorConstants next = (ColorConstants)colors.next();
157
			Rectangle nextColored = GMFGraphFactory.eINSTANCE.createRectangle();
158
			nextColored.setName(next.getLiteral());
159
			nextColored.setBackgroundColor(createConstantColor(next));
160
			rainbow.getChildren().add(nextColored);
161
		}
162
		performTests(rainbow);
163
	}
164
	
165
	public void testMaxAndMinSize(){
166
		RoundedRectangle withMinAndMaxSize = GMFGraphFactory.eINSTANCE.createRoundedRectangle();
167
		withMinAndMaxSize.setName("WithMinAndMaxSize");
168
		withMinAndMaxSize.setMaximumSize(createDimension(1000, 2000));
169
		withMinAndMaxSize.setMinimumSize(createDimension(234, 123));
170
		performTests(withMinAndMaxSize);
171
	}
172
	
173
	private Dimension createDimension(int x, int y){
174
		Dimension result = GMFGraphFactory.eINSTANCE.createDimension();
175
		result.setDx(x);
176
		result.setDy(y);
177
		return result;
178
	}
179
	
180
	private Color createConstantColor(ColorConstants constant) {
181
		ConstantColor result = GMFGraphFactory.eINSTANCE.createConstantColor();
182
		result.setValue(constant);
183
		return result;
184
	}
185
	
186
	
187
188
}
(-)src/org/eclipse/gmf/gmfgraph/LineBorder.java (-1 / +2 lines)
Lines 53-58 Link Here
53
53
54
	/**
54
	/**
55
	 * Returns the value of the '<em><b>Width</b></em>' attribute.
55
	 * Returns the value of the '<em><b>Width</b></em>' attribute.
56
	 * The default value is <code>"1"</code>.
56
	 * <!-- begin-user-doc -->
57
	 * <!-- begin-user-doc -->
57
	 * <p>
58
	 * <p>
58
	 * If the meaning of the '<em>Width</em>' attribute isn't clear,
59
	 * If the meaning of the '<em>Width</em>' attribute isn't clear,
Lines 62-68 Link Here
62
	 * @return the value of the '<em>Width</em>' attribute.
63
	 * @return the value of the '<em>Width</em>' attribute.
63
	 * @see #setWidth(int)
64
	 * @see #setWidth(int)
64
	 * @see org.eclipse.gmf.gmfgraph.GMFGraphPackage#getLineBorder_Width()
65
	 * @see org.eclipse.gmf.gmfgraph.GMFGraphPackage#getLineBorder_Width()
65
	 * @model
66
	 * @model default="1"
66
	 * @generated
67
	 * @generated
67
	 */
68
	 */
68
	int getWidth();
69
	int getWidth();
(-)models/gmfgraph.ecore (-1 / +2 lines)
Lines 281-287 Link Here
281
  <eClassifiers xsi:type="ecore:EClass" name="LineBorder" eSuperTypes="#//Border">
281
  <eClassifiers xsi:type="ecore:EClass" name="LineBorder" eSuperTypes="#//Border">
282
    <eStructuralFeatures xsi:type="ecore:EReference" name="color" eType="#//Color"
282
    <eStructuralFeatures xsi:type="ecore:EReference" name="color" eType="#//Color"
283
        containment="true"/>
283
        containment="true"/>
284
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="width" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
284
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="width" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"
285
        defaultValueLiteral="1"/>
285
  </eClassifiers>
286
  </eClassifiers>
286
  <eClassifiers xsi:type="ecore:EClass" name="MarginBorder" eSuperTypes="#//Border">
287
  <eClassifiers xsi:type="ecore:EClass" name="MarginBorder" eSuperTypes="#//Border">
287
    <eStructuralFeatures xsi:type="ecore:EReference" name="insets" eType="#//Insets"
288
    <eStructuralFeatures xsi:type="ecore:EReference" name="insets" eType="#//Insets"
(-)src/org/eclipse/gmf/gmfgraph/impl/GMFGraphPackageImpl.java (-1 / +1 lines)
Lines 2567-2573 Link Here
2567
2567
2568
		initEClass(lineBorderEClass, LineBorder.class, "LineBorder", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
2568
		initEClass(lineBorderEClass, LineBorder.class, "LineBorder", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
2569
		initEReference(getLineBorder_Color(), this.getColor(), null, "color", null, 0, 1, LineBorder.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
2569
		initEReference(getLineBorder_Color(), this.getColor(), null, "color", null, 0, 1, LineBorder.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
2570
		initEAttribute(getLineBorder_Width(), ecorePackage.getEInt(), "width", null, 0, 1, LineBorder.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
2570
		initEAttribute(getLineBorder_Width(), ecorePackage.getEInt(), "width", "1", 0, 1, LineBorder.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
2571
2571
2572
		initEClass(marginBorderEClass, MarginBorder.class, "MarginBorder", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
2572
		initEClass(marginBorderEClass, MarginBorder.class, "MarginBorder", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
2573
		initEReference(getMarginBorder_Insets(), this.getInsets(), null, "insets", null, 0, 1, MarginBorder.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
2573
		initEReference(getMarginBorder_Insets(), this.getInsets(), null, "insets", null, 0, 1, MarginBorder.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
(-)src/org/eclipse/gmf/gmfgraph/impl/LineBorderImpl.java (-1 / +1 lines)
Lines 49-55 Link Here
49
	 * @generated
49
	 * @generated
50
	 * @ordered
50
	 * @ordered
51
	 */
51
	 */
52
	protected static final int WIDTH_EDEFAULT = 0;
52
	protected static final int WIDTH_EDEFAULT = 1;
53
53
54
	/**
54
	/**
55
	 * The cached value of the '{@link #getWidth() <em>Width</em>}' attribute.
55
	 * The cached value of the '{@link #getWidth() <em>Width</em>}' attribute.
(-)templates/attr/Figure.javajet (+12 lines)
Lines 20-27 Link Here
20
<%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Size())) {
20
<%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Size())) {
21
		Point p = figureInstance.getSize();%>
21
		Point p = figureInstance.getSize();%>
22
		<%=figureVarName%>.setSize(<%=dispatcher.DPtoLP(p.getX())%>, <%=dispatcher.DPtoLP(p.getY())%>);
22
		<%=figureVarName%>.setSize(<%=dispatcher.DPtoLP(p.getX())%>, <%=dispatcher.DPtoLP(p.getY())%>);
23
<%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MaximumSize())) {
24
		Dimension d = figureInstance.getMaximumSize();%>
25
		<%=figureVarName%>.setMaximumSize(new <%=importManager.getImportedName("org.eclipse.draw2d.geometry.Dimension")%>(<%=dispatcher.DPtoLP(d.getDx())%>, <%=dispatcher.DPtoLP(d.getDy())%>));
26
<%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MinimumSize())) {
27
		Dimension d = figureInstance.getMinimumSize();%>
28
		<%=figureVarName%>.setMinimumSize(new <%=importManager.getImportedName("org.eclipse.draw2d.geometry.Dimension")%>(<%=dispatcher.DPtoLP(d.getDx())%>, <%=dispatcher.DPtoLP(d.getDy())%>));
23
<%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Font())) {
29
<%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Font())) {
24
		// XXX possible CCE when fonts other than Basic added to model 
30
		// XXX possible CCE when fonts other than Basic added to model 
25
		BasicFont font = (BasicFont) figureInstance.getFont();%>
31
		BasicFont font = (BasicFont) figureInstance.getFont();%>
26
		<%=figureVarName%>.setFont(new <%=importManager.getImportedName("org.eclipse.swt.graphics.Font")%>(<%=importManager.getImportedName("org.eclipse.swt.widgets.Display")%>.getCurrent(), "<%=font.getFaceName()%>", <%=font.getHeight()%>, <%=importManager.getImportedName("org.eclipse.swt.SWT")%>.<%=font.getStyle().getLiteral()%>));
32
		<%=figureVarName%>.setFont(new <%=importManager.getImportedName("org.eclipse.swt.graphics.Font")%>(<%=importManager.getImportedName("org.eclipse.swt.widgets.Display")%>.getCurrent(), "<%=font.getFaceName()%>", <%=font.getHeight()%>, <%=importManager.getImportedName("org.eclipse.swt.SWT")%>.<%=font.getStyle().getLiteral()%>));
33
<%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Insets())) {
34
		Insets insets = figureInstance.getInsets();%>
35
		<%=figureVarName%>.setBorder(new <%=importManager.getImportedName("org.eclipse.draw2d.MarginBorder")%>(<%=insets.getTop()%>, <%=insets.getLeft()%>, <%=insets.getBottom()%>, <%=insets.getRight()%>));
36
<%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Border())) {
37
		Border border = figureInstance.getBorder();%>
38
		<%=figureVarName%>.setBorder(<%=dispatcher.dispatch(border, new Object[] {border, dispatcher})%>);
27
<%}%>
39
<%}%>
(-)src/org/eclipse/gmf/graphdef/codegen/templates/FigureAttrGenerator.java (-14 / +78 lines)
Lines 43-55 Link Here
43
  protected final String TEXT_25 = ", ";
43
  protected final String TEXT_25 = ", ";
44
  protected final String TEXT_26 = ");";
44
  protected final String TEXT_26 = ");";
45
  protected final String TEXT_27 = NL + "\t\t";
45
  protected final String TEXT_27 = NL + "\t\t";
46
  protected final String TEXT_28 = ".setFont(new ";
46
  protected final String TEXT_28 = ".setMaximumSize(new ";
47
  protected final String TEXT_29 = "(";
47
  protected final String TEXT_29 = "(";
48
  protected final String TEXT_30 = ".getCurrent(), \"";
48
  protected final String TEXT_30 = ", ";
49
  protected final String TEXT_31 = "\", ";
49
  protected final String TEXT_31 = "));";
50
  protected final String TEXT_32 = ", ";
50
  protected final String TEXT_32 = NL + "\t\t";
51
  protected final String TEXT_33 = ".";
51
  protected final String TEXT_33 = ".setMinimumSize(new ";
52
  protected final String TEXT_34 = "));";
52
  protected final String TEXT_34 = "(";
53
  protected final String TEXT_35 = ", ";
54
  protected final String TEXT_36 = "));";
55
  protected final String TEXT_37 = NL + "\t\t";
56
  protected final String TEXT_38 = ".setFont(new ";
57
  protected final String TEXT_39 = "(";
58
  protected final String TEXT_40 = ".getCurrent(), \"";
59
  protected final String TEXT_41 = "\", ";
60
  protected final String TEXT_42 = ", ";
61
  protected final String TEXT_43 = ".";
62
  protected final String TEXT_44 = "));";
63
  protected final String TEXT_45 = NL + "\t\t";
64
  protected final String TEXT_46 = ".setBorder(new ";
65
  protected final String TEXT_47 = "(";
66
  protected final String TEXT_48 = ", ";
67
  protected final String TEXT_49 = ", ";
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 = ");";
53
73
54
  public String generate(Object argument)
74
  public String generate(Object argument)
55
  {
75
  {
Lines 122-145 Link Here
122
    stringBuffer.append(TEXT_25);
142
    stringBuffer.append(TEXT_25);
123
    stringBuffer.append(dispatcher.DPtoLP(p.getY()));
143
    stringBuffer.append(dispatcher.DPtoLP(p.getY()));
124
    stringBuffer.append(TEXT_26);
144
    stringBuffer.append(TEXT_26);
145
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MaximumSize())) {
146
		Dimension d = figureInstance.getMaximumSize();
147
    stringBuffer.append(TEXT_27);
148
    stringBuffer.append(figureVarName);
149
    stringBuffer.append(TEXT_28);
150
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.geometry.Dimension"));
151
    stringBuffer.append(TEXT_29);
152
    stringBuffer.append(dispatcher.DPtoLP(d.getDx()));
153
    stringBuffer.append(TEXT_30);
154
    stringBuffer.append(dispatcher.DPtoLP(d.getDy()));
155
    stringBuffer.append(TEXT_31);
156
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MinimumSize())) {
157
		Dimension d = figureInstance.getMinimumSize();
158
    stringBuffer.append(TEXT_32);
159
    stringBuffer.append(figureVarName);
160
    stringBuffer.append(TEXT_33);
161
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.geometry.Dimension"));
162
    stringBuffer.append(TEXT_34);
163
    stringBuffer.append(dispatcher.DPtoLP(d.getDx()));
164
    stringBuffer.append(TEXT_35);
165
    stringBuffer.append(dispatcher.DPtoLP(d.getDy()));
166
    stringBuffer.append(TEXT_36);
125
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Font())) {
167
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Font())) {
126
		// XXX possible CCE when fonts other than Basic added to model 
168
		// XXX possible CCE when fonts other than Basic added to model 
127
		BasicFont font = (BasicFont) figureInstance.getFont();
169
		BasicFont font = (BasicFont) figureInstance.getFont();
128
    stringBuffer.append(TEXT_27);
170
    stringBuffer.append(TEXT_37);
129
    stringBuffer.append(figureVarName);
171
    stringBuffer.append(figureVarName);
130
    stringBuffer.append(TEXT_28);
172
    stringBuffer.append(TEXT_38);
131
    stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Font"));
173
    stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Font"));
132
    stringBuffer.append(TEXT_29);
174
    stringBuffer.append(TEXT_39);
133
    stringBuffer.append(importManager.getImportedName("org.eclipse.swt.widgets.Display"));
175
    stringBuffer.append(importManager.getImportedName("org.eclipse.swt.widgets.Display"));
134
    stringBuffer.append(TEXT_30);
176
    stringBuffer.append(TEXT_40);
135
    stringBuffer.append(font.getFaceName());
177
    stringBuffer.append(font.getFaceName());
136
    stringBuffer.append(TEXT_31);
178
    stringBuffer.append(TEXT_41);
137
    stringBuffer.append(font.getHeight());
179
    stringBuffer.append(font.getHeight());
138
    stringBuffer.append(TEXT_32);
180
    stringBuffer.append(TEXT_42);
139
    stringBuffer.append(importManager.getImportedName("org.eclipse.swt.SWT"));
181
    stringBuffer.append(importManager.getImportedName("org.eclipse.swt.SWT"));
140
    stringBuffer.append(TEXT_33);
182
    stringBuffer.append(TEXT_43);
141
    stringBuffer.append(font.getStyle().getLiteral());
183
    stringBuffer.append(font.getStyle().getLiteral());
142
    stringBuffer.append(TEXT_34);
184
    stringBuffer.append(TEXT_44);
185
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Insets())) {
186
		Insets insets = figureInstance.getInsets();
187
    stringBuffer.append(TEXT_45);
188
    stringBuffer.append(figureVarName);
189
    stringBuffer.append(TEXT_46);
190
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.MarginBorder"));
191
    stringBuffer.append(TEXT_47);
192
    stringBuffer.append(insets.getTop());
193
    stringBuffer.append(TEXT_48);
194
    stringBuffer.append(insets.getLeft());
195
    stringBuffer.append(TEXT_49);
196
    stringBuffer.append(insets.getBottom());
197
    stringBuffer.append(TEXT_50);
198
    stringBuffer.append(insets.getRight());
199
    stringBuffer.append(TEXT_51);
200
    } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Border())) {
201
		Border border = figureInstance.getBorder();
202
    stringBuffer.append(TEXT_52);
203
    stringBuffer.append(figureVarName);
204
    stringBuffer.append(TEXT_53);
205
    stringBuffer.append(dispatcher.dispatch(border, new Object[] {border, dispatcher}));
206
    stringBuffer.append(TEXT_54);
143
    }
207
    }
144
    return stringBuffer.toString();
208
    return stringBuffer.toString();
145
  }
209
  }
(-)src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java (+12 lines)
Lines 16-21 Link Here
16
import org.eclipse.gmf.common.codegen.ImportAssistant;
16
import org.eclipse.gmf.common.codegen.ImportAssistant;
17
import org.eclipse.gmf.gmfgraph.BorderLayout;
17
import org.eclipse.gmf.gmfgraph.BorderLayout;
18
import org.eclipse.gmf.gmfgraph.BorderLayoutData;
18
import org.eclipse.gmf.gmfgraph.BorderLayoutData;
19
import org.eclipse.gmf.gmfgraph.CompoundBorder;
19
import org.eclipse.gmf.gmfgraph.CustomFigure;
20
import org.eclipse.gmf.gmfgraph.CustomFigure;
20
import org.eclipse.gmf.gmfgraph.CustomLayout;
21
import org.eclipse.gmf.gmfgraph.CustomLayout;
21
import org.eclipse.gmf.gmfgraph.CustomLayoutData;
22
import org.eclipse.gmf.gmfgraph.CustomLayoutData;
Lines 24-29 Link Here
24
import org.eclipse.gmf.gmfgraph.GridLayout;
25
import org.eclipse.gmf.gmfgraph.GridLayout;
25
import org.eclipse.gmf.gmfgraph.GridLayoutData;
26
import org.eclipse.gmf.gmfgraph.GridLayoutData;
26
import org.eclipse.gmf.gmfgraph.Label;
27
import org.eclipse.gmf.gmfgraph.Label;
28
import org.eclipse.gmf.gmfgraph.LineBorder;
29
import org.eclipse.gmf.gmfgraph.MarginBorder;
27
import org.eclipse.gmf.gmfgraph.PolygonDecoration;
30
import org.eclipse.gmf.gmfgraph.PolygonDecoration;
28
import org.eclipse.gmf.gmfgraph.Polyline;
31
import org.eclipse.gmf.gmfgraph.Polyline;
29
import org.eclipse.gmf.gmfgraph.PolylineConnection;
32
import org.eclipse.gmf.gmfgraph.PolylineConnection;
Lines 45-53 Link Here
45
import org.eclipse.gmf.graphdef.codegen.templates.InitGridLayoutGenerator;
48
import org.eclipse.gmf.graphdef.codegen.templates.InitGridLayoutGenerator;
46
import org.eclipse.gmf.graphdef.codegen.templates.InitXYLayoutDataGenerator;
49
import org.eclipse.gmf.graphdef.codegen.templates.InitXYLayoutDataGenerator;
47
import org.eclipse.gmf.graphdef.codegen.templates.LabelAttrGenerator;
50
import org.eclipse.gmf.graphdef.codegen.templates.LabelAttrGenerator;
51
import org.eclipse.gmf.graphdef.codegen.templates.NewCompoundBorderExpressionGenerator;
48
import org.eclipse.gmf.graphdef.codegen.templates.NewFigureGenerator;
52
import org.eclipse.gmf.graphdef.codegen.templates.NewFigureGenerator;
49
import org.eclipse.gmf.graphdef.codegen.templates.NewLayoutDataGenerator;
53
import org.eclipse.gmf.graphdef.codegen.templates.NewLayoutDataGenerator;
50
import org.eclipse.gmf.graphdef.codegen.templates.NewLayoutGenerator;
54
import org.eclipse.gmf.graphdef.codegen.templates.NewLayoutGenerator;
55
import org.eclipse.gmf.graphdef.codegen.templates.NewLineBorderExpressionGenerator;
56
import org.eclipse.gmf.graphdef.codegen.templates.NewMarginBorderExpressionGenerator;
51
import org.eclipse.gmf.graphdef.codegen.templates.PolygonDecorationAttrGenerator;
57
import org.eclipse.gmf.graphdef.codegen.templates.PolygonDecorationAttrGenerator;
52
import org.eclipse.gmf.graphdef.codegen.templates.PolylineAttrGenerator;
58
import org.eclipse.gmf.graphdef.codegen.templates.PolylineAttrGenerator;
53
import org.eclipse.gmf.graphdef.codegen.templates.PolylineDecorationAttrGenerator;
59
import org.eclipse.gmf.graphdef.codegen.templates.PolylineDecorationAttrGenerator;
Lines 160-165 Link Here
160
		tr.put(BorderLayoutData.class, "/layoutData/BorderLayoutData.javajet", InitBorderLayoutDataGenerator.class);
166
		tr.put(BorderLayoutData.class, "/layoutData/BorderLayoutData.javajet", InitBorderLayoutDataGenerator.class);
161
		tr.put(CustomLayoutData.class, "/layoutData/CustomLayoutData.javajet", InitCustomLayoutDataGenerator.class);
167
		tr.put(CustomLayoutData.class, "/layoutData/CustomLayoutData.javajet", InitCustomLayoutDataGenerator.class);
162
		tr.put(XYLayoutData.class, "/layoutData/XYLayoutData.javajet", InitXYLayoutDataGenerator.class);
168
		tr.put(XYLayoutData.class, "/layoutData/XYLayoutData.javajet", InitXYLayoutDataGenerator.class);
169
		
170
		//Borders 
171
		tr.put(LineBorder.class, "/new/LineBorder.javajet", NewLineBorderExpressionGenerator.class);
172
		tr.put(MarginBorder.class, "/new/MarginBorder.javajet", NewMarginBorderExpressionGenerator.class);
173
		tr.put(CompoundBorder.class, "/new/CompoundBorder.javajet", NewCompoundBorderExpressionGenerator.class);
174
163
		return tr;
175
		return tr;
164
	}
176
	}
165
177
(-)src/org/eclipse/gmf/graphdef/codegen/templates/NewCompoundBorderExpressionGenerator.java (+49 lines)
Added Link Here
1
package org.eclipse.gmf.graphdef.codegen.templates;
2
3
import org.eclipse.gmf.gmfgraph.*;
4
import org.eclipse.gmf.graphdef.codegen.*;
5
import org.eclipse.gmf.common.codegen.ImportAssistant;
6
7
public class NewCompoundBorderExpressionGenerator
8
{
9
  protected static String nl;
10
  public static synchronized NewCompoundBorderExpressionGenerator create(String lineSeparator)
11
  {
12
    nl = lineSeparator;
13
    NewCompoundBorderExpressionGenerator result = new NewCompoundBorderExpressionGenerator();
14
    nl = null;
15
    return result;
16
  }
17
18
  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
19
  protected final String TEXT_1 = "\t";
20
  protected final String TEXT_2 = NL + "new ";
21
  protected final String TEXT_3 = "(" + NL + "\t";
22
  protected final String TEXT_4 = ", " + NL + "\t";
23
  protected final String TEXT_5 = NL + ")";
24
25
  public String generate(Object argument)
26
  {
27
    StringBuffer stringBuffer = new StringBuffer();
28
    
29
Object[] args = (Object[]) argument;
30
final CompoundBorder border = (CompoundBorder)args[0];
31
final GraphDefDispatcher dispatcher = (GraphDefDispatcher)args[1];
32
final ImportAssistant importManager = dispatcher.getImportManager();
33
34
//We want NEITHER insert any names into the scope NOR produce statement. We need expression instead.
35
36
    stringBuffer.append(TEXT_1);
37
     	Border outer = border.getOuter();
38
		Border inner = border.getInner();
39
	
40
    stringBuffer.append(TEXT_2);
41
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.CompoundBorder"));
42
    stringBuffer.append(TEXT_3);
43
    stringBuffer.append( (outer == null) ? "null" : dispatcher.dispatch(outer, new Object[]{outer, dispatcher}));
44
    stringBuffer.append(TEXT_4);
45
    stringBuffer.append( (inner == null) ? "null" : dispatcher.dispatch(inner, new Object[]{inner, dispatcher}));
46
    stringBuffer.append(TEXT_5);
47
    return stringBuffer.toString();
48
  }
49
}
(-)templates/new/LineBorder.javajet (+34 lines)
Added Link Here
1
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="NewLineBorderExpressionGenerator"
2
	imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.* org.eclipse.gmf.common.codegen.ImportAssistant"%>
3
<%
4
Object[] args = (Object[]) argument;
5
final LineBorder border = (LineBorder)args[0];
6
final GraphDefDispatcher dispatcher = (GraphDefDispatcher)args[1];
7
final ImportAssistant importManager = dispatcher.getImportManager();
8
9
//We do not want to insert any names into the scope. 
10
//We want to provide EXPRESSION instead of statement
11
%>
12
<%
13
	String borderClazz = importManager.getImportedName("org.eclipse.draw2d.LineBorder");
14
	boolean hasColor = border.eIsSet(GMFGraphPackage.eINSTANCE.getLineBorder_Color());
15
	boolean hasWidth = border.eIsSet(GMFGraphPackage.eINSTANCE.getLineBorder_Width());
16
	Color colorVal = (hasColor) ? border.getColor() : null;
17
	if (hasColor && hasWidth){
18
%>
19
new <%=borderClazz%>(<%@ include file="../Color.jetinc"%>, <%=border.getWidth()%>)
20
<%
21
	} else if (hasColor && !hasWidth) {
22
%>
23
new <%=borderClazz%>(<%@ include file="../Color.jetinc"%>)
24
<%
25
	} else if (!hasColor && hasWidth){
26
%>
27
new <%=borderClazz%>(<%=border.getWidth()%>)
28
<%
29
	} else {
30
%>
31
new <%=borderClazz%>()
32
<%
33
	} 
34
%>
(-)src/org/eclipse/gmf/graphdef/codegen/templates/NewLineBorderExpressionGenerator.java (+125 lines)
Added Link Here
1
package org.eclipse.gmf.graphdef.codegen.templates;
2
3
import org.eclipse.gmf.gmfgraph.*;
4
import org.eclipse.gmf.graphdef.codegen.*;
5
import org.eclipse.gmf.common.codegen.ImportAssistant;
6
7
public class NewLineBorderExpressionGenerator
8
{
9
  protected static String nl;
10
  public static synchronized NewLineBorderExpressionGenerator create(String lineSeparator)
11
  {
12
    nl = lineSeparator;
13
    NewLineBorderExpressionGenerator result = new NewLineBorderExpressionGenerator();
14
    nl = null;
15
    return result;
16
  }
17
18
  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
19
  protected final String TEXT_1 = "new ";
20
  protected final String TEXT_2 = "(";
21
  protected final String TEXT_3 = "new ";
22
  protected final String TEXT_4 = "(null, ";
23
  protected final String TEXT_5 = ", ";
24
  protected final String TEXT_6 = ", ";
25
  protected final String TEXT_7 = ")";
26
  protected final String TEXT_8 = ".";
27
  protected final String TEXT_9 = ", ";
28
  protected final String TEXT_10 = ")";
29
  protected final String TEXT_11 = NL + "new ";
30
  protected final String TEXT_12 = "(";
31
  protected final String TEXT_13 = "new ";
32
  protected final String TEXT_14 = "(null, ";
33
  protected final String TEXT_15 = ", ";
34
  protected final String TEXT_16 = ", ";
35
  protected final String TEXT_17 = ")";
36
  protected final String TEXT_18 = ".";
37
  protected final String TEXT_19 = ")";
38
  protected final String TEXT_20 = NL + "new ";
39
  protected final String TEXT_21 = "(";
40
  protected final String TEXT_22 = ")";
41
  protected final String TEXT_23 = NL + "new ";
42
  protected final String TEXT_24 = "()";
43
44
  public String generate(Object argument)
45
  {
46
    StringBuffer stringBuffer = new StringBuffer();
47
    
48
Object[] args = (Object[]) argument;
49
final LineBorder border = (LineBorder)args[0];
50
final GraphDefDispatcher dispatcher = (GraphDefDispatcher)args[1];
51
final ImportAssistant importManager = dispatcher.getImportManager();
52
53
//We do not want to insert any names into the scope. 
54
//We want to provide EXPRESSION instead of statement
55
56
    
57
	String borderClazz = importManager.getImportedName("org.eclipse.draw2d.LineBorder");
58
	boolean hasColor = border.eIsSet(GMFGraphPackage.eINSTANCE.getLineBorder_Color());
59
	boolean hasWidth = border.eIsSet(GMFGraphPackage.eINSTANCE.getLineBorder_Width());
60
	Color colorVal = (hasColor) ? border.getColor() : null;
61
	if (hasColor && hasWidth){
62
63
    stringBuffer.append(TEXT_1);
64
    stringBuffer.append(borderClazz);
65
    stringBuffer.append(TEXT_2);
66
    if (colorVal instanceof RGBColor) {
67
    stringBuffer.append(TEXT_3);
68
    stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Color"));
69
    stringBuffer.append(TEXT_4);
70
    stringBuffer.append(((RGBColor) colorVal).getRed());
71
    stringBuffer.append(TEXT_5);
72
    stringBuffer.append(((RGBColor) colorVal).getGreen());
73
    stringBuffer.append(TEXT_6);
74
    stringBuffer.append(((RGBColor) colorVal).getBlue());
75
    stringBuffer.append(TEXT_7);
76
    } else if (colorVal instanceof ConstantColor) {
77
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants"));
78
    stringBuffer.append(TEXT_8);
79
    stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral());
80
    }
81
    stringBuffer.append(TEXT_9);
82
    stringBuffer.append(border.getWidth());
83
    stringBuffer.append(TEXT_10);
84
    
85
	} else if (hasColor && !hasWidth) {
86
87
    stringBuffer.append(TEXT_11);
88
    stringBuffer.append(borderClazz);
89
    stringBuffer.append(TEXT_12);
90
    if (colorVal instanceof RGBColor) {
91
    stringBuffer.append(TEXT_13);
92
    stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Color"));
93
    stringBuffer.append(TEXT_14);
94
    stringBuffer.append(((RGBColor) colorVal).getRed());
95
    stringBuffer.append(TEXT_15);
96
    stringBuffer.append(((RGBColor) colorVal).getGreen());
97
    stringBuffer.append(TEXT_16);
98
    stringBuffer.append(((RGBColor) colorVal).getBlue());
99
    stringBuffer.append(TEXT_17);
100
    } else if (colorVal instanceof ConstantColor) {
101
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants"));
102
    stringBuffer.append(TEXT_18);
103
    stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral());
104
    }
105
    stringBuffer.append(TEXT_19);
106
    
107
	} else if (!hasColor && hasWidth){
108
109
    stringBuffer.append(TEXT_20);
110
    stringBuffer.append(borderClazz);
111
    stringBuffer.append(TEXT_21);
112
    stringBuffer.append(border.getWidth());
113
    stringBuffer.append(TEXT_22);
114
    
115
	} else {
116
117
    stringBuffer.append(TEXT_23);
118
    stringBuffer.append(borderClazz);
119
    stringBuffer.append(TEXT_24);
120
    
121
	} 
122
123
    return stringBuffer.toString();
124
  }
125
}
(-)templates/new/MarginBorder.javajet (+24 lines)
Added Link Here
1
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="NewMarginBorderExpressionGenerator"
2
	imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.* org.eclipse.gmf.common.codegen.ImportAssistant"%>
3
<%
4
Object[] args = (Object[]) argument;
5
final MarginBorder border = (MarginBorder)args[0];
6
final GraphDefDispatcher dispatcher = (GraphDefDispatcher)args[1];
7
final ImportAssistant importManager = dispatcher.getImportManager();
8
9
//Produces EXPRESSION instead of statement
10
%>
11
<%
12
	int top = 0;
13
	int left = 0;
14
	int bottom = 0;
15
	int right = 0;
16
	if (border.eIsSet(GMFGraphPackage.eINSTANCE.getMarginBorder_Insets())){
17
		Insets insets = border.getInsets();
18
		top = insets.getTop();
19
		left = insets.getLeft();
20
		bottom = insets.getBottom();
21
		right = insets.getRight();
22
	}
23
%>	
24
new <%=importManager.getImportedName("org.eclipse.draw2d.MarginBorder")%>(<%=top%>, <%=left%>, <%=bottom%>, <%=right%>)
(-)templates/new/CompoundBorder.javajet (+17 lines)
Added Link Here
1
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="NewCompoundBorderExpressionGenerator"
2
	imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.* org.eclipse.gmf.common.codegen.ImportAssistant"%>
3
<%
4
Object[] args = (Object[]) argument;
5
final CompoundBorder border = (CompoundBorder)args[0];
6
final GraphDefDispatcher dispatcher = (GraphDefDispatcher)args[1];
7
final ImportAssistant importManager = dispatcher.getImportManager();
8
9
//We want NEITHER insert any names into the scope NOR produce statement. We need expression instead.
10
%>
11
	<% 	Border outer = border.getOuter();
12
		Border inner = border.getInner();
13
	%>
14
new <%=importManager.getImportedName("org.eclipse.draw2d.CompoundBorder")%>(
15
	<%= (outer == null) ? "null" : dispatcher.dispatch(outer, new Object[]{outer, dispatcher})%>, 
16
	<%= (inner == null) ? "null" : dispatcher.dispatch(inner, new Object[]{inner, dispatcher})%>
17
)
(-)src/org/eclipse/gmf/graphdef/codegen/templates/NewMarginBorderExpressionGenerator.java (+63 lines)
Added Link Here
1
package org.eclipse.gmf.graphdef.codegen.templates;
2
3
import org.eclipse.gmf.gmfgraph.*;
4
import org.eclipse.gmf.graphdef.codegen.*;
5
import org.eclipse.gmf.common.codegen.ImportAssistant;
6
7
public class NewMarginBorderExpressionGenerator
8
{
9
  protected static String nl;
10
  public static synchronized NewMarginBorderExpressionGenerator create(String lineSeparator)
11
  {
12
    nl = lineSeparator;
13
    NewMarginBorderExpressionGenerator result = new NewMarginBorderExpressionGenerator();
14
    nl = null;
15
    return result;
16
  }
17
18
  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
19
  protected final String TEXT_1 = "\t" + NL + "new ";
20
  protected final String TEXT_2 = "(";
21
  protected final String TEXT_3 = ", ";
22
  protected final String TEXT_4 = ", ";
23
  protected final String TEXT_5 = ", ";
24
  protected final String TEXT_6 = ")";
25
26
  public String generate(Object argument)
27
  {
28
    StringBuffer stringBuffer = new StringBuffer();
29
    
30
Object[] args = (Object[]) argument;
31
final MarginBorder border = (MarginBorder)args[0];
32
final GraphDefDispatcher dispatcher = (GraphDefDispatcher)args[1];
33
final ImportAssistant importManager = dispatcher.getImportManager();
34
35
//Produces EXPRESSION instead of statement
36
37
    
38
	int top = 0;
39
	int left = 0;
40
	int bottom = 0;
41
	int right = 0;
42
	if (border.eIsSet(GMFGraphPackage.eINSTANCE.getMarginBorder_Insets())){
43
		Insets insets = border.getInsets();
44
		top = insets.getTop();
45
		left = insets.getLeft();
46
		bottom = insets.getBottom();
47
		right = insets.getRight();
48
	}
49
50
    stringBuffer.append(TEXT_1);
51
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.MarginBorder"));
52
    stringBuffer.append(TEXT_2);
53
    stringBuffer.append(top);
54
    stringBuffer.append(TEXT_3);
55
    stringBuffer.append(left);
56
    stringBuffer.append(TEXT_4);
57
    stringBuffer.append(bottom);
58
    stringBuffer.append(TEXT_5);
59
    stringBuffer.append(right);
60
    stringBuffer.append(TEXT_6);
61
    return stringBuffer.toString();
62
  }
63
}
(-)models/gmfgraph.emf (-1 / +1 lines)
Lines 273-279 Link Here
273
273
274
class LineBorder extends Border {
274
class LineBorder extends Border {
275
	val Color color;
275
	val Color color;
276
	attr int width;
276
	attr int width = 1;
277
}
277
}
278
278
279
class MarginBorder extends Border {
279
class MarginBorder extends Border {

Return to bug 134249