Skip to content

Package: RuleConditionDmrControlSWTRendererService

RuleConditionDmrControlSWTRendererService

nameinstructionbranchcomplexitylinemethod
RuleConditionDmrControlSWTRendererService()
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: 59
100%
M: 1 C: 11
92%
M: 1 C: 6
86%
M: 0 C: 18
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-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.ecore.EReference;
18: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
19: import org.eclipse.emf.ecp.view.spi.model.VControl;
20: import org.eclipse.emf.ecp.view.spi.model.VElement;
21: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
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.swt.core.AbstractSWTRenderer;
28: import org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService;
29: import org.osgi.service.component.annotations.Component;
30: import org.osgi.service.component.annotations.Reference;
31:
32: /**
33: * DI renderer service for {@link RuleConditionDmrControlSWTRenderer}.
34: *
35: * @author Lucas Koehler
36: *
37: */
38: @Component(name = "RuleConditionDmrControlSWTRendererService")
39: public class RuleConditionDmrControlSWTRendererService implements EMFFormsDIRendererService<VControl> {
40:
41:         private EMFFormsDatabinding databindingService;
42:         private ReportService reportService;
43:
44:         /**
45:          * Called by the framework to set the {@link EMFFormsDatabinding}.
46:          *
47:          * @param databindingService The {@link EMFFormsDatabinding}
48:          */
49:         @Reference(unbind = "-")
50:         protected void setEMFFormsDatabinding(EMFFormsDatabinding databindingService) {
51:                 this.databindingService = databindingService;
52:         }
53:
54:         /**
55:          * Called by the framework to set the {@link ReportService}.
56:          *
57:          * @param reportService The {@link ReportService}
58:          */
59:         @Reference(unbind = "-")
60:         protected void setReportService(ReportService reportService) {
61:                 this.reportService = reportService;
62:         }
63:
64:         @Override
65:         public double isApplicable(VElement vElement, ViewModelContext viewModelContext) {
66:•                if (!VControl.class.isInstance(vElement)) {
67:                         return NOT_APPLICABLE;
68:                 }
69:                 final VControl control = (VControl) vElement;
70:•                if (control.getDomainModelReference() == null) {
71:                         return NOT_APPLICABLE;
72:                 }
73:                 IValueProperty<?, ?> valueProperty;
74:                 try {
75:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
76:                                 viewModelContext.getDomainModel());
77:                 } catch (final DatabindingFailedException ex) {
78:                         reportService.report(new DatabindingFailedReport(ex));
79:                         return NOT_APPLICABLE;
80:                 }
81:
82:                 // Applicable for references defined by a Condition and pointing to a single DMR
83:•                if (!(valueProperty.getValueType() instanceof EReference)) {
84:                         return NOT_APPLICABLE;
85:                 }
86:                 final EReference reference = (EReference) valueProperty.getValueType();
87:•                if (!reference.isMany()
88:•                        && RulePackage.Literals.CONDITION.isSuperTypeOf(reference.getEContainingClass())
89:•                        && reference.getEReferenceType() == VViewPackage.Literals.DOMAIN_MODEL_REFERENCE) {
90:                         return 5;
91:                 }
92:                 return NOT_APPLICABLE;
93:         }
94:
95:         @Override
96:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
97:                 return RuleConditionDmrControlSWTRenderer.class;
98:         }
99:
100: }