Skip to content

Package: DelegatingDomainModelReferenceConverter$2

DelegatingDomainModelReferenceConverter$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) 2019 Christian W. Damus 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: * Christian W. Damus - 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.EStructuralFeature;
35: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
36: import org.eclipse.emf.ecore.InternalEObject;
37: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
38: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
39: import org.eclipse.emf.edit.domain.EditingDomain;
40: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
41: import org.eclipse.emfforms.spi.core.services.databinding.emf.DomainModelReferenceConverterEMF;
42:
43: /**
44: * Converter for a DMR that needs to be delegated to another object than the
45: * source on which it is being accessed.
46: */
47: @SuppressWarnings({ "unchecked", "rawtypes", "restriction" }) // EMF APIs are provisional
48: class DelegatingDomainModelReferenceConverter implements DomainModelReferenceConverterEMF {
49:
50:         private final VFeaturePathDomainModelReference dmr;
51:         private final Function<? super EObject, ?> delegator;
52:
53:         /**
54:          * Initializes me with the DMR that I convert and a function computing the
55:          * source object to delegate the reference access to.
56:          *
57:          * @param dmr the DMR to convert
58:          * @param delegator mapping of source object to the object to which to delegate access
59:          * to the DMR
60:          */
61:         DelegatingDomainModelReferenceConverter(VFeaturePathDomainModelReference dmr,
62:                 Function<? super EObject, ?> delegator) {
63:
64:                 super();
65:
66:                 this.dmr = dmr;
67:                 this.delegator = delegator;
68:         }
69:
70:         @Override
71:         public double isApplicable(VDomainModelReference domainModelReference) {
72:                 return domainModelReference == dmr ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY;
73:         }
74:
75:         @Override
76:         public IEMFValueProperty convertToValueProperty(VDomainModelReference domainModelReference, EObject object)
77:                 throws DatabindingFailedException {
78:
79:                 return valueDecorator();
80:         }
81:
82:         private IEMFValueProperty valueDecorator() {
83:                 final EStructuralFeature feature = dmr.getDomainModelEFeature();
84:                 final IValueProperty property = EMFProperties.value(feature);
85:
86:                 return new EMFValuePropertyDecorator(new DelegatingValueProperty(feature) {
87:                         @Override
88:                         protected IValueProperty doGetDelegate(Object source) {
89:                                 return property;
90:                         }
91:
92:                         Object substitute(Object source) {
93:                                 return delegator.apply((EObject) source);
94:                         }
95:
96:                         @Override
97:                         protected Object doGetValue(Object source) {
98:                                 return super.doGetValue(substitute(source));
99:                         }
100:
101:                         @Override
102:                         protected void doSetValue(Object source, Object value) {
103:                                 super.doSetValue(substitute(source), value);
104:                         }
105:
106:                         @Override
107:                         public IObservableValue observe(Object source) {
108:                                 return super.observe(substitute(source));
109:                         }
110:
111:                         @Override
112:                         public IObservableValue observe(Realm realm, Object source) {
113:                                 return super.observe(realm, substitute(source));
114:                         }
115:                 }, feature);
116:         }
117:
118:         @Override
119:         public IEMFValueProperty convertToValueProperty(VDomainModelReference domainModelReference, EClass rootEClass,
120:                 EditingDomain editingDomain) throws DatabindingFailedException {
121:
122:                 return valueDecorator();
123:         }
124:
125:         @Override
126:         public IEMFListProperty convertToListProperty(VDomainModelReference domainModelReference, EObject object)
127:                 throws DatabindingFailedException {
128:
129:                 final EStructuralFeature feature = dmr.getDomainModelEFeature();
130:                 final IListProperty property = EMFProperties.list(feature);
131:
132:                 // BEGIN COMPLEX CODE
133:                 return new EMFListPropertyDecorator(new DelegatingListProperty(feature) {
134:                         @Override
135:                         protected IListProperty doGetDelegate(Object source) {
136:                                 return property;
137:                         }
138:
139:                         Object substitute(Object source) {
140:                                 return delegator.apply((EObject) source);
141:                         }
142:
143:                         @Override
144:                         protected List doGetList(Object source) {
145:                                 return super.doGetList(substitute(source));
146:                         }
147:
148:                         @Override
149:                         protected void doSetList(Object source, List list) {
150:                                 super.doSetList(substitute(source), list);
151:                         }
152:
153:                         @Override
154:                         protected void doUpdateList(Object source, ListDiff diff) {
155:                                 super.doUpdateList(substitute(source), diff);
156:                         }
157:
158:                         @Override
159:                         public IObservableList observe(Object source) {
160:                                 return super.observe(substitute(source));
161:                         }
162:
163:                         @Override
164:                         public IObservableList observe(Realm realm, Object source) {
165:                                 return super.observe(realm, substitute(source));
166:                         }
167:                 }, feature);
168:                 // END COMPLEX CODE
169:         }
170:
171:         @Override
172:         public Setting getSetting(VDomainModelReference domainModelReference, EObject object)
173:                 throws DatabindingFailedException {
174:
175:                 final EStructuralFeature feature = dmr.getDomainModelEFeature();
176:                 return ((InternalEObject) delegator.apply(object)).eSetting(feature);
177:         }
178:
179: }