| 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.repository.CompositeDataType; |
| 11 | import de.uka.ipd.sdq.pcm.repository.InnerDeclaration; |
| 12 | |
| 13 | /** |
| 14 | * The class define an action, which a InnerDeclaration for the |
| 15 | * CompositeDataType delete. |
| 16 | * |
| 17 | * @author Roman Andrej |
| 18 | */ |
| 19 | public class DeleteInnerDeclarationAction extends EditorContentsSelectionAction |
| 20 | implements SelectionListener { |
| 21 | |
| 22 | private PalladioDataTypeDialog dialog; |
| 23 | private TransactionalEditingDomain editingDomain; |
| 24 | |
| 25 | public DeleteInnerDeclarationAction(PalladioDataTypeDialog dialog, TransactionalEditingDomain editingDomain) { |
| 26 | this.dialog = dialog; |
| 27 | this.editingDomain = editingDomain; |
| 28 | } |
| 29 | |
| 30 | /* (non-Javadoc) |
| 31 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
| 32 | */ |
| 33 | public void widgetSelected(SelectionEvent e) { |
| 34 | |
| 35 | final InnerDeclaration selectedDeclaration = (InnerDeclaration) getSelectedDeclaration(); |
| 36 | CompositeDataType parentDataType = (CompositeDataType) selectedDeclaration |
| 37 | .eContainer(); |
| 38 | final EList<InnerDeclaration> declarations = parentDataType |
| 39 | .getInnerDeclaration_CompositeDataType(); |
| 40 | |
| 41 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
| 42 | @Override |
| 43 | protected void doExecute() { |
| 44 | declarations.remove(selectedDeclaration); |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | recCommand.setDescription("Delete ..."); |
| 49 | editingDomain.getCommandStack().execute(recCommand); |
| 50 | // validate the innerdeclaration |
| 51 | dialog.validateInput(); |
| 52 | } |
| 53 | |
| 54 | public void widgetDefaultSelected(SelectionEvent e) { |
| 55 | // TODO Auto-generated method stub |
| 56 | |
| 57 | } |
| 58 | } |