1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.pcmbench.tabs.parameters; |
5 | |
6 | import org.eclipse.emf.transaction.RecordingCommand; |
7 | import org.eclipse.emf.transaction.TransactionalEditingDomain; |
8 | import org.eclipse.emf.transaction.util.TransactionUtil; |
9 | import org.eclipse.swt.events.SelectionAdapter; |
10 | import org.eclipse.swt.events.SelectionEvent; |
11 | |
12 | import de.uka.ipd.sdq.pcm.core.CoreFactory; |
13 | import de.uka.ipd.sdq.pcm.core.PCMRandomVariable; |
14 | import de.uka.ipd.sdq.pcm.core.composition.AssemblyContext; |
15 | import de.uka.ipd.sdq.pcm.parameter.ParameterFactory; |
16 | import de.uka.ipd.sdq.pcm.parameter.VariableCharacterisation; |
17 | import de.uka.ipd.sdq.pcm.parameter.VariableUsage; |
18 | import de.uka.ipd.sdq.stoex.NamespaceReference; |
19 | import de.uka.ipd.sdq.stoex.StoexFactory; |
20 | import de.uka.ipd.sdq.stoex.VariableReference; |
21 | |
22 | /** |
23 | * @author Roman Andrej |
24 | * |
25 | */ |
26 | public class AddComponentParameterAction extends SelectionAdapter { |
27 | |
28 | private AssemblyContext context; |
29 | |
30 | /** |
31 | * The transactional editing domain which is used to get the commands and |
32 | * alter the model |
33 | */ |
34 | private TransactionalEditingDomain editingDomain = null; |
35 | |
36 | |
37 | /* (non-Javadoc) |
38 | * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
39 | */ |
40 | @Override |
41 | public void widgetSelected(SelectionEvent e) { |
42 | editingDomain = TransactionUtil.getEditingDomain(context); |
43 | |
44 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
45 | @Override |
46 | protected void doExecute() { |
47 | NamespaceReference namespaceReference = StoexFactory.eINSTANCE |
48 | .createNamespaceReference(); |
49 | namespaceReference.setReferenceName("ReferenceName"); |
50 | |
51 | VariableReference variableReference = StoexFactory.eINSTANCE |
52 | .createVariableReference(); |
53 | variableReference.setReferenceName("INNER"); |
54 | |
55 | namespaceReference |
56 | .setInnerReference_NamespaceReference(variableReference); |
57 | VariableUsage variableUsage = ParameterFactory.eINSTANCE |
58 | .createVariableUsage(); |
59 | variableUsage |
60 | .setNamedReference__VariableUsage(namespaceReference); |
61 | |
62 | PCMRandomVariable randomVariable = CoreFactory.eINSTANCE |
63 | .createPCMRandomVariable(); |
64 | randomVariable.setSpecification("0"); |
65 | |
66 | VariableCharacterisation characterisation = ParameterFactory.eINSTANCE |
67 | .createVariableCharacterisation(); |
68 | |
69 | characterisation |
70 | .setSpecification_VariableCharacterisation(randomVariable); |
71 | variableUsage.getVariableCharacterisation_VariableUsage().add( |
72 | characterisation); |
73 | |
74 | context.getConfigParameterUsages__AssemblyContext().add( |
75 | variableUsage); |
76 | } |
77 | }; |
78 | |
79 | recCommand.setDescription("Add new VariableUsage"); |
80 | editingDomain.getCommandStack().execute(recCommand); |
81 | } |
82 | |
83 | |
84 | /** |
85 | * @param context the context to set |
86 | */ |
87 | public void setContext(AssemblyContext context) { |
88 | this.context = context; |
89 | } |
90 | } |