KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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.IWorkbenchHelpContextIds;
20 import org.eclipse.ui.internal.WorkbenchMessages;
21 import org.eclipse.ui.internal.util.PrefUtil;
22
23 /**
24  * Action to open the dynamic help.
25  *
26  * @since 3.1
27  */

28 public class DynamicHelpAction extends Action implements IWorkbenchAction {
29     /**
30      * The workbench window; or <code>null</code> if this action has been
31      * <code>dispose</code>d.
32      */

33     private IWorkbenchWindow workbenchWindow;
34
35     /**
36      * Zero-arg constructor to allow cheat sheets to reuse this action.
37      */

38     public DynamicHelpAction() {
39         this(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
40     }
41
42     /**
43      * Constructor for use by ActionFactory.
44      *
45      * @param window
46      * the window
47      */

48     public DynamicHelpAction(IWorkbenchWindow window) {
49         if (window == null) {
50             throw new IllegalArgumentException JavaDoc();
51         }
52         this.workbenchWindow = window;
53         setActionDefinitionId("org.eclipse.ui.help.dynamicHelp"); //$NON-NLS-1$
54

55         // support for allowing a product to override the text for the action
56
String JavaDoc overrideText = PrefUtil.getAPIPreferenceStore().getString(
57                 IWorkbenchPreferenceConstants.DYNAMIC_HELP_ACTION_TEXT);
58         if ("".equals(overrideText)) { //$NON-NLS-1$
59
setText(appendAccelerator(WorkbenchMessages.DynamicHelpAction_text));
60             setToolTipText(WorkbenchMessages.DynamicHelpAction_toolTip);
61         } else {
62             setText(appendAccelerator(overrideText));
63             setToolTipText(Action.removeMnemonics(overrideText));
64         }
65         window.getWorkbench().getHelpSystem().setHelp(this,
66                 IWorkbenchHelpContextIds.DYNAMIC_HELP_ACTION);
67     }
68
69     private String JavaDoc appendAccelerator(String JavaDoc text) {
70         // We know that on Windows context help key is F1
71
// and cannot be changed by the user.
72
//
73
// Commented out due to the problem described in
74
// Bugzilla bug #95057
75

76         //if (Platform.getWS().equals(Platform.WS_WIN32))
77
// return text + "\t" + KeyStroke.getInstance(SWT.F1).format(); //$NON-NLS-1$
78
return text;
79     }
80
81     /*
82      * (non-Javadoc) Method declared on IAction.
83      */

84     public void run() {
85         if (workbenchWindow == null) {
86             // action has been disposed
87
return;
88         }
89         // This may take a while, so use the busy indicator
90
BusyIndicator.showWhile(null, new Runnable JavaDoc() {
91             public void run() {
92                 workbenchWindow.getWorkbench().getHelpSystem()
93                         .displayDynamicHelp();
94             }
95         });
96     }
97
98     /*
99      * (non-Javadoc) Method declared on ActionFactory.IWorkbenchAction.
100      */

101     public void dispose() {
102         workbenchWindow = null;
103     }
104
105 }
106
Popular Tags