Skip to content

Package: EEnumLiteralControlService

EEnumLiteralControlService

nameinstructionbranchcomplexitylinemethod
EEnumLiteralControlService()
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: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isApplicable(VElement, ViewModelContext)
M: 2 C: 41
95%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 11
92%
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: *
31: * This class decides, if the EEnumLiteralRenderer can be used for the provided EStructuralFeature.
32: *
33: * @author Clemens Elflein
34: *
35: */
36: public class EEnumLiteralControlService 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(org.eclipse.emf.ecp.view.spi.model.VElement,
63:          * org.eclipse.emf.ecp.view.spi.context.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:                 IValueProperty valueProperty;
72:                 try {
73:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
74:                                 viewModelContext.getDomainModel());
75:                 } catch (final DatabindingFailedException ex) {
76:                         reportService.report(new DatabindingFailedReport(ex));
77:                         return NOT_APPLICABLE;
78:                 }
79:                 final EStructuralFeature eStructuralFeature = EStructuralFeature.class.cast(valueProperty.getValueType());
80:•                if (eStructuralFeature.equals(EcorePackage.eINSTANCE.getEClassifier_DefaultValue())) {
81:                         return 10;
82:                 }
83:                 return NOT_APPLICABLE;
84:         }
85:
86:         /**
87:          * {@inheritDoc}
88:          *
89:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#getRendererClass()
90:          */
91:         @Override
92:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
93:                 return EEnumLiteralRenderer.class;
94:         }
95:
96: }