Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6f0a6dbca8317ef6a46f1f59d3054e8f4b46ec07 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/*****************************************************************************
 * Copyright (c) 2015 CEA LIST and others.
 * 
 * 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:
 *   Jeremie Tatibouet (CEA LIST)
 *   
 *****************************************************************************/
package org.eclipse.papyrus.uml.alf.transaction.observation.listener.filter;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.transaction.NotificationFilter;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.AssociationClass;
import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.CommunicationPath;
import org.eclipse.uml2.uml.Component;
import org.eclipse.uml2.uml.DataType;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Enumeration;
import org.eclipse.uml2.uml.Extension;
import org.eclipse.uml2.uml.Generalization;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Node;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.Signal;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;

public class FUMLFilter extends NotificationFilter.Custom {

	public FUMLFilter() {
	}

	/**
	 * Filter starting point
	 */
	public boolean matches(Notification notification) {
		Object notifier = notification.getNotifier();
		if (!this.isNotifierAllowed(notifier)) {
			return false;
		}
		Object feature = notification.getFeature();
		if (notifier != null && feature != null) {
			if (this.isEnumeration(notifier)) {
				return this.isEnumerationFeatureListened((EStructuralFeature) feature);
			} else if (this.isDataType(notifier)) {
				return this.isDatatypeFeatureListened((EStructuralFeature) feature);
			} else if (this.isPackage(notifier)) {
				return this.isPackageFeatureListened((EStructuralFeature) feature);
			} else if (this.isAssociation(notifier)) {
				return this.isAssociationFeatureListener((EStructuralFeature) feature);
			} else if (this.isSignal(notifier)) {
				return this.isSignalFeatureListened((EStructuralFeature) feature);
			} else if (this.isClass(notifier)) {
				return this.isClassFeatureListened((EStructuralFeature) feature);
			} else if (this.isGeneralization(notifier)) {
				return this.isGeneralizationtFeatureListened((EStructuralFeature) feature);
			}
		}
		return false;
	}

	private boolean isNotifierAllowed(Object notifier) {
		boolean allowed = false;
		if (notifier instanceof Element) {
			EObject target = (EObject) notifier;
			if (target.eResource() != null && target.eResource() instanceof UMLResource) {
				allowed = target.eResource().isTrackingModification();
			}
		}
		return allowed;
	}

	/*----------------------------------------------------------------------------*/
	/* Enforce the filter to respect the fUML subset */
	/*----------------------------------------------------------------------------*/

	private boolean isGeneralization(Object notifier) {
		return notifier instanceof Generalization;
	}

	/**
	 * 
	 * @param notifier
	 * @return
	 */
	private boolean isClass(Object notifier) {
		if (notifier instanceof Class &&
				(!(notifier instanceof AssociationClass) &&
						!(notifier instanceof Component) &&
						!(notifier instanceof Node) &&
						!(notifier instanceof Stereotype) &&
				!(notifier instanceof Behavior))) {
			return true;
		}
		return false;
	}

	/**
	 * 
	 * @param notifier
	 * @return
	 */
	private boolean isSignal(Object notifier) {
		return notifier instanceof Signal;
	}

	/**
	 * 
	 * @param notifier
	 * @return
	 */
	private boolean isDataType(Object notifier) {
		if (notifier instanceof DataType
				&& !(notifier instanceof Enumeration)) {
			return true;
		}
		return false;
	}

	/**
	 * 
	 * @param notifier
	 * @return
	 */
	private boolean isPackage(Object notifier) {
		if (notifier != null
				&& notifier instanceof Package
				&& !(notifier instanceof Model)
				&& !(notifier instanceof Profile)) {
			return true;
		}
		return false;
	}

	/**
	 * 
	 * @param notifier
	 * @return
	 */
	private boolean isEnumeration(Object notifier) {
		return notifier instanceof Enumeration;
	}

	/**
	 * 
	 * @param notifier
	 * @return
	 */
	private boolean isAssociation(Object notifier) {
		if (notifier instanceof Association
				&& !(notifier instanceof AssociationClass)
				&& !(notifier instanceof Extension)
				&& !(notifier instanceof CommunicationPath)) {
			return true;
		}
		return false;
	}

	/*----------------------------------------------------------------------------*/
	/* Low level checks encoding the UML meta-model hierarchy */
	/*----------------------------------------------------------------------------*/

	private boolean isGeneralizationtFeatureListened(EStructuralFeature feature) {
		if (UMLPackage.eINSTANCE.getGeneralization_General() == feature
				|| UMLPackage.eINSTANCE.getGeneralization_Specific() == feature) {
			return true;
		}
		return false;
	}

	private boolean isNamedElementFeatureListened(EStructuralFeature feature) {
		if (UMLPackage.eINSTANCE.getNamedElement_Name() == feature
				|| UMLPackage.eINSTANCE.getNamedElement_QualifiedName() == feature
				|| UMLPackage.eINSTANCE.getNamedElement_Namespace() == feature
				|| UMLPackage.eINSTANCE.getNamedElement_Visibility() == feature
				|| UMLPackage.eINSTANCE.getNamedElement_Namespace() == feature) {
			return true;
		}
		return false;
	}

	private boolean isTypeFeatureListened(EStructuralFeature feature) {
		return UMLPackage.eINSTANCE.getType_Package() == feature || this.isPackageableElementFeatureListened(feature);
	}

	private boolean isNamespaceFeatureListened(EStructuralFeature feature) {
		if (UMLPackage.eINSTANCE.getNamespace_ElementImport() == feature
				|| UMLPackage.eINSTANCE.getNamespace_ImportedMember() == feature
				|| UMLPackage.eINSTANCE.getNamespace_Member() == feature
				|| UMLPackage.eINSTANCE.getNamespace_OwnedMember() == feature
				|| UMLPackage.eINSTANCE.getNamespace_PackageImport() == feature
				|| this.isNamedElementFeatureListened(feature)) {
			return true;
		}
		return false;
	}

	private boolean isPackageableElementFeatureListened(EStructuralFeature feature) {
		return this.isNamedElementFeatureListened(feature);
	}

	private boolean isPackageFeatureListened(EStructuralFeature feature) {
		if (UMLPackage.eINSTANCE.getPackage_URI() == feature
				|| UMLPackage.eINSTANCE.getPackage_NestedPackage() == feature
				|| UMLPackage.eINSTANCE.getPackage_NestingPackage() == feature
				|| UMLPackage.eINSTANCE.getPackage_OwnedType() == feature
				|| UMLPackage.eINSTANCE.getPackage_PackagedElement() == feature
				|| this.isPackageableElementFeatureListened(feature)
				|| this.isNamespaceFeatureListened(feature)) {
			return true;
		}
		return false;
	}

	private boolean isClassifierFeatureListened(EStructuralFeature feature) {
		if (UMLPackage.eINSTANCE.getClassifier_IsFinalSpecialization() == feature
				|| UMLPackage.eINSTANCE.getClassifier_IsAbstract() == feature
				|| UMLPackage.eINSTANCE.getClassifier_Attribute() == feature
				|| UMLPackage.eINSTANCE.getClassifier_Feature() == feature
				|| UMLPackage.eINSTANCE.getClassifier_General() == feature
				|| UMLPackage.eINSTANCE.getClassifier_Generalization() == feature
				|| this.isNamespaceFeatureListened(feature)
				|| this.isTypeFeatureListened(feature)) {
			return true;
		}
		return false;
	}

	private boolean isStructuredClassifierFeatureListened(EStructuralFeature feature) {
		if (UMLPackage.eINSTANCE.getStructuredClassifier_OwnedAttribute() == feature
				|| this.isClassifierFeatureListened(feature)) {
			return true;
		}
		return false;
	}

	private boolean isEncapsulatedClassifierFeatureListened(EStructuralFeature feature) {
		return this.isStructuredClassifierFeatureListened(feature);
	}

	private boolean isBehavioredClassifierListened(EStructuralFeature feature) {
		if (UMLPackage.eINSTANCE.getBehavioredClassifier_ClassifierBehavior() == feature
				|| UMLPackage.eINSTANCE.getBehavioredClassifier_OwnedBehavior() == feature
				|| this.isClassifierFeatureListened(feature)) {
			return true;
		}
		return false;
	}

	private boolean isClassFeatureListened(EStructuralFeature feature) {
		if (UMLPackage.eINSTANCE.getClass_IsActive() == feature
				|| UMLPackage.eINSTANCE.getClass_NestedClassifier() == feature
				|| UMLPackage.eINSTANCE.getClass_OwnedOperation() == feature
				|| UMLPackage.eINSTANCE.getClass_OwnedReception() == feature
				|| UMLPackage.eINSTANCE.getClass_SuperClass() == feature
				|| this.isEncapsulatedClassifierFeatureListened(feature)
				|| this.isBehavioredClassifierListened(feature)) {
			return true;
		}
		return false;
	}

	private boolean isAssociationFeatureListener(EStructuralFeature feature) {
		return UMLPackage.eINSTANCE.getAssociation_OwnedEnd() == feature || this.isClassifierFeatureListened(feature);
	}

	private boolean isSignalFeatureListened(EStructuralFeature feature) {
		return UMLPackage.eINSTANCE.getSignal_OwnedAttribute() == feature || this.isClassifierFeatureListened(feature);
	}

	private boolean isDatatypeFeatureListened(EStructuralFeature feature) {
		return UMLPackage.eINSTANCE.getDataType_OwnedAttribute() == feature || this.isClassifierFeatureListened(feature);
	}

	private boolean isEnumerationFeatureListened(EStructuralFeature feature) {
		return UMLPackage.eINSTANCE.getEnumeration_OwnedLiteral() == feature || this.isDatatypeFeatureListened(feature);
	}
}

Back to the top