1 | package de.uka.ipd.sdq.pcmbench.tabs.operations; |
2 | |
3 | import org.eclipse.core.runtime.Assert; |
4 | import org.eclipse.emf.transaction.RecordingCommand; |
5 | import org.eclipse.emf.transaction.TransactionalEditingDomain; |
6 | import org.eclipse.emf.transaction.util.TransactionUtil; |
7 | import org.eclipse.swt.events.SelectionAdapter; |
8 | import org.eclipse.swt.events.SelectionEvent; |
9 | |
10 | import de.uka.ipd.sdq.pcm.repository.EventGroup; |
11 | import de.uka.ipd.sdq.pcm.repository.EventType; |
12 | import de.uka.ipd.sdq.pcm.repository.Parameter; |
13 | import de.uka.ipd.sdq.pcm.repository.PrimitiveDataType; |
14 | import de.uka.ipd.sdq.pcm.repository.PrimitiveTypeEnum; |
15 | import de.uka.ipd.sdq.pcm.repository.RepositoryFactory; |
16 | |
17 | /** |
18 | * Event Listener for the creation of a new event type. |
19 | * |
20 | * This event listener initialises the new event type. |
21 | * I.e. it sets the default event type name and adds a default parameter. |
22 | * |
23 | * @author Benjamin Klatt |
24 | * |
25 | */ |
26 | public class EventTypeAddActionListener extends SelectionAdapter { |
27 | |
28 | /** |
29 | * Define the selected interface. The variable is set not during the class |
30 | * production, separates later. |
31 | */ |
32 | private EventGroup selectedEventGroup; |
33 | |
34 | /* (non-Javadoc) |
35 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
36 | */ |
37 | @Override |
38 | public void widgetSelected(SelectionEvent e) { |
39 | Assert.isNotNull(selectedEventGroup); |
40 | |
41 | /** |
42 | * The transactional editing domain which is used to get the commands |
43 | * and alter the model |
44 | */ |
45 | TransactionalEditingDomain editingDomain = TransactionUtil |
46 | .getEditingDomain(selectedEventGroup); |
47 | |
48 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
49 | @Override |
50 | protected void doExecute() { |
51 | |
52 | // create the new event type |
53 | EventType eventType = RepositoryFactory.eINSTANCE |
54 | .createEventType(); |
55 | eventType |
56 | .setEntityName("EventTypeName" |
57 | + (selectedEventGroup.getEventTypes__EventGroup() |
58 | .size() + 1)); |
59 | |
60 | // create the event content parameter with a default name and String data type |
61 | Parameter parameter = RepositoryFactory.eINSTANCE.createParameter(); |
62 | parameter.setParameterName("eventConent"); |
63 | PrimitiveDataType dataType = RepositoryFactory.eINSTANCE.createPrimitiveDataType(); |
64 | dataType.setType(PrimitiveTypeEnum.STRING); |
65 | parameter.setDataType__Parameter(dataType); |
66 | eventType.setParameter__EventType(parameter); |
67 | |
68 | // add the prepared event type |
69 | selectedEventGroup.getEventTypes__EventGroup().add(eventType); |
70 | } |
71 | }; |
72 | |
73 | recCommand.setDescription("Add new event type"); |
74 | editingDomain.getCommandStack().execute(recCommand); |
75 | } |
76 | |
77 | /** |
78 | * @return the selected event group |
79 | */ |
80 | public EventGroup getSelectedEventGroup() { |
81 | return selectedEventGroup; |
82 | } |
83 | |
84 | /** |
85 | * @param selectedEventGroup The event group to set |
86 | */ |
87 | public void setSelectedInterface(EventGroup selectedEventGroup) { |
88 | this.selectedEventGroup = selectedEventGroup; |
89 | } |
90 | } |