Skip to content

Package: XMLDateControlSWTRendererService

XMLDateControlSWTRendererService

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