Skip to content

Package: TypedElementBoundsControlService

TypedElementBoundsControlService

nameinstructionbranchcomplexitylinemethod
TypedElementBoundsControlService()
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: 48
100%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 13
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-2015 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: * Clemens Elflein - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.editor.ecore.controls;
15:
16: import org.eclipse.core.databinding.property.value.IValueProperty;
17: import org.eclipse.emf.ecore.EStructuralFeature;
18: import org.eclipse.emf.ecore.EcorePackage;
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: * This class decides, if the TypedElementBoundsRenderer can be used for the provided EStructuralFeature.
31: *
32: * @author Clemens Elflein
33: *
34: */
35: public class TypedElementBoundsControlService implements EMFFormsDIRendererService<VControl> {
36:
37:         private EMFFormsDatabinding databindingService;
38:         private ReportService reportService;
39:
40:         /**
41:          * Called by the initializer to set the EMFFormsDatabinding.
42:          *
43:          * @param databindingService The EMFFormsDatabinding
44:          */
45:         protected void setEMFFormsDatabinding(EMFFormsDatabinding databindingService) {
46:                 this.databindingService = databindingService;
47:         }
48:
49:         /**
50:          * Called by the initializer to set the ReportService.
51:          *
52:          * @param reportService The ReportService
53:          */
54:         protected void setReportService(ReportService reportService) {
55:                 this.reportService = reportService;
56:         }
57:
58:         /**
59:          * {@inheritDoc}
60:          *
61:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#isApplicable(org.eclipse.emf.ecp.view.spi.model.VElement,
62:          * org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
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:                 IValueProperty valueProperty;
71:                 try {
72:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
73:                                 viewModelContext.getDomainModel());
74:                 } catch (final DatabindingFailedException ex) {
75:                         reportService.report(new DatabindingFailedReport(ex));
76:                         return NOT_APPLICABLE;
77:                 }
78:                 final EStructuralFeature eStructuralFeature = EStructuralFeature.class.cast(valueProperty.getValueType());
79:•                if (eStructuralFeature.equals(EcorePackage.eINSTANCE.getETypedElement_UpperBound())
80:•                        || eStructuralFeature.equals(EcorePackage.eINSTANCE.getETypedElement_LowerBound())) {
81:                         return 10;
82:                 }
83:                 return NOT_APPLICABLE;
84:         }
85:
86:         /**
87:          * {@inheritDoc}
88:          *
89:          * @see org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService#getRendererClass()
90:          */
91:         @Override
92:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
93:                 return TypedElementBoundsRenderer.class;
94:         }
95:
96: }