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 |
15 | * described by the SelectionListener interface to downItem - Button in the |
16 | * ParameterDialog. |
17 | * |
18 | * @author Roman Roman |
19 | * |
20 | */ |
21 | public class DownParameterAction extends EditorContentsSelectionAction |
22 | implements SelectionListener { |
23 | |
24 | private Signature parentSignature; |
25 | |
26 | /** |
27 | * The transactional editing domain which is used to get the commands and |
28 | * alter the model |
29 | */ |
30 | private TransactionalEditingDomain editingDomain = null; |
31 | |
32 | public DownParameterAction(Signature signature) { |
33 | this.parentSignature = signature; |
34 | this.editingDomain = TransactionUtil.getEditingDomain(signature); |
35 | } |
36 | |
37 | /* (non-Javadoc) |
38 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
39 | */ |
40 | public void widgetSelected(SelectionEvent e) { |
41 | final Parameter selectedParameter = (Parameter) getSelectedDeclaration(); |
42 | final EList<Parameter> parameters = ParametersUtil.getParametersOfSignature(parentSignature); |
43 | |
44 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
45 | @Override |
46 | protected void doExecute() { |
47 | int index = parameters.indexOf(selectedParameter); |
48 | if (index < parameters.size() - 1) { |
49 | parameters.move(index, index + 1); |
50 | try { |
51 | UpDownButtonsValidator.getSingelton().validate( |
52 | index + 1, parameters.size()); |
53 | } catch (Exception e) { |
54 | e.printStackTrace(); |
55 | } |
56 | } |
57 | } |
58 | }; |
59 | |
60 | recCommand.setDescription("Down ..."); |
61 | editingDomain.getCommandStack().execute(recCommand); |
62 | } |
63 | |
64 | public void widgetDefaultSelected(SelectionEvent e) { |
65 | // TODO Auto-generated method stub |
66 | |
67 | } |
68 | } |