KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > commands > actions > DebugCommandActionDelegate


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.commands.actions;
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 /**
22  * Abstract base class for debug action delegates performing debug commands.
23  *
24  * @since 3.3
25  */

26 public abstract class DebugCommandActionDelegate implements IWorkbenchWindowActionDelegate, IActionDelegate2 {
27
28     /**
29      *The real action for this delegate
30      */

31     private DebugCommandAction fDebugAction;
32     
33     /**
34      * The underlying action for this delegate
35      */

36     private IAction fWindowAction;
37     
38     /**
39      * Whether this action has been initialized before it has been run
40      * (ensures enablement state is up to date when lazily instantiated)
41      */

42     private boolean fInitialized = false;
43
44     public DebugCommandActionDelegate() {
45     }
46
47     /*
48      * (non-Javadoc)
49      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
50      */

51     public void dispose() {
52         fDebugAction.dispose();
53
54     }
55
56     /*
57      * (non-Javadoc)
58      * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
59      */

60     public void init(IAction action) {
61         fWindowAction = action;
62     }
63     
64     /*
65      * (non-Javadoc)
66      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
67      */

68     public void init(IWorkbenchWindow window) {
69         fDebugAction.init(window);
70     }
71     
72     /*
73      * (non-Javadoc)
74      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
75      */

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

93     public void runWithEvent(IAction action, Event event) {
94         run(action);
95     }
96
97     /*
98      * (non-Javadoc)
99      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
100      */

101     public void selectionChanged(IAction action, ISelection s) {
102         // do nothing
103
}
104
105     protected DebugCommandAction getAction() {
106         return fDebugAction;
107     }
108     
109     protected void setAction(DebugCommandAction action) {
110         fDebugAction = action;
111         action.setDelegate(this);
112     }
113
114     public void setEnabled(boolean enabled) {
115         synchronized (this) {
116             if (!fInitialized) {
117                 fInitialized = true;
118                 notifyAll();
119             }
120         }
121         fWindowAction.setEnabled(enabled);
122     }
123     
124     public void setChecked(boolean checked) {
125         fWindowAction.setChecked(checked);
126     }
127     
128     protected IAction getWindowAction()
129     {
130         return fWindowAction;
131     }
132     
133     
134 }
135
Popular Tags