Skip to content

Package: LeafConditionSegmentControlRendererService

LeafConditionSegmentControlRendererService

nameinstructionbranchcomplexitylinemethod
LeafConditionSegmentControlRendererService()
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: 41 C: 4
9%
M: 7 C: 1
13%
M: 4 C: 1
20%
M: 13 C: 2
13%
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-2019 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.ecp.view.spi.context.ViewModelContext;
18: import org.eclipse.emf.ecp.view.spi.model.VControl;
19: import org.eclipse.emf.ecp.view.spi.model.VElement;
20: import org.eclipse.emf.ecp.view.spi.rule.model.RulePackage;
21: import org.eclipse.emfforms.spi.common.report.ReportService;
22: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
23: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
24: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
25: import org.eclipse.emfforms.spi.ide.view.segments.ToolingModeUtil;
26: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
27: import org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService;
28: import org.osgi.service.component.annotations.Component;
29: import org.osgi.service.component.annotations.Reference;
30:
31: /**
32: * DI renderer service for {@link LeafConditionSegmentControlRendererService}.
33: *
34: * @author Lucas Koehler
35: *
36: */
37: @Component(name = "LeafConditionSegmentControlRendererService")
38: public class LeafConditionSegmentControlRendererService implements EMFFormsDIRendererService<VControl> {
39:
40:         private EMFFormsDatabinding databindingService;
41:         private ReportService reportService;
42:
43:         /**
44:          * Called by the framework to set the {@link EMFFormsDatabinding}.
45:          *
46:          * @param databindingService The {@link EMFFormsDatabinding}
47:          */
48:         @Reference(unbind = "-")
49:         protected void setEMFFormsDatabinding(EMFFormsDatabinding databindingService) {
50:                 this.databindingService = databindingService;
51:         }
52:
53:         /**
54:          * Called by the framework to set the {@link ReportService}.
55:          *
56:          * @param reportService The {@link ReportService}
57:          */
58:         @Reference(unbind = "-")
59:         protected void setReportService(ReportService reportService) {
60:                 this.reportService = reportService;
61:         }
62:
63:         @Override
64:         public double isApplicable(VElement vElement, ViewModelContext viewModelContext) {
65:•                if (!ToolingModeUtil.isSegmentToolingEnabled()) {
66:                         return NOT_APPLICABLE;
67:                 }
68:•                if (!VControl.class.isInstance(vElement)) {
69:                         return NOT_APPLICABLE;
70:                 }
71:                 final VControl control = (VControl) vElement;
72:•                if (control.getDomainModelReference() == null) {
73:                         return NOT_APPLICABLE;
74:                 }
75:                 IValueProperty<?, ?> valueProperty;
76:                 try {
77:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
78:                                 viewModelContext.getDomainModel());
79:                 } catch (final DatabindingFailedException ex) {
80:                         reportService.report(new DatabindingFailedReport(ex));
81:                         return NOT_APPLICABLE;
82:                 }
83:•                if (valueProperty.getValueType() == RulePackage.Literals.LEAF_CONDITION__EXPECTED_VALUE) {
84:                         return 3d;
85:                 }
86:                 return NOT_APPLICABLE;
87:         }
88:
89:         @Override
90:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
91:                 return LeafConditionSegmentControlRenderer.class;
92:         }
93:
94: }