Skip to content

Package: SingleReferenceRendererTester

SingleReferenceRendererTester

nameinstructionbranchcomplexitylinemethod
SingleReferenceRendererTester()
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%
isApplicable(VElement, ViewModelContext)
M: 67 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 19 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 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: * Lucas - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.model.common;
15:
16: import org.eclipse.core.databinding.property.value.IValueProperty;
17: import org.eclipse.emf.ecore.EReference;
18: import org.eclipse.emf.ecore.EStructuralFeature;
19: import org.eclipse.emf.ecore.EcorePackage;
20: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
21: import org.eclipse.emf.ecp.view.spi.model.VControl;
22: import org.eclipse.emf.ecp.view.spi.model.VElement;
23: import org.eclipse.emfforms.spi.common.report.ReportService;
24: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
25: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
26: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
27:
28: /**
29: * @author Lucas Koehler
30: *
31: */
32: public class SingleReferenceRendererTester implements ECPRendererTester {
33:
34:         /**
35:          *
36:          * {@inheritDoc}
37:          *
38:          * @see org.eclipse.emf.ecp.view.model.common.ECPRendererTester#isApplicable(org.eclipse.emf.ecp.view.spi.model.VElement,
39:          * org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
40:          */
41:         @Override
42:         public int isApplicable(VElement vElement, ViewModelContext viewModelContext) {
43:•                if (!VControl.class.isInstance(vElement)) {
44:                         return NOT_APPLICABLE;
45:                 }
46:                 final VControl control = (VControl) vElement;
47:•                if (control.getDomainModelReference() == null) {
48:                         return NOT_APPLICABLE;
49:                 }
50:                 IValueProperty valueProperty;
51:                 try {
52:                         valueProperty = viewModelContext.getService(EMFFormsDatabinding.class)
53:                                 .getValueProperty(control.getDomainModelReference(), viewModelContext.getDomainModel());
54:                 } catch (final DatabindingFailedException ex) {
55:                         viewModelContext.getService(ReportService.class).report(new DatabindingFailedReport(ex));
56:                         return NOT_APPLICABLE;
57:                 }
58:                 final EStructuralFeature feature = (EStructuralFeature) valueProperty.getValueType();
59:•                if (feature.isMany()) {
60:                         return NOT_APPLICABLE;
61:                 }
62:                 // if we have a reference
63:•                if (!EReference.class.isInstance(feature)) {
64:                         return NOT_APPLICABLE;
65:                 }
66:                 final EReference eReference = EReference.class.cast(feature);
67:•                if (EcorePackage.eINSTANCE.getEObject().isInstance(eReference.getEType())) {
68:                         return 3;
69:                 }
70:                 return NOT_APPLICABLE;
71:         }
72: }