| 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.OperationInterface; |
| 11 | import de.uka.ipd.sdq.pcm.repository.OperationSignature; |
| 12 | import de.uka.ipd.sdq.pcmbench.tabs.generic.SelectionChangedListener; |
| 13 | |
| 14 | public class OperationDeleteActionListener 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 OperationSignature selectedSignature = (OperationSignature) getSelectedElement(); |
| 29 | Assert.isNotNull(selectedSignature); |
| 30 | final OperationInterface selectedInterface = (OperationInterface) selectedSignature |
| 31 | .getInterface__OperationSignature(); |
| 32 | Assert.isNotNull(selectedInterface); |
| 33 | editingDomain = TransactionUtil.getEditingDomain(selectedSignature); |
| 34 | |
| 35 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
| 36 | @Override |
| 37 | protected void doExecute() { |
| 38 | selectedInterface.getSignatures__OperationInterface().remove( |
| 39 | selectedSignature); |
| 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 | } |