1+ package testing .actions ;
2+
3+ import org .eclipse .jface .action .IAction ;
4+ import org .eclipse .jface .viewers .ISelection ;
5+ import org .eclipse .ui .IWorkbenchWindow ;
6+ import org .eclipse .ui .IWorkbenchWindowActionDelegate ;
7+ import org .eclipse .jface .dialogs .MessageDialog ;
8+
9+ /**
10+ * Our sample action implements workbench action delegate.
11+ * The action proxy will be created by the workbench and
12+ * shown in the UI. When the user tries to use the action,
13+ * this delegate will be created and execution will be
14+ * delegated to it.
15+ * @see IWorkbenchWindowActionDelegate
16+ */
17+ public class SampleAction implements IWorkbenchWindowActionDelegate {
18+ private IWorkbenchWindow window ;
19+ /**
20+ * The constructor.
21+ */
22+ public SampleAction () {
23+ }
24+
25+ /**
26+ * The action has been activated. The argument of the
27+ * method represents the 'real' action sitting
28+ * in the workbench UI.
29+ * @see IWorkbenchWindowActionDelegate#run
30+ */
31+ public void run (IAction action ) {
32+ MessageDialog .openInformation (
33+ window .getShell (),
34+ "Testing" ,
35+ "Hello, Eclipse world" );
36+ }
37+
38+ /**
39+ * Selection in the workbench has been changed. We
40+ * can change the state of the 'real' action here
41+ * if we want, but this can only happen after
42+ * the delegate has been created.
43+ * @see IWorkbenchWindowActionDelegate#selectionChanged
44+ */
45+ public void selectionChanged (IAction action , ISelection selection ) {
46+ }
47+
48+ /**
49+ * We can use this method to dispose of any system
50+ * resources we previously allocated.
51+ * @see IWorkbenchWindowActionDelegate#dispose
52+ */
53+ public void dispose () {
54+ }
55+
56+ /**
57+ * We will cache window object in order to
58+ * be able to provide parent shell for the message dialog.
59+ * @see IWorkbenchWindowActionDelegate#init
60+ */
61+ public void init (IWorkbenchWindow window ) {
62+ this .window = window ;
63+ }
64+ }
0 commit comments