Skip to content

Package: PrefixDmrDomainModelReferenceRendererService

PrefixDmrDomainModelReferenceRendererService

nameinstructionbranchcomplexitylinemethod
PrefixDmrDomainModelReferenceRendererService()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
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(EStructuralFeature)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
isApplicable(VElement, ViewModelContext)
M: 39 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
setEMFFormsDatabinding(EMFFormsDatabinding)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setReportService(ReportService)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2018 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.indexdmr.tooling;
15:
16: import org.eclipse.core.databinding.property.value.IValueProperty;
17: import org.eclipse.emf.ecore.EStructuralFeature;
18: import org.eclipse.emf.ecp.view.internal.editor.controls.DomainModelReferenceControlSWTRenderer;
19: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
20: import org.eclipse.emf.ecp.view.spi.indexdmr.model.VIndexdmrPackage;
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: import org.osgi.service.component.annotations.Component;
30: import org.osgi.service.component.annotations.Reference;
31:
32: /**
33: * DI renderer service for {@link DomainModelReferenceControlSWTRenderer}.
34: *
35: * @author Lucas Koehler
36: *
37: */
38: @SuppressWarnings("restriction")
39: @Component(name = "PrefixDmrDomainModelReferenceRendererService")
40: public class PrefixDmrDomainModelReferenceRendererService 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 (!VControl.class.isInstance(vElement)) {
68:                         return NOT_APPLICABLE;
69:                 }
70:                 final VControl control = (VControl) vElement;
71:•                if (control.getDomainModelReference() == null) {
72:                         return NOT_APPLICABLE;
73:                 }
74:                 IValueProperty valueProperty;
75:                 try {
76:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
77:                                 viewModelContext.getDomainModel());
78:                 } catch (final DatabindingFailedException ex) {
79:                         reportService.report(new DatabindingFailedReport(ex));
80:                         return NOT_APPLICABLE;
81:                 }
82:                 return isApplicable((EStructuralFeature) valueProperty.getValueType());
83:         }
84:
85:         /**
86:          * Test if the structural feature contains the correct data.
87:          *
88:          * @param feature the {@link EStructuralFeature} to check
89:          * @return the priority of the control
90:          */
91:         private double isApplicable(EStructuralFeature feature) {
92:•                if (VIndexdmrPackage.Literals.INDEX_DOMAIN_MODEL_REFERENCE__PREFIX_DMR == feature) {
93:                         return 3;
94:                 }
95:                 return NOT_APPLICABLE;
96:         }
97:
98:         @Override
99:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
100:                 return DomainModelReferenceControlSWTRenderer.class;
101:         }
102:
103: }