Skip to content

Package: TableColumnsDMRTableControlService

TableColumnsDMRTableControlService

nameinstructionbranchcomplexitylinemethod
TableColumnsDMRTableControlService()
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: 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: 14 C: 51
78%
M: 3 C: 11
79%
M: 3 C: 5
63%
M: 4 C: 17
81%
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.EStructuralFeature;
18: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
19: import org.eclipse.emf.ecp.view.spi.model.VAttachment;
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.emf.ecp.view.spi.table.model.VTablePackage;
24: import org.eclipse.emf.emfforms.spi.view.annotation.model.VAnnotation;
25: import org.eclipse.emfforms.spi.common.report.ReportService;
26: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
27: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
28: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
29: import org.eclipse.emfforms.spi.ide.view.segments.ToolingModeUtil;
30: import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer;
31: import org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService;
32: import org.osgi.service.component.annotations.Component;
33: import org.osgi.service.component.annotations.Reference;
34:
35: /**
36: * DI renderer service for {@link TableColumnsDMRTableControl}.
37: *
38: * @author Lucas Koehler
39: *
40: */
41: @Component(name = "TableColumnsDMRTableControlService")
42: public class TableColumnsDMRTableControlService implements EMFFormsDIRendererService<VControl> {
43:         /**
44:          * Key of the annotation that defines that the child dmrs of a dmr's multi segment should be rendered.
45:          */
46:         private static final String SHOW_CHILD_DOMAIN_MODEL_REFERENCES = "showChildDomainModelReferences"; //$NON-NLS-1$
47:
48:         private EMFFormsDatabinding databindingService;
49:         private ReportService reportService;
50:
51:         /**
52:          * Called by the framework to set the {@link EMFFormsDatabinding}.
53:          *
54:          * @param databindingService The {@link EMFFormsDatabinding}
55:          */
56:         @Reference(unbind = "-")
57:         protected void setEMFFormsDatabinding(EMFFormsDatabinding databindingService) {
58:                 this.databindingService = databindingService;
59:         }
60:
61:         /**
62:          * Called by the framework to set the {@link ReportService}.
63:          *
64:          * @param reportService The {@link ReportService}
65:          */
66:         @Reference(unbind = "-")
67:         protected void setReportService(ReportService reportService) {
68:                 this.reportService = reportService;
69:         }
70:
71:         @Override
72:         public double isApplicable(VElement vElement, ViewModelContext viewModelContext) {
73:•                if (ToolingModeUtil.isSegmentToolingEnabled()) {
74:                         return NOT_APPLICABLE;
75:                 }
76:•                if (!VControl.class.isInstance(vElement)) {
77:                         return NOT_APPLICABLE;
78:                 }
79:                 final VControl control = (VControl) vElement;
80:•                if (control.getDomainModelReference() == null) {
81:                         return NOT_APPLICABLE;
82:                 }
83:•                if (viewModelContext.getDomainModel().eClass() != VTablePackage.Literals.TABLE_CONTROL) {
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.eINSTANCE.getControl_DomainModelReference() != feature
103:•                        && VTablePackage.Literals.TABLE_DOMAIN_MODEL_REFERENCE__COLUMN_DOMAIN_MODEL_REFERENCES != feature) {
104:                         return NOT_APPLICABLE;
105:                 }
106:                 return 10d;
107:         }
108:
109:         /**
110:          * Checks whether the control has the annotation which states that the columns should be rendered.
111:          *
112:          * @param control
113:          * @return <code>true</code> if the annotation is present
114:          */
115:         private boolean checkAnnotation(final VControl control) {
116:                 boolean showChildDmrs = false;
117:•                for (final VAttachment attachment : control.getAttachments()) {
118:•                        if (VAnnotation.class.isInstance(attachment)) {
119:                                 final VAnnotation annotation = (VAnnotation) attachment;
120:•                                if (SHOW_CHILD_DOMAIN_MODEL_REFERENCES.equals(annotation.getKey())) {
121:                                         showChildDmrs = true;
122:                                         break;
123:                                 }
124:                         }
125:                 }
126:                 return showChildDmrs;
127:         }
128:
129:         @Override
130:         public Class<? extends AbstractSWTRenderer<VControl>> getRendererClass() {
131:                 return TableColumnsDMRTableControl.class;
132:         }
133:
134: }