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.swt.events.SelectionAdapter; |
9 | import org.eclipse.swt.events.SelectionEvent; |
10 | |
11 | import de.uka.ipd.sdq.pcm.repository.ExceptionType; |
12 | import de.uka.ipd.sdq.pcm.repository.RepositoryFactory; |
13 | import de.uka.ipd.sdq.pcm.repository.Signature; |
14 | |
15 | /** |
16 | * @author roman |
17 | */ |
18 | public class AddExceptionTypeAction extends SelectionAdapter{ |
19 | |
20 | private Signature parentSignature; |
21 | |
22 | /** |
23 | * The transactional editing domain which is used to get the commands and |
24 | * alter the model |
25 | */ |
26 | protected TransactionalEditingDomain editingDomain = null; |
27 | |
28 | public AddExceptionTypeAction(Signature parentSignature) { |
29 | this.parentSignature = parentSignature; |
30 | this.editingDomain = TransactionUtil.getEditingDomain(parentSignature); |
31 | } |
32 | |
33 | /* |
34 | * (non-Javadoc) |
35 | * |
36 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
37 | */ |
38 | @Override |
39 | public void widgetSelected(SelectionEvent e) { |
40 | Assert.isNotNull(parentSignature); |
41 | |
42 | final EList<ExceptionType> exceptions = parentSignature |
43 | .getExceptions__Signature(); |
44 | |
45 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
46 | @Override |
47 | protected void doExecute() { |
48 | ExceptionType exceptionType = RepositoryFactory.eINSTANCE |
49 | .createExceptionType(); |
50 | exceptionType.setExceptionName("ExceptionName" + (exceptions.size() + 1)); |
51 | exceptions.add(exceptionType); |
52 | } |
53 | }; |
54 | |
55 | recCommand.setDescription("Add new ExceptionType to the signature"); |
56 | editingDomain.getCommandStack().execute(recCommand); |
57 | } |
58 | } |