Lines 19-24
Link Here
|
19 |
import org.eclipse.gmf.gmfgraph.BorderLayout; |
19 |
import org.eclipse.gmf.gmfgraph.BorderLayout; |
20 |
import org.eclipse.gmf.gmfgraph.BorderLayoutData; |
20 |
import org.eclipse.gmf.gmfgraph.BorderLayoutData; |
21 |
import org.eclipse.gmf.gmfgraph.CustomAttribute; |
21 |
import org.eclipse.gmf.gmfgraph.CustomAttribute; |
|
|
22 |
import org.eclipse.gmf.gmfgraph.CustomFigure; |
22 |
import org.eclipse.gmf.gmfgraph.CustomLayout; |
23 |
import org.eclipse.gmf.gmfgraph.CustomLayout; |
23 |
import org.eclipse.gmf.gmfgraph.Dimension; |
24 |
import org.eclipse.gmf.gmfgraph.Dimension; |
24 |
import org.eclipse.gmf.gmfgraph.Figure; |
25 |
import org.eclipse.gmf.gmfgraph.Figure; |
Lines 31-36
Link Here
|
31 |
import org.eclipse.gmf.gmfgraph.LayoutData; |
32 |
import org.eclipse.gmf.gmfgraph.LayoutData; |
32 |
import org.eclipse.gmf.gmfgraph.RGBColor; |
33 |
import org.eclipse.gmf.gmfgraph.RGBColor; |
33 |
import org.eclipse.gmf.gmfgraph.Rectangle; |
34 |
import org.eclipse.gmf.gmfgraph.Rectangle; |
|
|
35 |
import org.eclipse.gmf.gmfgraph.RoundedRectangle; |
34 |
import org.eclipse.gmf.gmfgraph.XYLayoutData; |
36 |
import org.eclipse.gmf.gmfgraph.XYLayoutData; |
35 |
|
37 |
|
36 |
public class FigureLayoutTest extends FigureCodegenTestBase { |
38 |
public class FigureLayoutTest extends FigureCodegenTestBase { |
Lines 58-64
Link Here
|
58 |
for (Iterator it = children.iterator(); it.hasNext();){ |
60 |
for (Iterator it = children.iterator(); it.hasNext();){ |
59 |
FigureMarker next = (FigureMarker)it.next(); |
61 |
FigureMarker next = (FigureMarker)it.next(); |
60 |
oddChild = !oddChild; |
62 |
oddChild = !oddChild; |
61 |
LayoutData data = createLayoutDataAllProperties(oddChild); |
63 |
LayoutData data = createGridLayoutDataAllProperties(oddChild); |
62 |
next.setLayoutData(data); |
64 |
next.setLayoutData(data); |
63 |
assertEquals("data-owner relation should be bidirectional", next, data.getOwner()); |
65 |
assertEquals("data-owner relation should be bidirectional", next, data.getOwner()); |
64 |
} |
66 |
} |
Lines 75-81
Link Here
|
75 |
|
77 |
|
76 |
for (Iterator children = parent.getChildren().iterator(); children.hasNext();){ |
78 |
for (Iterator children = parent.getChildren().iterator(); children.hasNext();){ |
77 |
FigureMarker next = (FigureMarker)children.next(); |
79 |
FigureMarker next = (FigureMarker)children.next(); |
78 |
GridLayoutData data = createLayoutDataAllProperties(false); |
80 |
GridLayoutData data = createGridLayoutDataAllProperties(false); |
79 |
data.setHorizontalAlignment(Alignment.FILL_LITERAL); |
81 |
data.setHorizontalAlignment(Alignment.FILL_LITERAL); |
80 |
data.setOwner(next); |
82 |
data.setOwner(next); |
81 |
assertEquals("data-owner relation should be bidirectional", data, next.getLayoutData()); |
83 |
assertEquals("data-owner relation should be bidirectional", data, next.getLayoutData()); |
Lines 91-97
Link Here
|
91 |
for (int i = 0; i < 4; i++){ |
93 |
for (int i = 0; i < 4; i++){ |
92 |
next = addPairOfChildRectanglesAndReturnLeft(next); |
94 |
next = addPairOfChildRectanglesAndReturnLeft(next); |
93 |
} |
95 |
} |
94 |
performGridLayoutTests(parent); |
96 |
performTests(parent); |
95 |
} |
97 |
} |
96 |
|
98 |
|
97 |
public void testLayoutDefaults(){ |
99 |
public void testLayoutDefaults(){ |
Lines 122-133
Link Here
|
122 |
|
124 |
|
123 |
FigureRef refChildA = GMFGraphFactory.eINSTANCE.createFigureRef(); |
125 |
FigureRef refChildA = GMFGraphFactory.eINSTANCE.createFigureRef(); |
124 |
refChildA.setFigure(referencedFigure); |
126 |
refChildA.setFigure(referencedFigure); |
125 |
refChildA.setLayoutData(createLayoutDataAllProperties(false)); |
127 |
refChildA.setLayoutData(createGridLayoutDataAllProperties(false)); |
126 |
|
128 |
|
127 |
//same figure is referenced, different layout data |
129 |
//same figure is referenced, different layout data |
128 |
FigureRef refChildB = GMFGraphFactory.eINSTANCE.createFigureRef(); |
130 |
FigureRef refChildB = GMFGraphFactory.eINSTANCE.createFigureRef(); |
129 |
refChildB.setFigure(referencedFigure); |
131 |
refChildB.setFigure(referencedFigure); |
130 |
refChildB.setLayoutData(createLayoutDataAllProperties(true)); |
132 |
refChildB.setLayoutData(createGridLayoutDataAllProperties(true)); |
131 |
|
133 |
|
132 |
parent.getChildren().add(refChildA); |
134 |
parent.getChildren().add(refChildA); |
133 |
parent.getChildren().add(refChildB); |
135 |
parent.getChildren().add(refChildB); |
Lines 142-148
Link Here
|
142 |
|
144 |
|
143 |
Figure child = GMFGraphFactory.eINSTANCE.createRectangle(); |
145 |
Figure child = GMFGraphFactory.eINSTANCE.createRectangle(); |
144 |
child.setName("childWithLayoutData"); |
146 |
child.setName("childWithLayoutData"); |
145 |
child.setLayoutData(createLayoutDataAllProperties(false)); |
147 |
child.setLayoutData(createGridLayoutDataAllProperties(false)); |
146 |
|
148 |
|
147 |
parent.getChildren().add(child); |
149 |
parent.getChildren().add(child); |
148 |
|
150 |
|
Lines 263-271
Link Here
|
263 |
|
265 |
|
264 |
public void testXYLayout(){ |
266 |
public void testXYLayout(){ |
265 |
Figure group = createRGBGroup("XY"); |
267 |
Figure group = createRGBGroup("XY"); |
|
|
268 |
Figure left = (Figure) group.getChildren().get(0); |
269 |
Figure right = (Figure) group.getChildren().get(1); |
270 |
|
271 |
setupXYLayout(group, left, right); |
272 |
|
273 |
performTests(group); |
274 |
performTests(right); |
275 |
performTests(left); |
276 |
} |
277 |
|
278 |
public void testXYLayoutForCustomFigure(){ |
279 |
CustomFigure group = GMFGraphFactory.eINSTANCE.createCustomFigure(); |
280 |
group.setBundleName("org.eclipse.draw2d"); |
281 |
group.setQualifiedClassName("org.eclipse.draw2d.Layer"); |
282 |
group.setName("CustomLayer"); |
283 |
|
284 |
Rectangle left = GMFGraphFactory.eINSTANCE.createRectangle(); |
285 |
left.setName("Left"); |
286 |
group.getChildren().add(left); |
287 |
|
288 |
RoundedRectangle right = GMFGraphFactory.eINSTANCE.createRoundedRectangle(); |
289 |
right.setName("Right"); |
290 |
group.getChildren().add(right); |
291 |
|
292 |
setupXYLayout(group, left, right); |
293 |
|
294 |
performTests(group); |
295 |
} |
296 |
|
297 |
private void setupXYLayout(final Figure group, final Figure left, final Figure right){ |
298 |
assertTrue(group.getChildren().contains(left)); |
299 |
assertTrue(group.getChildren().contains(right)); |
300 |
assertNotSame(left, right); |
301 |
|
266 |
group.setLayout(GMFGraphFactory.eINSTANCE.createXYLayout()); |
302 |
group.setLayout(GMFGraphFactory.eINSTANCE.createXYLayout()); |
267 |
|
303 |
|
268 |
Figure left = (Figure) group.getChildren().get(0); |
|
|
269 |
XYLayoutData leftDataCorrect = GMFGraphFactory.eINSTANCE.createXYLayoutData(); |
304 |
XYLayoutData leftDataCorrect = GMFGraphFactory.eINSTANCE.createXYLayoutData(); |
270 |
leftDataCorrect.setTopLeft(GMFGraphFactory.eINSTANCE.createPoint()); |
305 |
leftDataCorrect.setTopLeft(GMFGraphFactory.eINSTANCE.createPoint()); |
271 |
leftDataCorrect.getTopLeft().setX(12); |
306 |
leftDataCorrect.getTopLeft().setX(12); |
Lines 275-290
Link Here
|
275 |
leftDataCorrect.getSize().setDy(30); |
310 |
leftDataCorrect.getSize().setDy(30); |
276 |
leftDataCorrect.setOwner(left); |
311 |
leftDataCorrect.setOwner(left); |
277 |
|
312 |
|
278 |
Figure right = (Figure) group.getChildren().get(1); |
|
|
279 |
XYLayoutData rightDataIncomplete = GMFGraphFactory.eINSTANCE.createXYLayoutData(); |
313 |
XYLayoutData rightDataIncomplete = GMFGraphFactory.eINSTANCE.createXYLayoutData(); |
280 |
rightDataIncomplete.setSize(GMFGraphFactory.eINSTANCE.createDimension()); |
314 |
rightDataIncomplete.setSize(GMFGraphFactory.eINSTANCE.createDimension()); |
281 |
rightDataIncomplete.getSize().setDx(30); |
315 |
rightDataIncomplete.getSize().setDx(30); |
282 |
rightDataIncomplete.getSize().setDy(20); |
316 |
rightDataIncomplete.getSize().setDy(20); |
283 |
right.setLayoutData(rightDataIncomplete); |
317 |
right.setLayoutData(rightDataIncomplete); |
284 |
|
|
|
285 |
performTests(group); |
286 |
performTests(right); |
287 |
performTests(left); |
288 |
} |
318 |
} |
289 |
|
319 |
|
290 |
private Figure createRGBGroup(String rootName){ |
320 |
private Figure createRGBGroup(String rootName){ |
Lines 307-332
Link Here
|
307 |
} |
337 |
} |
308 |
|
338 |
|
309 |
private Figure addPairOfChildRectanglesAndReturnLeft(Figure parent){ |
339 |
private Figure addPairOfChildRectanglesAndReturnLeft(Figure parent){ |
310 |
GridLayout parentLayout = createGridLayoutAllProperties(); |
340 |
parent.setLayout(createBorderLayoutAllProperties()); |
311 |
parentLayout.setNumColumns(2); |
|
|
312 |
parentLayout.setMargins(null); |
313 |
parentLayout.setSpacing(null); |
314 |
parent.setLayout(parentLayout); |
315 |
|
341 |
|
316 |
Rectangle left = GMFGraphFactory.eINSTANCE.createRectangle(); |
342 |
Rectangle left = GMFGraphFactory.eINSTANCE.createRectangle(); |
317 |
left.setName(parent.getName() + "_1"); |
343 |
left.setName(parent.getName() + "_1"); |
318 |
left.setLayoutData(createLayoutDataAllProperties(true)); |
344 |
left.setLayoutData(createBorderLayoutDataAllProperties(Alignment.BEGINNING_LITERAL, false)); |
319 |
parent.getChildren().add(left); |
345 |
parent.getChildren().add(left); |
320 |
|
346 |
|
321 |
Rectangle right = GMFGraphFactory.eINSTANCE.createRectangle(); |
347 |
Rectangle right = GMFGraphFactory.eINSTANCE.createRectangle(); |
322 |
right.setName(parent.getName() + "_2"); |
348 |
right.setName(parent.getName() + "_2"); |
323 |
right.setLayoutData(createLayoutDataAllProperties(false)); |
349 |
right.setLayoutData(createBorderLayoutDataAllProperties(Alignment.END_LITERAL, false)); |
324 |
parent.getChildren().add(right); |
350 |
parent.getChildren().add(right); |
325 |
|
351 |
|
326 |
return left; |
352 |
return left; |
327 |
} |
353 |
} |
328 |
|
354 |
|
329 |
private GridLayoutData createLayoutDataAllProperties(boolean horizontalBeginningNotEnd) { |
355 |
private GridLayoutData createGridLayoutDataAllProperties(boolean horizontalBeginningNotEnd) { |
330 |
GridLayoutData data = GMFGraphFactory.eINSTANCE.createGridLayoutData(); |
356 |
GridLayoutData data = GMFGraphFactory.eINSTANCE.createGridLayoutData(); |
331 |
data.setGrabExcessHorizontalSpace(true); |
357 |
data.setGrabExcessHorizontalSpace(true); |
332 |
data.setGrabExcessVerticalSpace(false); |
358 |
data.setGrabExcessVerticalSpace(false); |
Lines 352-361
Link Here
|
352 |
spacing.setDx(7); |
378 |
spacing.setDx(7); |
353 |
spacing.setDy(8); |
379 |
spacing.setDy(8); |
354 |
layout.setSpacing(spacing); |
380 |
layout.setSpacing(spacing); |
355 |
|
381 |
|
356 |
return layout; |
382 |
return layout; |
357 |
} |
383 |
} |
358 |
|
384 |
|
|
|
385 |
private BorderLayout createBorderLayoutAllProperties(){ |
386 |
BorderLayout result = GMFGraphFactory.eINSTANCE.createBorderLayout(); |
387 |
Dimension spacing = GMFGraphFactory.eINSTANCE.createDimension(); |
388 |
spacing.setDx(11); |
389 |
spacing.setDy(12); |
390 |
result.setSpacing(spacing); |
391 |
return result; |
392 |
} |
393 |
|
394 |
private BorderLayoutData createBorderLayoutDataAllProperties(Alignment alignment, boolean isVertical){ |
395 |
BorderLayoutData result = GMFGraphFactory.eINSTANCE.createBorderLayoutData(); |
396 |
result.setAlignment(alignment); |
397 |
result.setVertical(isVertical); |
398 |
return result; |
399 |
} |
400 |
|
359 |
private Dimension createDimension(int dx, int dy){ |
401 |
private Dimension createDimension(int dx, int dy){ |
360 |
Dimension result = GMFGraphFactory.eINSTANCE.createDimension(); |
402 |
Dimension result = GMFGraphFactory.eINSTANCE.createDimension(); |
361 |
result.setDx(dx); |
403 |
result.setDx(dx); |
Lines 379-385
Link Here
|
379 |
} |
421 |
} |
380 |
|
422 |
|
381 |
private void performGridLayoutTests(Figure figure){ |
423 |
private void performGridLayoutTests(Figure figure){ |
382 |
|
424 |
generateAndParse(figure); |
383 |
} |
425 |
} |
384 |
|
426 |
|
385 |
} |
427 |
} |