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.InfrastructureInterface; |
11 | import de.uka.ipd.sdq.pcm.repository.InfrastructureSignature; |
12 | import de.uka.ipd.sdq.pcm.repository.RepositoryFactory; |
13 | |
14 | public class InfrastructureSignatureAddActionListener extends SelectionAdapter { |
15 | |
16 | /** |
17 | * Define the selected interface. The variable is set not during the class |
18 | * production, separates later. |
19 | */ |
20 | private InfrastructureInterface 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 | InfrastructureSignature signature = RepositoryFactory.eINSTANCE |
40 | .createInfrastructureSignature(); |
41 | signature |
42 | .setEntityName("Signature" |
43 | + (selectedInterface.getInfrastructureSignatures__InfrastructureInterface() |
44 | .size() + 1)); |
45 | selectedInterface.getInfrastructureSignatures__InfrastructureInterface().add(signature); |
46 | } |
47 | }; |
48 | |
49 | recCommand.setDescription("Add new infrastructure signature"); |
50 | editingDomain.getCommandStack().execute(recCommand); |
51 | } |
52 | |
53 | /** |
54 | * @return the selected infrastructure interface |
55 | */ |
56 | public InfrastructureInterface getSelectedInterface() { |
57 | return selectedInterface; |
58 | } |
59 | |
60 | /** |
61 | * @param selectedInterface the selected infrastructure interface to set |
62 | */ |
63 | public void setSelectedInterface(InfrastructureInterface selectedInterface) { |
64 | this.selectedInterface = selectedInterface; |
65 | } |
66 | } |