Skip to content

Package: LinkControlSWTRendererService

LinkControlSWTRendererService

nameinstructionbranchcomplexitylinemethod
LinkControlSWTRendererService()
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: 2 C: 54
96%
M: 1 C: 9
90%
M: 1 C: 5
83%
M: 1 C: 17
94%
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: * Alexandra Buzila- initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.core.swt.renderer;
15:
16: import org.eclipse.core.databinding.property.value.IValueProperty;
17: import org.eclipse.emf.ecore.EReference;
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.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:
29: /**
30: * The renderer service for the {@link LinkControlSWTRenderer}.
31: *
32: * @author Alexandra Buzila
33: *
34: */
35: public class LinkControlSWTRendererService implements EMFFormsDIRendererService<VControl> {
36:
37:         private EMFFormsDatabinding databindingService;
38:         private ReportService reportService;
39:
40:         @Override
41:         public double isApplicable(VElement vElement, ViewModelContext viewModelContext) {
42:•                if (!VControl.class.isInstance(vElement)) {
43:                         return NOT_APPLICABLE;
44:                 }
45:                 final VControl control = (VControl) vElement;
46:•                if (control.getDomainModelReference() == null) {
47:                         return NOT_APPLICABLE;
48:                 }
49:                 IValueProperty valueProperty;
50:                 try {
51:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
52:                                 viewModelContext.getDomainModel());
53:                 } catch (final DatabindingFailedException ex) {
54:                         reportService.report(new DatabindingFailedReport(ex));
55:                         return NOT_APPLICABLE;
56:                 }
57:                 final EStructuralFeature eStructuralFeature = EStructuralFeature.class.cast(valueProperty.getValueType());
58:•                if (eStructuralFeature == null) {
59:                         return NOT_APPLICABLE;
60:                 }
61:•                if (eStructuralFeature.isMany()) {
62:                         return NOT_APPLICABLE;
63:                 }
64:•                if (!EReference.class.isInstance(eStructuralFeature)) {
65:                         return NOT_APPLICABLE;
66:                 }
67:                 return 2d;
68:         }
69:
70:         /**
71:          * Called by the initializer to set the EMFFormsDatabinding.
72:          *
73:          * @param databindingService The EMFFormsDatabinding
74:          */
75:         protected void setEMFFormsDatabinding(EMFFormsDatabinding databindingService) {
76:                 this.databindingService = databindingService;
77:         }
78:
79:         /**
80:          * Called by the initializer to set the ReportService.
81:          *
82:          * @param reportService The ReportService
83:          */
84:         protected void setReportService(ReportService reportService) {
85:                 this.reportService = reportService;
86:         }
87:
88:         @Override
89:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
90:                 return LinkControlSWTRenderer.class;
91:         }
92:
93: }