1 | package de.uka.ipd.sdq.pcm.dialogs.parameters; |
2 | |
3 | import org.eclipse.emf.common.util.EList; |
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.SelectionEvent; |
8 | import org.eclipse.swt.events.SelectionListener; |
9 | |
10 | import de.uka.ipd.sdq.pcm.repository.Parameter; |
11 | import de.uka.ipd.sdq.pcm.repository.Signature; |
12 | |
13 | /** |
14 | * This adapter class provides default implementations for the methods described |
15 | * by the SelectionListener interface to upItem - Button in the ParameterDialog. |
16 | * |
17 | * @author Roman Andrej |
18 | */ |
19 | public class UpParameterAction extends EditorContentsSelectionAction |
20 | implements SelectionListener { |
21 | |
22 | private Signature parentSignature; |
23 | |
24 | /** |
25 | * The transactional editing domain which is used to get the commands and |
26 | * alter the model |
27 | */ |
28 | protected TransactionalEditingDomain editingDomain = null; |
29 | |
30 | public UpParameterAction(Signature signature) { |
31 | this.parentSignature = signature; |
32 | this.editingDomain = TransactionUtil.getEditingDomain(signature); |
33 | } |
34 | |
35 | /* (non-Javadoc) |
36 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
37 | */ |
38 | public void widgetSelected(SelectionEvent e) { |
39 | final Parameter selectedParameter = (Parameter) getSelectedDeclaration(); |
40 | final EList<Parameter> parameters = ParametersUtil.getParametersOfSignature(parentSignature); |
41 | |
42 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
43 | @Override |
44 | protected void doExecute() { |
45 | int index = parameters.indexOf(selectedParameter); |
46 | if (index != 0) { |
47 | parameters.move(index, index - 1); |
48 | try { |
49 | UpDownButtonsValidator.getSingelton().validate( |
50 | index - 1, parameters.size()); |
51 | } catch (Exception e) { |
52 | e.printStackTrace(); |
53 | } |
54 | } |
55 | } |
56 | }; |
57 | |
58 | recCommand.setDescription("Up ..."); |
59 | editingDomain.getCommandStack().execute(recCommand); |
60 | } |
61 | |
62 | public void widgetDefaultSelected(SelectionEvent e) { |
63 | // TODO Auto-generated method stub |
64 | |
65 | } |
66 | } |