Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2d008f3636a8d39c22dbd513ebdcca94aa8c6c8f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*******************************************************************************
 * Copyright (c) 2013 CEA LIST.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Cedric Dumoulin - cedric.dumoulin@lifl.fr
 ******************************************************************************/
package org.eclipse.papyrus.layers.runtime;

import java.util.List;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.layers.stackmodel.NotFoundException;
import org.eclipse.papyrus.layers.stackmodel.layers.AbstractLayer;
import org.eclipse.papyrus.layers.stackmodel.layers.LayersPackage;
import org.eclipse.papyrus.layers.stackmodel.layers.impl.StringToTypeInstanceMapImpl;
import org.eclipse.papyrus.layers.stackmodel.layers.util.ECoreUtils;


/**
 *
 * @author cedric dumoulin
 *
 */
public class LayersModelEventUtils {


	static public class PropertyEvents {

		/**
		 * Get the abstract layer containing the notifier.
		 *
		 * @param notification
		 * @return
		 * @throws NotFoundException
		 */
		static public AbstractLayer getAbstractLayer(Notification notification) throws NotFoundException {
			return (AbstractLayer) ECoreUtils.lookupAncestorOfType((EObject) notification.getNotifier(), LayersPackage.eINSTANCE.getAbstractLayer());
		}

		/**
		 * Get the name of the property concerned by the event.
		 *
		 * @return
		 */
		static public String getPropertyNameFromValueAdd(Notification notification) {

			StringToTypeInstanceMapImpl entry = (StringToTypeInstanceMapImpl) notification.getNewValue();
			return entry.getKey();
		}

		/**
		 * Get the name of the property concerned by the event.
		 *
		 * @return
		 */
		static public String getPropertyNameFromValueRemove(Notification notification) {

			StringToTypeInstanceMapImpl entry = (StringToTypeInstanceMapImpl) notification.getOldValue();
			return entry.getKey();
		}

		/**
		 * Get the name of the property concerned by the event.
		 *
		 * @return
		 * @throws NotFoundException
		 */
		static public String getPropertyNameFromValueSet(Notification notification) throws NotFoundException {

			StringToTypeInstanceMapImpl entry = (StringToTypeInstanceMapImpl) ECoreUtils.lookupAncestorOfType((EObject) notification.getNotifier(), LayersPackage.eINSTANCE.getStringToTypeInstanceMap());
			return entry.getKey();
		}
	}

	/**
	 *
	 *
	 */
	static public class ViewEvents {

		/**
		 * Get the abstract layer containing the notifier.
		 *
		 * @param notification
		 * @return
		 * @throws NotFoundException
		 */
		static public AbstractLayer getAbstractLayer(Notification notification) throws NotFoundException {
			return (AbstractLayer) notification.getNotifier();
		}

		/**
		 * Get the view added to layer
		 *
		 * @param notification
		 * @return
		 * @throws NotFoundException
		 */
		static public View getViewAdded(Notification notification) throws NotFoundException {
			return (View) notification.getNewValue();
		}

		/**
		 * Get the view removed from layer
		 *
		 * @param notification
		 * @return
		 * @throws NotFoundException
		 */
		static public View getViewRemoved(Notification notification) throws NotFoundException {
			return (View) notification.getOldValue();
		}

		/**
		 * Get the views[*] that have been removed from the layer.
		 *
		 * @param notification
		 * @return
		 */
		public static List<View> getViewsRemoved(Notification notification) {
			return (List<View>) notification.getOldValue();
		}

		public static List<View> getViewsAdded(Notification notification) {
			return (List<View>) notification.getNewValue();
		}


	}
}

Back to the top