Skip to content

Package: TableValidator

TableValidator

nameinstructionbranchcomplexitylinemethod
TableValidator()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
TableValidator(EMFFormsDatabindingEMF)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
createDiagnostic(int, int, String, EObject, EStructuralFeature)
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%
getEMFFormsDatabinding()
M: 0 C: 9
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getEPackage()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getResourceLocator()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getRootEClass(EObject)
M: 0 C: 25
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
getSubClasses(EClass)
M: 0 C: 59
100%
M: 2 C: 10
83%
M: 2 C: 5
71%
M: 0 C: 10
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
validate(int, Object, DiagnosticChain, Map)
M: 37 C: 23
38%
M: 6 C: 3
33%
M: 6 C: 3
33%
M: 6 C: 4
40%
M: 0 C: 1
100%
validateColumnForRootEClass(VDomainModelReference, EClass)
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
validateDetailEditing(DetailEditing, DiagnosticChain, Map)
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
validateEnablementConfiguration(VEnablementConfiguration, DiagnosticChain, Map)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
validateReadOnlyColumnConfiguration(VReadOnlyColumnConfiguration, DiagnosticChain, Map)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
validateSingleColumnConfiguration(VSingleColumnConfiguration, DiagnosticChain, Map)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
validateTableColumnConfiguration(VTableColumnConfiguration, DiagnosticChain, Map)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
validateTableControl(VTableControl, DiagnosticChain, Map)
M: 2 C: 110
98%
M: 9 C: 25
74%
M: 9 C: 9
50%
M: 1 C: 19
95%
M: 0 C: 1
100%
validateTableControl_resolveable(VTableControl, DiagnosticChain, Map)
M: 7 C: 33
83%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 10
91%
M: 0 C: 1
100%
validateTableDomainModelReference(VTableDomainModelReference, DiagnosticChain, Map)
M: 18 C: 94
84%
M: 25 C: 9
26%
M: 17 C: 1
6%
M: 1 C: 19
95%
M: 0 C: 1
100%
validateTableDomainModelReference_resolveable(VTableDomainModelReference, DiagnosticChain, Map)
M: 43 C: 263
86%
M: 5 C: 45
90%
M: 5 C: 21
81%
M: 10 C: 69
87%
M: 0 C: 1
100%
validateWidthConfiguration(VWidthConfiguration, DiagnosticChain, Map)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
validate_EveryMultiplicityConforms(EObject, DiagnosticChain, Map)
M: 2 C: 43
96%
M: 1 C: 9
90%
M: 1 C: 5
83%
M: 1 C: 10
91%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (c) 2011-2013 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: * Eugen Neufeld - initial API and implementation
13: */
14: package org.eclipse.emf.ecp.view.spi.table.model.util;
15:
16: import java.util.ArrayList;
17: import java.util.Collection;
18: import java.util.HashSet;
19: import java.util.LinkedHashMap;
20: import java.util.LinkedHashSet;
21: import java.util.List;
22: import java.util.Map;
23: import java.util.Optional;
24: import java.util.Set;
25:
26: import org.eclipse.core.databinding.property.value.IValueProperty;
27: import org.eclipse.emf.common.util.BasicDiagnostic;
28: import org.eclipse.emf.common.util.Diagnostic;
29: import org.eclipse.emf.common.util.DiagnosticChain;
30: import org.eclipse.emf.common.util.ResourceLocator;
31: import org.eclipse.emf.ecore.EClass;
32: import org.eclipse.emf.ecore.EClassifier;
33: import org.eclipse.emf.ecore.EObject;
34: import org.eclipse.emf.ecore.EPackage;
35: import org.eclipse.emf.ecore.EReference;
36: import org.eclipse.emf.ecore.EStructuralFeature;
37: import org.eclipse.emf.ecore.EValidator;
38: import org.eclipse.emf.ecore.util.EObjectValidator;
39: import org.eclipse.emf.ecp.view.internal.table.model.Activator;
40: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
41: import org.eclipse.emf.ecp.view.spi.model.VView;
42: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
43: import org.eclipse.emf.ecp.view.spi.model.util.ViewValidator;
44: import org.eclipse.emf.ecp.view.spi.table.model.DetailEditing;
45: import org.eclipse.emf.ecp.view.spi.table.model.VEnablementConfiguration;
46: import org.eclipse.emf.ecp.view.spi.table.model.VReadOnlyColumnConfiguration;
47: import org.eclipse.emf.ecp.view.spi.table.model.VSingleColumnConfiguration;
48: import org.eclipse.emf.ecp.view.spi.table.model.VTableColumnConfiguration;
49: import org.eclipse.emf.ecp.view.spi.table.model.VTableControl;
50: import org.eclipse.emf.ecp.view.spi.table.model.VTableDomainModelReference;
51: import org.eclipse.emf.ecp.view.spi.table.model.VTablePackage;
52: import org.eclipse.emf.ecp.view.spi.table.model.VWidthConfiguration;
53: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
54: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
55: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
56: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsDatabindingEMF;
57:
58: /**
59: * <!-- begin-user-doc -->
60: * The <b>Validator</b> for the model.
61: *
62: * @since 1.5
63: * <!-- end-user-doc -->
64: * @see org.eclipse.emf.ecp.view.spi.table.model.VTablePackage
65: * @generated
66: */
67: public class TableValidator extends EObjectValidator {
68:         private static final String VALIDATING_TABLE_CONTROL_KEY = "ValidatingTableControl"; //$NON-NLS-1$
69:
70:         /**
71:          * The cached model package
72:          * <!-- begin-user-doc -->
73:          * <!-- end-user-doc -->
74:          *
75:          * @generated
76:          */
77:         public static final TableValidator INSTANCE = new TableValidator();
78:
79:         /**
80:          * A constant for the {@link org.eclipse.emf.common.util.Diagnostic#getSource() source} of diagnostic
81:          * {@link org.eclipse.emf.common.util.Diagnostic#getCode() codes} from this package.
82:          * <!-- begin-user-doc -->
83:          * <!-- end-user-doc -->
84:          *
85:          * @see org.eclipse.emf.common.util.Diagnostic#getSource()
86:          * @see org.eclipse.emf.common.util.Diagnostic#getCode()
87:          * @generated
88:          */
89:         public static final String DIAGNOSTIC_SOURCE = "org.eclipse.emf.ecp.view.spi.table.model"; //$NON-NLS-1$
90:
91:         /**
92:          * A constant with a fixed name that can be used as the base value for additional hand written constants.
93:          * <!-- begin-user-doc -->
94:          * <!-- end-user-doc -->
95:          *
96:          * @generated
97:          */
98:         private static final int GENERATED_DIAGNOSTIC_CODE_COUNT = 0;
99:
100:         /**
101:          * A constant with a fixed name that can be used as the base value for additional hand written constants in a
102:          * derived class.
103:          * <!-- begin-user-doc -->
104:          * <!-- end-user-doc -->
105:          *
106:          * @generated
107:          */
108:         protected static final int DIAGNOSTIC_CODE_COUNT = GENERATED_DIAGNOSTIC_CODE_COUNT;
109:
110:         /**
111:          * The cached base package validator.
112:          * <!-- begin-user-doc -->
113:          * <!-- end-user-doc -->
114:          *
115:          * @generated
116:          */
117:         protected ViewValidator viewValidator;
118:         /**
119:          * The test EMFFormsDatabinding service.
120:          * <!-- begin-user-doc -->
121:          * <!-- end-user-doc -->
122:          *
123:          * @generated NOT
124:          */
125:         private EMFFormsDatabindingEMF emfFormsDatabinding;
126:
127:         /**
128:          * Creates an instance of the switch.
129:          * <!-- begin-user-doc -->
130:          * This is a constructor for test cases.
131:          * <!-- end-user-doc -->
132:          *
133:          * @generated NOT
134:          * @param emfFormsDatabinding An {@link EMFFormsDatabinding}
135:          */
136:         TableValidator(EMFFormsDatabindingEMF emfFormsDatabinding) {
137:                 this();
138:                 this.emfFormsDatabinding = emfFormsDatabinding;
139:         }
140:
141:         /**
142:          * Creates an instance of the switch.
143:          * <!-- begin-user-doc -->
144:          * <!-- end-user-doc -->
145:          *
146:          * @generated
147:          */
148:         public TableValidator() {
149:                 super();
150:                 viewValidator = ViewValidator.INSTANCE;
151:         }
152:
153:         /**
154:          * Returns the package of this validator switch.
155:          * <!-- begin-user-doc -->
156:          * <!-- end-user-doc -->
157:          *
158:          * @generated
159:          */
160:         @Override
161:         protected EPackage getEPackage() {
162:                 return VTablePackage.eINSTANCE;
163:         }
164:
165:         /**
166:          * Calls <code>validateXXX</code> for the corresponding classifier of the model.
167:          * <!-- begin-user-doc -->
168:          * <!-- end-user-doc -->
169:          *
170:          * @generated
171:          */
172:         @Override
173:         protected boolean validate(int classifierID, Object value, DiagnosticChain diagnostics,
174:                 Map<Object, Object> context) {
175:•                switch (classifierID) {
176:                 case VTablePackage.TABLE_CONTROL:
177:                         return validateTableControl((VTableControl) value, diagnostics, context);
178:                 case VTablePackage.TABLE_COLUMN_CONFIGURATION:
179:                         return validateTableColumnConfiguration((VTableColumnConfiguration) value, diagnostics, context);
180:                 case VTablePackage.TABLE_DOMAIN_MODEL_REFERENCE:
181:                         return validateTableDomainModelReference((VTableDomainModelReference) value, diagnostics, context);
182:                 case VTablePackage.READ_ONLY_COLUMN_CONFIGURATION:
183:                         return validateReadOnlyColumnConfiguration((VReadOnlyColumnConfiguration) value, diagnostics, context);
184:                 case VTablePackage.WIDTH_CONFIGURATION:
185:                         return validateWidthConfiguration((VWidthConfiguration) value, diagnostics, context);
186:                 case VTablePackage.ENABLEMENT_CONFIGURATION:
187:                         return validateEnablementConfiguration((VEnablementConfiguration) value, diagnostics, context);
188:                 case VTablePackage.SINGLE_COLUMN_CONFIGURATION:
189:                         return validateSingleColumnConfiguration((VSingleColumnConfiguration) value, diagnostics, context);
190:                 case VTablePackage.DETAIL_EDITING:
191:                         return validateDetailEditing((DetailEditing) value, diagnostics, context);
192:                 default:
193:                         return true;
194:                 }
195:         }
196:
197:         /**
198:          * <!-- begin-user-doc -->
199:          * <!-- end-user-doc -->
200:          *
201:          * @generated
202:          */
203:         public boolean validateTableControl(VTableControl tableControl, DiagnosticChain diagnostics,
204:                 Map<Object, Object> context) {
205:•                if (!validate_NoCircularContainment(tableControl, diagnostics, context)) {
206:                         return false;
207:                 }
208:                 boolean result = validate_EveryMultiplicityConforms(tableControl, diagnostics, context);
209:•                if (result || diagnostics != null) {
210:                         result &= validate_EveryDataValueConforms(tableControl, diagnostics, context);
211:                 }
212:•                if (result || diagnostics != null) {
213:                         result &= validate_EveryReferenceIsContained(tableControl, diagnostics, context);
214:                 }
215:•                if (result || diagnostics != null) {
216:                         result &= validate_EveryBidirectionalReferenceIsPaired(tableControl, diagnostics, context);
217:                 }
218:•                if (result || diagnostics != null) {
219:                         result &= validate_EveryProxyResolves(tableControl, diagnostics, context);
220:                 }
221:•                if (result || diagnostics != null) {
222:                         result &= validate_UniqueID(tableControl, diagnostics, context);
223:                 }
224:•                if (result || diagnostics != null) {
225:                         result &= validate_EveryKeyUnique(tableControl, diagnostics, context);
226:                 }
227:•                if (result || diagnostics != null) {
228:                         result &= validate_EveryMapEntryUnique(tableControl, diagnostics, context);
229:                 }
230:•                if (result || diagnostics != null) {
231:                         result &= validateTableControl_resolveable(tableControl, diagnostics, context);
232:                 }
233:                 return result;
234:         }
235:
236:         /**
237:          * Validates the resolveable constraint of '<em>Control</em>'.
238:          * <!-- begin-user-doc -->
239:          *
240:          * @param tableControl the {@link VTableControl} to check
241:          * @param diagnostics the diagnostics
242:          * @param context the validation context
243:          * <!-- end-user-doc -->
244:          * @return the validation result
245:          *
246:          * @generated NOT
247:          * @since 1.10
248:          */
249:         // CHECKSTYLE.OFF: MethodName
250:         public boolean validateTableControl_resolveable(VTableControl tableControl, DiagnosticChain diagnostics,
251:                 Map<Object, Object> context) {
252:                 // CHECKSTYLE.ON: MethodName
253:                 final VDomainModelReference domainModelReference = tableControl.getDomainModelReference();
254:•                if (domainModelReference == null) {
255:                         diagnostics
256:                                 .add(createDiagnostic(Diagnostic.ERROR, 0, "No Domain Model Reference set.", //$NON-NLS-1$
257:                                         tableControl, VViewPackage.eINSTANCE.getControl_DomainModelReference()));
258:                         return false;
259:                 }
260:•                if (domainModelReference instanceof VTableDomainModelReference) {
261:                         context.put(VALIDATING_TABLE_CONTROL_KEY, true);
262:                         return validateTableDomainModelReference((VTableDomainModelReference) domainModelReference, diagnostics,
263:                                 context);
264:                 }
265:                 return viewValidator.validateDomainModelReference(domainModelReference, diagnostics, context);
266:         }
267:         // end of custom code
268:
269:         /**
270:          * <!-- begin-user-doc -->
271:          * <!-- end-user-doc -->
272:          *
273:          * @generated
274:          */
275:         public boolean validateTableColumnConfiguration(VTableColumnConfiguration tableColumnConfiguration,
276:                 DiagnosticChain diagnostics, Map<Object, Object> context) {
277:                 return validate_EveryDefaultConstraint(tableColumnConfiguration, diagnostics, context);
278:         }
279:
280:         /**
281:          * <!-- begin-user-doc -->
282:          * <!-- end-user-doc -->
283:          *
284:          * @generated
285:          */
286:         public boolean validateTableDomainModelReference(VTableDomainModelReference tableDomainModelReference,
287:                 DiagnosticChain diagnostics, Map<Object, Object> context) {
288:•                if (!validate_NoCircularContainment(tableDomainModelReference, diagnostics, context)) {
289:                         return false;
290:                 }
291:                 boolean result = validate_EveryMultiplicityConforms(tableDomainModelReference, diagnostics, context);
292:•                if (result || diagnostics != null) {
293:                         result &= validate_EveryDataValueConforms(tableDomainModelReference, diagnostics, context);
294:                 }
295:•                if (result || diagnostics != null) {
296:                         result &= validate_EveryReferenceIsContained(tableDomainModelReference, diagnostics, context);
297:                 }
298:•                if (result || diagnostics != null) {
299:                         result &= validate_EveryBidirectionalReferenceIsPaired(tableDomainModelReference, diagnostics, context);
300:                 }
301:•                if (result || diagnostics != null) {
302:                         result &= validate_EveryProxyResolves(tableDomainModelReference, diagnostics, context);
303:                 }
304:•                if (result || diagnostics != null) {
305:                         result &= validate_UniqueID(tableDomainModelReference, diagnostics, context);
306:                 }
307:•                if (result || diagnostics != null) {
308:                         result &= validate_EveryKeyUnique(tableDomainModelReference, diagnostics, context);
309:                 }
310:•                if (result || diagnostics != null) {
311:                         result &= validate_EveryMapEntryUnique(tableDomainModelReference, diagnostics, context);
312:                 }
313:•                if (result || diagnostics != null) {
314:                         result &= validateTableDomainModelReference_resolveable(tableDomainModelReference, diagnostics, context);
315:                 }
316:                 return result;
317:         }
318:
319:         /**
320:          *
321:          * {@inheritDoc}
322:          *
323:          * @see org.eclipse.emf.ecore.util.EObjectValidator#validate_EveryMultiplicityConforms(org.eclipse.emf.ecore.EObject,
324:          * org.eclipse.emf.common.util.DiagnosticChain, java.util.Map)
325:          *
326:          * @generated NOT
327:          *
328:          */
329:         // BEGIN COMPLEX CODE
330:         @Override
331:         public boolean validate_EveryMultiplicityConforms(EObject eObject, DiagnosticChain diagnostics,
332:                 Map<Object, Object> context) {
333:                 boolean result = true;
334:                 final EClass eClass = eObject.eClass();
335:•                for (int i = 0, size = eClass.getFeatureCount(); i < size; ++i) {
336:                         // begin custom
337:•                        if (VTableDomainModelReference.class.isInstance(eObject)
338:•                                && eClass.getEStructuralFeature(i) == VViewPackage.eINSTANCE
339:                                         .getFeaturePathDomainModelReference_DomainModelEFeature()) {
340:                                 continue;
341:                         }
342:                         // end custom
343:                         result &= validate_MultiplicityConforms(eObject, eClass.getEStructuralFeature(i), diagnostics, context);
344:•                        if (!result && diagnostics == null) {
345:                                 return false;
346:                         }
347:                 }
348:                 return result;
349:         }
350:
351:         // END COMPLEX CODE
352:
353:         /**
354:          * Validates the resolveable constraint of '<em>Domain Model Reference</em>'.
355:          * <!-- begin-user-doc -->
356:          * <!-- end-user-doc -->
357:          *
358:          * @generated NOT
359:          */
360:         // BEGIN COMPLEX CODE
361:         public boolean validateTableDomainModelReference_resolveable(VTableDomainModelReference tableDomainModelReference,
362:                 DiagnosticChain diagnostics, Map<Object, Object> context) {
363:                 // validate path to table
364:                 VDomainModelReference pathToMultiRef = tableDomainModelReference.getDomainModelReference();
365:                 final EValidator validator;
366:•                if (pathToMultiRef != null) {
367:                         context.put(ViewValidator.ECLASS_KEY, null);
368:                         validator = EValidator.Registry.INSTANCE.getEValidator(pathToMultiRef.eClass().getEPackage());
369:                 } else {
370:                         pathToMultiRef = tableDomainModelReference;
371:                         validator = viewValidator;
372:                 }
373:•                if (!validator.validate(pathToMultiRef, diagnostics, context)) {
374:•                        if (pathToMultiRef != tableDomainModelReference && tableDomainModelReference.eContainer() != null
375:•                                && diagnostics != null) {
376:                                 diagnostics.add(createDiagnostic(Diagnostic.ERROR, 0, "Error on path to multi reference", //$NON-NLS-1$
377:                                         tableDomainModelReference.eContainer(),
378:                                         tableDomainModelReference.eContainingFeature()));
379:                         }
380:                         return false;
381:                 }
382:
383:                 // test if table ends a multi reference
384:                 IValueProperty valueProperty;
385:                 try {
386:                         final Optional<EClass> rootEClass = getRootEClass(pathToMultiRef);
387:•                        if (!rootEClass.isPresent()) {
388:•                                if (diagnostics != null) {
389:                                         final String message = "The table DMR could not be resolved because it is not contained in a View with a root EClass"; //$NON-NLS-1$
390:•                                        if (tableDomainModelReference.eContainer() != null) {
391:                                                 diagnostics.add(createDiagnostic(Diagnostic.ERROR, 0, message,
392:                                                         tableDomainModelReference.eContainer(), tableDomainModelReference.eContainingFeature()));
393:                                         }
394:•                                        if (pathToMultiRef == tableDomainModelReference) {
395:                                                 diagnostics.add(createDiagnostic(Diagnostic.ERROR, 0, message, pathToMultiRef,
396:                                                         VViewPackage.eINSTANCE.getFeaturePathDomainModelReference_DomainModelEFeature()));
397:                                         } else {
398:                                                 diagnostics.add(createDiagnostic(Diagnostic.ERROR, 0, message, tableDomainModelReference,
399:                                                         VTablePackage.eINSTANCE.getTableDomainModelReference_DomainModelReference()));
400:                                         }
401:                                 }
402:
403:                                 return false;
404:                         }
405:                         valueProperty = getEMFFormsDatabinding()
406:                                 .getValueProperty(pathToMultiRef, rootEClass.get());
407:                 } catch (final DatabindingFailedException ex) {
408:                         Activator.getDefault().getReportService().report(new DatabindingFailedReport(ex));
409:                         return true;
410:                 }
411:                 final EStructuralFeature feature = (EStructuralFeature) valueProperty.getValueType();
412:•                if (!EReference.class.isInstance(feature) || !feature.isMany()) {
413:•                        if (diagnostics != null) {
414:                                 final String message = "Domain model reference does not end at a multi reference."; //$NON-NLS-1$
415:•                                if (tableDomainModelReference.eContainer() != null) {
416:                                         diagnostics.add(createDiagnostic(Diagnostic.ERROR, 0, message,
417:                                                 tableDomainModelReference.eContainer(), tableDomainModelReference.eContainingFeature()));
418:                                 }
419:•                                if (pathToMultiRef == tableDomainModelReference) {
420:                                         diagnostics.add(createDiagnostic(Diagnostic.ERROR, 0, message, pathToMultiRef,
421:                                                 VViewPackage.eINSTANCE.getFeaturePathDomainModelReference_DomainModelEFeature()));
422:                                 } else {
423:                                         diagnostics.add(createDiagnostic(Diagnostic.ERROR, 0, message, tableDomainModelReference,
424:                                                 VTablePackage.eINSTANCE.getTableDomainModelReference_DomainModelReference()));
425:                                 }
426:                         }
427:                         return false;
428:                 }
429:•                if (context.containsKey(VALIDATING_TABLE_CONTROL_KEY)) {
430:                         return true;
431:                 }
432:                 // test if columns are resolveable
433:                 final EReference reference = EReference.class.cast(feature);
434:                 final EClass referenceType = reference.getEReferenceType();
435:                 boolean success = true;
436:•                for (final VDomainModelReference columnDMR : tableDomainModelReference.getColumnDomainModelReferences()) {
437:                         success &= validateColumnForRootEClass(columnDMR, referenceType);
438:•                        if (!success) {
439:                                 break;
440:                         }
441:                 }
442:•                if (success) {
443:                         return true;
444:                 }
445:
446:                 // test if columns are resolvable against a subclass
447:                 final Collection<EClass> subClasses = getSubClasses(referenceType);
448:                 final Set<EClass> usableSubclasses = new LinkedHashSet<EClass>();
449:•                for (final EClass subClass : subClasses) {
450:                         success = true;
451:•                        for (final VDomainModelReference columnDMR : tableDomainModelReference.getColumnDomainModelReferences()) {
452:                                 success &= validateColumnForRootEClass(columnDMR, subClass);
453:•                                if (!success) {
454:                                         break;
455:                                 }
456:                         }
457:•                        if (success) {
458:                                 usableSubclasses.add(subClass);
459:                         }
460:                 }
461:
462:•                if (usableSubclasses.isEmpty()) {
463:•                        if (diagnostics != null) {
464:                                 final String message = "Some columns may not be resolvable"; //$NON-NLS-1$
465:                                 diagnostics.add(createDiagnostic(Diagnostic.WARNING, 0, message, tableDomainModelReference,
466:                                         VTablePackage.eINSTANCE.getTableDomainModelReference_ColumnDomainModelReferences()));
467:                         }
468:                         return false;
469:                 }
470:
471:•                if (diagnostics != null) {
472:                         final String message = "Columns are resovable against a subclass of " + referenceType.getName(); //$NON-NLS-1$
473:                         diagnostics.add(createDiagnostic(Diagnostic.INFO, 0, message, tableDomainModelReference,
474:                                 VTablePackage.eINSTANCE.getTableDomainModelReference_ColumnDomainModelReferences()));
475:                 }
476:                 return true;
477:
478:         }
479:
480:         private EMFFormsDatabindingEMF getEMFFormsDatabinding() {
481:•                if (emfFormsDatabinding != null) {
482:                         return emfFormsDatabinding;
483:                 }
484:                 return Activator.getDefault().getEMFFormsDatabinding();
485:         }
486:
487:         /**
488:          * Go upwards in the EObject's containment history to find the root EClass.
489:          *
490:          * @param eObject
491:          * @return the root {@link EClass} if this EObject is contained in a VView
492:          */
493:         private Optional<EClass> getRootEClass(EObject eObject) {
494:                 EObject testObject = eObject;
495:•                while (!VView.class.isInstance(testObject)
496:•                        && testObject != null) {
497:                         testObject = testObject.eContainer();
498:                 }
499:•                if (VView.class.isInstance(testObject)) {
500:                         return Optional.of(VView.class.cast(testObject).getRootEClass());
501:                 }
502:                 return Optional.empty();
503:         }
504:         // END COMPLEX CODE
505:
506:         private Diagnostic createDiagnostic(int severity, int code, String message, EObject object,
507:                 EStructuralFeature feature) {
508:                 return new BasicDiagnostic(
509:                         severity,
510:                         DIAGNOSTIC_SOURCE,
511:                         code,
512:                         message,
513:                         new Object[] { object, feature });
514:         }
515:
516:         private boolean validateColumnForRootEClass(VDomainModelReference columnDMR, EClass rootEClass) {
517:                 final EValidator validator = EValidator.Registry.INSTANCE.getEValidator(columnDMR.eClass().getEPackage());
518:                 final Map<Object, Object> context = new LinkedHashMap<Object, Object>();
519:                 context.put(ViewValidator.ECLASS_KEY, rootEClass);
520:                 return validator.validate(columnDMR, null, context);
521:         }
522:
523:         /**
524:          * <!-- begin-user-doc -->.
525:          * <!-- end-user-doc -->
526:          *
527:          * @generated
528:          */
529:         public boolean validateReadOnlyColumnConfiguration(VReadOnlyColumnConfiguration readOnlyColumnConfiguration,
530:                 DiagnosticChain diagnostics, Map<Object, Object> context) {
531:                 return validate_EveryDefaultConstraint(readOnlyColumnConfiguration, diagnostics, context);
532:         }
533:
534:         /**
535:          * <!-- begin-user-doc -->
536:          *
537:          * @since 1.9
538:          * <!-- end-user-doc -->
539:          * @generated
540:          */
541:         public boolean validateWidthConfiguration(VWidthConfiguration widthConfiguration, DiagnosticChain diagnostics,
542:                 Map<Object, Object> context) {
543:                 return validate_EveryDefaultConstraint(widthConfiguration, diagnostics, context);
544:         }
545:
546:         /**
547:          * <!-- begin-user-doc -->
548:          *
549:          * @since 1.13
550:          * <!-- end-user-doc -->
551:          * @generated
552:          */
553:         public boolean validateEnablementConfiguration(VEnablementConfiguration enablementConfiguration,
554:                 DiagnosticChain diagnostics, Map<Object, Object> context) {
555:                 return validate_EveryDefaultConstraint(enablementConfiguration, diagnostics, context);
556:         }
557:
558:         /**
559:          * <!-- begin-user-doc -->
560:          *
561:          * @since 1.13
562:          * <!-- end-user-doc -->
563:          * @generated
564:          */
565:         public boolean validateSingleColumnConfiguration(VSingleColumnConfiguration singleColumnConfiguration,
566:                 DiagnosticChain diagnostics, Map<Object, Object> context) {
567:                 return validate_EveryDefaultConstraint(singleColumnConfiguration, diagnostics, context);
568:         }
569:
570:         /**
571:          * <!-- begin-user-doc -->
572:          * <!-- end-user-doc -->
573:          *
574:          * @generated
575:          */
576:         public boolean validateDetailEditing(DetailEditing detailEditing, DiagnosticChain diagnostics,
577:                 Map<Object, Object> context) {
578:                 return true;
579:         }
580:
581:         /**
582:          * Returns the resource locator that will be used to fetch messages for this validator's diagnostics.
583:          * <!-- begin-user-doc -->
584:          * <!-- end-user-doc -->
585:          *
586:          * @generated
587:          */
588:         @Override
589:         public ResourceLocator getResourceLocator() {
590:                 // TODO
591:                 // Specialize this to return a resource locator for messages specific to this validator.
592:                 // Ensure that you remove @generated or mark it @generated NOT
593:                 return super.getResourceLocator();
594:         }
595:
596:         private static Collection<EClass> getSubClasses(EClass superClass) {
597:                 final Collection<EClass> classes = new HashSet<EClass>();
598:
599:                 // avoid ConcurrentModificationException while iterating over the registry's key set
600:                 final List<String> keySet = new ArrayList<String>(org.eclipse.emf.ecore.EPackage.Registry.INSTANCE.keySet());
601:•                for (final String nsURI : keySet) {
602:                         final EPackage ePackage = org.eclipse.emf.ecore.EPackage.Registry.INSTANCE.getEPackage(nsURI);
603:•                        for (final EClassifier eClassifier : ePackage.getEClassifiers()) {
604:•                                if (eClassifier instanceof EClass) {
605:                                         final EClass eClass = (EClass) eClassifier;
606:•                                        if (superClass.isSuperTypeOf(eClass) && !eClass.isAbstract() && !eClass.isInterface()) {
607:                                                 classes.add(eClass);
608:                                         }
609:                                 }
610:                         }
611:                 }
612:                 return classes;
613:         }
614:
615: } // TableValidator