1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.seff.helper; |
5 | |
6 | import java.util.ArrayList; |
7 | |
8 | import org.eclipse.emf.ecore.EObject; |
9 | import org.eclipse.emf.ecore.EReference; |
10 | import org.eclipse.gmf.runtime.common.core.command.ICommand; |
11 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice; |
12 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice; |
13 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
14 | import org.eclipse.ui.PlatformUI; |
15 | |
16 | import de.uka.ipd.sdq.pcm.dialogs.selection.PalladioSelectEObjectDialog; |
17 | import de.uka.ipd.sdq.pcm.repository.BasicComponent; |
18 | import de.uka.ipd.sdq.pcm.repository.EventGroup; |
19 | import de.uka.ipd.sdq.pcm.repository.EventType; |
20 | import de.uka.ipd.sdq.pcm.repository.RepositoryPackage; |
21 | import de.uka.ipd.sdq.pcm.repository.SourceRole; |
22 | |
23 | /** |
24 | * Edit helper for the EmitEventAction. |
25 | * Features are: |
26 | * - Open EventType selection dialog when EmitEventAction is created |
27 | * |
28 | * @author Benjamin Klatt |
29 | * |
30 | */ |
31 | public class EmitEventActionEditHelperAdvice extends |
32 | AbstractEditHelperAdvice implements IEditHelperAdvice { |
33 | |
34 | /** |
35 | * When an EmitEventAction is created: |
36 | * - Open the dialog to select an EventType this action is able to emit |
37 | * - Get the selected EventType and store it in the action |
38 | * |
39 | * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterConfigureCommand(org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest) |
40 | */ |
41 | @Override |
42 | protected ICommand getAfterConfigureCommand(ConfigureRequest request) { |
43 | EObject eObject = searchBasicComponent(request.getElementToConfigure()); |
44 | SourceRole sourceRole = null; |
45 | |
46 | // define the filter list |
47 | ArrayList<Object> filterList = new ArrayList<Object>(); |
48 | filterList.add(SourceRole.class); |
49 | filterList.add(EventGroup.class); |
50 | filterList.add(EventType.class); |
51 | |
52 | // define the additional references |
53 | ArrayList<EReference> additionalReferences = new ArrayList<EReference>(); |
54 | additionalReferences.add(RepositoryPackage.eINSTANCE |
55 | .getSourceRole_EventGroup__SourceRole()); |
56 | |
57 | // create the dialog |
58 | PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog( |
59 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
60 | filterList, additionalReferences, eObject); |
61 | dialog.setProvidedService(EventType.class); |
62 | dialog.open(); |
63 | if (dialog.getResult() == null) |
64 | return new CanceledCommand(); |
65 | if (!(dialog.getResult() instanceof EventType)) |
66 | return new CanceledCommand(); |
67 | |
68 | // set the EventType for EmitEventAction |
69 | EventType eventType = (EventType) dialog.getResult(); |
70 | |
71 | // set the required role for EmitEventAction |
72 | if (dialog.getViewerRootElement() instanceof SourceRole) { |
73 | sourceRole = (SourceRole) dialog.getRootOfResult(); |
74 | } |
75 | |
76 | // create and execute the EmitEventActionConfigureCommand command |
77 | return new EmitEventActionConfigureCommand(request, eventType, |
78 | sourceRole); |
79 | } |
80 | |
81 | private EObject searchBasicComponent(EObject elementToConfigure) { |
82 | EObject o = elementToConfigure; |
83 | while (!(o instanceof BasicComponent)) |
84 | o = o.eContainer(); |
85 | return o; |
86 | } |
87 | } |