Skip to content

Package: MappedEClassControlSWTRendererTester

MappedEClassControlSWTRendererTester

nameinstructionbranchcomplexitylinemethod
MappedEClassControlSWTRendererTester()
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%
getRendererClass()
M: 2 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: 44 C: 7
14%
M: 7 C: 1
13%
M: 4 C: 1
20%
M: 14 C: 3
18%
M: 0 C: 1
100%
setEMFFormsDatabinding(EMFFormsDatabinding)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setReportService(ReportService)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
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: * Eugen Neufeld - initial API and implementation
13: * Lucas Koehler - adapted to segments
14: */
15: package org.eclipse.emfforms.internal.ide.view.mappingsegment;
16:
17: import org.eclipse.core.databinding.property.value.IValueProperty;
18: import org.eclipse.emf.ecore.EStructuralFeature;
19: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
20: import org.eclipse.emf.ecp.view.spi.model.VControl;
21: import org.eclipse.emf.ecp.view.spi.model.VElement;
22: import org.eclipse.emfforms.spi.common.report.ReportService;
23: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
24: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
25: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
26: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
27: import org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService;
28: import org.eclipse.emfforms.spi.view.mappingsegment.model.VMappingDomainModelReferenceSegment;
29: import org.eclipse.emfforms.spi.view.mappingsegment.model.VMappingsegmentPackage;
30: import org.osgi.service.component.annotations.Component;
31: import org.osgi.service.component.annotations.Reference;
32:
33: /**
34: * A tester for a control for mapping eclasses.
35: *
36: * @author Eugen Neufeld
37: *
38: */
39: @Component(name = "MappedEClassControlSWTRendererTester")
40: public class MappedEClassControlSWTRendererTester implements EMFFormsDIRendererService<VControl> {
41:
42:         private EMFFormsDatabinding databindingService;
43:         private ReportService reportService;
44:
45:         /**
46:          * Called by the framework to set the {@link EMFFormsDatabinding}.
47:          *
48:          * @param databindingService The {@link EMFFormsDatabinding}
49:          */
50:         @Reference(unbind = "-")
51:         protected void setEMFFormsDatabinding(EMFFormsDatabinding databindingService) {
52:                 this.databindingService = databindingService;
53:         }
54:
55:         /**
56:          * Called by the framework to set the {@link ReportService}.
57:          *
58:          * @param reportService The {@link ReportService}
59:          */
60:         @Reference(unbind = "-")
61:         protected void setReportService(ReportService reportService) {
62:                 this.reportService = reportService;
63:         }
64:
65:         @Override
66:         public double isApplicable(VElement vElement, ViewModelContext viewModelContext) {
67:                 if (!VMappingDomainModelReferenceSegment.class.isInstance(viewModelContext
68:•                        .getDomainModel())) {
69:                         return NOT_APPLICABLE;
70:                 }
71:•                if (!VControl.class.isInstance(vElement)) {
72:                         return NOT_APPLICABLE;
73:                 }
74:
75:                 final VControl control = (VControl) vElement;
76:•                if (control.getDomainModelReference() == null) {
77:                         return NOT_APPLICABLE;
78:                 }
79:                 IValueProperty<?, ?> valueProperty;
80:                 try {
81:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
82:                                 viewModelContext.getDomainModel());
83:                 } catch (final DatabindingFailedException ex) {
84:                         reportService.report(new DatabindingFailedReport(ex));
85:                         return NOT_APPLICABLE;
86:                 }
87:                 final EStructuralFeature feature = (EStructuralFeature) valueProperty.getValueType();
88:•                if (VMappingsegmentPackage.Literals.MAPPING_DOMAIN_MODEL_REFERENCE_SEGMENT__MAPPED_CLASS == feature) {
89:                         return 5;
90:                 }
91:                 return NOT_APPLICABLE;
92:         }
93:
94:         @Override
95:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
96:                 return MappedEClassControlSWTRenderer.class;
97:         }
98:
99: }