Skip to content

Package: EnumLiteralFilteredComboViewerSWTRendererService

EnumLiteralFilteredComboViewerSWTRendererService

nameinstructionbranchcomplexitylinemethod
EnumLiteralFilteredComboViewerSWTRendererService()
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: 65
100%
M: 0 C: 10
100%
M: 0 C: 6
100%
M: 0 C: 19
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) 2017 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: * Edgar Mueller - 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.ecore.EcorePackage;
20: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
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: * {@link EnumLiteralFilteredComboViewerSWTRenderer} service.
32: *
33: */
34: public class EnumLiteralFilteredComboViewerSWTRendererService 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(VElement,ViewModelContext)
61:          */
62:         @Override
63:         public double isApplicable(VElement vElement, ViewModelContext viewModelContext) {
64:•                if (!VControl.class.isInstance(vElement)) {
65:                         return NOT_APPLICABLE;
66:                 }
67:                 final VControl control = (VControl) vElement;
68:•                if (control.getDomainModelReference() == null) {
69:                         return NOT_APPLICABLE;
70:                 }
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.isMany()) {
81:                         return NOT_APPLICABLE;
82:                 }
83:•                if (!EAttribute.class.isInstance(eStructuralFeature)) {
84:                         return NOT_APPLICABLE;
85:                 }
86:                 final EAttribute eAttribute = EAttribute.class.cast(eStructuralFeature);
87:
88:•                if (!EcorePackage.eINSTANCE.getEEnum().isInstance(eAttribute.getEType())) {
89:                         return NOT_APPLICABLE;
90:                 }
91:
92:                 // higher than default EnumComboViewerSWTRenderer
93:                 return 4;
94:         }
95:
96:         /**
97:          * {@inheritDoc}
98:          *
99:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#getRendererClass()
100:          */
101:         @Override
102:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
103:                 return EnumLiteralFilteredComboViewerSWTRenderer.class;
104:         }
105: }