KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > AbstractRemoveAllActionDelegate


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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 package org.eclipse.debug.internal.ui.actions;
12
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.IViewActionDelegate;
19 import org.eclipse.ui.IViewPart;
20 import org.eclipse.ui.IWorkbenchWindow;
21 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
22
23 /**
24  * This class is a base implementation of a 'remove all' debug action
25  *
26  * This class is intended to be extended by clients
27  * @see {@link IViewActionDelegate}
28  * @see {@link IActionDelegate2}}
29  * @see {@link IWorkbenchWindowActionDelegate}
30  */

31 public abstract class AbstractRemoveAllActionDelegate implements IViewActionDelegate, IActionDelegate2, IWorkbenchWindowActionDelegate {
32     
33     /**
34      * The underlying <code>IAction</code>
35      */

36     private IAction fAction;
37
38     /**
39      * Needed for reflective creation
40      */

41     public AbstractRemoveAllActionDelegate() {}
42     
43     /* (non-Javadoc)
44      * @see org.eclipse.ui.IActionDelegate2#dispose()
45      */

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

53     public void init(IAction action) {
54         fAction = action;
55     }
56
57     /**
58      * Returns this delegate's action.
59      *
60      * @return the underlying <code>IAction</code>
61      */

62     protected IAction getAction() {
63         return fAction;
64     }
65     
66     /* (non-Javadoc)
67      * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
68      */

69     public void runWithEvent(IAction action, Event event) {
70         run(action);
71     }
72
73     /* (non-Javadoc)
74      * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
75      */

76     public void init(IViewPart view) {
77         initialize();
78         update();
79     }
80
81     /* (non-Javadoc)
82      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
83      */

84     public void init(IWorkbenchWindow window) {
85         initialize();
86         update();
87     }
88
89     /**
90      * Initializes any listeners, etc.
91      */

92     protected abstract void initialize();
93     
94     /**
95      * Update enablement.
96      */

97     protected void update() {
98         IAction action = getAction();
99         if (action != null) {
100             action.setEnabled(isEnabled());
101         }
102     }
103     
104     /**
105      * Returns whether this action is enabled
106      *
107      * @return true if this action is enabled, false otherwise
108      */

109     protected abstract boolean isEnabled();
110     
111     /* (non-Javadoc)
112      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
113      */

114     public void selectionChanged(IAction action, ISelection s) {
115         // do nothing
116
}
117 }
118
Popular Tags