Skip to content

Package: InstanceTypeNameSWTRendererService

InstanceTypeNameSWTRendererService

nameinstructionbranchcomplexitylinemethod
InstanceTypeNameSWTRendererService()
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(VElement, ViewModelContext)
M: 2 C: 48
96%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 1 C: 13
93%
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-2016 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.emfforms.internal.editor.ecore.controls;
15:
16: import org.eclipse.core.databinding.property.value.IValueProperty;
17: import org.eclipse.emf.ecore.EStructuralFeature;
18: import org.eclipse.emf.ecore.EcorePackage;
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.osgi.service.component.annotations.Component;
29: import org.osgi.service.component.annotations.Reference;
30:
31: /**
32: * DI renderer service for {@link InstanceTypeNameSWTRenderer}.
33: *
34: * @author Lucas Koehler
35: *
36: */
37: @Component(name = "InstanceTypeNameSWTRendererService")
38: public class InstanceTypeNameSWTRendererService implements EMFFormsDIRendererService<VControl> {
39:
40:         private EMFFormsDatabinding databindingService;
41:         private ReportService reportService;
42:
43:         /**
44:          * Called by the initializer to set the EMFFormsDatabinding.
45:          *
46:          * @param databindingService The EMFFormsDatabinding
47:          */
48:         @Reference(unbind = "-")
49:         protected void setEMFFormsDatabinding(EMFFormsDatabinding databindingService) {
50:                 this.databindingService = databindingService;
51:         }
52:
53:         /**
54:          * Called by the initializer to set the ReportService.
55:          *
56:          * @param reportService The ReportService
57:          */
58:         @Reference(unbind = "-")
59:         protected void setReportService(ReportService reportService) {
60:                 this.reportService = reportService;
61:         }
62:
63:         /**
64:          * {@inheritDoc}
65:          *
66:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#isApplicable(org.eclipse.emf.ecp.view.spi.model.VElement,
67:          * org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
68:          */
69:         @Override
70:         public double isApplicable(VElement vElement, ViewModelContext viewModelContext) {
71:•                if (!VControl.class.isInstance(vElement)) {
72:                         return NOT_APPLICABLE;
73:                 }
74:                 final VControl control = (VControl) vElement;
75:                 IValueProperty valueProperty;
76:                 try {
77:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
78:                                 viewModelContext.getDomainModel());
79:                 } catch (final DatabindingFailedException ex) {
80:                         reportService.report(new DatabindingFailedReport(ex));
81:                         return NOT_APPLICABLE;
82:                 }
83:                 final EStructuralFeature eStructuralFeature = EStructuralFeature.class.cast(valueProperty.getValueType());
84:•                if (eStructuralFeature.equals(EcorePackage.eINSTANCE.getEClassifier_InstanceTypeName())) {
85:                         return 10d;
86:                 }
87:•                if (eStructuralFeature.equals(EcorePackage.eINSTANCE.getEClassifier_InstanceClassName())) {
88:                         return 10d;
89:                 }
90:                 return NOT_APPLICABLE;
91:         }
92:
93:         /**
94:          * {@inheritDoc}
95:          *
96:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#getRendererClass()
97:          */
98:         @Override
99:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
100:                 return InstanceTypeNameSWTRenderer.class;
101:         }
102:
103: }