KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > LockToolBarAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.ui.internal;
12
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.ui.IWorkbenchWindow;
15 import org.eclipse.ui.actions.ActionFactory;
16
17 /**
18  * The <code>LockToolBarAction</code> is used to lock the toolbars for the
19  * workbench. The toolbar for all perspectives is locked.
20  */

21 public class LockToolBarAction extends Action implements
22         ActionFactory.IWorkbenchAction {
23
24     /**
25      * The workbench window; or <code>null</code> if this
26      * action has been <code>dispose</code>d.
27      */

28     private IWorkbenchWindow workbenchWindow;
29
30     /**
31      * Create a new instance of <code>LockToolBarAction</code>
32      *
33      * @param window the workbench window this action applies to
34      */

35     public LockToolBarAction(IWorkbenchWindow window) {
36         super(WorkbenchMessages.LockToolBarAction_text);
37         if (window == null) {
38             throw new IllegalArgumentException JavaDoc();
39         }
40         this.workbenchWindow = window;
41         setActionDefinitionId("org.eclipse.ui.window.lockToolBar"); //$NON-NLS-1$
42
// @issue missing action id
43
setToolTipText(WorkbenchMessages.LockToolBarAction_toolTip);
44         setEnabled(true);
45         // queue the update for the checked state since this action is created
46
// before the coolbar
47
window.getWorkbench().getDisplay().asyncExec(new Runnable JavaDoc() {
48             public void run() {
49                 if (workbenchWindow != null) {
50                     setChecked(((WorkbenchWindow) workbenchWindow)
51                             .isCoolBarLocked());
52                 }
53             }
54         });
55         window.getWorkbench().getHelpSystem().setHelp(this,
56                 IWorkbenchHelpContextIds.LOCK_TOOLBAR_ACTION);
57     }
58
59     /* (non-Javadoc)
60      * Method declared on IAction.
61      */

62     public void run() {
63         if (workbenchWindow == null) {
64             // action has been disposed
65
return;
66         }
67         boolean locked = isChecked();
68         ((WorkbenchWindow) workbenchWindow).lockCoolBar(locked);
69     }
70
71     /* (non-Javadoc)
72      * Method declared on ActionFactory.IWorkbenchAction.
73      */

74     public void dispose() {
75         workbenchWindow = null;
76     }
77
78 }
79
Popular Tags