| 1 | package de.uka.ipd.sdq.pcm.dialogs.datatype; |
| 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.swt.events.SelectionEvent; |
| 7 | import org.eclipse.swt.events.SelectionListener; |
| 8 | |
| 9 | import de.uka.ipd.sdq.pcm.dialogs.parameters.EditorContentsSelectionAction; |
| 10 | import de.uka.ipd.sdq.pcm.dialogs.parameters.UpDownButtonsValidator; |
| 11 | import de.uka.ipd.sdq.pcm.repository.CompositeDataType; |
| 12 | import de.uka.ipd.sdq.pcm.repository.InnerDeclaration; |
| 13 | |
| 14 | /** |
| 15 | * This adapter class provides default implementations for the methods described |
| 16 | * by the SelectionListener interface to downItem - Button in the |
| 17 | * CompositeDataType edit area. |
| 18 | * |
| 19 | * @author Roman Andrej |
| 20 | */ |
| 21 | public class DownInnerDeclarationAction extends EditorContentsSelectionAction |
| 22 | implements SelectionListener { |
| 23 | |
| 24 | private PalladioDataTypeDialog dialog; |
| 25 | private TransactionalEditingDomain editingDomain; |
| 26 | |
| 27 | public DownInnerDeclarationAction(PalladioDataTypeDialog dialog, TransactionalEditingDomain editingDomain) { |
| 28 | this.dialog = dialog; |
| 29 | this.editingDomain = editingDomain; |
| 30 | } |
| 31 | |
| 32 | /* (non-Javadoc) |
| 33 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
| 34 | */ |
| 35 | public void widgetSelected(SelectionEvent e) { |
| 36 | |
| 37 | final InnerDeclaration selectedDeclaration = (InnerDeclaration) getSelectedDeclaration(); |
| 38 | CompositeDataType parentDataType = (CompositeDataType) selectedDeclaration |
| 39 | .eContainer(); |
| 40 | final EList<InnerDeclaration> declarations = parentDataType |
| 41 | .getInnerDeclaration_CompositeDataType(); |
| 42 | |
| 43 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
| 44 | @Override |
| 45 | protected void doExecute() { |
| 46 | int index = declarations.indexOf(selectedDeclaration); |
| 47 | if (index >= 0 && index < declarations.size() - 1) { |
| 48 | declarations.move(index, index + 1); |
| 49 | try { |
| 50 | UpDownButtonsValidator.getSingelton().validate( |
| 51 | index + 1, declarations.size()); |
| 52 | } catch (Exception e) { |
| 53 | e.printStackTrace(); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | recCommand.setDescription("Down ..."); |
| 60 | editingDomain.getCommandStack().execute(recCommand); |
| 61 | |
| 62 | dialog.validateInput(); |
| 63 | } |
| 64 | |
| 65 | public void widgetDefaultSelected(SelectionEvent e) { |
| 66 | // TODO Auto-generated method stub |
| 67 | |
| 68 | } |
| 69 | |
| 70 | } |