Skip to content

Package: TableDMRConverter

TableDMRConverter

nameinstructionbranchcomplexitylinemethod
TableDMRConverter()
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%
activate(BundleContext)
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%
convertToListProperty(VDomainModelReference, EObject)
M: 36 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
convertToValueProperty(VDomainModelReference, EClass, EditingDomain)
M: 22 C: 24
52%
M: 4 C: 4
50%
M: 4 C: 1
20%
M: 7 C: 8
53%
M: 0 C: 1
100%
convertToValueProperty(VDomainModelReference, EObject)
M: 6 C: 11
65%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 2
67%
M: 0 C: 1
100%
deactivate(BundleContext)
M: 0 C: 12
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getEMFFormsDatabindingEMF()
M: 5 C: 23
82%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 5
83%
M: 0 C: 1
100%
getEditingDomain(EObject)
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%
getSetting(VDomainModelReference, EObject)
M: 20 C: 32
62%
M: 5 C: 5
50%
M: 5 C: 1
17%
M: 7 C: 11
61%
M: 0 C: 1
100%
isApplicable(VDomainModelReference)
M: 0 C: 14
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 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: * Eugen - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.table.model;
15:
16: import org.eclipse.emf.databinding.IEMFListProperty;
17: import org.eclipse.emf.databinding.IEMFValueProperty;
18: import org.eclipse.emf.ecore.EClass;
19: import org.eclipse.emf.ecore.EObject;
20: import org.eclipse.emf.ecore.EReference;
21: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
22: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
23: import org.eclipse.emf.ecp.view.spi.table.model.VTableDomainModelReference;
24: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
25: import org.eclipse.emf.edit.domain.EditingDomain;
26: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
27: import org.eclipse.emfforms.spi.core.services.databinding.DomainModelReferenceConverter;
28: import org.eclipse.emfforms.spi.core.services.databinding.emf.DomainModelReferenceConverterEMF;
29: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsDatabindingEMF;
30: import org.osgi.framework.BundleContext;
31: import org.osgi.framework.ServiceReference;
32: import org.osgi.service.component.annotations.Activate;
33: import org.osgi.service.component.annotations.Component;
34: import org.osgi.service.component.annotations.Deactivate;
35:
36: /**
37: * This is the DomainModelReferenceConverterEMF for {@link VTableDomainModelReference}.
38: *
39: * @author Eugen Neufeld
40: *
41: */
42: @Component(service = { DomainModelReferenceConverterEMF.class, DomainModelReferenceConverter.class })
43: public class TableDMRConverter implements DomainModelReferenceConverterEMF {
44:         private EMFFormsDatabindingEMF emfFormsDatabinding;
45:         private ServiceReference<EMFFormsDatabindingEMF> databindingServiceReference;
46:         private BundleContext bundleContext;
47:
48:         /**
49:          * This method is called by the OSGI framework when this {@link DomainModelReferenceConverterEMF} is activated. It
50:          * retrieves the {@link EMFFormsDatabindingEMF EMF Forms databinding service}.
51:          *
52:          * @param bundleContext The {@link BundleContext} of this classes bundle.
53:          */
54:         @Activate
55:         protected final void activate(BundleContext bundleContext) {
56:                 this.bundleContext = bundleContext;
57:         }
58:
59:         /**
60:          * This method is called by the OSGI framework when this {@link DomainModelReferenceConverterEMF} is deactivated.
61:          * It frees the {@link EMFFormsDatabindingEMF EMF Forms databinding service}.
62:          *
63:          * @param bundleContext The {@link BundleContext} of this classes bundle.
64:          */
65:         @Deactivate
66:         protected final void deactivate(BundleContext bundleContext) {
67:•                if (databindingServiceReference != null) {
68:                         bundleContext.ungetService(databindingServiceReference);
69:                         emfFormsDatabinding = null;
70:                 }
71:         }
72:
73:         private EMFFormsDatabindingEMF getEMFFormsDatabindingEMF() {
74:•                if (emfFormsDatabinding == null) {
75:                         databindingServiceReference = bundleContext.getServiceReference(EMFFormsDatabindingEMF.class);
76:•                        if (databindingServiceReference == null) {
77:                                 throw new IllegalStateException("No EMFFormsDatabindingEMF available!"); //$NON-NLS-1$
78:                         }
79:                         emfFormsDatabinding = bundleContext.getService(databindingServiceReference);
80:                 }
81:                 return emfFormsDatabinding;
82:         }
83:
84:         @Override
85:         public double isApplicable(VDomainModelReference domainModelReference) {
86:•                if (VTableDomainModelReference.class.isInstance(domainModelReference)
87:•                        && VTableDomainModelReference.class.cast(domainModelReference).getDomainModelReference() != null) {
88:                         return 5;
89:                 }
90:                 return NOT_APPLICABLE;
91:         }
92:
93:         @Override
94:         public IEMFValueProperty convertToValueProperty(VDomainModelReference domainModelReference, EObject object)
95:                 throws DatabindingFailedException {
96:•                if (object == null) {
97:                         return convertToValueProperty(domainModelReference, null, null);
98:                 }
99:                 return convertToValueProperty(domainModelReference, object.eClass(), getEditingDomain(object));
100:         }
101:
102:         private EditingDomain getEditingDomain(EObject object) throws DatabindingFailedException {
103:                 return AdapterFactoryEditingDomain.getEditingDomainFor(object);
104:         }
105:
106:         @Override
107:         public IEMFValueProperty convertToValueProperty(VDomainModelReference domainModelReference, EClass rootEClass,
108:                 EditingDomain editingDomain) throws DatabindingFailedException {
109:•                if (domainModelReference == null) {
110:                         throw new IllegalArgumentException("The given VDomainModelReference must not be null."); //$NON-NLS-1$
111:                 }
112:•                if (!VTableDomainModelReference.class.isInstance(domainModelReference)) {
113:                         throw new IllegalArgumentException(
114:                                 "DomainModelReference must be an instance of VTableDomainModelReference."); //$NON-NLS-1$
115:                 }
116:
117:                 final VTableDomainModelReference tableDomainModelReference = VTableDomainModelReference.class
118:                         .cast(domainModelReference);
119:•                if (tableDomainModelReference.getDomainModelReference() == null) {
120:                         throw new DatabindingFailedException(
121:                                 "The field domainModelReference of the given VTableDomainModelReference must not be null."); //$NON-NLS-1$
122:                 }
123:•                if (rootEClass == null) {
124:                         return getEMFFormsDatabindingEMF().getValueProperty(tableDomainModelReference.getDomainModelReference(),
125:                                 (EObject) null);
126:                 }
127:                 return getEMFFormsDatabindingEMF().getValueProperty(tableDomainModelReference.getDomainModelReference(),
128:                         rootEClass, editingDomain);
129:         }
130:
131:         @Override
132:         public IEMFListProperty convertToListProperty(VDomainModelReference domainModelReference, EObject object)
133:                 throws DatabindingFailedException {
134:•                if (domainModelReference == null) {
135:                         throw new IllegalArgumentException("The given VDomainModelReference must not be null."); //$NON-NLS-1$
136:                 }
137:•                if (!VTableDomainModelReference.class.isInstance(domainModelReference)) {
138:                         throw new IllegalArgumentException(
139:                                 "DomainModelReference must be an instance of VTableDomainModelReference."); //$NON-NLS-1$
140:                 }
141:
142:                 final VTableDomainModelReference tableDomainModelReference = VTableDomainModelReference.class
143:                         .cast(domainModelReference);
144:•                if (tableDomainModelReference.getDomainModelReference() == null) {
145:                         throw new DatabindingFailedException(
146:                                 "The field domainModelReference of the given VTableDomainModelReference must not be null."); //$NON-NLS-1$
147:                 }
148:                 return getEMFFormsDatabindingEMF().getListProperty(tableDomainModelReference.getDomainModelReference(), object);
149:         }
150:
151:         @Override
152:         public Setting getSetting(VDomainModelReference domainModelReference, EObject object)
153:                 throws DatabindingFailedException {
154:•                if (domainModelReference == null) {
155:                         throw new IllegalArgumentException("The given VDomainModelReference must not be null."); //$NON-NLS-1$
156:                 }
157:•                if (!VTableDomainModelReference.class.isInstance(domainModelReference)) {
158:                         throw new IllegalArgumentException(
159:                                 "DomainModelReference must be an instance of VTableDomainModelReference."); //$NON-NLS-1$
160:                 }
161:
162:                 final VTableDomainModelReference tableDomainModelReference = VTableDomainModelReference.class
163:                         .cast(domainModelReference);
164:•                if (tableDomainModelReference.getDomainModelReference() == null) {
165:                         throw new DatabindingFailedException(
166:                                 "The field domainModelReference of the given VTableDomainModelReference must not be null."); //$NON-NLS-1$
167:                 }
168:                 final Setting setting = getEMFFormsDatabindingEMF().getSetting(
169:                         tableDomainModelReference.getDomainModelReference(),
170:                         object);
171:•                if (!setting.getEStructuralFeature().isMany()
172:•                        || !EReference.class.isInstance(setting.getEStructuralFeature())) {
173:                         throw new DatabindingFailedException(
174:                                 "The field domainModelReference of the given VTableDomainModelReference must be a multi reference."); //$NON-NLS-1$
175:                 }
176:                 return setting;
177:         }
178:
179: }