01: /*******************************************************************************
02: * Copyright (c) 2004, 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.actions;
11:
12: import org.eclipse.jface.action.Action;
13: import org.eclipse.swt.custom.BusyIndicator;
14: import org.eclipse.ui.IWorkbenchPreferenceConstants;
15: import org.eclipse.ui.IWorkbenchWindow;
16: import org.eclipse.ui.PlatformUI;
17: import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
18: import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
19: import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
20: import org.eclipse.ui.internal.WorkbenchImages;
21: import org.eclipse.ui.internal.WorkbenchMessages;
22: import org.eclipse.ui.internal.util.PrefUtil;
23:
24: /**
25: * Action to open the help contents.
26: *
27: * @since 3.0
28: */
29: public class HelpContentsAction extends Action implements
30: IWorkbenchAction {
31: /**
32: * The workbench window; or <code>null</code> if this
33: * action has been <code>dispose</code>d.
34: */
35: private IWorkbenchWindow workbenchWindow;
36:
37: /**
38: * Zero-arg constructor to allow cheat sheets to reuse this action.
39: */
40: public HelpContentsAction() {
41: this (PlatformUI.getWorkbench().getActiveWorkbenchWindow());
42: }
43:
44: /**
45: * Constructor for use by ActionFactory.
46: *
47: * @param window the window
48: */
49: public HelpContentsAction(IWorkbenchWindow window) {
50: if (window == null) {
51: throw new IllegalArgumentException();
52: }
53: this .workbenchWindow = window;
54: setActionDefinitionId("org.eclipse.ui.help.helpContents"); //$NON-NLS-1$
55:
56: // support for allowing a product to override the text for the action
57: String overrideText = PrefUtil
58: .getAPIPreferenceStore()
59: .getString(
60: IWorkbenchPreferenceConstants.HELP_CONTENTS_ACTION_TEXT);
61: if ("".equals(overrideText)) { //$NON-NLS-1$
62: setText(WorkbenchMessages.HelpContentsAction_text);
63: setToolTipText(WorkbenchMessages.HelpContentsAction_toolTip);
64: } else {
65: setText(overrideText);
66: setToolTipText(Action.removeMnemonics(overrideText));
67: }
68: setImageDescriptor(WorkbenchImages
69: .getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_HELP_CONTENTS));
70: window.getWorkbench().getHelpSystem().setHelp(this ,
71: IWorkbenchHelpContextIds.HELP_CONTENTS_ACTION);
72: }
73:
74: /* (non-Javadoc)
75: * Method declared on IAction.
76: */
77: public void run() {
78: if (workbenchWindow == null) {
79: // action has been disposed
80: return;
81: }
82: //This may take a while, so use the busy indicator
83: BusyIndicator.showWhile(null, new Runnable() {
84: public void run() {
85: workbenchWindow.getWorkbench().getHelpSystem()
86: .displayHelp();
87: }
88: });
89: }
90:
91: /* (non-Javadoc)
92: * Method declared on ActionFactory.IWorkbenchAction.
93: */
94: public void dispose() {
95: workbenchWindow = null;
96: }
97:
98: }
|