Skip to content

Package: ControlGridSWTRenderer_ITest$DummyRenderer

ControlGridSWTRenderer_ITest$DummyRenderer

nameinstructionbranchcomplexitylinemethod
ControlGridSWTRenderer_ITest.DummyRenderer(VControl, ViewModelContext, ReportService, SWTGridDescription)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
createLabel(int, Composite)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getGridDescription(SWTGridDescription)
M: 0 C: 19
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
renderControl(SWTGridCell, Composite)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * jfaltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.spi.swt.controlgrid.renderer;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertFalse;
18: import static org.junit.Assert.assertNotNull;
19: import static org.junit.Assert.assertNull;
20: import static org.junit.Assert.assertSame;
21: import static org.junit.Assert.assertTrue;
22: import static org.mockito.Matchers.any;
23: import static org.mockito.Mockito.mock;
24: import static org.mockito.Mockito.when;
25:
26: import java.text.MessageFormat;
27: import java.util.Arrays;
28: import java.util.Collections;
29: import java.util.Map;
30: import java.util.Set;
31:
32: import org.eclipse.emf.ecp.test.common.DefaultRealm;
33: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
34: import org.eclipse.emf.ecp.view.spi.model.VControl;
35: import org.eclipse.emf.ecp.view.spi.model.VElement;
36: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
37: import org.eclipse.emf.ecp.view.spi.renderer.NoPropertyDescriptorFoundExeption;
38: import org.eclipse.emf.ecp.view.spi.renderer.NoRendererFoundException;
39: import org.eclipse.emf.emfforms.spi.view.controlgrid.model.VControlGrid;
40: import org.eclipse.emf.emfforms.spi.view.controlgrid.model.VControlGridCell;
41: import org.eclipse.emf.emfforms.spi.view.controlgrid.model.VControlGridRow;
42: import org.eclipse.emf.emfforms.spi.view.controlgrid.model.VControlgridFactory;
43: import org.eclipse.emfforms.spi.common.report.ReportService;
44: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
45: import org.eclipse.emfforms.spi.swt.core.EMFFormsNoRendererException;
46: import org.eclipse.emfforms.spi.swt.core.EMFFormsRendererFactory;
47: import org.eclipse.emfforms.spi.swt.core.layout.GridDescriptionFactory;
48: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridCell;
49: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridDescription;
50: import org.eclipse.swt.SWT;
51: import org.eclipse.swt.layout.GridData;
52: import org.eclipse.swt.layout.GridLayout;
53: import org.eclipse.swt.widgets.Composite;
54: import org.eclipse.swt.widgets.Control;
55: import org.eclipse.swt.widgets.Label;
56: import org.eclipse.swt.widgets.Layout;
57: import org.eclipse.swt.widgets.Shell;
58: import org.junit.After;
59: import org.junit.Before;
60: import org.junit.Test;
61:
62: public class ControlGridSWTRenderer_ITest {
63:
64:         private DefaultRealm realm;
65:         private VControlGrid controlGrid;
66:         private ViewModelContext viewModelContext;
67:         private ReportService reportService;
68:         private EMFFormsRendererFactory emfFormsRendererFactory;
69:         private Shell shell;
70:
71:         @Before
72:         public void before() {
73:                 realm = new DefaultRealm();
74:                 shell = new Shell();
75:                 controlGrid = mock(VControlGrid.class);
76:                 viewModelContext = mock(ViewModelContext.class);
77:                 reportService = mock(ReportService.class);
78:                 emfFormsRendererFactory = mock(EMFFormsRendererFactory.class);
79:         }
80:
81:         @After
82:         public void after() {
83:                 shell.dispose();
84:                 realm.dispose();
85:         }
86:
87:         private ControlGridSWTRenderer createRenderer() {
88:                 return new ControlGridSWTRenderer(controlGrid, viewModelContext, reportService, emfFormsRendererFactory);
89:         }
90:
91:         @Test
92:         public void testGetRendererFactory() {
93:                 final ControlGridSWTRenderer renderer = createRenderer();
94:                 assertSame(emfFormsRendererFactory, renderer.getRendererFactory());
95:         }
96:
97:         @Test
98:         public void testGetGridDescription() {
99:                 final ControlGridSWTRenderer renderer = createRenderer();
100:                 final SWTGridDescription gridDescription = renderer.getGridDescription(mock(SWTGridDescription.class));
101:                 assertEquals(1, gridDescription.getColumns());
102:                 assertEquals(1, gridDescription.getRows());
103:                 assertEquals(1, gridDescription.getGrid().size());
104:
105:                 final SWTGridCell cell = gridDescription.getGrid().get(0);
106:                 assertEquals(0, cell.getColumn());
107:                 assertEquals(1, cell.getHorizontalSpan());
108:                 assertEquals(0, cell.getRow());
109:                 assertSame(renderer, cell.getRenderer());
110:                 assertTrue(cell.isHorizontalFill());
111:                 assertTrue(cell.isHorizontalGrab());
112:                 assertTrue(cell.isVerticalFill());
113:                 assertFalse(cell.isVerticalGrab());
114:         }
115:
116:         @Test
117:         public void testGetChildRenderers() throws EMFFormsNoRendererException {
118:                 /* setup */
119:                 controlGrid = VControlgridFactory.eINSTANCE.createControlGrid();
120:
121:                 final VControlGridRow row1 = VControlgridFactory.eINSTANCE.createControlGridRow();
122:                 final VControlGridRow row2 = VControlgridFactory.eINSTANCE.createControlGridRow();
123:                 controlGrid.getRows().addAll(Arrays.asList(row1, row2));
124:
125:                 final VControlGridCell cell11 = VControlgridFactory.eINSTANCE.createControlGridCell();
126:                 final VControlGridCell cell21 = VControlgridFactory.eINSTANCE.createControlGridCell();
127:                 row1.getCells().add(cell11);
128:                 row2.getCells().add(cell21);
129:
130:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
131:                 final VControl control2 = VViewFactory.eINSTANCE.createControl();
132:                 cell11.setControl(control1);
133:                 cell21.setControl(control2);
134:
135:                 final ControlGridSWTRenderer renderer = createRenderer();
136:
137:                 @SuppressWarnings("unchecked")
138:                 final AbstractSWTRenderer<VElement> renderer1 = mock(AbstractSWTRenderer.class);
139:                 when(emfFormsRendererFactory.getRendererInstance(control1, viewModelContext)).thenReturn(renderer1);
140:
141:                 @SuppressWarnings("unchecked")
142:                 final AbstractSWTRenderer<VElement> renderer2 = mock(AbstractSWTRenderer.class);
143:                 when(emfFormsRendererFactory.getRendererInstance(control2, viewModelContext)).thenReturn(renderer2);
144:
145:                 /* act */
146:                 final Map<VControlGridCell, AbstractSWTRenderer<VElement>> renderers = renderer.getChildRenderers();
147:
148:                 /* assert */
149:                 assertEquals(2, renderers.size());
150:                 assertTrue(renderers.containsKey(cell11));
151:                 assertTrue(renderers.containsKey(cell21));
152:                 assertSame(renderer1, renderers.get(cell11));
153:                 assertSame(renderer2, renderers.get(cell21));
154:         }
155:
156:         @Test
157:         public void testGetChildRenderersEmptyCell() throws EMFFormsNoRendererException {
158:                 /* setup */
159:                 controlGrid = VControlgridFactory.eINSTANCE.createControlGrid();
160:
161:                 final VControlGridRow row1 = VControlgridFactory.eINSTANCE.createControlGridRow();
162:                 final VControlGridRow row2 = VControlgridFactory.eINSTANCE.createControlGridRow();
163:                 controlGrid.getRows().addAll(Arrays.asList(row1, row2));
164:
165:                 final VControlGridCell cell11 = VControlgridFactory.eINSTANCE.createControlGridCell();
166:                 final VControlGridCell cell21 = VControlgridFactory.eINSTANCE.createControlGridCell();
167:                 row1.getCells().add(cell11);
168:                 row2.getCells().add(cell21);
169:
170:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
171:                 cell11.setControl(control1);
172:
173:                 final ControlGridSWTRenderer renderer = createRenderer();
174:
175:                 @SuppressWarnings("unchecked")
176:                 final AbstractSWTRenderer<VElement> renderer1 = mock(AbstractSWTRenderer.class);
177:                 when(emfFormsRendererFactory.getRendererInstance(control1, viewModelContext)).thenReturn(renderer1);
178:
179:                 /* act */
180:                 final Map<VControlGridCell, AbstractSWTRenderer<VElement>> renderers = renderer.getChildRenderers();
181:
182:                 /* assert */
183:                 assertEquals(1, renderers.size());
184:                 assertTrue(renderers.containsKey(cell11));
185:                 assertFalse(renderers.containsKey(cell21));
186:                 assertSame(renderer1, renderers.get(cell11));
187:         }
188:
189:         @SuppressWarnings("unchecked")
190:         @Test
191:         public void testGetChildRenderersNoRendererException() throws EMFFormsNoRendererException {
192:                 /* setup */
193:                 controlGrid = VControlgridFactory.eINSTANCE.createControlGrid();
194:
195:                 final VControlGridRow row1 = VControlgridFactory.eINSTANCE.createControlGridRow();
196:                 final VControlGridRow row2 = VControlgridFactory.eINSTANCE.createControlGridRow();
197:                 controlGrid.getRows().addAll(Arrays.asList(row1, row2));
198:
199:                 final VControlGridCell cell11 = VControlgridFactory.eINSTANCE.createControlGridCell();
200:                 final VControlGridCell cell21 = VControlgridFactory.eINSTANCE.createControlGridCell();
201:                 row1.getCells().add(cell11);
202:                 row2.getCells().add(cell21);
203:
204:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
205:                 final VControl control2 = VViewFactory.eINSTANCE.createControl();
206:                 cell11.setControl(control1);
207:                 cell21.setControl(control2);
208:
209:                 final ControlGridSWTRenderer renderer = createRenderer();
210:
211:                 final AbstractSWTRenderer<VElement> renderer1 = mock(AbstractSWTRenderer.class);
212:                 when(emfFormsRendererFactory.getRendererInstance(control1, viewModelContext)).thenReturn(renderer1);
213:
214:                 when(emfFormsRendererFactory.getRendererInstance(control2, viewModelContext))
215:                         .thenThrow(EMFFormsNoRendererException.class);
216:
217:                 /* act */
218:                 final Map<VControlGridCell, AbstractSWTRenderer<VElement>> renderers = renderer.getChildRenderers();
219:
220:                 /* assert */
221:                 assertEquals(1, renderers.size());
222:                 assertTrue(renderers.containsKey(cell11));
223:                 assertFalse(renderers.containsKey(cell21));
224:                 assertSame(renderer1, renderers.get(cell11));
225:         }
226:
227:         @SuppressWarnings("unchecked")
228:         @Test
229:         public void testGetGridDescriptions() {
230:                 final AbstractSWTRenderer<VElement> renderer1 = mock(AbstractSWTRenderer.class);
231:                 final SWTGridDescription swtGridDescription1 = mock(SWTGridDescription.class);
232:                 when(renderer1.getGridDescription(any(SWTGridDescription.class))).thenReturn(swtGridDescription1);
233:
234:                 final AbstractSWTRenderer<VElement> renderer2 = mock(AbstractSWTRenderer.class);
235:                 final SWTGridDescription swtGridDescription2 = mock(SWTGridDescription.class);
236:                 when(renderer2.getGridDescription(any(SWTGridDescription.class))).thenReturn(swtGridDescription2);
237:
238:                 final ControlGridSWTRenderer renderer = createRenderer();
239:
240:                 final Map<AbstractSWTRenderer<VElement>, SWTGridDescription> gridDescriptions = renderer
241:                         .getGridDescriptions(Arrays.asList(renderer1, renderer2));
242:
243:                 assertEquals(2, gridDescriptions.size());
244:                 assertTrue(gridDescriptions.containsKey(renderer1));
245:                 assertTrue(gridDescriptions.containsKey(renderer2));
246:                 assertSame(swtGridDescription1, gridDescriptions.get(renderer1));
247:                 assertSame(swtGridDescription2, gridDescriptions.get(renderer2));
248:
249:         }
250:
251:         @Test
252:         public void testGetRequiredColumnSizesOfRenderers() {
253:                 final SWTGridDescription description1 = mock(SWTGridDescription.class);
254:                 when(description1.getColumns()).thenReturn(1);
255:
256:                 final SWTGridDescription description2 = mock(SWTGridDescription.class);
257:                 when(description2.getColumns()).thenReturn(2);
258:
259:                 final ControlGridSWTRenderer renderer = createRenderer();
260:
261:                 final Map<SWTGridDescription, Integer> sizes = renderer
262:                         .getRequiredColumnSizesOfRenderers(Arrays.asList(description1, description2));
263:
264:                 assertEquals(2, sizes.size());
265:                 assertTrue(sizes.containsKey(description1));
266:                 assertTrue(sizes.containsKey(description2));
267:                 assertEquals(new Integer(2), sizes.get(description1));
268:                 assertEquals(new Integer(3), sizes.get(description2));
269:         }
270:
271:         @Test
272:         public void testGetColumnsPerRenderer() {
273:                 final ControlGridSWTRenderer renderer = createRenderer();
274:                 assertEquals(12, renderer.getColumnsPerRenderer(Arrays.asList(1, 2, 3, 4)));
275:         }
276:
277:         @Test
278:         public void testGetColumnCountsFromRows() {
279:                 controlGrid = VControlgridFactory.eINSTANCE.createControlGrid();
280:
281:                 final VControlGridRow row1 = VControlgridFactory.eINSTANCE.createControlGridRow();
282:                 final VControlGridRow row2 = VControlgridFactory.eINSTANCE.createControlGridRow();
283:                 final VControlGridRow row3 = VControlgridFactory.eINSTANCE.createControlGridRow();
284:
285:                 controlGrid.getRows().addAll(Arrays.asList(row1, row2, row3));
286:
287:                 final VControlGridCell cell11 = VControlgridFactory.eINSTANCE.createControlGridCell();
288:                 final VControlGridCell cell21 = VControlgridFactory.eINSTANCE.createControlGridCell();
289:                 final VControlGridCell cell22 = VControlgridFactory.eINSTANCE.createControlGridCell();
290:
291:                 row1.getCells().add(cell11);
292:                 row2.getCells().addAll(Arrays.asList(cell21, cell22));
293:
294:                 final ControlGridSWTRenderer renderer = createRenderer();
295:
296:                 final Set<Integer> columnCountsFromRows = renderer.getColumnCountsFromRows();
297:
298:                 assertEquals(3, columnCountsFromRows.size());
299:                 assertTrue(columnCountsFromRows.contains(0));
300:                 assertTrue(columnCountsFromRows.contains(1));
301:                 assertTrue(columnCountsFromRows.contains(2));
302:         }
303:
304:         @Test
305:         public void testComputeColumnCountSoThatAllRowsCanBeRendered() {
306:                 final ControlGridSWTRenderer renderer = createRenderer();
307:                 assertEquals(12, renderer.computeColumnCountSoThatAllRowsCanBeRendered(Arrays.asList(0, 1, 2, 3, 4)));
308:         }
309:
310:         @Test
311:         public void testComputeColumnsForSWTLayout() {
312:                 assertEquals(12, createRenderer().computeColumnsForSWTLayout(2, 6));
313:         }
314:
315:         @Test
316:         public void testCreateControlGridComposite() {
317:                 final ControlGridSWTRenderer renderer = createRenderer();
318:                 final Composite composite = renderer.createControlGridComposite(shell, 12);
319:                 final Layout layout = composite.getLayout();
320:                 assertNotNull(layout);
321:                 assertTrue(GridLayout.class.isInstance(layout));
322:                 assertEquals(12, GridLayout.class.cast(layout).numColumns);
323:         }
324:
325:         @Test
326:         public void testCreateGridDescriptionForEmptyCellsEmpty() {
327:                 /* setup */
328:                 final ControlGridSWTRenderer renderer = createRenderer();
329:
330:                 /* act */
331:                 final SWTGridDescription empty = renderer
332:                         .createGridDescriptionForEmptyCells(Collections.<SWTGridDescription> emptyList());
333:
334:                 /* assert */
335:                 assertEquals(1, empty.getRows());
336:                 assertEquals(1, empty.getColumns());
337:                 assertEquals(1, empty.getGrid().size());
338:                 assertFalse(empty.getGrid().get(0).isHorizontalFill());
339:                 assertFalse(empty.getGrid().get(0).isHorizontalGrab());
340:                 assertNull(empty.getGrid().get(0).getPreferredSize());
341:         }
342:
343:         @Test
344:         public void testCreateGridDescriptionForEmptyCellsDifferent() {
345:                 /* setup */
346:                 final ControlGridSWTRenderer renderer = createRenderer();
347:
348:                 /* act */
349:                 final SWTGridDescription empty = renderer
350:                         .createGridDescriptionForEmptyCells(
351:                                 Arrays.asList(
352:                                         GridDescriptionFactory.INSTANCE.createSimpleGrid(1, 1, null),
353:                                         GridDescriptionFactory.INSTANCE.createSimpleGrid(1, 3, null)));
354:
355:                 /* assert */
356:                 assertEquals(1, empty.getRows());
357:                 assertEquals(1, empty.getColumns());
358:                 assertEquals(1, empty.getGrid().size());
359:                 assertFalse(empty.getGrid().get(0).isHorizontalFill());
360:                 assertFalse(empty.getGrid().get(0).isHorizontalGrab());
361:                 assertNull(empty.getGrid().get(0).getPreferredSize());
362:         }
363:
364:         @Test
365:         public void testCreateGridDescriptionForEmptyCellsSame() {
366:                 /* setup */
367:                 final ControlGridSWTRenderer renderer = createRenderer();
368:
369:                 final SWTGridDescription simpleGrid1 = GridDescriptionFactory.INSTANCE.createSimpleGrid(1, 3, null);
370:                 final SWTGridDescription simpleGrid2 = GridDescriptionFactory.INSTANCE.createSimpleGrid(1, 3, null);
371:
372:                 simpleGrid1.getGrid().get(0).setHorizontalGrab(false);
373:                 simpleGrid1.getGrid().get(0).setHorizontalFill(false);
374:                 simpleGrid1.getGrid().get(0).setPreferredSize(50, SWT.DEFAULT);
375:                 simpleGrid2.getGrid().get(0).setHorizontalGrab(false);
376:                 simpleGrid2.getGrid().get(0).setHorizontalFill(false);
377:                 simpleGrid2.getGrid().get(0).setPreferredSize(50, SWT.DEFAULT);
378:
379:                 simpleGrid1.getGrid().get(1).setHorizontalGrab(false);
380:                 simpleGrid1.getGrid().get(1).setHorizontalFill(false);
381:                 simpleGrid1.getGrid().get(1).setPreferredSize(16, 17);
382:                 simpleGrid2.getGrid().get(1).setHorizontalGrab(false);
383:                 simpleGrid2.getGrid().get(1).setHorizontalFill(false);
384:                 simpleGrid2.getGrid().get(1).setPreferredSize(16, 17);
385:
386:                 simpleGrid1.getGrid().get(2).setHorizontalGrab(true);
387:                 simpleGrid1.getGrid().get(2).setHorizontalFill(true);
388:                 simpleGrid1.getGrid().get(2).setPreferredSize(null);
389:                 simpleGrid2.getGrid().get(2).setHorizontalGrab(false);
390:                 simpleGrid2.getGrid().get(2).setHorizontalFill(false);
391:                 simpleGrid2.getGrid().get(2).setPreferredSize(1968, SWT.DEFAULT);
392:
393:                 /* act */
394:                 final SWTGridDescription empty = renderer
395:                         .createGridDescriptionForEmptyCells(
396:                                 Arrays.asList(
397:                                         simpleGrid1,
398:                                         simpleGrid2));
399:
400:                 /* assert */
401:                 assertEquals(1, empty.getRows());
402:                 assertEquals(3, empty.getColumns());
403:                 assertEquals(3, empty.getGrid().size());
404:
405:                 assertFalse(empty.getGrid().get(0).isHorizontalFill());
406:                 assertFalse(empty.getGrid().get(0).isHorizontalGrab());
407:                 assertEquals(50, empty.getGrid().get(0).getPreferredSize().x);
408:                 assertEquals(SWT.DEFAULT, empty.getGrid().get(0).getPreferredSize().y);
409:
410:                 assertFalse(empty.getGrid().get(1).isHorizontalFill());
411:                 assertFalse(empty.getGrid().get(1).isHorizontalGrab());
412:                 assertEquals(16, empty.getGrid().get(1).getPreferredSize().x);
413:                 assertEquals(17, empty.getGrid().get(1).getPreferredSize().y);
414:
415:                 assertFalse(empty.getGrid().get(2).isHorizontalFill());
416:                 assertFalse(empty.getGrid().get(2).isHorizontalGrab());
417:                 assertEquals(1968, empty.getGrid().get(2).getPreferredSize().x);
418:                 assertEquals(SWT.DEFAULT, empty.getGrid().get(2).getPreferredSize().y);
419:         }
420:
421:         @Test
422:         public void testComputePreferredWidthBasedOnPixelGridSize() {
423:                 final ControlGridSWTRenderer renderer = createRenderer();
424:                 assertEquals(50, renderer.computePreferredWidthBasedOnPixelGridSize(50, 50));
425:                 assertEquals(100, renderer.computePreferredWidthBasedOnPixelGridSize(51, 50));
426:                 assertEquals(100, renderer.computePreferredWidthBasedOnPixelGridSize(99, 50));
427:                 assertEquals(100, renderer.computePreferredWidthBasedOnPixelGridSize(100, 50));
428:         }
429:
430:         @Test
431:         public void testRenderEmptyRow() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
432:                 final SWTGridCell swtGridCell = mock(SWTGridCell.class);
433:                 when(swtGridCell.getColumn()).thenReturn(0);
434:                 when(swtGridCell.getRow()).thenReturn(0);
435:
436:                 controlGrid = VControlgridFactory.eINSTANCE.createControlGrid();
437:                 final VControlGridRow row = VControlgridFactory.eINSTANCE.createControlGridRow();
438:                 controlGrid.getRows().add(row);
439:
440:                 final ControlGridSWTRenderer renderer = createRenderer();
441:                 renderer.init();
442:                 final Control control = renderer.render(swtGridCell, shell);
443:
444:                 assertTrue(Composite.class.isInstance(control));
445:                 final Composite composite = Composite.class.cast(control);
446:                 assertEquals(1, composite.getChildren().length);
447:
448:                 assertTrue(Label.class.isInstance(composite.getChildren()[0]));
449:                 final Label label = Label.class.cast(composite.getChildren()[0]);
450:                 assertLabelIsEmpty(label);
451:                 assertGridData(label, 1, false);
452:         }
453:
454:         @Test
455:         public void testRenderEmptyCell() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
456:                 final SWTGridCell swtGridCell = mock(SWTGridCell.class);
457:                 when(swtGridCell.getColumn()).thenReturn(0);
458:                 when(swtGridCell.getRow()).thenReturn(0);
459:
460:                 controlGrid = VControlgridFactory.eINSTANCE.createControlGrid();
461:                 final VControlGridRow row = VControlgridFactory.eINSTANCE.createControlGridRow();
462:                 controlGrid.getRows().add(row);
463:                 final VControlGridCell cell = VControlgridFactory.eINSTANCE.createControlGridCell();
464:                 row.getCells().add(cell);
465:
466:                 final ControlGridSWTRenderer renderer = createRenderer();
467:                 renderer.init();
468:                 final Control control = renderer.render(swtGridCell, shell);
469:
470:                 assertTrue(Composite.class.isInstance(control));
471:                 final Composite composite = Composite.class.cast(control);
472:                 assertEquals(2, composite.getChildren().length);
473:
474:                 assertTrue(Composite.class.isInstance(composite.getChildren()[0]));
475:                 final Composite wrapperComposite = Composite.class.cast(composite.getChildren()[0]);
476:                 assertEquals(1, wrapperComposite.getChildren().length);
477:                 assertGridData(wrapperComposite, 1, true);
478:
479:                 assertTrue(Label.class.isInstance(wrapperComposite.getChildren()[0]));
480:                 final Label emptyCell = Label.class.cast(wrapperComposite.getChildren()[0]);
481:                 assertLabelIsEmpty(emptyCell);
482:                 assertGridData(emptyCell, 1, false);
483:
484:                 assertTrue(Label.class.isInstance(composite.getChildren()[1]));
485:                 final Label spacing = Label.class.cast(composite.getChildren()[1]);
486:                 assertLabelIsEmpty(spacing);
487:                 assertGridData(spacing, 1, false);
488:         }
489:
490:         @Test
491:         public void testRenderControl()
492:                 throws NoRendererFoundException, NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
493:                 /* setup */
494:                 final SWTGridCell swtGridCell = mock(SWTGridCell.class);
495:                 when(swtGridCell.getColumn()).thenReturn(0);
496:                 when(swtGridCell.getRow()).thenReturn(0);
497:
498:                 controlGrid = VControlgridFactory.eINSTANCE.createControlGrid();
499:                 final VControlGridRow row = VControlgridFactory.eINSTANCE.createControlGridRow();
500:                 controlGrid.getRows().add(row);
501:                 final VControlGridCell cell = VControlgridFactory.eINSTANCE.createControlGridCell();
502:                 row.getCells().add(cell);
503:
504:                 final VControl vControl = VViewFactory.eINSTANCE.createControl();
505:                 cell.setControl(vControl);
506:
507:                 final DummyRenderer dummyRenderer = new DummyRenderer(vControl, viewModelContext, reportService,
508:                         createGridDescription(false, false, true));
509:                 dummyRenderer.init();
510:                 when(emfFormsRendererFactory.getRendererInstance(vControl, viewModelContext)).thenReturn(dummyRenderer);
511:
512:                 final ControlGridSWTRenderer renderer = createRenderer();
513:                 renderer.init();
514:
515:                 /* act */
516:                 final Control control = renderer.render(swtGridCell, shell);
517:
518:                 /* assert */
519:                 assertTrue(Composite.class.isInstance(control));
520:                 final Composite composite = Composite.class.cast(control);
521:                 assertEquals(4, composite.getChildren().length);
522:
523:                 assertTrue(Composite.class.isInstance(composite.getChildren()[0]));
524:                 assertGridData(Composite.class.cast(composite.getChildren()[0]), 1, false);
525:                 assertTrue(Label.class.isInstance(Composite.class.cast(composite.getChildren()[0]).getChildren()[0]));
526:                 final Label controlLabel1 = Label.class.cast(Composite.class.cast(composite.getChildren()[0]).getChildren()[0]);
527:                 assertLabelText(controlLabel1, 0);
528:                 assertGridData(controlLabel1, 1, false);
529:
530:                 assertTrue(Composite.class.isInstance(composite.getChildren()[1]));
531:                 assertGridData(Composite.class.cast(composite.getChildren()[1]), 1, false);
532:                 assertTrue(Label.class.isInstance(Composite.class.cast(composite.getChildren()[1]).getChildren()[0]));
533:                 final Label controlLabel2 = Label.class.cast(Composite.class.cast(composite.getChildren()[1]).getChildren()[0]);
534:                 assertLabelText(controlLabel2, 1);
535:                 assertGridData(controlLabel2, 1, false);
536:
537:                 assertTrue(Composite.class.isInstance(composite.getChildren()[2]));
538:                 assertGridData(Composite.class.cast(composite.getChildren()[2]), 1, true);
539:                 assertTrue(Label.class.isInstance(Composite.class.cast(composite.getChildren()[2]).getChildren()[0]));
540:                 final Label controlLabel3 = Label.class.cast(Composite.class.cast(composite.getChildren()[2]).getChildren()[0]);
541:                 assertLabelText(controlLabel3, 2);
542:                 assertGridData(controlLabel3, 1, true);
543:
544:                 assertTrue(Label.class.isInstance(composite.getChildren()[3]));
545:                 final Label spacing = Label.class.cast(composite.getChildren()[3]);
546:                 assertLabelIsEmpty(spacing);
547:                 assertGridData(spacing, 1, false);
548:         }
549:
550:         // BEGIN COMPLEX CODE
551:         /**
552:          * Expectation is
553:          *
554:          * L1 L2 L2 L3
555:          * L1 L2 L3 L4
556:          */
557:         @Test
558:         public void testRenderControlSpan()
559:                 throws NoRendererFoundException, NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
560:                 /* setup */
561:                 final SWTGridCell swtGridCell = mock(SWTGridCell.class);
562:                 when(swtGridCell.getColumn()).thenReturn(0);
563:                 when(swtGridCell.getRow()).thenReturn(0);
564:
565:                 controlGrid = VControlgridFactory.eINSTANCE.createControlGrid();
566:
567:                 /* first row */
568:                 final VControlGridRow row1 = VControlgridFactory.eINSTANCE.createControlGridRow();
569:                 controlGrid.getRows().add(row1);
570:                 final VControlGridCell cell1 = VControlgridFactory.eINSTANCE.createControlGridCell();
571:                 row1.getCells().add(cell1);
572:                 final VControl vControl1 = VViewFactory.eINSTANCE.createControl();
573:                 cell1.setControl(vControl1);
574:                 final DummyRenderer dummyRenderer1 = new DummyRenderer(vControl1, viewModelContext, reportService,
575:                         createGridDescription(false, true, false));
576:                 dummyRenderer1.init();
577:                 when(emfFormsRendererFactory.getRendererInstance(vControl1, viewModelContext)).thenReturn(dummyRenderer1);
578:
579:                 /* second row */
580:                 final VControlGridRow row2 = VControlgridFactory.eINSTANCE.createControlGridRow();
581:                 controlGrid.getRows().add(row2);
582:                 final VControlGridCell cell2 = VControlgridFactory.eINSTANCE.createControlGridCell();
583:                 row2.getCells().add(cell2);
584:                 final VControl vControl2 = VViewFactory.eINSTANCE.createControl();
585:                 cell2.setControl(vControl2);
586:                 final DummyRenderer dummyRenderer2 = new DummyRenderer(vControl2, viewModelContext, reportService,
587:                         createGridDescription(false, false, true, false));
588:                 dummyRenderer2.init();
589:                 when(emfFormsRendererFactory.getRendererInstance(vControl2, viewModelContext)).thenReturn(dummyRenderer2);
590:
591:                 final ControlGridSWTRenderer renderer = createRenderer();
592:                 renderer.init();
593:
594:                 /* act */
595:                 final Control control = renderer.render(swtGridCell, shell);
596:
597:                 /* assert */
598:                 assertTrue(Composite.class.isInstance(control));
599:                 final Composite composite = Composite.class.cast(control);
600:                 assertGridLayout(composite, 20);
601:                 assertEquals(9, composite.getChildren().length);
602:
603:                 /* control 1 */
604:                 assertTrue(Composite.class.isInstance(composite.getChildren()[0]));
605:                 assertGridData(Composite.class.cast(composite.getChildren()[0]), 1, false);
606:                 assertTrue(Label.class.isInstance(Composite.class.cast(composite.getChildren()[0]).getChildren()[0]));
607:                 final Label controlLabel1 = Label.class.cast(Composite.class.cast(composite.getChildren()[0]).getChildren()[0]);
608:                 assertLabelText(controlLabel1, 0);
609:                 assertGridData(controlLabel1, 1, false);
610:
611:                 assertTrue(Composite.class.isInstance(composite.getChildren()[1]));
612:                 assertGridData(Composite.class.cast(composite.getChildren()[1]), 20 - 1 - 1 - 1, true);// 20-3times non spanning
613:                 assertTrue(Label.class.isInstance(Composite.class.cast(composite.getChildren()[1]).getChildren()[0]));
614:                 final Label controlLabel2 = Label.class.cast(Composite.class.cast(composite.getChildren()[1]).getChildren()[0]);
615:                 assertLabelText(controlLabel2, 1);
616:                 assertGridData(controlLabel2, 1, true);
617:
618:                 assertTrue(Composite.class.isInstance(composite.getChildren()[2]));
619:                 assertGridData(Composite.class.cast(composite.getChildren()[2]), 1, false);
620:                 assertTrue(Label.class.isInstance(Composite.class.cast(composite.getChildren()[2]).getChildren()[0]));
621:                 final Label controlLabel3 = Label.class.cast(Composite.class.cast(composite.getChildren()[2]).getChildren()[0]);
622:                 assertLabelText(controlLabel3, 2);
623:                 assertGridData(controlLabel3, 1, false);
624:
625:                 assertTrue(Label.class.isInstance(composite.getChildren()[3]));
626:                 final Label spacing = Label.class.cast(composite.getChildren()[3]);
627:                 assertLabelIsEmpty(spacing);
628:                 assertGridData(spacing, 1, false);
629:
630:                 /* control 2 */
631:                 assertTrue(Composite.class.isInstance(composite.getChildren()[4]));
632:                 assertGridData(Composite.class.cast(composite.getChildren()[4]), 1, false);
633:                 assertTrue(Label.class.isInstance(Composite.class.cast(composite.getChildren()[4]).getChildren()[0]));
634:                 final Label controlLabel4 = Label.class.cast(Composite.class.cast(composite.getChildren()[4]).getChildren()[0]);
635:                 assertLabelText(controlLabel4, 0);
636:                 assertGridData(controlLabel4, 1, false);
637:
638:                 assertTrue(Composite.class.isInstance(composite.getChildren()[5]));
639:                 assertGridData(Composite.class.cast(composite.getChildren()[5]), 1, false);
640:                 assertTrue(Label.class.isInstance(Composite.class.cast(composite.getChildren()[5]).getChildren()[0]));
641:                 final Label controlLabel5 = Label.class.cast(Composite.class.cast(composite.getChildren()[5]).getChildren()[0]);
642:                 assertLabelText(controlLabel5, 1);
643:                 assertGridData(controlLabel5, 1, false);
644:
645:                 assertTrue(Composite.class.isInstance(composite.getChildren()[6]));
646:                 assertGridData(Composite.class.cast(composite.getChildren()[6]), 20 - 1 - 1 - 1 - 1, true);// 20-4 times non
647:                                                                                                                                                                                                         // spanning
648:                 assertTrue(Label.class.isInstance(Composite.class.cast(composite.getChildren()[6]).getChildren()[0]));
649:                 final Label controlLabel6 = Label.class.cast(Composite.class.cast(composite.getChildren()[6]).getChildren()[0]);
650:                 assertLabelText(controlLabel6, 2);
651:                 assertGridData(controlLabel6, 1, true);
652:
653:                 assertTrue(Composite.class.isInstance(composite.getChildren()[7]));
654:                 assertGridData(Composite.class.cast(composite.getChildren()[7]), 1, false);
655:                 assertTrue(Label.class.isInstance(Composite.class.cast(composite.getChildren()[7]).getChildren()[0]));
656:                 final Label controlLabel7 = Label.class.cast(Composite.class.cast(composite.getChildren()[7]).getChildren()[0]);
657:                 assertLabelText(controlLabel7, 3);
658:                 assertGridData(controlLabel7, 1, false);
659:
660:                 assertTrue(Label.class.isInstance(composite.getChildren()[8]));
661:                 final Label spacing2 = Label.class.cast(composite.getChildren()[8]);
662:                 assertLabelIsEmpty(spacing2);
663:                 assertGridData(spacing2, 1, false);
664:         }
665:
666:         /**
667:          * Control Control Control
668:          * Control Empty-- Control
669:          * Empty Row--------------
670:          * Control---- Control----
671:          */
672:         @Test
673:         public void testComplexScenario()
674:                 throws EMFFormsNoRendererException, NoRendererFoundException, NoPropertyDescriptorFoundExeption {
675:                 /* Setup ************************************************************************************************/
676:                 /* swt grid cell */
677:                 final SWTGridCell swtGridCell = mock(SWTGridCell.class);
678:                 when(swtGridCell.getColumn()).thenReturn(0);
679:                 when(swtGridCell.getRow()).thenReturn(0);
680:
681:                 /* Control Grid */
682:                 controlGrid = VControlgridFactory.eINSTANCE.createControlGrid();
683:
684:                 /* Rows */
685:                 final VControlGridRow row1 = VControlgridFactory.eINSTANCE.createControlGridRow();
686:                 final VControlGridRow row2 = VControlgridFactory.eINSTANCE.createControlGridRow();
687:                 final VControlGridRow row3 = VControlgridFactory.eINSTANCE.createControlGridRow();
688:                 final VControlGridRow row4 = VControlgridFactory.eINSTANCE.createControlGridRow();
689:                 controlGrid.getRows().addAll(Arrays.asList(row1, row2, row3, row4));
690:
691:                 /* Row1 */
692:                 final VControlGridCell cell11 = VControlgridFactory.eINSTANCE.createControlGridCell();
693:                 final VControl control11 = VViewFactory.eINSTANCE.createControl();
694:                 cell11.setControl(control11);
695:                 final VControlGridCell cell12 = VControlgridFactory.eINSTANCE.createControlGridCell();
696:                 final VControl control12 = VViewFactory.eINSTANCE.createControl();
697:                 cell12.setControl(control12);
698:                 final VControlGridCell cell13 = VControlgridFactory.eINSTANCE.createControlGridCell();
699:                 final VControl control13 = VViewFactory.eINSTANCE.createControl();
700:                 cell13.setControl(control13);
701:                 row1.getCells().addAll(Arrays.asList(cell11, cell12, cell13));
702:
703:                 /* Row2 */
704:                 final VControlGridCell cell21 = VControlgridFactory.eINSTANCE.createControlGridCell();
705:                 final VControl control21 = VViewFactory.eINSTANCE.createControl();
706:                 cell21.setControl(control21);
707:                 final VControlGridCell cell22 = VControlgridFactory.eINSTANCE.createControlGridCell();
708:                 final VControlGridCell cell23 = VControlgridFactory.eINSTANCE.createControlGridCell();
709:                 final VControl control23 = VViewFactory.eINSTANCE.createControl();
710:                 cell23.setControl(control23);
711:                 row2.getCells().addAll(Arrays.asList(cell21, cell22, cell23));
712:
713:                 /* Row3 */
714:                 /* empty */
715:
716:                 /* Row4 */
717:                 final VControlGridCell cell31 = VControlgridFactory.eINSTANCE.createControlGridCell();
718:                 final VControl control31 = VViewFactory.eINSTANCE.createControl();
719:                 cell31.setControl(control31);
720:                 final VControlGridCell cell32 = VControlgridFactory.eINSTANCE.createControlGridCell();
721:                 final VControl control32 = VViewFactory.eINSTANCE.createControl();
722:                 cell32.setControl(control32);
723:                 row4.getCells().addAll(Arrays.asList(cell31, cell32));
724:
725:                 /* Renderers */
726:                 final DummyRenderer dr11 = new DummyRenderer(control11, viewModelContext, reportService,
727:                         createGridDescription(false, false, true));
728:                 dr11.init();
729:                 final DummyRenderer dr12 = new DummyRenderer(control12, viewModelContext, reportService,
730:                         createGridDescription(false, false, true));
731:                 dr12.init();
732:                 final DummyRenderer dr13 = new DummyRenderer(control13, viewModelContext, reportService,
733:                         createGridDescription(false, false, true));
734:                 dr13.init();
735:                 final DummyRenderer dr21 = new DummyRenderer(control21, viewModelContext, reportService,
736:                         createGridDescription(false, false, true));
737:                 dr21.init();
738:                 final DummyRenderer dr23 = new DummyRenderer(control23, viewModelContext, reportService,
739:                         createGridDescription(false, false, true));
740:                 dr23.init();
741:                 final DummyRenderer dr31 = new DummyRenderer(control31, viewModelContext, reportService,
742:                         createGridDescription(false, false, true));
743:                 dr31.init();
744:                 final DummyRenderer dr32 = new DummyRenderer(control32, viewModelContext, reportService,
745:                         createGridDescription(false, false, true));
746:                 dr32.init();
747:
748:                 /* Renderer factory */
749:                 when(emfFormsRendererFactory.getRendererInstance(control11, viewModelContext)).thenReturn(dr11);
750:                 when(emfFormsRendererFactory.getRendererInstance(control12, viewModelContext)).thenReturn(dr12);
751:                 when(emfFormsRendererFactory.getRendererInstance(control13, viewModelContext)).thenReturn(dr13);
752:                 when(emfFormsRendererFactory.getRendererInstance(control21, viewModelContext)).thenReturn(dr21);
753:                 when(emfFormsRendererFactory.getRendererInstance(control23, viewModelContext)).thenReturn(dr23);
754:                 when(emfFormsRendererFactory.getRendererInstance(control31, viewModelContext)).thenReturn(dr31);
755:                 when(emfFormsRendererFactory.getRendererInstance(control32, viewModelContext)).thenReturn(dr32);
756:
757:                 /* control grid renderer */
758:                 final ControlGridSWTRenderer renderer = createRenderer();
759:                 renderer.init();
760:                 /* Setup End ********************************************************************************************/
761:
762:                 /* Act */
763:                 final Control render = renderer.render(swtGridCell, shell);
764:                 /* Act End */
765:
766:                 /* Assert ************************************************************************************************/
767:                 /* Composite with expected column count and children size */
768:                 assertTrue(Composite.class.isInstance(render));
769:                 final Composite composite = Composite.class.cast(render);
770:                 // 1. row 3*4 (controls)
771:                 // 2. row 2*4 (controls) + 4 (empty cell)
772:                 // 3. row 1 (empty row)
773:                 // 4. row 2*4 (controls)
774:                 assertEquals(3 * 4 + 2 * 4 + 4 + 1 + 2 * 4, composite.getChildren().length);
775:                 // renderers require 3 columns (+1 for spacing) -> 4 required
776:                 // rows require 3, 2 and 1 columns -> 6 required
777:                 // -> total = 4*6
778:                 assertGridLayout(composite, 4 * 6);
779:
780:                 /* Row1 Control1 */
781:                 final Composite control111 = Composite.class.cast(composite.getChildren()[0]);
782:                 assertLabelText(control111, 0);
783:                 assertGridData(control111, 1, false);
784:
785:                 final Composite control112 = Composite.class.cast(composite.getChildren()[1]);
786:                 assertLabelText(control112, 1);
787:                 assertGridData(control112, 1, false);
788:
789:                 final Composite control113 = Composite.class.cast(composite.getChildren()[2]);
790:                 assertLabelText(control113, 2);
791:                 assertGridData(control113, (4 * 6 - 3 * 3) / 3, true); // columns - 3*3 (1-spanning) divided by 3 (# controls)
792:
793:                 final Label control11s = Label.class.cast(composite.getChildren()[3]);
794:                 assertLabelIsEmpty(control11s);
795:                 assertGridData(control11s, 1, false);
796:
797:                 /* Row1 Control2 */
798:                 final Composite control121 = Composite.class.cast(composite.getChildren()[4]);
799:                 assertLabelText(control121, 0);
800:                 assertGridData(control121, 1, false);
801:
802:                 final Composite control122 = Composite.class.cast(composite.getChildren()[5]);
803:                 assertLabelText(control122, 1);
804:                 assertGridData(control122, 1, false);
805:
806:                 final Composite control123 = Composite.class.cast(composite.getChildren()[6]);
807:                 assertLabelText(control123, 2);
808:                 assertGridData(control123, (4 * 6 - 3 * 3) / 3, true); // columns - 3*3 (1-spanning) divided by 3 (# controls)
809:
810:                 final Label control12s = Label.class.cast(composite.getChildren()[7]);
811:                 assertLabelIsEmpty(control12s);
812:                 assertGridData(control12s, 1, false);
813:
814:                 /* Row1 Control3 */
815:                 final Composite control131 = Composite.class.cast(composite.getChildren()[8]);
816:                 assertLabelText(control131, 0);
817:                 assertGridData(control131, 1, false);
818:
819:                 final Composite control132 = Composite.class.cast(composite.getChildren()[9]);
820:                 assertLabelText(control132, 1);
821:                 assertGridData(control132, 1, false);
822:
823:                 final Composite control133 = Composite.class.cast(composite.getChildren()[10]);
824:                 assertLabelText(control133, 2);
825:                 assertGridData(control133, (4 * 6 - 3 * 3) / 3, true); // columns - 3*3 (1-spanning) divided by 3 (# controls)
826:
827:                 final Label control13s = Label.class.cast(composite.getChildren()[11]);
828:                 assertLabelIsEmpty(control13s);
829:                 assertGridData(control13s, 1, false);
830:
831:                 /* Row2 Control1 */
832:                 final Composite control211 = Composite.class.cast(composite.getChildren()[12]);
833:                 assertLabelText(control211, 0);
834:                 assertGridData(control211, 1, false);
835:
836:                 final Composite control212 = Composite.class.cast(composite.getChildren()[13]);
837:                 assertLabelText(control212, 1);
838:                 assertGridData(control212, 1, false);
839:
840:                 final Composite control213 = Composite.class.cast(composite.getChildren()[14]);
841:                 assertLabelText(control213, 2);
842:                 assertGridData(control213, (4 * 6 - 3 * 3) / 3, true); // columns - 3*3 (1-spanning) divided by 3 (# controls)
843:
844:                 final Label control21s = Label.class.cast(composite.getChildren()[15]);
845:                 assertLabelIsEmpty(control21s);
846:                 assertGridData(control21s, 1, false);
847:
848:                 /* Row2 Empty cell */
849:                 final Composite empty221 = Composite.class.cast(composite.getChildren()[16]);
850:                 assertLabelIsEmpty(empty221);
851:                 assertGridData(empty221, 1, false);
852:
853:                 final Composite empty222 = Composite.class.cast(composite.getChildren()[17]);
854:                 assertLabelIsEmpty(empty222);
855:                 assertGridData(empty222, 1, false);
856:
857:                 final Composite empty223 = Composite.class.cast(composite.getChildren()[18]);
858:                 assertLabelIsEmpty(empty223);
859:                 assertGridData(empty223, (4 * 6 - 3 * 3) / 3, true); // columns - 3*3 (1-spanning) divided by 3 (# controls)
860:
861:                 final Label empty22s = Label.class.cast(composite.getChildren()[19]);
862:                 assertLabelIsEmpty(empty22s);
863:                 assertGridData(empty22s, 1, false);
864:
865:                 /* Row2 Control3 */
866:                 final Composite control231 = Composite.class.cast(composite.getChildren()[20]);
867:                 assertLabelText(control231, 0);
868:                 assertGridData(control231, 1, false);
869:
870:                 final Composite control232 = Composite.class.cast(composite.getChildren()[21]);
871:                 assertLabelText(control232, 1);
872:                 assertGridData(control232, 1, false);
873:
874:                 final Composite control233 = Composite.class.cast(composite.getChildren()[22]);
875:                 assertLabelText(control233, 2);
876:                 assertGridData(control233, (4 * 6 - 3 * 3) / 3, true); // columns - 3*3 (1-spanning) divided by 3 (# controls)
877:
878:                 final Label control23s = Label.class.cast(composite.getChildren()[23]);
879:                 assertLabelIsEmpty(control23s);
880:                 assertGridData(control23s, 1, false);
881:
882:                 /* Row3 */
883:                 final Label emptyRow3 = Label.class.cast(composite.getChildren()[24]);
884:                 assertLabelIsEmpty(emptyRow3);
885:                 assertGridData(emptyRow3, 4 * 6, false);// full width
886:
887:                 /* Row4 Control1 */
888:                 final Composite control411 = Composite.class.cast(composite.getChildren()[25]);
889:                 assertLabelText(control411, 0);
890:                 assertGridData(control411, 1, false);
891:
892:                 final Composite control412 = Composite.class.cast(composite.getChildren()[26]);
893:                 assertLabelText(control412, 1);
894:                 assertGridData(control412, 1, false);
895:
896:                 final Composite control413 = Composite.class.cast(composite.getChildren()[27]);
897:                 assertLabelText(control413, 2);
898:                 assertGridData(control413, (4 * 6 - 2 * 3) / 2, true); // columns - 2*3 (1-spanning) divided by 2 (# controls)
899:
900:                 final Label control41s = Label.class.cast(composite.getChildren()[28]);
901:                 assertLabelIsEmpty(control41s);
902:                 assertGridData(control41s, 1, false);
903:
904:                 /* Row4 Control2 */
905:                 final Composite control421 = Composite.class.cast(composite.getChildren()[29]);
906:                 assertLabelText(control421, 0);
907:                 assertGridData(control421, 1, false);
908:
909:                 final Composite control422 = Composite.class.cast(composite.getChildren()[30]);
910:                 assertLabelText(control422, 1);
911:                 assertGridData(control422, 1, false);
912:
913:                 final Composite control423 = Composite.class.cast(composite.getChildren()[31]);
914:                 assertLabelText(control423, 2);
915:                 assertGridData(control423, (4 * 6 - 2 * 3) / 2, true); // columns - 2*3 (1-spanning) divided by 2 (# controls)
916:
917:                 final Label control42s = Label.class.cast(composite.getChildren()[32]);
918:                 assertLabelIsEmpty(control42s);
919:                 assertGridData(control42s, 1, false);
920:
921:                 /* last child should have index 32 */
922:         }
923:
924:         // END COMPLEX CODE
925:
926:         @Test
927:         public void testReadOnlyDoesNotDisableComposite()
928:                 throws NoRendererFoundException, NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
929:                 /* setup */
930:                 final SWTGridCell swtGridCell = mock(SWTGridCell.class);
931:                 when(swtGridCell.getColumn()).thenReturn(0);
932:                 when(swtGridCell.getRow()).thenReturn(0);
933:
934:                 controlGrid = VControlgridFactory.eINSTANCE.createControlGrid();
935:                 controlGrid.setReadonly(true);
936:                 final VControlGridRow row = VControlgridFactory.eINSTANCE.createControlGridRow();
937:                 controlGrid.getRows().add(row);
938:                 final VControlGridCell cell = VControlgridFactory.eINSTANCE.createControlGridCell();
939:                 row.getCells().add(cell);
940:
941:                 final VControl vControl = VViewFactory.eINSTANCE.createControl();
942:                 cell.setControl(vControl);
943:
944:                 final DummyRenderer dummyRenderer = new DummyRenderer(vControl, viewModelContext, reportService,
945:                         createGridDescription(false, false, true));
946:                 dummyRenderer.init();
947:                 when(emfFormsRendererFactory.getRendererInstance(vControl, viewModelContext)).thenReturn(dummyRenderer);
948:
949:                 final ControlGridSWTRenderer renderer = createRenderer();
950:                 renderer.init();
951:
952:                 /* act */
953:                 final Control control = renderer.render(swtGridCell, shell);
954:                 renderer.finalizeRendering(shell);
955:
956:                 /* assert */
957:
958:                 assertTrue(Composite.class.isInstance(control));
959:                 assertTrue(control.isEnabled());
960:                 final Composite composite = Composite.class.cast(control);
961:                 assertEquals(4, composite.getChildren().length);
962:
963:                 assertTrue(Composite.class.isInstance(composite.getChildren()[0]));
964:                 assertTrue(composite.isEnabled());
965:
966:                 // verify that the control wrapper composites are enabled
967:                 assertTrue(Composite.class.cast(composite.getChildren()[0]).isEnabled());
968:                 assertTrue(Composite.class.cast(composite.getChildren()[1]).isEnabled());
969:                 assertTrue(Composite.class.cast(composite.getChildren()[2]).isEnabled());
970:         }
971:
972:         private static SWTGridDescription createGridDescription(Boolean... grab) {
973:                 final SWTGridDescription grid = GridDescriptionFactory.INSTANCE.createSimpleGrid(1, grab.length, null);
974:                 for (int i = 0; i < grid.getGrid().size(); i++) {
975:                         final SWTGridCell swtGridCell = grid.getGrid().get(i);
976:                         swtGridCell.setHorizontalGrab(grab[i]);
977:                 }
978:                 return grid;
979:         }
980:
981:         private static void assertLabelIsEmpty(Label label) {
982:                 assertTrue((label.getText() == null || label.getText().isEmpty()) && label.getImage() == null);
983:         }
984:
985:         private static void assertLabelText(Label label, int text) {
986:                 assertEquals(String.valueOf(text), label.getText());
987:         }
988:
989:         private static void assertLabelText(Composite composite, int text) {
990:                 assertEquals(1, composite.getChildren().length);
991:                 assertLabelText(Label.class.cast(composite.getChildren()[0]), text);
992:         }
993:
994:         private static void assertLabelIsEmpty(Composite composite) {
995:                 assertEquals(1, composite.getChildren().length);
996:                 final Label label = (Label) composite.getChildren()[0];
997:                 assertTrue((label.getText() == null || label.getText().isEmpty()) && label.getImage() == null);
998:         }
999:
1000:         private static void assertGridData(Control control, int hSpan, boolean horizontalGrab) {
1001:                 assertTrue(GridData.class.isInstance(control.getLayoutData()));
1002:                 final GridData gridData = GridData.class.cast(control.getLayoutData());
1003:                 if (hSpan == 1) {
1004:                         assertTrue(MessageFormat.format("Expected {0} but was {1}", hSpan, gridData.horizontalSpan), //$NON-NLS-1$
1005:                                 gridData.horizontalSpan == 0 || gridData.horizontalSpan == 1);
1006:                 } else {
1007:                         assertEquals(hSpan, gridData.horizontalSpan);
1008:                 }
1009:                 assertEquals(horizontalGrab, gridData.grabExcessHorizontalSpace);
1010:         }
1011:
1012:         private static void assertGridLayout(Composite composite, int numColumns) {
1013:                 assertTrue(GridLayout.class.isInstance(composite.getLayout()));
1014:                 final GridLayout gridLayout = GridLayout.class.cast(composite.getLayout());
1015:                 assertEquals(numColumns, gridLayout.numColumns);
1016:         }
1017:
1018:         private static final class DummyRenderer extends AbstractSWTRenderer<VElement> {
1019:
1020:                 private final SWTGridDescription rendererGridDescription;
1021:
1022:                 DummyRenderer(VControl vElement, ViewModelContext viewContext, ReportService reportService,
1023:                         SWTGridDescription rendererGridDescription) {
1024:                         super(vElement, viewContext, reportService);
1025:                         this.rendererGridDescription = rendererGridDescription;
1026:                 }
1027:
1028:                 @Override
1029:                 public SWTGridDescription getGridDescription(SWTGridDescription gridDescription) {
1030:•                        for (final SWTGridCell swtGridCell : rendererGridDescription.getGrid()) {
1031:                                 swtGridCell.setRenderer(this);
1032:                         }
1033:                         return rendererGridDescription;
1034:                 }
1035:
1036:                 @Override
1037:                 protected Control renderControl(SWTGridCell gridCell, Composite parent)
1038:                         throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
1039:                         return createLabel(gridCell.getColumn(), parent);
1040:
1041:                 }
1042:
1043:                 private Control createLabel(int string, Composite parent) {
1044:                         final Label label = new Label(parent, SWT.NONE);
1045:                         label.setText(String.valueOf(string));
1046:                         return label;
1047:                 }
1048:
1049:         }
1050:
1051: }