KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > context > AbstractDebugContextActionDelegate


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.debug.internal.ui.actions.context;
13
14 import org.eclipse.jface.action.IAction;
15 import org.eclipse.jface.viewers.ISelection;
16 import org.eclipse.swt.widgets.Event;
17 import org.eclipse.ui.IActionDelegate2;
18 import org.eclipse.ui.IWorkbenchWindow;
19 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
20
21 public abstract class AbstractDebugContextActionDelegate implements IWorkbenchWindowActionDelegate, IActionDelegate2 {
22
23     /**
24      *The real action for this delegate
25      */

26     private AbstractDebugContextAction fDebugAction;
27     
28     /**
29      * The underlying action for this delegate
30      */

31     private IAction fWindowAction;
32     
33     /**
34      * Whether this action has been initialized before it has been run
35      * (ensures enablement state is up to date when lazily instantiated)
36      */

37     private boolean fInitialized = false;
38
39     public AbstractDebugContextActionDelegate() {
40     }
41
42     /*
43      * (non-Javadoc)
44      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
45      */

46     public void dispose() {
47         fDebugAction.dispose();
48
49     }
50
51     /*
52      * (non-Javadoc)
53      * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
54      */

55     public void init(IAction action) {
56         fWindowAction = action;
57     }
58     
59     /*
60      * (non-Javadoc)
61      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
62      */

63     public void init(IWorkbenchWindow window) {
64         setWindow(window);
65         fDebugAction.init(window);
66     }
67     
68     /*
69      * (non-Javadoc)
70      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
71      */

72     public synchronized void run(IAction action) {
73         if (!fInitialized) {
74             try {
75                 wait();
76             } catch (InterruptedException JavaDoc e) {
77             }
78         }
79         fDebugAction.run();
80     }
81
82     
83     /*
84      * (non-Javadoc)
85      * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
86      */

87     public void runWithEvent(IAction action, Event event) {
88         run(action);
89     }
90
91     /*
92      * (non-Javadoc)
93      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
94      */

95     public void selectionChanged(IAction action, ISelection s) {
96         // do nothing
97
}
98
99     protected AbstractDebugContextAction getAction() {
100         return fDebugAction;
101     }
102     
103     protected void setAction(AbstractDebugContextAction action) {
104         fDebugAction = action;
105         action.setDelegate(this);
106     }
107
108     protected IWorkbenchWindow getWindow() {
109         return fDebugAction.getWindow();
110     }
111
112     protected void setWindow(IWorkbenchWindow window) {
113         fDebugAction.setWindow(window);
114     }
115
116     public synchronized void setEnabled(boolean enabled) {
117         if (!fInitialized) {
118             fInitialized = true;
119             notifyAll();
120         }
121         fWindowAction.setEnabled(enabled);
122     }
123     
124     protected IAction getWindowAction()
125     {
126         return fWindowAction;
127     }
128     
129     
130 }
131
Popular Tags