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.SelectionAdapter; |
8 | import org.eclipse.swt.events.SelectionEvent; |
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.pcm.repository.RepositoryFactory; |
13 | |
14 | public class OperationAddActionListener extends SelectionAdapter { |
15 | |
16 | /** |
17 | * Define the selected interface. The variable is set not during the class |
18 | * production, separates later. |
19 | */ |
20 | private OperationInterface selectedInterface; |
21 | |
22 | /* (non-Javadoc) |
23 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
24 | */ |
25 | @Override |
26 | public void widgetSelected(SelectionEvent e) { |
27 | Assert.isNotNull(selectedInterface); |
28 | |
29 | /** |
30 | * The transactional editing domain which is used to get the commands |
31 | * and alter the model |
32 | */ |
33 | TransactionalEditingDomain editingDomain = TransactionUtil |
34 | .getEditingDomain(selectedInterface); |
35 | |
36 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
37 | @Override |
38 | protected void doExecute() { |
39 | OperationSignature signature = RepositoryFactory.eINSTANCE |
40 | .createOperationSignature(); |
41 | signature |
42 | .setEntityName("ServiceName" |
43 | + (selectedInterface.getSignatures__OperationInterface() |
44 | .size() + 1)); |
45 | selectedInterface.getSignatures__OperationInterface().add(signature); |
46 | } |
47 | }; |
48 | |
49 | recCommand.setDescription("Add new signature"); |
50 | editingDomain.getCommandStack().execute(recCommand); |
51 | } |
52 | |
53 | /** |
54 | * @return the selectedInterface |
55 | */ |
56 | public OperationInterface getSelectedInterface() { |
57 | return selectedInterface; |
58 | } |
59 | |
60 | /** |
61 | * @param selectedInterface the selectedInterface to set |
62 | */ |
63 | public void setSelectedInterface(OperationInterface selectedInterface) { |
64 | this.selectedInterface = selectedInterface; |
65 | } |
66 | } |