Skip to content

Package: ModelChangeNotification

ModelChangeNotification

nameinstructionbranchcomplexitylinemethod
ModelChangeNotification(Notification)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getNewEObjects()
M: 7 C: 17
71%
M: 2 C: 3
60%
M: 2 C: 2
50%
M: 2 C: 4
67%
M: 0 C: 1
100%
getNotifier()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getOldEObjects()
M: 7 C: 17
71%
M: 2 C: 3
60%
M: 2 C: 2
50%
M: 2 C: 4
67%
M: 0 C: 1
100%
getRawNotification()
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%
getStructuralFeature()
M: 0 C: 5
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-2013 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: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.spi.model;
15:
16: import java.util.Collection;
17: import java.util.Collections;
18:
19: import org.eclipse.emf.common.notify.Notification;
20: import org.eclipse.emf.ecore.EObject;
21: import org.eclipse.emf.ecore.EReference;
22: import org.eclipse.emf.ecore.EStructuralFeature;
23:
24: /**
25: * The Class ModelChangeNotification.
26: * Such a notification is issued by the ViewModelContext when a change in the domain or the view model occurs.
27: *
28: * @author Eugen Neufeld
29: * @since 1.3
30: * @noextend This class is not intended to be subclassed by clients.
31: */
32: public class ModelChangeNotification {
33:
34:         /** The notification. */
35:         private final Notification notification;
36:
37:         /**
38:          * Instantiates a new model change notification.
39:          *
40:          * @param notification the {@link Notification}
41:          */
42:         public ModelChangeNotification(Notification notification) {
43:                 this.notification = notification;
44:         }
45:
46:         /**
47:          * Gets the structural feature.
48:          *
49:          * @return the {@link EStructuralFeature} which value changed
50:          */
51:         public EStructuralFeature getStructuralFeature() {
52:                 return (EStructuralFeature) notification.getFeature();
53:         }
54:
55:         /**
56:          * Gets the notifier.
57:          *
58:          * @return the notifier which value changed
59:          */
60:         public EObject getNotifier() {
61:                 return (EObject) notification.getNotifier();
62:         }
63:
64:         /**
65:          * Gets the raw notification.
66:          *
67:          * @return the raw {@link Notification}
68:          */
69:         public Notification getRawNotification() {
70:                 return notification;
71:         }
72:
73:         /**
74:          * Returns the collection of new EObjects.
75:          *
76:          * @return The collection of added EObjects, the collection might be empty but never null.
77:          * @since 1.5
78:          */
79:         @SuppressWarnings("unchecked")
80:         public Collection<EObject> getNewEObjects() {
81:•                if (!EReference.class.isInstance(getStructuralFeature())) {
82:                         return Collections.emptySet();
83:                 }
84:•                switch (getRawNotification().getEventType()) {
85:                 case Notification.ADD:
86:                         return Collections.singleton((EObject) getRawNotification().getNewValue());
87:                 case Notification.ADD_MANY:
88:                         return (Collection<EObject>) getRawNotification().getNewValue();
89:                 default:
90:                         return Collections.emptySet();
91:                 }
92:         }
93:
94:         /**
95:          * Returns the collection of old EObjects.
96:          *
97:          * @return The collection of removed EObjects, the collection might be empty but never null.
98:          * @since 1.10
99:          */
100:         @SuppressWarnings("unchecked")
101:         public Collection<EObject> getOldEObjects() {
102:•                if (!EReference.class.isInstance(getStructuralFeature())) {
103:                         return Collections.emptySet();
104:                 }
105:•                switch (getRawNotification().getEventType()) {
106:                 case Notification.REMOVE:
107:                         return Collections.singleton((EObject) getRawNotification().getOldValue());
108:                 case Notification.REMOVE_MANY:
109:                         return (Collection<EObject>) getRawNotification().getOldValue();
110:                 default:
111:                         return Collections.emptySet();
112:                 }
113:         }
114: }