KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > actions > HelpContentsAction


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.actions;
12
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.swt.custom.BusyIndicator;
15 import org.eclipse.ui.IWorkbenchPreferenceConstants;
16 import org.eclipse.ui.IWorkbenchWindow;
17 import org.eclipse.ui.PlatformUI;
18 import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
19 import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
20 import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
21 import org.eclipse.ui.internal.WorkbenchImages;
22 import org.eclipse.ui.internal.WorkbenchMessages;
23 import org.eclipse.ui.internal.util.PrefUtil;
24
25 /**
26  * Action to open the help contents.
27  *
28  * @since 3.0
29  */

30 public class HelpContentsAction extends Action implements 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 JavaDoc();
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 JavaDoc overrideText = PrefUtil.getAPIPreferenceStore().getString(
58                 IWorkbenchPreferenceConstants.HELP_CONTENTS_ACTION_TEXT);
59         if ("".equals(overrideText)) { //$NON-NLS-1$
60
setText(WorkbenchMessages.HelpContentsAction_text);
61             setToolTipText(WorkbenchMessages.HelpContentsAction_toolTip);
62         } else {
63             setText(overrideText);
64             setToolTipText(Action.removeMnemonics(overrideText));
65         }
66         setImageDescriptor(WorkbenchImages
67                 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_HELP_CONTENTS));
68         window.getWorkbench().getHelpSystem().setHelp(this,
69                 IWorkbenchHelpContextIds.HELP_CONTENTS_ACTION);
70     }
71
72     /* (non-Javadoc)
73      * Method declared on IAction.
74      */

75     public void run() {
76         if (workbenchWindow == null) {
77             // action has been disposed
78
return;
79         }
80         //This may take a while, so use the busy indicator
81
BusyIndicator.showWhile(null, new Runnable JavaDoc() {
82             public void run() {
83                 workbenchWindow.getWorkbench().getHelpSystem().displayHelp();
84             }
85         });
86     }
87
88     /* (non-Javadoc)
89      * Method declared on ActionFactory.IWorkbenchAction.
90      */

91     public void dispose() {
92         workbenchWindow = null;
93     }
94
95 }
96
Popular Tags