Skip to content

Package: MultiSegmentChildDmrsSWTRendererService

MultiSegmentChildDmrsSWTRendererService

nameinstructionbranchcomplexitylinemethod
MultiSegmentChildDmrsSWTRendererService()
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%
checkAnnotation(VControl)
M: 0 C: 31
100%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 0 C: 8
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: 14 C: 46
77%
M: 2 C: 8
80%
M: 2 C: 4
67%
M: 4 C: 15
79%
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-2019 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.emfforms.internal.view.multisegment.tooling;
15:
16: import org.eclipse.core.databinding.property.value.IValueProperty;
17: import org.eclipse.emf.ecore.EClass;
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.editor.controls.Helper;
21: import org.eclipse.emf.ecp.view.spi.model.VAttachment;
22: import org.eclipse.emf.ecp.view.spi.model.VControl;
23: import org.eclipse.emf.ecp.view.spi.model.VElement;
24: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
25: import org.eclipse.emf.ecp.view.spi.table.model.VTablePackage;
26: import org.eclipse.emf.emfforms.spi.view.annotation.model.VAnnotation;
27: import org.eclipse.emfforms.spi.common.report.ReportService;
28: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
29: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
30: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
31: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
32: import org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService;
33: import org.osgi.service.component.annotations.Component;
34: import org.osgi.service.component.annotations.Reference;
35:
36: /**
37: * DI renderer service for {@link MultiSegmentChildDmrsSWTRenderer}.
38: *
39: * @author Lucas Koehler
40: *
41: */
42: @Component(name = "MultiSegmentChildDmrsSWTRendererService")
43: public class MultiSegmentChildDmrsSWTRendererService implements EMFFormsDIRendererService<VControl> {
44:
45:         /**
46:          * Key of the annotation that defines that the child dmrs of a dmr's multi segment should be rendered.
47:          */
48:         private static final String SHOW_CHILD_DOMAIN_MODEL_REFERENCES = "showChildDomainModelReferences"; //$NON-NLS-1$
49:         private EMFFormsDatabinding databindingService;
50:         private ReportService reportService;
51:
52:         /**
53:          * Called by the framework to set the {@link EMFFormsDatabinding}.
54:          *
55:          * @param databindingService The {@link EMFFormsDatabinding}
56:          */
57:         @Reference(unbind = "-")
58:         protected void setEMFFormsDatabinding(EMFFormsDatabinding databindingService) {
59:                 this.databindingService = databindingService;
60:         }
61:
62:         /**
63:          * Called by the framework to set the {@link ReportService}.
64:          *
65:          * @param reportService The {@link ReportService}
66:          */
67:         @Reference(unbind = "-")
68:         protected void setReportService(ReportService reportService) {
69:                 this.reportService = reportService;
70:         }
71:
72:         @Override
73:         public double isApplicable(VElement vElement, ViewModelContext viewModelContext) {
74:•                if (!VControl.class.isInstance(vElement)) {
75:                         return NOT_APPLICABLE;
76:                 }
77:                 final VControl control = (VControl) vElement;
78:•                if (control.getDomainModelReference() == null) {
79:                         return NOT_APPLICABLE;
80:                 }
81:                 // Test that a feature of a table dmr is rendered
82:                 final EClass rootEClass = Helper.getRootEClass(vElement);
83:•                if (!VTablePackage.eINSTANCE.getTableControl().equals(rootEClass)) {
84:                         return NOT_APPLICABLE;
85:                 }
86:
87:                 // Check that the correct annotation is set
88:•                if (!checkAnnotation(control)) {
89:                         return NOT_APPLICABLE;
90:                 }
91:
92:                 IValueProperty<?, ?> valueProperty;
93:                 try {
94:                         valueProperty = databindingService.getValueProperty(control.getDomainModelReference(),
95:                                 viewModelContext.getDomainModel());
96:                 } catch (final DatabindingFailedException ex) {
97:                         reportService.report(new DatabindingFailedReport(ex));
98:                         return NOT_APPLICABLE;
99:                 }
100:                 final EStructuralFeature feature = (EStructuralFeature) valueProperty.getValueType();
101:
102:•                if (VViewPackage.Literals.CONTROL__DOMAIN_MODEL_REFERENCE != feature) {
103:                         return NOT_APPLICABLE;
104:                 }
105:                 return 10d;
106:         }
107:
108:         private boolean checkAnnotation(final VControl control) {
109:                 boolean showChildDmrs = false;
110:•                for (final VAttachment attachment : control.getAttachments()) {
111:•                        if (VAnnotation.class.isInstance(attachment)) {
112:                                 final VAnnotation annotation = (VAnnotation) attachment;
113:•                                if (SHOW_CHILD_DOMAIN_MODEL_REFERENCES.equals(annotation.getKey())) {
114:                                         showChildDmrs = true;
115:                                         break;
116:                                 }
117:                         }
118:                 }
119:                 return showChildDmrs;
120:         }
121:
122:         @Override
123:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
124:                 return MultiSegmentChildDmrsSWTRenderer.class;
125:         }
126:
127: }