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.InfrastructureInterface; |
11 | import de.uka.ipd.sdq.pcm.repository.InfrastructureSignature; |
12 | import de.uka.ipd.sdq.pcmbench.tabs.generic.SelectionChangedListener; |
13 | |
14 | /**Removes selected signatures from an infrastructure interface. |
15 | * @author groenda |
16 | * |
17 | */ |
18 | public class InfrastructureSignatureDeleteActionListener extends SelectionChangedListener implements SelectionListener { |
19 | |
20 | /** |
21 | * The transactional editing domain which is used to get the commands and |
22 | * alter the model |
23 | */ |
24 | private TransactionalEditingDomain editingDomain = null; |
25 | |
26 | |
27 | /* (non-Javadoc) |
28 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
29 | */ |
30 | public void widgetSelected(SelectionEvent e) { |
31 | |
32 | final InfrastructureSignature selectedSignature = (InfrastructureSignature) getSelectedElement(); |
33 | Assert.isNotNull(selectedSignature); |
34 | final InfrastructureInterface selectedInterface = (InfrastructureInterface) selectedSignature |
35 | .getInfrastructureInterface__InfrastructureSignature(); |
36 | Assert.isNotNull(selectedInterface); |
37 | editingDomain = TransactionUtil.getEditingDomain(selectedSignature); |
38 | |
39 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
40 | @Override |
41 | protected void doExecute() { |
42 | selectedInterface.getInfrastructureSignatures__InfrastructureInterface().remove( |
43 | selectedSignature); |
44 | } |
45 | }; |
46 | |
47 | recCommand.setDescription("Delete ..."); |
48 | editingDomain.getCommandStack().execute(recCommand); |
49 | } |
50 | |
51 | /* (non-Javadoc) |
52 | * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) |
53 | */ |
54 | public void widgetDefaultSelected(SelectionEvent e) { |
55 | // The implementation is not necessary. |
56 | } |
57 | } |