| 1 | package de.uka.ipd.sdq.pcm.dialogs.exception; |
| 2 | |
| 3 | import org.eclipse.core.runtime.Assert; |
| 4 | import org.eclipse.emf.common.util.EList; |
| 5 | import org.eclipse.emf.transaction.RecordingCommand; |
| 6 | import org.eclipse.emf.transaction.TransactionalEditingDomain; |
| 7 | import org.eclipse.emf.transaction.util.TransactionUtil; |
| 8 | import org.eclipse.jface.viewers.ISelectionChangedListener; |
| 9 | import org.eclipse.jface.viewers.IStructuredSelection; |
| 10 | import org.eclipse.jface.viewers.SelectionChangedEvent; |
| 11 | import org.eclipse.swt.events.SelectionAdapter; |
| 12 | import org.eclipse.swt.events.SelectionEvent; |
| 13 | |
| 14 | import de.uka.ipd.sdq.pcm.repository.ExceptionType; |
| 15 | import de.uka.ipd.sdq.pcm.repository.Signature; |
| 16 | |
| 17 | /** @author roman */ |
| 18 | public class DeleteExctentionAction extends SelectionAdapter implements ISelectionChangedListener { |
| 19 | |
| 20 | private Signature parentSignature; |
| 21 | private ExceptionType exceptionType = null; |
| 22 | |
| 23 | /** |
| 24 | * The transactional editing domain which is used to get the commands and |
| 25 | * alter the model |
| 26 | */ |
| 27 | protected TransactionalEditingDomain editingDomain = null; |
| 28 | |
| 29 | public DeleteExctentionAction(Signature signature) { |
| 30 | this.parentSignature = signature; |
| 31 | this.editingDomain = TransactionUtil.getEditingDomain(signature); |
| 32 | } |
| 33 | |
| 34 | /* (non-Javadoc) |
| 35 | * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) |
| 36 | */ |
| 37 | public void selectionChanged(SelectionChangedEvent event) { |
| 38 | IStructuredSelection sel = (IStructuredSelection) event.getSelection(); |
| 39 | Object selection = (Object) sel.getFirstElement(); |
| 40 | this.exceptionType = (ExceptionType) selection; |
| 41 | } |
| 42 | |
| 43 | /* (non-Javadoc) |
| 44 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
| 45 | */ |
| 46 | @Override |
| 47 | public void widgetSelected(SelectionEvent e) { |
| 48 | Assert.isNotNull(exceptionType); |
| 49 | final EList<ExceptionType> exceptions = parentSignature.getExceptions__Signature(); |
| 50 | |
| 51 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
| 52 | @Override |
| 53 | protected void doExecute() { |
| 54 | exceptions.remove(exceptionType); |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | recCommand.setDescription("Delete ..."); |
| 59 | editingDomain.getCommandStack().execute(recCommand); |
| 60 | } |
| 61 | } |