| 1 | /* |
| 2 | *Copyright 2007, SDQ, IPD, U KA |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.allocation.part; |
| 5 | |
| 6 | import org.eclipse.emf.edit.ui.action.LoadResourceAction; |
| 7 | import org.eclipse.emf.edit.ui.action.LoadResourceAction.LoadResourceDialog; |
| 8 | import org.eclipse.jface.action.IAction; |
| 9 | import org.eclipse.jface.viewers.ISelection; |
| 10 | import org.eclipse.jface.viewers.IStructuredSelection; |
| 11 | import org.eclipse.swt.widgets.Shell; |
| 12 | import org.eclipse.ui.IObjectActionDelegate; |
| 13 | import org.eclipse.ui.IWorkbenchPart; |
| 14 | import de.uka.ipd.sdq.pcm.gmf.allocation.edit.parts.AllocationEditPart; |
| 15 | |
| 16 | /** |
| 17 | * @generated |
| 18 | */ |
| 19 | public class PalladioComponentModelLoadResourceAction implements |
| 20 | IObjectActionDelegate { |
| 21 | |
| 22 | /** |
| 23 | * @generated |
| 24 | */ |
| 25 | private AllocationEditPart mySelectedElement; |
| 26 | |
| 27 | /** |
| 28 | * @generated |
| 29 | */ |
| 30 | private Shell myShell; |
| 31 | |
| 32 | /** |
| 33 | * @generated |
| 34 | */ |
| 35 | public void setActivePart(IAction action, IWorkbenchPart targetPart) { |
| 36 | myShell = targetPart.getSite().getShell(); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @generated |
| 41 | */ |
| 42 | public void run(IAction action) { |
| 43 | LoadResourceAction.LoadResourceDialog loadResourceDialog = new LoadResourceAction.LoadResourceDialog( |
| 44 | myShell, mySelectedElement.getEditingDomain()); |
| 45 | loadResourceDialog.open(); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @generated |
| 50 | */ |
| 51 | public void selectionChanged(IAction action, ISelection selection) { |
| 52 | mySelectedElement = null; |
| 53 | if (selection instanceof IStructuredSelection) { |
| 54 | IStructuredSelection structuredSelection = (IStructuredSelection) selection; |
| 55 | if (structuredSelection.size() == 1 |
| 56 | && structuredSelection.getFirstElement() instanceof AllocationEditPart) { |
| 57 | mySelectedElement = (AllocationEditPart) structuredSelection |
| 58 | .getFirstElement(); |
| 59 | } |
| 60 | } |
| 61 | action.setEnabled(isEnabled()); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @generated |
| 66 | */ |
| 67 | private boolean isEnabled() { |
| 68 | return mySelectedElement != null; |
| 69 | } |
| 70 | |
| 71 | } |