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