Skip to content

Package: StackItemControlRendererService

StackItemControlRendererService

nameinstructionbranchcomplexitylinemethod
StackItemControlRendererService()
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: 2 C: 61
97%
M: 1 C: 9
90%
M: 1 C: 5
83%
M: 1 C: 18
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.stack.model.VStackPackage;
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 StackItemControlRenderer}.
34: *
35: * @author Lucas Koehler
36: *
37: */
38: @Component(name = "StackItemControlRendererService")
39: public class StackItemControlRendererService 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:         /**
65:          * {@inheritDoc}
66:          *
67:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#isApplicable(org.eclipse.emf.ecp.view.spi.model.VElement,
68:          * org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
69:          */
70:         @Override
71:         public double isApplicable(VElement vElement, ViewModelContext viewModelContext) {
72:•                if (!VControl.class.isInstance(vElement)) {
73:                         return NOT_APPLICABLE;
74:                 }
75:                 final VControl control = (VControl) vElement;
76:•                if (control.getDomainModelReference() == null) {
77:                         return NOT_APPLICABLE;
78:                 }
79:                 IValueProperty valueProperty;
80:                 try {
81:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
82:                                 viewModelContext.getDomainModel());
83:                 } catch (final DatabindingFailedException ex) {
84:                         reportService.report(new DatabindingFailedReport(ex));
85:                         return NOT_APPLICABLE;
86:                 }
87:                 final EStructuralFeature feature = (EStructuralFeature) valueProperty.getValueType();
88:•                if (feature.isMany()) {
89:                         return NOT_APPLICABLE;
90:                 }
91:                 // if we have an attribute
92:•                if (!EAttribute.class.isInstance(feature)) {
93:                         return NOT_APPLICABLE;
94:                 }
95:                 final EAttribute eAttribute = EAttribute.class.cast(feature);
96:•                if (eAttribute.getEContainingClass().equals(VStackPackage.eINSTANCE.getStackItem())) {
97:                         return 3d;
98:                 }
99:
100:                 return NOT_APPLICABLE;
101:         }
102:
103:         /**
104:          * {@inheritDoc}
105:          *
106:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#getRendererClass()
107:          */
108:         @Override
109:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
110:                 return StackItemControlRenderer.class;
111:         }
112:
113: }