Skip to content

Package: DomainModelReferenceControlSWTRendererService

DomainModelReferenceControlSWTRendererService

nameinstructionbranchcomplexitylinemethod
DomainModelReferenceControlSWTRendererService()
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: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isApplicable(EStructuralFeature)
M: 2 C: 24
92%
M: 1 C: 7
88%
M: 1 C: 4
80%
M: 1 C: 8
89%
M: 0 C: 1
100%
isApplicable(VElement, ViewModelContext)
M: 0 C: 39
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 11
100%
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: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.editor.controls;
15:
16: import org.eclipse.core.databinding.property.value.IValueProperty;
17: import org.eclipse.emf.ecore.EStructuralFeature;
18: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
19: import org.eclipse.emf.ecp.view.spi.label.model.VLabelPackage;
20: import org.eclipse.emf.ecp.view.spi.model.VControl;
21: import org.eclipse.emf.ecp.view.spi.model.VElement;
22: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
23: import org.eclipse.emf.ecp.view.spi.stack.model.VStackPackage;
24: import org.eclipse.emf.ecp.view.spi.table.model.VTablePackage;
25: import org.eclipse.emfforms.spi.common.report.ReportService;
26: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
27: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
28: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
29: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
30: import org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService;
31: import org.osgi.service.component.annotations.Component;
32: import org.osgi.service.component.annotations.Reference;
33:
34: /**
35: * DI renderer service for {@link DomainModelReferenceControlSWTRenderer}.
36: *
37: * @author Lucas Koehler
38: *
39: */
40: @Component(name = "DomainModelReferenceControlSWTRendererService")
41: public class DomainModelReferenceControlSWTRendererService implements EMFFormsDIRendererService<VControl> {
42:
43:         private EMFFormsDatabinding databindingService;
44:         private ReportService reportService;
45:
46:         /**
47:          * Called by the framework to set the {@link EMFFormsDatabinding}.
48:          *
49:          * @param databindingService The {@link EMFFormsDatabinding}
50:          */
51:         @Reference(unbind = "-")
52:         protected void setEMFFormsDatabinding(EMFFormsDatabinding databindingService) {
53:                 this.databindingService = databindingService;
54:         }
55:
56:         /**
57:          * Called by the framework to set the {@link ReportService}.
58:          *
59:          * @param reportService The {@link ReportService}
60:          */
61:         @Reference(unbind = "-")
62:         protected void setReportService(ReportService reportService) {
63:                 this.reportService = reportService;
64:         }
65:
66:         /**
67:          * {@inheritDoc}
68:          *
69:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#isApplicable(org.eclipse.emf.ecp.view.spi.model.VElement,
70:          * org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
71:          */
72:         @Override
73:         public double isApplicable(VElement vElement, ViewModelContext viewModelContext) {
74:•                if (!VControl.class.isInstance(vElement)) {
75:                         return NOT_APPLICABLE;
76:                 }
77:                 final VControl control = (VControl) vElement;
78:•                if (control.getDomainModelReference() == null) {
79:                         return NOT_APPLICABLE;
80:                 }
81:                 IValueProperty<?, ?> valueProperty;
82:                 try {
83:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
84:                                 viewModelContext.getDomainModel());
85:                 } catch (final DatabindingFailedException ex) {
86:                         reportService.report(new DatabindingFailedReport(ex));
87:                         return NOT_APPLICABLE;
88:                 }
89:                 return isApplicable((EStructuralFeature) valueProperty.getValueType());
90:         }
91:
92:         /**
93:          * Test if the structural feature contains the correct data.
94:          *
95:          * @param feature the {@link EStructuralFeature} to check
96:          * @return the priority of the control
97:          */
98:         private double isApplicable(EStructuralFeature feature) {
99:•                if (VViewPackage.eINSTANCE.getControl_DomainModelReference() == feature) {
100:                         return 3;
101:                 }
102:•                if (VLabelPackage.eINSTANCE.getLabel_DomainModelReference() == feature) {
103:                         return 3;
104:                 }
105:•                if (VStackPackage.eINSTANCE.getStackLayout_DomainModelReference() == feature) {
106:                         return 3;
107:                 }
108:•                if (VTablePackage.eINSTANCE.getTableDomainModelReference_DomainModelReference() == feature) {
109:                         return 3;
110:                 }
111:
112:                 return NOT_APPLICABLE;
113:         }
114:
115:         @Override
116:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
117:                 return DomainModelReferenceControlSWTRenderer.class;
118:         }
119:
120: }