Skip to content

Package: DataTypeControlService

DataTypeControlService

nameinstructionbranchcomplexitylinemethod
DataTypeControlService()
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: 43
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 12
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: * Clemens Elflein - 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:
29: /**
30: * This class decides, if the DataTypeControl can be used for the provided EStructuralFeature.
31: *
32: * @author Clemens Elflein
33: */
34: public class DataTypeControlService implements EMFFormsDIRendererService<VControl> {
35:
36:         private EMFFormsDatabinding databindingService;
37:         private ReportService reportService;
38:
39:         /**
40:          * Called by the initializer to set the EMFFormsDatabinding.
41:          *
42:          * @param databindingService The EMFFormsDatabinding
43:          */
44:         protected void setEMFFormsDatabinding(EMFFormsDatabinding databindingService) {
45:                 this.databindingService = databindingService;
46:         }
47:
48:         /**
49:          * Called by the initializer to set the ReportService.
50:          *
51:          * @param reportService The ReportService
52:          */
53:         protected void setReportService(ReportService reportService) {
54:                 this.reportService = reportService;
55:         }
56:
57:         /**
58:          * {@inheritDoc}
59:          *
60:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#isApplicable(org.eclipse.emf.ecp.view.spi.model.VElement,
61:          * org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
62:          */
63:         @Override
64:         public double isApplicable(VElement vElement, ViewModelContext viewModelContext) {
65:•                if (!VControl.class.isInstance(vElement)) {
66:                         return NOT_APPLICABLE;
67:                 }
68:                 final VControl control = (VControl) vElement;
69:                 IValueProperty valueProperty;
70:                 try {
71:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
72:                                 viewModelContext.getDomainModel());
73:                 } catch (final DatabindingFailedException ex) {
74:                         reportService.report(new DatabindingFailedReport(ex));
75:                         return NOT_APPLICABLE;
76:                 }
77:                 final EStructuralFeature eStructuralFeature = EStructuralFeature.class.cast(valueProperty.getValueType());
78:•                if (eStructuralFeature.equals(EcorePackage.eINSTANCE.getETypedElement_EType())) {
79:                         return 10;
80:                 }
81:                 return NOT_APPLICABLE;
82:         }
83:
84:         /**
85:          * {@inheritDoc}
86:          *
87:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#getRendererClass()
88:          */
89:         @Override
90:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
91:                 return DataTypeControl.class;
92:         }
93:
94: }