Skip to content

Package: DelegatingDmrSegmentConverter$2

DelegatingDmrSegmentConverter$2

nameinstructionbranchcomplexitylinemethod
doGetDelegate(Object)
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%
doGetList(Object)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
doSetList(Object, List)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
doUpdateList(Object, ListDiff)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
observe(Object)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
observe(Realm, Object)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
substitute(Object)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
{...}
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
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.swt.internal.reference.table;
15:
16: import java.util.List;
17: import java.util.function.Function;
18:
19: import org.eclipse.core.databinding.observable.Realm;
20: import org.eclipse.core.databinding.observable.list.IObservableList;
21: import org.eclipse.core.databinding.observable.list.ListDiff;
22: import org.eclipse.core.databinding.observable.value.IObservableValue;
23: import org.eclipse.core.databinding.property.list.DelegatingListProperty;
24: import org.eclipse.core.databinding.property.list.IListProperty;
25: import org.eclipse.core.databinding.property.value.DelegatingValueProperty;
26: import org.eclipse.core.databinding.property.value.IValueProperty;
27: import org.eclipse.emf.databinding.EMFProperties;
28: import org.eclipse.emf.databinding.IEMFListProperty;
29: import org.eclipse.emf.databinding.IEMFValueProperty;
30: import org.eclipse.emf.databinding.internal.EMFListPropertyDecorator;
31: import org.eclipse.emf.databinding.internal.EMFValuePropertyDecorator;
32: import org.eclipse.emf.ecore.EClass;
33: import org.eclipse.emf.ecore.EObject;
34: import org.eclipse.emf.ecore.EReference;
35: import org.eclipse.emf.ecore.EStructuralFeature;
36: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
37: import org.eclipse.emf.ecore.InternalEObject;
38: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReferenceSegment;
39: import org.eclipse.emf.ecp.view.spi.model.VFeatureDomainModelReferenceSegment;
40: import org.eclipse.emf.edit.domain.EditingDomain;
41: import org.eclipse.emfforms.internal.core.services.databinding.SegmentConverterListResultImpl;
42: import org.eclipse.emfforms.internal.core.services.databinding.SegmentConverterValueResultImpl;
43: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
44: import org.eclipse.emfforms.spi.core.services.databinding.emf.DomainModelReferenceSegmentConverterEMF;
45: import org.eclipse.emfforms.spi.core.services.databinding.emf.SegmentConverterListResultEMF;
46: import org.eclipse.emfforms.spi.core.services.databinding.emf.SegmentConverterValueResultEMF;
47:
48: /**
49: * Converter for a DMR Segment that needs to be delegated to another object than the
50: * source on which it is being accessed.
51: *
52: * @author Lucas Koehler
53: *
54: */
55: @SuppressWarnings({ "unchecked", "rawtypes", "restriction" }) // EMF APIs are provisional
56: class DelegatingDmrSegmentConverter implements DomainModelReferenceSegmentConverterEMF {
57:
58:         private final VFeatureDomainModelReferenceSegment segment;
59:         private final EStructuralFeature segmentFeature;
60:         private final Function<? super EObject, ?> delegator;
61:
62:         /**
63:          * Default constructor.
64:          *
65:          * @param segment The {@link VDomainModelReferenceSegment} this segment converter is applicable for
66:          * @param segmentFeature The {@link EStructuralFeature} of the segment
67:          * @param delegator mapping of source object to the object to which to delegate access
68:          * to the segment
69:          */
70:         DelegatingDmrSegmentConverter(VFeatureDomainModelReferenceSegment segment, EStructuralFeature segmentFeature,
71:                 Function<? super EObject, ?> delegator) {
72:                 this.segment = segment;
73:                 this.segmentFeature = segmentFeature;
74:                 this.delegator = delegator;
75:         }
76:
77:         @Override
78:         public double isApplicable(VDomainModelReferenceSegment segment) {
79:                 return segment == this.segment ? Double.POSITIVE_INFINITY : NOT_APPLICABLE;
80:         }
81:
82:         @Override
83:         public SegmentConverterValueResultEMF convertToValueProperty(VDomainModelReferenceSegment segment,
84:                 EClass segmentRoot, EditingDomain editingDomain) throws DatabindingFailedException {
85:                 final EClass nextEClass = segmentFeature instanceof EReference
86:                         ? EReference.class.cast(segmentFeature).getEReferenceType()
87:                         : null;
88:                 return new SegmentConverterValueResultImpl(valueDecorator(), nextEClass);
89:         }
90:
91:         private IEMFValueProperty valueDecorator() {
92:                 final EStructuralFeature feature = segmentFeature;
93:                 final IValueProperty property = EMFProperties.value(feature);
94:
95:                 return new EMFValuePropertyDecorator(new DelegatingValueProperty(feature) {
96:                         @Override
97:                         protected IValueProperty doGetDelegate(Object source) {
98:                                 return property;
99:                         }
100:
101:                         Object substitute(Object source) {
102:                                 return delegator.apply((EObject) source);
103:                         }
104:
105:                         @Override
106:                         protected Object doGetValue(Object source) {
107:                                 return super.doGetValue(substitute(source));
108:                         }
109:
110:                         @Override
111:                         protected void doSetValue(Object source, Object value) {
112:                                 super.doSetValue(substitute(source), value);
113:                         }
114:
115:                         @Override
116:                         public IObservableValue observe(Object source) {
117:                                 return super.observe(substitute(source));
118:                         }
119:
120:                         @Override
121:                         public IObservableValue observe(Realm realm, Object source) {
122:                                 return super.observe(realm, substitute(source));
123:                         }
124:                 }, feature);
125:         }
126:
127:         @Override
128:         public SegmentConverterListResultEMF convertToListProperty(VDomainModelReferenceSegment segment, EClass segmentRoot,
129:                 EditingDomain editingDomain) throws DatabindingFailedException {
130:                 final EClass nextEClass = segmentFeature instanceof EReference
131:                         ? EReference.class.cast(segmentFeature).getEReferenceType()
132:                         : null;
133:                 return new SegmentConverterListResultImpl(listDecorator(), nextEClass);
134:         }
135:
136:         private IEMFListProperty listDecorator() {
137:
138:                 final EStructuralFeature feature = segmentFeature;
139:                 final IListProperty property = EMFProperties.list(feature);
140:
141:                 // BEGIN COMPLEX CODE
142:                 return new EMFListPropertyDecorator(new DelegatingListProperty(feature) {
143:                         @Override
144:                         protected IListProperty doGetDelegate(Object source) {
145:                                 return property;
146:                         }
147:
148:                         Object substitute(Object source) {
149:                                 return delegator.apply((EObject) source);
150:                         }
151:
152:                         @Override
153:                         protected List doGetList(Object source) {
154:                                 return super.doGetList(substitute(source));
155:                         }
156:
157:                         @Override
158:                         protected void doSetList(Object source, List list) {
159:                                 super.doSetList(substitute(source), list);
160:                         }
161:
162:                         @Override
163:                         protected void doUpdateList(Object source, ListDiff diff) {
164:                                 super.doUpdateList(substitute(source), diff);
165:                         }
166:
167:                         @Override
168:                         public IObservableList observe(Object source) {
169:                                 return super.observe(substitute(source));
170:                         }
171:
172:                         @Override
173:                         public IObservableList observe(Realm realm, Object source) {
174:                                 return super.observe(realm, substitute(source));
175:                         }
176:                 }, feature);
177:         }
178:
179:         @Override
180:         public Setting getSetting(VDomainModelReferenceSegment segment, EObject eObject) throws DatabindingFailedException {
181:                 return ((InternalEObject) delegator.apply(eObject)).eSetting(segmentFeature);
182:         }
183: }