Skip to content

Package: ControlRootEClassControlChangeableSWTRendererService

ControlRootEClassControlChangeableSWTRendererService

nameinstructionbranchcomplexitylinemethod
ControlRootEClassControlChangeableSWTRendererService()
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(EStructuralFeature)
M: 5 C: 31
86%
M: 2 C: 6
75%
M: 2 C: 3
60%
M: 2 C: 9
82%
M: 0 C: 1
100%
isApplicable(VElement, ViewModelContext)
M: 0 C: 41
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 12
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-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.core.runtime.Platform;
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.model.VViewPackage;
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 ControlRootEClassControlChangeableSWTRenderer}.
34: *
35: * @author Lucas Koehler
36: *
37: */
38: @Component(name = "ControlRootEClassControlChangeableSWTRendererService")
39: public class ControlRootEClassControlChangeableSWTRendererService 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:
89:                 return isApplicable(feature);
90:         }
91:
92:         /**
93:          * Test if the structural feature and the corresponding EObject contain the correct data.
94:          *
95:          * @param feature The {@link EStructuralFeature} to check
96:          * @return the priority of the control
97:          */
98:         private double isApplicable(EStructuralFeature feature) {
99:•                if (VViewPackage.eINSTANCE.getView_RootEClass() != feature) {
100:                         return NOT_APPLICABLE;
101:                 }
102:                 boolean allowChange = Boolean.FALSE;
103:                 final String[] commandLineArgs = Platform.getCommandLineArgs();
104:•                for (int i = 0; i < commandLineArgs.length; i++) {
105:                         final String arg = commandLineArgs[i];
106:•                        if ("-changeableClass".equalsIgnoreCase(arg)) { //$NON-NLS-1$
107:                                 allowChange = Boolean.TRUE;
108:                         }
109:                 }
110:•                if (allowChange) {
111:                         return 4d;
112:                 }
113:                 return NOT_APPLICABLE;
114:         }
115:
116:         /**
117:          * {@inheritDoc}
118:          *
119:          * @see org.eclipse.emf.ecp.view.internal.editor.controls.ControlRootEClassControl2SWTRendererService#getRendererClass()
120:          */
121:         @Override
122:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
123:                 return ControlRootEClassControlChangeableSWTRenderer.class;
124:         }
125:
126: }