| 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 upItem - Button in the ColpositeDataType edit area. |
| 17 | * |
| 18 | * @author Roman Andrej |
| 19 | */ |
| 20 | public class UpInnerDeclarationAction extends EditorContentsSelectionAction implements |
| 21 | SelectionListener { |
| 22 | |
| 23 | private PalladioDataTypeDialog dialog; |
| 24 | private TransactionalEditingDomain editingDomain; |
| 25 | |
| 26 | public UpInnerDeclarationAction(PalladioDataTypeDialog dialog, TransactionalEditingDomain editingDomain) { |
| 27 | this.dialog = dialog; |
| 28 | this.editingDomain = editingDomain; |
| 29 | } |
| 30 | |
| 31 | /* (non-Javadoc) |
| 32 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
| 33 | */ |
| 34 | public void widgetSelected(SelectionEvent e) { |
| 35 | |
| 36 | final InnerDeclaration selectedDeclaration = (InnerDeclaration) getSelectedDeclaration(); |
| 37 | CompositeDataType parentDataType = (CompositeDataType) selectedDeclaration |
| 38 | .eContainer(); |
| 39 | final EList<InnerDeclaration> declarations = parentDataType |
| 40 | .getInnerDeclaration_CompositeDataType(); |
| 41 | |
| 42 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
| 43 | @Override |
| 44 | protected void doExecute() { |
| 45 | int index = declarations.indexOf(selectedDeclaration); |
| 46 | if (index > 0) { |
| 47 | declarations.move(index, index - 1); |
| 48 | try { |
| 49 | UpDownButtonsValidator.getSingelton().validate( |
| 50 | index - 1, declarations.size()); |
| 51 | } catch (Exception e) { |
| 52 | e.printStackTrace(); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | recCommand.setDescription("Up ..."); |
| 59 | editingDomain.getCommandStack().execute(recCommand); |
| 60 | |
| 61 | dialog.validateInput(); |
| 62 | } |
| 63 | |
| 64 | public void widgetDefaultSelected(SelectionEvent e) { |
| 65 | // TODO Auto-generated method stub |
| 66 | } |
| 67 | } |