| 1 | package de.uka.ipd.sdq.pcm.dialogs.datatype; |
| 2 | |
| 3 | import org.eclipse.emf.transaction.RecordingCommand; |
| 4 | import org.eclipse.emf.transaction.TransactionalEditingDomain; |
| 5 | import org.eclipse.swt.events.SelectionAdapter; |
| 6 | import org.eclipse.swt.events.SelectionEvent; |
| 7 | |
| 8 | import de.uka.ipd.sdq.pcm.repository.CompositeDataType; |
| 9 | import de.uka.ipd.sdq.pcm.repository.InnerDeclaration; |
| 10 | import de.uka.ipd.sdq.pcm.repository.RepositoryFactory; |
| 11 | |
| 12 | /** |
| 13 | * The class define an action, which a new InnerDeclaration to the CompositeDateType adds. |
| 14 | * |
| 15 | * @author Roman Andrej |
| 16 | */ |
| 17 | public class AddInnerDeclarationAction extends SelectionAdapter { |
| 18 | |
| 19 | private CompositeDataType compositeDataType; |
| 20 | private PalladioDataTypeDialog dialog; |
| 21 | |
| 22 | /** |
| 23 | * The transactional editing domain which is used to get the commands and |
| 24 | * alter the model |
| 25 | */ |
| 26 | private TransactionalEditingDomain editingDomain = null; |
| 27 | |
| 28 | /** |
| 29 | * @param compositeDataType |
| 30 | */ |
| 31 | public AddInnerDeclarationAction(PalladioDataTypeDialog dialog, TransactionalEditingDomain editingDomain) { |
| 32 | this.dialog = dialog; |
| 33 | this.editingDomain = editingDomain; |
| 34 | this.compositeDataType = dialog.getCompositeDataType(); |
| 35 | } |
| 36 | |
| 37 | /* |
| 38 | * (non-Javadoc) |
| 39 | * |
| 40 | * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
| 41 | */ |
| 42 | @Override |
| 43 | public void widgetSelected(SelectionEvent e) { |
| 44 | |
| 45 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
| 46 | @Override |
| 47 | protected void doExecute() { |
| 48 | |
| 49 | if (compositeDataType == null) { |
| 50 | // nur for own instance of the compositeDataType |
| 51 | compositeDataType = RepositoryFactory.eINSTANCE |
| 52 | .createCompositeDataType(); |
| 53 | } |
| 54 | InnerDeclaration declaration = RepositoryFactory.eINSTANCE |
| 55 | .createInnerDeclaration(); |
| 56 | // Build the name with count |
| 57 | String declaratonName = "DeclarationName" |
| 58 | + (compositeDataType |
| 59 | .getInnerDeclaration_CompositeDataType().size() + 1); |
| 60 | |
| 61 | declaration.setEntityName(declaratonName); |
| 62 | |
| 63 | compositeDataType.getInnerDeclaration_CompositeDataType().add( |
| 64 | declaration); |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | recCommand.setDescription("Add new CompositeDataTYpe"); |
| 69 | editingDomain.getCommandStack().execute(recCommand); |
| 70 | |
| 71 | /** |
| 72 | * set and validate a new CompositeDataType |
| 73 | */ |
| 74 | dialog.setCompositeDataType(compositeDataType); |
| 75 | dialog.getEditorContents().setViewerInput(compositeDataType); |
| 76 | dialog.validateInput(); |
| 77 | } |
| 78 | } |