Skip to content

Package: TemplateInstanceRendererService

TemplateInstanceRendererService

nameinstructionbranchcomplexitylinemethod
TemplateInstanceRendererService()
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: 0 C: 47
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 14
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-2018 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.emfforms.internal.datatemplate.tooling.editor;
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.model.VControl;
20: import org.eclipse.emf.ecp.view.spi.model.VElement;
21: import org.eclipse.emfforms.datatemplate.DataTemplatePackage;
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: * The OSGi Service for registering the {@link TemplateInstanceRenderer}.
33: *
34: * @author Eugen Neufeld
35: *
36: */
37: @Component
38: public class TemplateInstanceRendererService implements EMFFormsDIRendererService<VControl> {
39:
40:         private EMFFormsDatabinding databindingService;
41:         private ReportService reportService;
42:
43:         /**
44:          * {@inheritDoc}
45:          *
46:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#isApplicable(org.eclipse.emf.ecp.view.spi.model.VElement,
47:          * org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
48:          */
49:         @Override
50:         public double isApplicable(VElement vElement, ViewModelContext viewModelContext) {
51:•                if (!VControl.class.isInstance(vElement)) {
52:                         return NOT_APPLICABLE;
53:                 }
54:                 final VControl control = (VControl) vElement;
55:•                if (control.getDomainModelReference() == null) {
56:                         return NOT_APPLICABLE;
57:                 }
58:                 IValueProperty valueProperty;
59:                 try {
60:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
61:                                 viewModelContext.getDomainModel());
62:                 } catch (final DatabindingFailedException ex) {
63:                         reportService.report(new DatabindingFailedReport(ex));
64:                         return NOT_APPLICABLE;
65:                 }
66:                 final EStructuralFeature eStructuralFeature = EStructuralFeature.class.cast(valueProperty.getValueType());
67:•                if (eStructuralFeature == DataTemplatePackage.eINSTANCE.getTemplate_Instance()) {
68:                         return 10;
69:                 }
70:                 return NOT_APPLICABLE;
71:         }
72:
73:         /**
74:          * Called by the initializer to set the EMFFormsDatabinding.
75:          *
76:          * @param databindingService The EMFFormsDatabinding
77:          */
78:         @Reference
79:         protected void setEMFFormsDatabinding(EMFFormsDatabinding databindingService) {
80:                 this.databindingService = databindingService;
81:         }
82:
83:         /**
84:          * Called by the initializer to set the ReportService.
85:          *
86:          * @param reportService The ReportService
87:          */
88:         @Reference
89:         protected void setReportService(ReportService reportService) {
90:                 this.reportService = reportService;
91:         }
92:
93:         @Override
94:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
95:                 return TemplateInstanceRenderer.class;
96:         }
97:
98: }