Skip to content

Package: FeatureSegmentStructuralChangeTester

FeatureSegmentStructuralChangeTester

nameinstructionbranchcomplexitylinemethod
FeatureSegmentStructuralChangeTester()
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%
isApplicable(VDomainModelReferenceSegment)
M: 0 C: 19
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
isStructureChanged(VDomainModelReferenceSegment, EObject, ModelChangeNotification)
M: 10 C: 51
84%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 2 C: 12
86%
M: 0 C: 1
100%
setEMFFormsSegmentResolver(EMFFormsSegmentResolver)
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-2018 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.core.services.segments.featurepath;
15:
16: import org.eclipse.emf.ecore.EObject;
17: import org.eclipse.emf.ecore.EReference;
18: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
19: import org.eclipse.emf.ecp.common.spi.asserts.Assert;
20: import org.eclipse.emf.ecp.view.spi.model.ModelChangeNotification;
21: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReferenceSegment;
22: import org.eclipse.emf.ecp.view.spi.model.VFeatureDomainModelReferenceSegment;
23: import org.eclipse.emfforms.spi.common.report.AbstractReport;
24: import org.eclipse.emfforms.spi.common.report.ReportService;
25: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
26: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedReport;
27: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsSegmentResolver;
28: import org.eclipse.emfforms.spi.core.services.structuralchange.StructuralChangeSegmentTester;
29: import org.osgi.service.component.annotations.Component;
30: import org.osgi.service.component.annotations.Reference;
31:
32: /**
33: * A {@link StructuralChangeSegmentTester} implementation for {@link VFeatureDomainModelReferenceSegment
34: * VFeatureDomainModelReferenceSegments}.
35: *
36: * @author Lucas Koehler
37: *
38: */
39: @Component(name = "FeatureSegmentStructuralChangeTester")
40: public class FeatureSegmentStructuralChangeTester implements StructuralChangeSegmentTester {
41:         private EMFFormsSegmentResolver segmentResolver;
42:         private ReportService reportService;
43:
44:         /**
45:          * Sets the {@link EMFFormsSegmentResolver}.
46:          *
47:          * @param segmentResolver The {@link EMFFormsSegmentResolver}
48:          */
49:         @Reference(unbind = "-")
50:         protected void setEMFFormsSegmentResolver(EMFFormsSegmentResolver segmentResolver) {
51:                 this.segmentResolver = segmentResolver;
52:         }
53:
54:         /**
55:          * Sets 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:         @Override
65:         public boolean isStructureChanged(VDomainModelReferenceSegment segment, EObject domainObject,
66:                 ModelChangeNotification notification) {
67:                 Assert.create(segment).notNull();
68:                 Assert.create(domainObject).notNull();
69:                 Assert.create(segment).ofClass(VFeatureDomainModelReferenceSegment.class);
70:
71:•                if (notification.getRawNotification().isTouch()) {
72:                         return false;
73:                 }
74:
75:                 /*
76:                  * Check whether the notifying EObject and the EReference match the notification.
77:                  * If the EStructuralFeature of the resolved Setting is an EAttribute, its change is irrelevant.
78:                  */
79:                 Setting setting;
80:                 try {
81:                         setting = segmentResolver.resolveSegment(segment, domainObject);
82:                 } catch (final DatabindingFailedException ex) {
83:                         reportService.report(new DatabindingFailedReport(ex));
84:                         return false;
85:                 }
86:•                if (EReference.class.isInstance(setting.getEStructuralFeature())) {
87:                         final EReference eReference = (EReference) setting.getEStructuralFeature();
88:•                        return eReference.equals(notification.getStructuralFeature())
89:•                                && notification.getNotifier() == setting.getEObject();
90:                 }
91:
92:                 return false;
93:         }
94:
95:         @Override
96:         public double isApplicable(VDomainModelReferenceSegment segment) {
97:•                if (segment == null) {
98:                         reportService.report(new AbstractReport("Warning: The given domain model reference segment was null.")); //$NON-NLS-1$
99:                         return NOT_APPLICABLE;
100:                 }
101:•                if (VFeatureDomainModelReferenceSegment.class.isInstance(segment)) {
102:                         return 1d;
103:                 }
104:                 return NOT_APPLICABLE;
105:         }
106:
107: }