Skip to content

Package: EMFMappingValueProperty

EMFMappingValueProperty

nameinstructionbranchcomplexitylinemethod
EMFMappingValueProperty(EditingDomain, EClass, EStructuralFeature)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
doGetValue(Object)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
doSetValue(Object, Object)
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
toString()
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
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 Neufeld - initial API and implementation
13: * Lucas Koehler - moved/copied here from org.eclipse.emf.ecp.view.mappingdmr.databinding
14: ******************************************************************************/
15: package org.eclipse.emfforms.internal.core.services.segments.mapping;
16:
17: import org.eclipse.emf.common.util.EMap;
18: import org.eclipse.emf.databinding.internal.EMFValueProperty;
19: import org.eclipse.emf.ecore.EClass;
20: import org.eclipse.emf.ecore.EObject;
21: import org.eclipse.emf.ecore.EStructuralFeature;
22: import org.eclipse.emf.edit.command.ChangeCommand;
23: import org.eclipse.emf.edit.domain.EditingDomain;
24:
25: /**
26: * This class provides a ValueProperty for EClass Mappings.
27: *
28: * @author Eugen Neufeld
29: * @author Lucas Koehler
30: *
31: */
32: @SuppressWarnings("restriction")
33: public class EMFMappingValueProperty extends EMFValueProperty {
34:
35:         private final EClass mappedEClass;
36:         private final EditingDomain editingDomain;
37:
38:         /**
39:          * Constructor for a EClassMapping ValueProperty.
40:          *
41:          * @param editingDomain The {@link EditingDomain}
42:          * @param mappedEClass the EClass being mapped
43:          * @param eStructuralFeature the {@link EStructuralFeature} of the map
44:          */
45:         public EMFMappingValueProperty(EditingDomain editingDomain, EClass mappedEClass,
46:                 EStructuralFeature eStructuralFeature) {
47:                 super(eStructuralFeature);
48:                 this.editingDomain = editingDomain;
49:                 this.mappedEClass = mappedEClass;
50:         }
51:
52:         @SuppressWarnings("unchecked")
53:         @Override
54:         protected Object doGetValue(Object source) {
55:                 final Object result = super.doGetValue(source);
56:                 final EMap<EClass, Object> map = (EMap<EClass, Object>) result;
57:                 return map.get(mappedEClass);
58:         }
59:
60:         @SuppressWarnings("unchecked")
61:         @Override
62:         protected void doSetValue(Object source, final Object value) {
63:                 final Object result = super.doGetValue(source);
64:                 final EObject eObject = (EObject) source;
65:                 final ChangeCommand command = new ChangeCommand(eObject) {
66:
67:                         @Override
68:                         protected void doExecute() {
69:                                 final EMap<EClass, Object> map = (EMap<EClass, Object>) result;
70:                                 map.put(mappedEClass, value);
71:                         }
72:                 };
73:                 editingDomain.getCommandStack().execute(command);
74:         }
75:
76:         @Override
77:         public String toString() {
78:                 String s = super.toString();
79:                 s += " mapping " + mappedEClass.getName(); //$NON-NLS-1$
80:                 return s;
81:         }
82: }