| 1 | /* |
| 2 | * Copyright 2007, IPD, SDQ, University of Karlsruhe |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.repository.edit.commands; |
| 5 | |
| 6 | import java.util.Collections; |
| 7 | import java.util.Iterator; |
| 8 | import java.util.List; |
| 9 | |
| 10 | import org.eclipse.core.commands.ExecutionException; |
| 11 | import org.eclipse.core.runtime.IAdaptable; |
| 12 | import org.eclipse.core.runtime.IProgressMonitor; |
| 13 | import org.eclipse.emf.ecore.EAnnotation; |
| 14 | import org.eclipse.emf.ecore.EcoreFactory; |
| 15 | import org.eclipse.emf.transaction.TransactionalEditingDomain; |
| 16 | import org.eclipse.gmf.runtime.common.core.command.CommandResult; |
| 17 | import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest; |
| 18 | import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; |
| 19 | import org.eclipse.gmf.runtime.notation.View; |
| 20 | |
| 21 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.parts.RepositoryEditPart; |
| 22 | |
| 23 | /** |
| 24 | * @generated |
| 25 | */ |
| 26 | public class PalladioComponentModelCreateShortcutDecorationsCommand extends |
| 27 | AbstractTransactionalCommand { |
| 28 | |
| 29 | /** |
| 30 | * @generated |
| 31 | */ |
| 32 | private List myDescriptors; |
| 33 | |
| 34 | /** |
| 35 | * @generated |
| 36 | */ |
| 37 | public PalladioComponentModelCreateShortcutDecorationsCommand( |
| 38 | TransactionalEditingDomain editingDomain, View parentView, |
| 39 | List viewDescriptors) { |
| 40 | super(editingDomain, "Create Shortcuts", getWorkspaceFiles(parentView)); //$NON-NLS-1$ |
| 41 | myDescriptors = viewDescriptors; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @generated |
| 46 | */ |
| 47 | public PalladioComponentModelCreateShortcutDecorationsCommand( |
| 48 | TransactionalEditingDomain editingDomain, View parentView, |
| 49 | CreateViewRequest.ViewDescriptor viewDescriptor) { |
| 50 | this(editingDomain, parentView, Collections |
| 51 | .singletonList(viewDescriptor)); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @generated |
| 56 | */ |
| 57 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
| 58 | IAdaptable info) throws ExecutionException { |
| 59 | for (Iterator it = myDescriptors.iterator(); it.hasNext();) { |
| 60 | CreateViewRequest.ViewDescriptor nextDescriptor = (CreateViewRequest.ViewDescriptor) it |
| 61 | .next(); |
| 62 | View view = (View) nextDescriptor.getAdapter(View.class); |
| 63 | if (view != null && view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ |
| 64 | EAnnotation shortcutAnnotation = EcoreFactory.eINSTANCE |
| 65 | .createEAnnotation(); |
| 66 | shortcutAnnotation.setSource("Shortcut"); //$NON-NLS-1$ |
| 67 | shortcutAnnotation.getDetails().put( |
| 68 | "modelID", RepositoryEditPart.MODEL_ID); //$NON-NLS-1$ |
| 69 | view.getEAnnotations().add(shortcutAnnotation); |
| 70 | } |
| 71 | } |
| 72 | return CommandResult.newOKCommandResult(); |
| 73 | } |
| 74 | |
| 75 | } |