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.SelectionEvent; |
8 | import org.eclipse.swt.events.SelectionListener; |
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.pcmbench.tabs.generic.SelectionChangedListener; |
13 | |
14 | public class EventTypeDeleteActionListener extends SelectionChangedListener implements SelectionListener { |
15 | |
16 | /** |
17 | * The transactional editing domain which is used to get the commands and |
18 | * alter the model |
19 | */ |
20 | private TransactionalEditingDomain editingDomain = null; |
21 | |
22 | |
23 | /* (non-Javadoc) |
24 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
25 | */ |
26 | public void widgetSelected(SelectionEvent e) { |
27 | |
28 | final EventType selectedEventType = (EventType) getSelectedElement(); |
29 | Assert.isNotNull(selectedEventType); |
30 | final EventGroup selectedEventGroup = (EventGroup) selectedEventType |
31 | .getEventGroup__EventType(); |
32 | Assert.isNotNull(selectedEventGroup); |
33 | editingDomain = TransactionUtil.getEditingDomain(selectedEventType); |
34 | |
35 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
36 | @Override |
37 | protected void doExecute() { |
38 | selectedEventGroup.getEventTypes__EventGroup().remove( |
39 | selectedEventType); |
40 | } |
41 | }; |
42 | |
43 | recCommand.setDescription("Delete ..."); |
44 | editingDomain.getCommandStack().execute(recCommand); |
45 | } |
46 | |
47 | /* (non-Javadoc) |
48 | * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) |
49 | */ |
50 | public void widgetDefaultSelected(SelectionEvent e) { |
51 | // The implementation is not necessary. |
52 | } |
53 | } |