01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal;
11:
12: import org.eclipse.jface.action.Action;
13: import org.eclipse.ui.IWorkbenchWindow;
14: import org.eclipse.ui.actions.ActionFactory;
15:
16: /**
17: * The <code>LockToolBarAction</code> is used to lock the toolbars for the
18: * workbench. The toolbar for all perspectives is locked.
19: */
20: public class LockToolBarAction extends Action implements
21: ActionFactory.IWorkbenchAction {
22:
23: /**
24: * The workbench window; or <code>null</code> if this
25: * action has been <code>dispose</code>d.
26: */
27: private IWorkbenchWindow workbenchWindow;
28:
29: /**
30: * Create a new instance of <code>LockToolBarAction</code>
31: *
32: * @param window the workbench window this action applies to
33: */
34: public LockToolBarAction(IWorkbenchWindow window) {
35: super (WorkbenchMessages.LockToolBarAction_text);
36: if (window == null) {
37: throw new IllegalArgumentException();
38: }
39: this .workbenchWindow = window;
40: setActionDefinitionId("org.eclipse.ui.window.lockToolBar"); //$NON-NLS-1$
41: // @issue missing action id
42: setToolTipText(WorkbenchMessages.LockToolBarAction_toolTip);
43: setEnabled(true);
44: // queue the update for the checked state since this action is created
45: // before the coolbar
46: window.getWorkbench().getDisplay().asyncExec(new Runnable() {
47: public void run() {
48: if (workbenchWindow != null) {
49: setChecked(((WorkbenchWindow) workbenchWindow)
50: .isCoolBarLocked());
51: }
52: }
53: });
54: window.getWorkbench().getHelpSystem().setHelp(this ,
55: IWorkbenchHelpContextIds.LOCK_TOOLBAR_ACTION);
56: }
57:
58: /* (non-Javadoc)
59: * Method declared on IAction.
60: */
61: public void run() {
62: if (workbenchWindow == null) {
63: // action has been disposed
64: return;
65: }
66: boolean locked = isChecked();
67: ((WorkbenchWindow) workbenchWindow).lockCoolBar(locked);
68: }
69:
70: /* (non-Javadoc)
71: * Method declared on ActionFactory.IWorkbenchAction.
72: */
73: public void dispose() {
74: workbenchWindow = null;
75: }
76:
77: }
|