blob: 60fe4c5d8e045856c6d5879fa4316a807b44fbd8 (
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
|
/*****************************************************************************
* Copyright (c) 2012 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:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.profilefacet.listener;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.TriggerListener;
import org.eclipse.papyrus.uml.profilefacet.metamodel.profilefacet.ProfileFacetSet;
import org.eclipse.papyrus.uml.profilefacet.utils.ProfileFacetSetDestroyer;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.ProfileApplication;
/**
*
* This trigger listener listen the profile application to manage the existing {@link ProfileFacetSet} in the model
*
*/
public class ReapplyProfileTriggerListener extends TriggerListener {
/**
*
* @see org.eclipse.emf.transaction.TriggerListener#trigger(org.eclipse.emf.transaction.TransactionalEditingDomain,
* org.eclipse.emf.common.notify.Notification)
*
* @param domain
* @param notification
* @return
*/
@Override
protected Command trigger(final TransactionalEditingDomain domain, final Notification notification) {
final int eventType = notification.getEventType();
final Object notifier = notification.getNotifier();
final Object newValue = notification.getNewValue();
if(eventType == Notification.SET && newValue instanceof EPackage && notifier instanceof EAnnotation) {
Profile appliedProfile = getAppliedProfile((EAnnotation)notifier);
while(appliedProfile.eContainer() != null) {
appliedProfile = (Profile)appliedProfile.eContainer();
}
if(appliedProfile != null) {
return getUpdateFacetSetCommand(appliedProfile);
}
}
return null;
}
/**
*
* @param profile
* a profile
* @return
* the command to update the ProfileFacetSets which references this profile or <code>null</code>
*/
protected Command getUpdateFacetSetCommand(final Profile profile) {
final ProfileFacetSetDestroyer updater = new ProfileFacetSetDestroyer(profile);
final Command cmd = updater.getDestroyFacetSetCommand();
if(cmd != null && cmd.canExecute()) {
return cmd;
}
return null;
}
/**
*
* @param annotation
* an eannotation
* @return
* the profile referenced by the eannotation or <code>null</code>
*/
protected Profile getAppliedProfile(final EAnnotation annotation) {
final EObject container = annotation.eContainer();
if(container instanceof ProfileApplication) {
return ((ProfileApplication)container).getAppliedProfile();
}
return null;
}
}
|