Skip to content

Package: GridTable_PTest

GridTable_PTest

nameinstructionbranchcomplexitylinemethod
GridTable_PTest()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
after()
M: 8 C: 4
33%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 2
67%
M: 0 C: 1
100%
afterClass()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
assertGridItemOrder(Grid, Object[])
M: 0 C: 27
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
beforeClass()
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
createDMR(EAttribute, EReference[])
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createDetailView()
M: 0 C: 41
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
createEAttribute(String, EClassifier, int, int)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
createEClass(String, String)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createRendererInstanceWithCustomCellEditor(VTableControl)
M: 0 C: 57
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
createTableWithTwoTableColumns()
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
getTable(Control)
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
gridSorting_autoSortOnEdit()
M: 2 C: 178
99%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 35
97%
M: 0 C: 1
100%
gridSorting_sortIndicatorReset()
M: 2 C: 143
99%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 28
97%
M: 0 C: 1
100%
init()
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
testInitializedTableWithoutColumnsAndEmptyReference()
M: 3 C: 22
88%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 1 C: 7
88%
M: 0 C: 1
100%
testInitializedTableWithoutColumnsEmptySingleReference()
M: 32 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
testInitializedTableWithoutColumnsSingleReference()
M: 38 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
testPanelTableWithTwoColumns()
M: 2 C: 237
99%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 46
98%
M: 0 C: 1
100%
testTableSorting()
M: 2 C: 249
99%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 39
98%
M: 0 C: 1
100%
testTableSortingWithCellEditor()
M: 2 C: 244
99%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 38
97%
M: 0 C: 1
100%
testTableWithTwoColumns()
M: 0 C: 29
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testTableWithTwoColumnsAdd()
M: 2 C: 58
97%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 13
93%
M: 0 C: 1
100%
testTableWithTwoColumnsClear()
M: 2 C: 63
97%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 14
93%
M: 0 C: 1
100%
testTableWithTwoColumnsRemove()
M: 2 C: 63
97%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 13
93%
M: 0 C: 1
100%
testTableWithTwoColumnsWithoutViewServices()
M: 1 C: 51
98%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 13
93%
M: 0 C: 1
100%
testTableWithoutColumns()
M: 0 C: 52
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
testTableWithoutColumnsWithoutViewServices()
M: 1 C: 62
98%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 15
94%
M: 0 C: 1
100%
testUninitializedTableWithoutColumns()
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2019 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: * Johannes Faltermeier - initial API and implementation
13: * Mat Hansen - modifications for Nebula Grid
14: * Christian W. Damus - bugs 527686, 548592
15: *******************************************************************************/
16: package org.eclipse.emf.ecp.view.internal.table.nebula.grid;
17:
18: import static java.util.Arrays.asList;
19: import static org.hamcrest.CoreMatchers.notNullValue;
20: import static org.hamcrest.Matchers.greaterThan;
21: import static org.hamcrest.Matchers.hasItem;
22: import static org.hamcrest.Matchers.instanceOf;
23: import static org.hamcrest.Matchers.lessThan;
24: import static org.junit.Assert.assertEquals;
25: import static org.junit.Assert.assertSame;
26: import static org.junit.Assert.assertThat;
27: import static org.junit.Assert.assertTrue;
28: import static org.junit.Assert.fail;
29:
30: import java.io.ByteArrayOutputStream;
31: import java.io.PrintStream;
32: import java.util.Arrays;
33: import java.util.Set;
34:
35: import org.eclipse.e4.core.contexts.IEclipseContext;
36: import org.eclipse.emf.ecore.EAttribute;
37: import org.eclipse.emf.ecore.EClass;
38: import org.eclipse.emf.ecore.EClassifier;
39: import org.eclipse.emf.ecore.EObject;
40: import org.eclipse.emf.ecore.EReference;
41: import org.eclipse.emf.ecore.EStructuralFeature;
42: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
43: import org.eclipse.emf.ecore.EcoreFactory;
44: import org.eclipse.emf.ecore.EcorePackage;
45: import org.eclipse.emf.ecp.common.spi.UniqueSetting;
46: import org.eclipse.emf.ecp.edit.spi.swt.table.ECPCellEditorComparator;
47: import org.eclipse.emf.ecp.edit.spi.swt.table.StringCellEditor;
48: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
49: import org.eclipse.emf.ecp.view.spi.context.ViewModelContextDisposeListener;
50: import org.eclipse.emf.ecp.view.spi.context.ViewModelService;
51: import org.eclipse.emf.ecp.view.spi.context.ViewModelServiceProvider;
52: import org.eclipse.emf.ecp.view.spi.model.ModelChangeListener;
53: import org.eclipse.emf.ecp.view.spi.model.VControl;
54: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
55: import org.eclipse.emf.ecp.view.spi.model.VElement;
56: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
57: import org.eclipse.emf.ecp.view.spi.model.VView;
58: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
59: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
60: import org.eclipse.emf.ecp.view.spi.renderer.NoPropertyDescriptorFoundExeption;
61: import org.eclipse.emf.ecp.view.spi.renderer.NoRendererFoundException;
62: import org.eclipse.emf.ecp.view.spi.table.model.DetailEditing;
63: import org.eclipse.emf.ecp.view.spi.table.model.VTableControl;
64: import org.eclipse.emf.ecp.view.spi.table.model.VTableDomainModelReference;
65: import org.eclipse.emf.ecp.view.spi.table.nebula.grid.GridControlSWTRenderer;
66: import org.eclipse.emf.ecp.view.spi.table.swt.TableControlSWTRenderer;
67: import org.eclipse.emf.ecp.view.spi.util.swt.ImageRegistryService;
68: import org.eclipse.emf.ecp.view.table.test.common.TableControlHandle;
69: import org.eclipse.emf.ecp.view.table.test.common.TableTestUtil;
70: import org.eclipse.emf.ecp.view.template.model.VTViewTemplateProvider;
71: import org.eclipse.emf.ecp.view.test.common.swt.spi.DatabindingClassRunner;
72: import org.eclipse.emf.ecp.view.test.common.swt.spi.SWTTestUtil;
73: import org.eclipse.emf.ecp.view.test.common.swt.spi.SWTViewTestHelper;
74: import org.eclipse.emfforms.spi.common.converter.EStructuralFeatureValueConverterService;
75: import org.eclipse.emfforms.spi.common.report.ReportService;
76: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsDatabindingEMF;
77: import org.eclipse.emfforms.spi.core.services.editsupport.EMFFormsEditSupport;
78: import org.eclipse.emfforms.spi.core.services.label.EMFFormsLabelProvider;
79: import org.eclipse.emfforms.spi.core.services.view.EMFFormsContextListener;
80: import org.eclipse.emfforms.spi.core.services.view.RootDomainModelChangeListener;
81: import org.eclipse.emfforms.spi.localization.EMFFormsLocalizationService;
82: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
83: import org.eclipse.emfforms.spi.swt.core.EMFFormsNoRendererException;
84: import org.eclipse.emfforms.spi.swt.core.EMFFormsRendererFactory;
85: import org.eclipse.emfforms.spi.swt.core.di.EMFFormsContextProvider;
86: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridCell;
87: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridDescription;
88: import org.eclipse.jface.viewers.CellEditor;
89: import org.eclipse.jface.viewers.StructuredSelection;
90: import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
91: import org.eclipse.nebula.widgets.grid.Grid;
92: import org.eclipse.nebula.widgets.grid.GridItem;
93: import org.eclipse.swt.SWT;
94: import org.eclipse.swt.custom.SashForm;
95: import org.eclipse.swt.custom.ScrolledComposite;
96: import org.eclipse.swt.custom.StackLayout;
97: import org.eclipse.swt.widgets.Composite;
98: import org.eclipse.swt.widgets.Control;
99: import org.eclipse.swt.widgets.Label;
100: import org.eclipse.swt.widgets.Shell;
101: import org.junit.After;
102: import org.junit.AfterClass;
103: import org.junit.Before;
104: import org.junit.BeforeClass;
105: import org.junit.Ignore;
106: import org.junit.Test;
107: import org.junit.runner.RunWith;
108: import org.osgi.framework.BundleContext;
109: import org.osgi.framework.FrameworkUtil;
110: import org.osgi.framework.ServiceReference;
111:
112: /**
113: * This is a basically a copy of the SWTTable_PTest for the sake of completeness.
114: *
115: * @author Mat Hansen <mhansen@eclipsesource.com>
116: *
117: */
118: @RunWith(DatabindingClassRunner.class)
119: public class GridTable_PTest {
120:         private static String log;
121:         private static ServiceReference<EMFFormsRendererFactory> factoryServiceReference;
122:         private static EMFFormsRendererFactory rendererFactory;
123:         private static PrintStream systemErr;
124:         private Shell shell;
125:         private EObject domainElement;
126:
127:         @BeforeClass
128:         public static void beforeClass() {
129:                 systemErr = System.err;
130:                 System.setErr(new PrintStreamWrapper(systemErr));
131:                 final BundleContext bundleContext = FrameworkUtil.getBundle(GridTable_PTest.class).getBundleContext();
132:                 factoryServiceReference = bundleContext.getServiceReference(EMFFormsRendererFactory.class);
133:                 rendererFactory = bundleContext.getService(factoryServiceReference);
134:         }
135:
136:         @AfterClass
137:         public static void afterClass() {
138:                 System.setErr(systemErr);
139:                 final BundleContext bundleContext = FrameworkUtil.getBundle(GridTable_PTest.class).getBundleContext();
140:                 bundleContext.ungetService(factoryServiceReference);
141:         }
142:
143:         @Before
144:         public void init() {
145:                 log = "";
146:                 shell = SWTViewTestHelper.createShell();
147:
148:                 final EClass eClass = EcoreFactory.eINSTANCE.createEClass();
149:                 eClass.getESuperTypes().add(EcorePackage.eINSTANCE.getEClass());
150:                 domainElement = eClass;
151:         }
152:
153:         @After
154:         public void after() {
155:•                if (!log.isEmpty()) {
156:                         fail("Unexpected log to System.err: " + log);
157:                 }
158:         }
159:
160:         @Test
161:         public void testUninitializedTableWithoutColumns() throws NoRendererFoundException,
162:                 NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
163:                 // setup model
164:                 final TableControlHandle handle = TableTestUtil.createUninitializedTableWithoutColumns();
165:                 //
166:                 final Control render = SWTViewTestHelper.render(handle.getTableControl(), domainElement, shell);
167:                 assertTrue(Label.class.isInstance(render));// Error label with error text
168:                 assertEquals("The field domainModelEFeature of the given VFeaturePathDomainModelReference must not be null.",
169:                         Label.class.cast(render).getText());
170:         }
171:
172:         @Test
173:         public void testInitializedTableWithoutColumnsAndEmptyReference() throws NoRendererFoundException,
174:                 NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
175:                 // setup model
176:                 final EClass createEClass = EcoreFactory.eINSTANCE.createEClass();
177:                 createEClass.eUnset(EcorePackage.eINSTANCE.getEClass_ESuperTypes());
178:                 domainElement = createEClass;
179:                 final TableControlHandle handle = TableTestUtil.createInitializedTableWithoutTableColumns();
180:
181:                 try {
182:                         SWTViewTestHelper.render(handle.getTableControl(), domainElement, shell);
183:                 } catch (final NullPointerException e) {
184:                         fail("Fails without a reference in domain object");
185:                 }
186:
187:         }
188:
189:         @Ignore
190:         @Test
191:         public void testInitializedTableWithoutColumnsSingleReference() throws NoRendererFoundException,
192:                 NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
193:                 // setup model
194:                 final VView view = VViewFactory.eINSTANCE.createView();
195:                 view.setRootEClass(VViewPackage.eINSTANCE.getView());
196:                 domainElement = view;
197:                 final TableControlHandle handle = TableTestUtil.createInitializedTableWithoutTableColumns();
198:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
199:                         .createFeaturePathDomainModelReference();
200:                 domainModelReference.setDomainModelEFeature(VViewPackage.eINSTANCE.getView_RootEClass());
201:                 handle.getTableControl().setDomainModelReference(domainModelReference);
202:
203:                 try {
204:                         SWTViewTestHelper.render(handle.getTableControl(), domainElement, shell);
205:                 } catch (final ClassCastException e) {
206:                         e.printStackTrace();
207:                         fail("Fails with single reference in domain object");
208:                 }
209:
210:         }
211:
212:         @Ignore
213:         @Test
214:         public void testInitializedTableWithoutColumnsEmptySingleReference() throws NoRendererFoundException,
215:                 NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
216:                 // setup model
217:                 final VView view = VViewFactory.eINSTANCE.createView();
218:                 domainElement = view;
219:                 final TableControlHandle handle = TableTestUtil.createInitializedTableWithoutTableColumns();
220:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
221:                         .createFeaturePathDomainModelReference();
222:                 domainModelReference.setDomainModelEFeature(VViewPackage.eINSTANCE.getView_RootEClass());
223:                 handle.getTableControl().setDomainModelReference(domainModelReference);
224:
225:                 try {
226:                         SWTViewTestHelper.render(handle.getTableControl(), domainElement, shell);
227:                 } catch (final NullPointerException e) {
228:                         fail("Fails with empty single reference in domain object");
229:                 }
230:
231:         }
232:
233:         @Test
234:         public void testTableWithoutColumns() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption,
235:                 EMFFormsNoRendererException {
236:                 // setup model
237:                 final TableControlHandle handle = TableTestUtil.createInitializedTableWithoutTableColumns();
238:
239:                 final Control render = SWTViewTestHelper.render(handle.getTableControl(), domainElement, shell);
240:                 assertTrue(render instanceof Composite);
241:
242:                 // see bug #533262, TableColumnGenerator now includes attributes from super types
243:                 // if this is not desired the user has to specify the columns in the view model
244:                 assertEquals(domainElement.eClass().getEAllAttributes().size(),
245:                         VTableDomainModelReference.class.cast(handle.getTableControl().getDomainModelReference())
246:                                 .getColumnDomainModelReferences().size());
247:
248:                 final Control control = getTable(render);
249:                 assertTrue(control instanceof Grid);
250:                 final Grid table = (Grid) control;
251:                 assertEquals(domainElement.eClass().getEAllAttributes().size() + 1, table.getColumnCount());
252:         }
253:
254:         @Test
255:         public void testTableWithoutColumnsWithoutViewServices() throws NoRendererFoundException,
256:                 NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
257:                 final TableControlHandle handle = TableTestUtil.createInitializedTableWithoutTableColumns();
258:                 final AbstractSWTRenderer<VElement> tableRenderer = rendererFactory.getRendererInstance(
259:                         handle.getTableControl(),
260:                         new ViewModelContextWithoutServices(handle.getTableControl()));
261:                 tableRenderer.getGridDescription(new SWTGridDescription());
262:                 final Control render = tableRenderer.render(new SWTGridCell(0, 0, tableRenderer), shell);
263:•                if (render == null) {
264:                         fail();
265:                 }
266:                 assertTrue(render instanceof Composite);
267:
268:                 assertEquals(0, VTableDomainModelReference.class.cast(handle.getTableControl().getDomainModelReference())
269:                         .getColumnDomainModelReferences().size());
270:
271:                 final Control control = getTable(render);
272:                 assertTrue(control instanceof Grid);
273:                 final Grid table = (Grid) control;
274:                 assertEquals(1, table.getColumnCount());
275:         }
276:
277:         @Test
278:         public void testTableWithTwoColumns() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption,
279:                 EMFFormsNoRendererException {
280:                 // setup model
281:                 final TableControlHandle handle = createTableWithTwoTableColumns();
282:                 final Control render = SWTViewTestHelper.render(handle.getTableControl(), domainElement, shell);
283:                 assertTrue(render instanceof Composite);
284:
285:                 final Control control = getTable(render);
286:                 assertTrue(control instanceof Grid);
287:                 final Grid table = (Grid) control;
288:                 assertEquals(2 + 1, table.getColumnCount());
289:
290:         }
291:
292:         @Test
293:         public void testTableWithTwoColumnsWithoutViewServices() throws NoRendererFoundException,
294:                 NoPropertyDescriptorFoundExeption, EMFFormsNoRendererException {
295:                 // setup model
296:                 final TableControlHandle handle = createTableWithTwoTableColumns();
297:                 final AbstractSWTRenderer<VElement> tableRenderer = rendererFactory.getRendererInstance(
298:                         handle.getTableControl(),
299:                         new ViewModelContextWithoutServices(handle.getTableControl()));
300:                 tableRenderer.getGridDescription(new SWTGridDescription());
301:                 final Control render = tableRenderer.render(new SWTGridCell(0, 0, tableRenderer), shell);
302:•                if (render == null) {
303:                         fail();
304:                 }
305:                 assertTrue(render instanceof Composite);
306:
307:                 final Control control = getTable(render);
308:                 assertTrue(control instanceof Grid);
309:                 final Grid table = (Grid) control;
310:                 assertEquals(2 + 1, table.getColumnCount());
311:         }
312:
313:         @Test
314:         public void testTableWithTwoColumnsAdd() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption,
315:                 EMFFormsNoRendererException {
316:                 final TableControlHandle handle = createTableWithTwoTableColumns();
317:                 final AbstractSWTRenderer<VElement> tableRenderer = rendererFactory.getRendererInstance(
318:                         handle.getTableControl(),
319:                         new ViewModelContextWithoutServices(handle.getTableControl()));
320:                 tableRenderer.getGridDescription(new SWTGridDescription());
321:                 final Control control = tableRenderer.render(new SWTGridCell(0, 0, tableRenderer), shell);
322:•                if (control == null) {
323:                         fail("No control was rendered");
324:                 }
325:                 final Grid table = (Grid) getTable(control);
326:                 assertEquals(1, table.getItemCount());
327:                 final EClass eClass = EcoreFactory.eINSTANCE.createEClass();
328:                 ((EClass) domainElement).getESuperTypes().add(eClass);
329:                 assertEquals(2, table.getItemCount());
330:         }
331:
332:         @Test
333:         public void testTableWithTwoColumnsRemove() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption,
334:                 EMFFormsNoRendererException {
335:                 final TableControlHandle handle = createTableWithTwoTableColumns();
336:                 final AbstractSWTRenderer<VElement> tableRenderer = rendererFactory.getRendererInstance(
337:                         handle.getTableControl(),
338:                         new ViewModelContextWithoutServices(handle.getTableControl()));
339:                 tableRenderer.getGridDescription(new SWTGridDescription());
340:                 final Control control = tableRenderer.render(new SWTGridCell(0, 0, tableRenderer), shell);
341:•                if (control == null) {
342:                         fail("No control was rendered");
343:                 }
344:                 final Grid table = (Grid) getTable(control);
345:                 assertEquals(1, table.getItemCount());
346:                 final EClass eClass = ((EClass) domainElement).getESuperTypes().get(0);
347:                 ((EClass) domainElement).getESuperTypes().remove(eClass);
348:                 assertEquals(0, table.getItemCount());
349:         }
350:
351:         @Test
352:         public void testTableWithTwoColumnsClear() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption,
353:                 EMFFormsNoRendererException {
354:                 final EClass eClass = EcoreFactory.eINSTANCE.createEClass();
355:                 ((EClass) domainElement).getESuperTypes().add(eClass);
356:                 final TableControlHandle handle = createTableWithTwoTableColumns();
357:                 final AbstractSWTRenderer<VElement> tableRenderer = rendererFactory.getRendererInstance(
358:                         handle.getTableControl(),
359:                         new ViewModelContextWithoutServices(handle.getTableControl()));
360:                 tableRenderer.getGridDescription(new SWTGridDescription());
361:                 final Control control = tableRenderer.render(new SWTGridCell(0, 0, tableRenderer), shell);
362:•                if (control == null) {
363:                         fail("No control was rendered");
364:                 }
365:                 final Grid table = (Grid) getTable(control);
366:                 assertEquals(2, table.getItemCount());
367:                 ((EClass) domainElement).getESuperTypes().clear();
368:                 assertEquals(0, table.getItemCount());
369:         }
370:
371:         @Test
372:         public void testPanelTableWithTwoColumns() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption,
373:                 EMFFormsNoRendererException {
374:                 final EClass eClass = EcoreFactory.eINSTANCE.createEClass();
375:                 ((EClass) domainElement).getESuperTypes().add(eClass);
376:                 final TableControlHandle handle = createTableWithTwoTableColumns();
377:                 handle.getTableControl().setDetailEditing(DetailEditing.WITH_PANEL);
378:                 handle.getTableControl().setDetailView(createDetailView());
379:                 final AbstractSWTRenderer<VElement> tableRenderer = rendererFactory.getRendererInstance(
380:                         handle.getTableControl(),
381:                         new ViewModelContextWithoutServices(handle.getTableControl()));
382:                 tableRenderer.getGridDescription(new SWTGridDescription());
383:                 final Control render = tableRenderer.render(new SWTGridCell(0, 0, tableRenderer), shell);
384:                 final Control control = Composite.class.cast(render).getChildren()[0];
385:•                if (control == null) {
386:                         fail("No control was rendered");
387:                 }
388:                 final Composite controlComposite = (Composite) ((Composite) control).getChildren()[1];
389:                 final SashForm sash = (SashForm) controlComposite.getChildren()[0];
390:                 final Composite tableWrapperComposite = (Composite) sash.getChildren()[0];
391:                 final Composite tableComposite = (Composite) tableWrapperComposite.getChildren()[0];
392:                 final Grid table = (Grid) tableComposite.getChildren()[0];
393:                 final ScrolledComposite scrolledComposite = (ScrolledComposite) sash.getChildren()[1];
394:                 final Composite parentForECPView = (Composite) scrolledComposite.getChildren()[0];
395:                 assertEquals(2, table.getItemCount());
396:                 final GridTableViewer tableViewer = GridTestsUtil.getTableViewerFromRenderer(tableRenderer);
397:
398:                 // no initial selection
399:                 assertThat("Composite for no selection not present",
400:                         asList(parentForECPView.getChildren()), hasItem(instanceOf(Composite.class)));
401:                 final Composite stackComposite = (Composite) parentForECPView.getChildren()[0];
402:                 final StackLayout stack = (StackLayout) stackComposite.getLayout();
403:                 Composite labelComposite = (Composite) stack.topControl;
404:                 assertThat("Composite for label not present", labelComposite, notNullValue());
405:                 assertThat("Label for no selection not present",
406:                         asList(labelComposite.getChildren()), hasItem(instanceOf(Label.class)));
407:
408:                 // single selection
409:                 tableViewer.setSelection(new StructuredSelection(table.getItem(0).getData()));
410:                 Composite detailComposite = (Composite) stack.topControl;
411:                 assertEquals(6, detailComposite.getChildren().length);
412:
413:                 // multi selection (it's like no selection)
414:                 tableViewer.setSelection(new StructuredSelection(new Object[] { table.getItem(0).getData(),
415:                         table.getItem(1).getData() }));
416:                 detailComposite = (Composite) stack.topControl;
417:                 assertThat("Label for multi selection not present",
418:                         asList(labelComposite.getChildren()), hasItem(instanceOf(Label.class)));
419:
420:                 // select again
421:                 tableViewer.setSelection(new StructuredSelection(table.getItem(0).getData()));
422:                 detailComposite = (Composite) stack.topControl;
423:                 assertEquals(6, detailComposite.getChildren().length);
424:
425:                 // no selection
426:                 tableViewer.setSelection(new StructuredSelection());
427:                 labelComposite = (Composite) stack.topControl;
428:                 assertThat("Composite for label not present", labelComposite, notNullValue());
429:                 assertThat("Label for no selection not present",
430:                         asList(labelComposite.getChildren()), hasItem(instanceOf(Label.class)));
431:         }
432:
433:         @Test
434:         public void testTableSorting() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption,
435:                 EMFFormsNoRendererException {
436:                 // domain
437:                 ((EClass) domainElement).getESuperTypes().clear();
438:                 final EClass class1 = createEClass("a", "b");
439:                 final EClass class2 = createEClass("b", "c");
440:                 final EClass class3 = createEClass("c", "a");
441:                 ((EClass) domainElement).getESuperTypes().add(class1);
442:                 ((EClass) domainElement).getESuperTypes().add(class2);
443:                 ((EClass) domainElement).getESuperTypes().add(class3);
444:
445:                 // table control
446:                 final VTableControl tableControl = TableTestUtil.createTableControl();
447:                 final VTableDomainModelReference tableDMR = (VTableDomainModelReference) tableControl.getDomainModelReference();
448:                 tableDMR.setDomainModelEFeature(EcorePackage.eINSTANCE.getEClass_ESuperTypes());
449:                 tableDMR.getColumnDomainModelReferences().add(createDMR(EcorePackage.eINSTANCE.getENamedElement_Name()));
450:                 tableDMR.getColumnDomainModelReferences().add(
451:                         createDMR(EcorePackage.eINSTANCE.getEClassifier_InstanceClassName()));
452:
453:                 // render
454:                 final AbstractSWTRenderer<VElement> tableRenderer = rendererFactory.getRendererInstance(tableControl,
455:                         new ViewModelContextWithoutServices(tableControl));
456:                 tableRenderer.getGridDescription(new SWTGridDescription());
457:                 final Control control = tableRenderer.render(new SWTGridCell(0, 0, tableRenderer), shell);
458:•                if (control == null) {
459:                         fail("No control was rendered");
460:                 }
461:                 final Grid table = SWTTestUtil.findControl(control, 0, Grid.class);
462:                 assertGridItemOrder(table, class1, class2, class3);
463:
464:                 // column 0 is validation column
465:
466:                 // select column 1
467:                 // up
468:                 SWTTestUtil.selectWidget(table.getColumns()[1]);
469:                 SWTTestUtil.waitForUIThread();
470:                 assertGridItemOrder(table, class1, class2, class3);
471:                 // down
472:                 SWTTestUtil.selectWidget(table.getColumns()[1]);
473:                 SWTTestUtil.waitForUIThread();
474:                 assertGridItemOrder(table, class3, class2, class1);
475:                 // none
476:                 SWTTestUtil.selectWidget(table.getColumns()[1]);
477:                 SWTTestUtil.waitForUIThread();
478:                 assertGridItemOrder(table, class1, class2, class3);
479:
480:                 // select column 2
481:                 // up
482:                 SWTTestUtil.selectWidget(table.getColumns()[2]);
483:                 SWTTestUtil.waitForUIThread();
484:                 assertGridItemOrder(table, class3, class1, class2);
485:                 // down
486:                 SWTTestUtil.selectWidget(table.getColumns()[2]);
487:                 SWTTestUtil.waitForUIThread();
488:                 assertGridItemOrder(table, class2, class1, class3);
489:                 // none
490:                 SWTTestUtil.selectWidget(table.getColumns()[2]);
491:                 SWTTestUtil.waitForUIThread();
492:                 assertGridItemOrder(table, class1, class2, class3);
493:         }
494:
495:         @Test
496:         public void testTableSortingWithCellEditor() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption,
497:                 EMFFormsNoRendererException {
498:                 // domain
499:                 ((EClass) domainElement).getESuperTypes().clear();
500:                 final EClass class1 = createEClass("a", "b");
501:                 final EClass class2 = createEClass("b", "c");
502:                 final EClass class3 = createEClass("c", "a");
503:                 ((EClass) domainElement).getESuperTypes().add(class1);
504:                 ((EClass) domainElement).getESuperTypes().add(class2);
505:                 ((EClass) domainElement).getESuperTypes().add(class3);
506:
507:                 // table control
508:                 final VTableControl tableControl = TableTestUtil.createTableControl();
509:                 final VTableDomainModelReference tableDMR = (VTableDomainModelReference) tableControl.getDomainModelReference();
510:                 tableDMR.setDomainModelEFeature(EcorePackage.eINSTANCE.getEClass_ESuperTypes());
511:                 tableDMR.getColumnDomainModelReferences().add(createDMR(EcorePackage.eINSTANCE.getENamedElement_Name()));
512:                 tableDMR.getColumnDomainModelReferences().add(
513:                         createDMR(EcorePackage.eINSTANCE.getEClassifier_InstanceClassName()));
514:
515:                 // render
516:                 final TableControlSWTRenderer tableRenderer = createRendererInstanceWithCustomCellEditor(tableControl);
517:                 tableRenderer.getGridDescription(new SWTGridDescription());
518:                 final Control control = tableRenderer.render(new SWTGridCell(0, 0, tableRenderer), shell);
519:•                if (control == null) {
520:                         fail("No control was rendered");
521:                 }
522:                 final Grid table = SWTTestUtil.findControl(control, 0, Grid.class);
523:                 assertGridItemOrder(table, class1, class2, class3);
524:
525:                 // column 0 is validation column
526:
527:                 // select column 1
528:                 // up
529:                 SWTTestUtil.selectWidget(table.getColumns()[1]);
530:                 SWTTestUtil.waitForUIThread();
531:                 assertGridItemOrder(table, class3, class2, class1);
532:                 // down
533:                 SWTTestUtil.selectWidget(table.getColumns()[1]);
534:                 SWTTestUtil.waitForUIThread();
535:                 assertGridItemOrder(table, class1, class2, class3);
536:                 // none
537:                 SWTTestUtil.selectWidget(table.getColumns()[1]);
538:                 SWTTestUtil.waitForUIThread();
539:                 assertGridItemOrder(table, class1, class2, class3);
540:
541:                 // select column 2
542:                 // up
543:                 SWTTestUtil.selectWidget(table.getColumns()[2]);
544:                 SWTTestUtil.waitForUIThread();
545:                 assertGridItemOrder(table, class3, class1, class2);
546:                 // down
547:                 SWTTestUtil.selectWidget(table.getColumns()[2]);
548:                 SWTTestUtil.waitForUIThread();
549:                 assertGridItemOrder(table, class2, class1, class3);
550:                 // none
551:                 SWTTestUtil.selectWidget(table.getColumns()[2]);
552:                 SWTTestUtil.waitForUIThread();
553:                 assertGridItemOrder(table, class1, class2, class3);
554:         }
555:
556:         @Test
557:         public void gridSorting_autoSortOnEdit()
558:                 throws EMFFormsNoRendererException, NoRendererFoundException, NoPropertyDescriptorFoundExeption {
559:                 // domain
560:                 ((EClass) domainElement).getEStructuralFeatures().clear();
561:                 final EAttribute attribute1 = createEAttribute("a", EcorePackage.Literals.ESTRING, 0, 2);
562:                 final EAttribute attribute2 = createEAttribute("b", EcorePackage.Literals.ESTRING, 0, 11);
563:                 final EAttribute attribute3 = createEAttribute("c", EcorePackage.Literals.ESTRING, 0, 1);
564:                 ((EClass) domainElement).getEStructuralFeatures().add(attribute1);
565:                 ((EClass) domainElement).getEStructuralFeatures().add(attribute2);
566:                 ((EClass) domainElement).getEStructuralFeatures().add(attribute3);
567:
568:                 // table control
569:                 final VTableControl tableControl = TableTestUtil.createTableControl();
570:                 final VTableDomainModelReference tableDMR = (VTableDomainModelReference) tableControl.getDomainModelReference();
571:                 tableDMR.setDomainModelEFeature(EcorePackage.eINSTANCE.getEClass_EAttributes());
572:                 tableDMR.getColumnDomainModelReferences().add(createDMR(EcorePackage.eINSTANCE.getENamedElement_Name()));
573:                 tableDMR.getColumnDomainModelReferences().add(
574:                         createDMR(EcorePackage.eINSTANCE.getETypedElement_UpperBound()));
575:
576:                 // render
577:                 shell.open();
578:                 // With this shell size, the table will be 77 pixels high and show 2 rows
579:                 shell.setSize(200, 150);
580:                 final Control control = SWTViewTestHelper.render(tableControl, domainElement, shell);
581:•                if (control == null) {
582:                         fail("No control was rendered");
583:                 }
584:                 shell.layout();
585:                 final Grid grid = SWTTestUtil.findControl(control, 0, Grid.class);
586:
587:                 // column 0 is validation column
588:                 // select column 1 (name) and ascending sorting
589:                 SWTTestUtil.selectWidget(grid.getColumns()[1]);
590:                 SWTTestUtil.waitForUIThread();
591:                 assertGridItemOrder(grid, attribute1, attribute2, attribute3);
592:
593:                 // Change the attribute the sorting is currently applied on and assert that the table was automatically
594:                 // re-sorted
595:                 attribute1.setName("z");
596:                 SWTTestUtil.waitForUIThread();
597:                 assertGridItemOrder(grid, attribute2, attribute3, attribute1);
598:
599:                 final GridItem sortItem = grid.getItem(2);
600:                 final int itemLowerEnd = sortItem.getBounds(1).y + sortItem.getBounds(1).height;
601:                 // Assert that the edited grid item was revealed after it had been moved to the end of the grid.
602:                 assertThat(
603:                         "The edited grid item is not fully visible after the auto sort because the grid didn't scroll down.",
604:                         itemLowerEnd, lessThan(grid.getBounds().height));
605:                 assertThat(
606:                         "The edited grid item is not fully visible after the auto sort because the grid is scrolled too far down.",
607:                         sortItem.getBounds(1).y, greaterThan(grid.getHeaderHeight()));
608:
609:                 shell.close();
610:         }
611:
612:         /** Tests that the sort indicator of a column is removed when another column is used for sorting. */
613:         @Test
614:         public void gridSorting_sortIndicatorReset()
615:                 throws EMFFormsNoRendererException, NoRendererFoundException, NoPropertyDescriptorFoundExeption {
616:                 // domain
617:                 ((EClass) domainElement).getESuperTypes().clear();
618:                 final EClass class1 = createEClass("a", "b");
619:                 final EClass class2 = createEClass("b", "c");
620:                 ((EClass) domainElement).getESuperTypes().add(class1);
621:                 ((EClass) domainElement).getESuperTypes().add(class2);
622:
623:                 // table control
624:                 final VTableControl tableControl = TableTestUtil.createTableControl();
625:                 final VTableDomainModelReference tableDMR = (VTableDomainModelReference) tableControl.getDomainModelReference();
626:                 tableDMR.setDomainModelEFeature(EcorePackage.eINSTANCE.getEClass_ESuperTypes());
627:                 tableDMR.getColumnDomainModelReferences().add(createDMR(EcorePackage.eINSTANCE.getENamedElement_Name()));
628:                 tableDMR.getColumnDomainModelReferences().add(
629:                         createDMR(EcorePackage.eINSTANCE.getEClassifier_InstanceClassName()));
630:
631:                 // render
632:                 final AbstractSWTRenderer<VElement> tableRenderer = rendererFactory.getRendererInstance(tableControl,
633:                         new ViewModelContextWithoutServices(tableControl));
634:                 tableRenderer.getGridDescription(new SWTGridDescription());
635:                 final Control control = tableRenderer.render(new SWTGridCell(0, 0, tableRenderer), shell);
636:•                if (control == null) {
637:                         fail("No control was rendered");
638:                 }
639:                 final Grid table = SWTTestUtil.findControl(control, 0, Grid.class);
640:                 assertEquals(SWT.NONE, table.getColumn(1).getSort());
641:                 assertEquals(SWT.NONE, table.getColumn(2).getSort());
642:
643:                 // column 0 is validation column
644:
645:                 // select column 1
646:                 SWTTestUtil.selectWidget(table.getColumns()[1]);
647:                 SWTTestUtil.waitForUIThread();
648:                 assertEquals(SWT.DOWN, table.getColumn(1).getSort());
649:                 assertEquals(SWT.NONE, table.getColumn(2).getSort());
650:
651:                 // select column 2 -> column 1 indicator should be reset
652:                 SWTTestUtil.selectWidget(table.getColumn(2));
653:                 SWTTestUtil.waitForUIThread();
654:                 assertEquals(SWT.NONE, table.getColumn(1).getSort());
655:                 assertEquals(SWT.DOWN, table.getColumn(2).getSort());
656:         }
657:
658:         private GridControlSWTRenderer createRendererInstanceWithCustomCellEditor(final VTableControl tableControl)
659:                 throws EMFFormsNoRendererException {
660:                 final ViewModelContextWithoutServices viewModelContext = new ViewModelContextWithoutServices(tableControl);
661:                 final EMFFormsContextProvider contextProvider = viewModelContext.getService(EMFFormsContextProvider.class);
662:                 final IEclipseContext eclipseContext = contextProvider.getContext();
663:                 final GridControlSWTRenderer tableControlSWTRenderer = new GridControlSWTRenderer(
664:                         tableControl,
665:                         viewModelContext,
666:                         eclipseContext.get(ReportService.class),
667:                         eclipseContext.get(EMFFormsDatabindingEMF.class),
668:                         eclipseContext.get(EMFFormsLabelProvider.class),
669:                         eclipseContext.get(VTViewTemplateProvider.class),
670:                         eclipseContext.get(ImageRegistryService.class),
671:                         eclipseContext.get(EMFFormsEditSupport.class),
672:                         eclipseContext.get(EStructuralFeatureValueConverterService.class),
673:                         eclipseContext.get(EMFFormsLocalizationService.class)) {
674:
675:                         @Override
676:                         protected CellEditor createCellEditor(EObject tempInstance, EStructuralFeature feature, Composite table) {
677:                                 if (feature == EcorePackage.eINSTANCE.getENamedElement_Name()) {
678:                                         return new CompareCellEditor(table);
679:                                 }
680:                                 return super.createCellEditor(tempInstance, feature, table);
681:                         }
682:                 };
683:                 tableControlSWTRenderer.init();
684:                 return tableControlSWTRenderer;
685:         }
686:
687:         private static void assertGridItemOrder(Grid table, Object... objects) {
688:                 assertEquals(objects.length, table.getItemCount());
689:                 final GridItem[] items = table.getItems();
690:•                for (int i = 0; i < items.length; i++) {
691:                         assertSame(objects[i], items[i].getData());
692:                 }
693:         }
694:
695:         private static EClass createEClass(String name, String instanceClassName) {
696:                 final EClass clazz = EcoreFactory.eINSTANCE.createEClass();
697:                 clazz.setName(name);
698:                 clazz.setInstanceClassName(instanceClassName);
699:                 return clazz;
700:         }
701:
702:         private static EAttribute createEAttribute(String name, EClassifier classifier, int lowerBound, int upperBound) {
703:                 final EAttribute attribute = EcoreFactory.eINSTANCE.createEAttribute();
704:                 attribute.setName(name);
705:                 attribute.setEType(classifier);
706:                 attribute.setLowerBound(lowerBound);
707:                 attribute.setUpperBound(upperBound);
708:                 return attribute;
709:         }
710:
711:         private static VFeaturePathDomainModelReference createDMR(EAttribute attribute, EReference... refs) {
712:                 final VFeaturePathDomainModelReference dmr = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
713:                 dmr.setDomainModelEFeature(attribute);
714:                 dmr.getDomainModelEReferencePath().addAll(Arrays.asList(refs));
715:                 return dmr;
716:         }
717:
718:         private VView createDetailView() {
719:                 final VView detailView = VViewFactory.eINSTANCE.createView();
720:                 final VControl name = VViewFactory.eINSTANCE.createControl();
721:                 final VFeaturePathDomainModelReference nameRef = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
722:                 nameRef.setDomainModelEFeature(EcorePackage.eINSTANCE.getENamedElement_Name());
723:                 name.setDomainModelReference(nameRef);
724:                 detailView.getChildren().add(name);
725:                 final VControl abstr = VViewFactory.eINSTANCE.createControl();
726:                 final VFeaturePathDomainModelReference abstractRef = VViewFactory.eINSTANCE
727:                         .createFeaturePathDomainModelReference();
728:                 abstractRef.setDomainModelEFeature(EcorePackage.eINSTANCE.getEClass_Abstract());
729:                 abstr.setDomainModelReference(abstractRef);
730:                 detailView.getChildren().add(abstr);
731:                 return detailView;
732:
733:         }
734:
735:         private Control getTable(Control render) {
736:                 Composite composite = (Composite) render;
737:                 composite = (Composite) composite.getChildren()[0];
738:                 composite = (Composite) composite.getChildren()[1];
739:                 // composite = (Composite) composite.getChildren()[0];
740:                 // composite = (Composite) composite.getChildren()[0];
741:                 // composite = (Composite) composite.getChildren()[0];
742:                 return composite.getChildren()[0];
743:         }
744:
745:         private static TableControlHandle createTableWithTwoTableColumns() {
746:                 final TableControlHandle tableControlHandle = TableTestUtil.createInitializedTableWithoutTableColumns();
747:                 final VDomainModelReference tableColumn1 = TableTestUtil
748:                         .createTableColumn(EcorePackage.eINSTANCE.getEClass_Abstract());
749:
750:                 tableControlHandle.addFirstTableColumn(tableColumn1);
751:                 final VDomainModelReference tableColumn2 = TableTestUtil
752:                         .createTableColumn(EcorePackage.eINSTANCE.getEClass_Abstract());
753:                 tableControlHandle.addSecondTableColumn(tableColumn2);
754:                 return tableControlHandle;
755:         }
756:
757:         /**
758:          * Stub implementation without getting services from ex. point.
759:          *
760:          * @author jfaltermeier
761:          *
762:          */
763:         private class ViewModelContextWithoutServices implements ViewModelContext {
764:
765:                 private final VElement view;
766:                 private final EMFFormsContextProvider contextProvider;
767:
768:                 @SuppressWarnings("restriction")
769:                 ViewModelContextWithoutServices(VElement view) {
770:                         this.view = view;
771:                         contextProvider = new org.eclipse.emfforms.internal.swt.core.di.EMFFormsContextProviderImpl();
772:                         contextProvider.instantiate(this);
773:                 }
774:
775:                 /**
776:                  * {@inheritDoc}
777:                  *
778:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#getViewModel()
779:                  */
780:                 @Override
781:                 public VElement getViewModel() {
782:                         return view;
783:                 }
784:
785:                 /**
786:                  * {@inheritDoc}
787:                  *
788:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#getDomainModel()
789:                  */
790:                 @Override
791:                 public EObject getDomainModel() {
792:                         return domainElement;
793:                 }
794:
795:                 /**
796:                  *
797:                  * {@inheritDoc}
798:                  *
799:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#registerViewChangeListener(org.eclipse.emf.ecp.view.spi.model.ModelChangeListener)
800:                  */
801:                 @Override
802:                 public void registerViewChangeListener(ModelChangeListener modelChangeListener) {
803:                         // not needed
804:                 }
805:
806:                 /**
807:                  *
808:                  * {@inheritDoc}
809:                  *
810:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#unregisterViewChangeListener(org.eclipse.emf.ecp.view.spi.model.ModelChangeListener)
811:                  */
812:                 @Override
813:                 public void unregisterViewChangeListener(ModelChangeListener modelChangeListener) {
814:                         // not needed
815:                 }
816:
817:                 /**
818:                  *
819:                  * {@inheritDoc}
820:                  *
821:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#registerDomainChangeListener(org.eclipse.emf.ecp.view.spi.model.ModelChangeListener)
822:                  */
823:                 @Override
824:                 public void registerDomainChangeListener(ModelChangeListener modelChangeListener) {
825:                         // not needed
826:                 }
827:
828:                 /**
829:                  *
830:                  * {@inheritDoc}
831:                  *
832:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#unregisterDomainChangeListener(org.eclipse.emf.ecp.view.spi.model.ModelChangeListener)
833:                  */
834:                 @Override
835:                 public void unregisterDomainChangeListener(ModelChangeListener modelChangeListener) {
836:                         // not needed
837:                 }
838:
839:                 /**
840:                  * {@inheritDoc}
841:                  *
842:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#dispose()
843:                  */
844:                 @Override
845:                 public void dispose() {
846:                         // not needed
847:                 }
848:
849:                 /**
850:                  * {@inheritDoc}
851:                  *
852:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#hasService(java.lang.Class)
853:                  */
854:                 @Override
855:                 public <T> boolean hasService(Class<T> serviceType) {
856:                         if (EMFFormsContextProvider.class.equals(serviceType)) {
857:                                 return true;
858:                         }
859:                         return false;
860:                 }
861:
862:                 /**
863:                  * {@inheritDoc}
864:                  *
865:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#getService(java.lang.Class)
866:                  */
867:                 @SuppressWarnings("unchecked")
868:                 @Override
869:                 public <T> T getService(Class<T> serviceType) {
870:                         if (EMFFormsContextProvider.class.equals(serviceType)) {
871:                                 return (T) contextProvider;
872:                         }
873:                         return null;
874:                 }
875:
876:                 /**
877:                  * {@inheritDoc}
878:                  *
879:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#getControlsFor(org.eclipse.emf.ecore.EStructuralFeature.Setting)
880:                  * @deprecated
881:                  */
882:                 @Deprecated
883:                 @Override
884:                 public Set<VControl> getControlsFor(Setting setting) {
885:                         return null;
886:                 }
887:
888:                 /**
889:                  * {@inheritDoc}
890:                  *
891:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#getControlsFor(org.eclipse.emf.ecp.common.spi.UniqueSetting)
892:                  * @deprecated
893:                  */
894:                 @Deprecated
895:                 @Override
896:                 public Set<VElement> getControlsFor(UniqueSetting setting) {
897:                         return null;
898:                 }
899:
900:                 /**
901:                  * {@inheritDoc}
902:                  *
903:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#getContextValue(java.lang.String)
904:                  */
905:                 @Override
906:                 public Object getContextValue(String key) {
907:                         return null;
908:                 }
909:
910:                 /**
911:                  * {@inheritDoc}
912:                  *
913:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#putContextValue(java.lang.String,
914:                  * java.lang.Object)
915:                  */
916:                 @Override
917:                 public void putContextValue(String key, Object value) {
918:
919:                 }
920:
921:                 /**
922:                  * {@inheritDoc}
923:                  *
924:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#registerDisposeListener(org.eclipse.emf.ecp.view.spi.context.ViewModelContextDisposeListener)
925:                  */
926:                 @Override
927:                 public void registerDisposeListener(ViewModelContextDisposeListener listener) {
928:                         // TODO Auto-generated method stub
929:
930:                 }
931:
932:                 /**
933:                  * {@inheritDoc}
934:                  *
935:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#addContextUser(java.lang.Object)
936:                  */
937:                 @Override
938:                 public void addContextUser(Object user) {
939:                         // TODO Auto-generated method stub
940:
941:                 }
942:
943:                 /**
944:                  * {@inheritDoc}
945:                  *
946:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#removeContextUser(java.lang.Object)
947:                  */
948:                 @Override
949:                 public void removeContextUser(Object user) {
950:                         // TODO Auto-generated method stub
951:
952:                 }
953:
954:                 /**
955:                  * {@inheritDoc}
956:                  *
957:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#getChildContext(org.eclipse.emf.ecore.EObject,
958:                  * org.eclipse.emf.ecp.view.spi.model.VElement, org.eclipse.emf.ecp.view.spi.model.VView,
959:                  * org.eclipse.emf.ecp.view.spi.context.ViewModelService[])
960:                  */
961:                 @Override
962:                 public ViewModelContext getChildContext(EObject eObject, VElement parent, VView vView,
963:                         ViewModelService... viewModelServices) {
964:                         // TODO Auto-generated method stub
965:                         final ViewModelContextWithoutServices vmcws = new ViewModelContextWithoutServices(vView);
966:
967:                         return vmcws;
968:                 }
969:
970:                 /**
971:                  * {@inheritDoc}
972:                  *
973:                  * @see org.eclipse.emfforms.spi.core.services.view.EMFFormsViewContext#registerEMFFormsContextListener(org.eclipse.emfforms.spi.core.services.view.EMFFormsContextListener)
974:                  */
975:                 @Override
976:                 public void registerEMFFormsContextListener(EMFFormsContextListener contextListener) {
977:                 }
978:
979:                 /**
980:                  * {@inheritDoc}
981:                  *
982:                  * @see org.eclipse.emfforms.spi.core.services.view.EMFFormsViewContext#unregisterEMFFormsContextListener(org.eclipse.emfforms.spi.core.services.view.EMFFormsContextListener)
983:                  */
984:                 @Override
985:                 public void unregisterEMFFormsContextListener(EMFFormsContextListener contextListener) {
986:                 }
987:
988:                 /**
989:                  * {@inheritDoc}
990:                  *
991:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#getParentContext()
992:                  */
993:                 @Override
994:                 public ViewModelContext getParentContext() {
995:                         // TODO Auto-generated method stub
996:                         return null;
997:                 }
998:
999:                 /**
1000:                  * {@inheritDoc}
1001:                  *
1002:                  * @see org.eclipse.emfforms.spi.core.services.view.EMFFormsViewContext#changeDomainModel(org.eclipse.emf.ecore.EObject)
1003:                  */
1004:                 @Override
1005:                 public void changeDomainModel(EObject newDomainModel) {
1006:                         // TODO Auto-generated method stub
1007:
1008:                 }
1009:
1010:                 /**
1011:                  * {@inheritDoc}
1012:                  *
1013:                  * @see org.eclipse.emfforms.spi.core.services.view.EMFFormsViewContext#registerRootDomainModelChangeListener(org.eclipse.emfforms.spi.core.services.view.RootDomainModelChangeListener)
1014:                  */
1015:                 @Override
1016:                 public void registerRootDomainModelChangeListener(RootDomainModelChangeListener rootDomainModelChangeListener) {
1017:                         // TODO Auto-generated method stub
1018:
1019:                 }
1020:
1021:                 /**
1022:                  * {@inheritDoc}
1023:                  *
1024:                  * @see org.eclipse.emfforms.spi.core.services.view.EMFFormsViewContext#unregisterRootDomainModelChangeListener(org.eclipse.emfforms.spi.core.services.view.RootDomainModelChangeListener)
1025:                  */
1026:                 @Override
1027:                 public void unregisterRootDomainModelChangeListener(
1028:                         RootDomainModelChangeListener rootDomainModelChangeListener) {
1029:                         // TODO Auto-generated method stub
1030:
1031:                 }
1032:
1033:                 /**
1034:                  * {@inheritDoc}
1035:                  *
1036:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#getParentVElement()
1037:                  */
1038:                 @Override
1039:                 public VElement getParentVElement() {
1040:                         // TODO Auto-generated method stub
1041:                         return null;
1042:                 }
1043:
1044:                 /**
1045:                  * {@inheritDoc}
1046:                  *
1047:                  * @see org.eclipse.emf.ecp.view.spi.context.ViewModelContext#getChildContext(org.eclipse.emf.ecore.EObject,
1048:                  * org.eclipse.emf.ecp.view.spi.model.VElement, org.eclipse.emf.ecp.view.spi.model.VView,
1049:                  * org.eclipse.emf.ecp.view.spi.context.ViewModelServiceProvider)
1050:                  */
1051:                 @Override
1052:                 public ViewModelContext getChildContext(EObject eObject, VElement parent, VView vView,
1053:                         ViewModelServiceProvider viewModelServiceProvider) {
1054:                         // TODO Auto-generated method stub
1055:                         return null;
1056:                 }
1057:
1058:                 @Override
1059:                 public void pause() {
1060:                         // do nothing
1061:                 }
1062:
1063:                 @Override
1064:                 public void reactivate() {
1065:                         // do nothing
1066:                 }
1067:
1068:         }
1069:
1070:         private static class PrintStreamWrapper extends PrintStream {
1071:
1072:                 private final PrintStream printStream;
1073:
1074:                 PrintStreamWrapper(PrintStream printStream) {
1075:                         super(new ByteArrayOutputStream());
1076:                         this.printStream = printStream;
1077:                 }
1078:
1079:                 /**
1080:                  * {@inheritDoc}
1081:                  *
1082:                  * @see java.io.PrintStream#print(java.lang.String)
1083:                  */
1084:                 @Override
1085:                 public void print(String s) {
1086:                         log = log.concat("\n" + s);
1087:                         printStream.print(s + "\n");
1088:                 }
1089:         }
1090:
1091:         private static class CompareCellEditor extends StringCellEditor implements ECPCellEditorComparator {
1092:
1093:                 CompareCellEditor(Composite table) {
1094:                         super(table);
1095:                 }
1096:
1097:                 @Override
1098:                 public int compare(Object e1, Object e2, int direction) {
1099:                         final String value1 = String.class.cast(e1);
1100:                         final String value2 = String.class.cast(e2);
1101:                         int result;
1102:                         if (value1 == null) {
1103:                                 result = 1;
1104:                         } else if (value2 == null) {
1105:                                 result = -1;
1106:                         } else {
1107:                                 result = value1.toString().compareTo(value2.toString()) * -1;// we flip the oder in our custom
1108:                                                                                                                                                                 // comparator
1109:                         }
1110:                         // If descending order, flip the direction
1111:                         if (direction == 2) {
1112:                                 result = -result;
1113:                         }
1114:                         return result;
1115:                 }
1116:
1117:         }
1118:
1119: }