Skip to content

Package: MultiAttributeRendererService

MultiAttributeRendererService

nameinstructionbranchcomplexitylinemethod
MultiAttributeRendererService()
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: 4 C: 56
93%
M: 2 C: 8
80%
M: 2 C: 4
67%
M: 2 C: 16
89%
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-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: * David Soto Setzke - initial API and implementation
13: * Johannes Faltermeier - initial API and implementation
14: ******************************************************************************/
15: package org.eclipse.emfforms.internal.view.control.multiattribute;
16:
17: import org.eclipse.core.databinding.property.value.IValueProperty;
18: import org.eclipse.emf.ecore.EAttribute;
19: import org.eclipse.emf.ecore.EReference;
20: import org.eclipse.emf.ecore.EStructuralFeature;
21: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
22: import org.eclipse.emf.ecp.view.spi.model.VControl;
23: import org.eclipse.emf.ecp.view.spi.model.VElement;
24: import org.eclipse.emfforms.spi.common.report.ReportService;
25: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
26: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
27: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
28: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
29: import org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService;
30: import org.eclipse.emfforms.spi.view.control.multiattribute.MultiAttributeSWTRenderer;
31: import org.osgi.service.component.annotations.Component;
32: import org.osgi.service.component.annotations.Reference;
33: import org.osgi.service.component.annotations.ReferenceCardinality;
34:
35: /**
36: * Tester for MultiReference Control.
37: *
38: * @author David Soto Setzke
39: * @author Johannes Faltermeier
40: *
41: */
42: @Component(name = "MultiAttributeRendererService")
43: public class MultiAttributeRendererService implements EMFFormsDIRendererService<VControl> {
44:
45:         private EMFFormsDatabinding databindingService;
46:         private ReportService reportService;
47:
48:         /**
49:          * Called by the initializer to set the EMFFormsDatabinding.
50:          *
51:          * @param databindingService The EMFFormsDatabinding
52:          */
53:         @Reference(cardinality = ReferenceCardinality.MANDATORY, unbind = "-")
54:         protected void setEMFFormsDatabinding(EMFFormsDatabinding databindingService) {
55:                 this.databindingService = databindingService;
56:         }
57:
58:         /**
59:          * Called by the initializer to set the ReportService.
60:          *
61:          * @param reportService The ReportService
62:          */
63:         @Reference(cardinality = ReferenceCardinality.MANDATORY, unbind = "-")
64:         protected void setReportService(ReportService reportService) {
65:                 this.reportService = reportService;
66:         }
67:
68:         /**
69:          * {@inheritDoc}
70:          *
71:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#isApplicable(org.eclipse.emf.ecp.view.spi.model.VElement,
72:          * org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
73:          */
74:         @Override
75:         public double isApplicable(VElement vElement, ViewModelContext viewModelContext) {
76:•                if (!VControl.class.isInstance(vElement)) {
77:                         return NOT_APPLICABLE;
78:                 }
79:                 final VControl control = VControl.class.cast(vElement);
80:•                if (control.getDomainModelReference() == null) {
81:                         return NOT_APPLICABLE;
82:                 }
83:                 IValueProperty valueProperty;
84:                 try {
85:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
86:                                 viewModelContext.getDomainModel());
87:                 } catch (final DatabindingFailedException ex) {
88:                         reportService.report(new DatabindingFailedReport(ex));
89:                         return NOT_APPLICABLE;
90:                 }
91:                 final EStructuralFeature feature = EStructuralFeature.class.cast(valueProperty.getValueType());
92:•                if (!feature.isMany()) {
93:                         return NOT_APPLICABLE;
94:                 }
95:•                if (EReference.class.isInstance(feature)) {
96:                         return NOT_APPLICABLE;
97:                 }
98:•                if (!EAttribute.class.isInstance(feature)) {
99:                         return NOT_APPLICABLE;
100:                 }
101:                 return 10;
102:         }
103:
104:         /**
105:          * {@inheritDoc}
106:          *
107:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#getRendererClass()
108:          */
109:         @Override
110:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
111:                 return MultiAttributeSWTRenderer.class;
112:         }
113: }