Skip to content

Package: LeafConditionControlRendererService

LeafConditionControlRendererService

nameinstructionbranchcomplexitylinemethod
LeafConditionControlRendererService()
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: 70
97%
M: 1 C: 13
93%
M: 1 C: 7
88%
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-2016 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: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.editor.controls;
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.model.VControl;
21: import org.eclipse.emf.ecp.view.spi.model.VElement;
22: import org.eclipse.emf.ecp.view.spi.rule.model.RulePackage;
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.ide.view.segments.ToolingModeUtil;
28: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
29: import org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService;
30: import org.osgi.service.component.annotations.Component;
31: import org.osgi.service.component.annotations.Reference;
32:
33: /**
34: * DI renderer service for {@link LeafConditionControlRenderer}.
35: *
36: * @author Lucas Koehler
37: *
38: */
39: @Component(name = "LeafConditionControlRendererService")
40: public class LeafConditionControlRendererService implements EMFFormsDIRendererService<VControl> {
41:
42:         private EMFFormsDatabinding databindingService;
43:         private ReportService reportService;
44:
45:         /**
46:          * Called by the framework to set the {@link EMFFormsDatabinding}.
47:          *
48:          * @param databindingService The {@link EMFFormsDatabinding}
49:          */
50:         @Reference(unbind = "-")
51:         protected void setEMFFormsDatabinding(EMFFormsDatabinding databindingService) {
52:                 this.databindingService = databindingService;
53:         }
54:
55:         /**
56:          * Called by the framework to set the {@link ReportService}.
57:          *
58:          * @param reportService The {@link ReportService}
59:          */
60:         @Reference(unbind = "-")
61:         protected void setReportService(ReportService reportService) {
62:                 this.reportService = reportService;
63:         }
64:
65:         @Override
66:         public double isApplicable(VElement vElement, ViewModelContext viewModelContext) {
67:•                if (ToolingModeUtil.isSegmentToolingEnabled()) {
68:                         return NOT_APPLICABLE;
69:                 }
70:•                if (!VControl.class.isInstance(vElement)) {
71:                         return NOT_APPLICABLE;
72:                 }
73:                 final VControl control = (VControl) vElement;
74:•                if (control.getDomainModelReference() == null) {
75:                         return NOT_APPLICABLE;
76:                 }
77:                 IValueProperty valueProperty;
78:                 try {
79:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
80:                                 viewModelContext.getDomainModel());
81:                 } catch (final DatabindingFailedException ex) {
82:                         reportService.report(new DatabindingFailedReport(ex));
83:                         return NOT_APPLICABLE;
84:                 }
85:                 final EStructuralFeature feature = (EStructuralFeature) valueProperty.getValueType();
86:•                if (feature.isMany()) {
87:                         return NOT_APPLICABLE;
88:                 }
89:                 // if we have an attribute
90:•                if (!EAttribute.class.isInstance(feature)) {
91:                         return NOT_APPLICABLE;
92:                 }
93:                 final EAttribute eAttribute = EAttribute.class.cast(feature);
94:•                if (eAttribute.getEContainingClass().equals(RulePackage.eINSTANCE.getLeafCondition())
95:•                        && eAttribute.equals(RulePackage.eINSTANCE.getLeafCondition_ExpectedValue())) {
96:                         return 3d;
97:                 }
98:
99:                 return NOT_APPLICABLE;
100:         }
101:
102:         /**
103:          * {@inheritDoc}
104:          *
105:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#getRendererClass()
106:          */
107:         @Override
108:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
109:                 return LeafConditionControlRenderer.class;
110:         }
111:
112: }