Skip to content

Package: TextControlSWTRendererService

TextControlSWTRendererService

nameinstructionbranchcomplexitylinemethod
TextControlSWTRendererService()
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: 69
97%
M: 1 C: 11
92%
M: 1 C: 6
86%
M: 1 C: 21
95%
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-2015 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.emf.ecp.view.internal.core.swt.renderer;
15:
16: import org.eclipse.core.databinding.property.value.IValueProperty;
17: import org.eclipse.emf.ecore.EAttribute;
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.core.swt.renderer.TextControlSWTRenderer;
21: import org.eclipse.emf.ecp.view.spi.model.VControl;
22: import org.eclipse.emf.ecp.view.spi.model.VElement;
23: import org.eclipse.emfforms.spi.common.report.ReportService;
24: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
25: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
26: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
27: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
28: import org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService;
29:
30: /**
31: * TextControlSWTRendererService which provides the TextControlSWTRenderer.
32: *
33: * @author Eugen Neufeld
34: *
35: */
36: public class TextControlSWTRendererService implements EMFFormsDIRendererService<VControl> {
37:
38:         private EMFFormsDatabinding databindingService;
39:         private ReportService reportService;
40:
41:         /**
42:          * Called by the initializer to set the EMFFormsDatabinding.
43:          *
44:          * @param databindingService The EMFFormsDatabinding
45:          */
46:         protected void setEMFFormsDatabinding(EMFFormsDatabinding databindingService) {
47:                 this.databindingService = databindingService;
48:         }
49:
50:         /**
51:          * Called by the initializer to set the ReportService.
52:          *
53:          * @param reportService The ReportService
54:          */
55:         protected void setReportService(ReportService reportService) {
56:                 this.reportService = reportService;
57:         }
58:
59:         /**
60:          * {@inheritDoc}
61:          *
62:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#isApplicable(VElement,ViewModelContext)
63:          */
64:         @Override
65:         public double isApplicable(VElement vElement, ViewModelContext viewModelContext) {
66:•                if (!VControl.class.isInstance(vElement)) {
67:                         return NOT_APPLICABLE;
68:                 }
69:                 final VControl control = (VControl) vElement;
70:•                if (control.getDomainModelReference() == null) {
71:                         return NOT_APPLICABLE;
72:                 }
73:                 IValueProperty valueProperty;
74:                 try {
75:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
76:                                 viewModelContext.getDomainModel());
77:                 } catch (final DatabindingFailedException ex) {
78:                         reportService.report(new DatabindingFailedReport(ex));
79:                         return NOT_APPLICABLE;
80:                 }
81:                 final EStructuralFeature eStructuralFeature = EStructuralFeature.class.cast(valueProperty.getValueType());
82:•                if (eStructuralFeature.isMany()) {
83:                         return NOT_APPLICABLE;
84:                 }
85:•                if (!EAttribute.class.isInstance(eStructuralFeature)) {
86:                         return NOT_APPLICABLE;
87:                 }
88:                 final EAttribute eAttribute = EAttribute.class.cast(eStructuralFeature);
89:
90:                 final Class<?> instanceClass = eAttribute.getEAttributeType().getInstanceClass();
91:•                if (instanceClass == null) {
92:                         return NOT_APPLICABLE;
93:                 }
94:•                if (String.class.isAssignableFrom(instanceClass)) {
95:                         return 1.1d;
96:                 }
97:                 return NOT_APPLICABLE;
98:         }
99:
100:         /**
101:          * {@inheritDoc}
102:          *
103:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#getRendererClass()
104:          */
105:         @Override
106:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
107:                 return TextControlSWTRenderer.class;
108:         }
109:
110: }