Skip to content

Package: KeyValueControlRendererService

KeyValueControlRendererService

nameinstructionbranchcomplexitylinemethod
KeyValueControlRendererService()
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(VElement, ViewModelContext)
M: 45 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 14 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.keyattributedmr.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.spi.context.ViewModelContext;
19: import org.eclipse.emf.ecp.view.spi.keyattributedmr.model.VKeyattributedmrPackage;
20: import org.eclipse.emf.ecp.view.spi.model.VControl;
21: import org.eclipse.emf.ecp.view.spi.model.VElement;
22: import org.eclipse.emfforms.spi.common.report.ReportService;
23: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
24: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
25: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
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 KeyValueControlRenderer}.
33: *
34: * @author Lucas Koehler
35: *
36: */
37: @Component(name = "KeyValueControlRendererService")
38: public class KeyValueControlRendererService 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 (!VControl.class.isInstance(vElement)) {
66:                         return NOT_APPLICABLE;
67:                 }
68:                 final VControl control = (VControl) vElement;
69:•                if (control.getDomainModelReference() == null) {
70:                         return NOT_APPLICABLE;
71:                 }
72:                 IValueProperty valueProperty;
73:                 try {
74:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
75:                                 viewModelContext.getDomainModel());
76:                 } catch (final DatabindingFailedException ex) {
77:                         reportService.report(new DatabindingFailedReport(ex));
78:                         return NOT_APPLICABLE;
79:                 }
80:                 final EStructuralFeature feature = (EStructuralFeature) valueProperty.getValueType();
81:
82:•                if (VKeyattributedmrPackage.eINSTANCE.getKeyAttributeDomainModelReference_KeyValue() == feature) {
83:                         return 6;
84:                 }
85:
86:                 return NOT_APPLICABLE;
87:         }
88:
89:         @Override
90:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
91:                 return KeyValueControlRenderer.class;
92:         }
93:
94: }