Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 84d3240bfddf81c146ac27f66ca33084ae19d5cb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.ui.help;

import org.eclipse.help.IContext;
import org.eclipse.help.IHelp;
import org.eclipse.jface.action.IAction;
import org.eclipse.swt.events.HelpListener;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommand;
import org.eclipse.ui.internal.help.WorkbenchHelpSystem;

/**
 * Provides methods for accessing the help UI.
 * <p>
 * The help UI is optional, to allow applications to be configured
 * without one.
 * </p>
 * <p>
 * The various <code>setHelp</code> methods allow context help to be hooked in
 * to SWT menus, menu items, and controls, and into JFace actions. This involves 
 * furnishing a help context id. When the user requests help for one of the 
 * established widgets (for instance, by hitting F1), the context id is
 * retrieved and passed to the help UI using 
 * <code>WorkbenchHelp.displayContext(helpContext, xposition, yposition)</code>.
 * </p>
 * <p>
 * In cases more dynamic situations, clients may hook their own help listener
 * and call <code>WorkbenchHelp.displayContext</code> with an 
 * <code>IContext</code>.
 * </p>
 * <p>
 * This class provides static methods only; it is not intended to be instantiated
 * or subclassed.
 * </p>
 *
 * @deprecated clients should use <code>IWorkbenchHelpSystem</code> instead
 * 
 * @see org.eclipse.help.HelpSystem
 * @see org.eclipse.ui.help.IWorkbenchHelpSystem
 * @see org.eclipse.ui.IWorkbench#getHelpSystem()
 * @noinstantiate This class is not intended to be instantiated by clients.
 * @noextend This class is not intended to be subclassed by clients.
 */
public class WorkbenchHelp {

    /**
     * This class is not intented to be instantiated
     */
    private WorkbenchHelp() {
    }

    /**
     * Displays the entire help bookshelf.
     * <p>
     * Ignored if no help UI is available.
     * </p>
     * 
     * @since 3.0
     */
    public static void displayHelp() {
    	PlatformUI.getWorkbench().getHelpSystem().displayHelp();
    }

    /**
     * Displays context-sensitive help for the given context.
     * <p>
     * (x,y) coordinates specify the location where the context sensitive 
     * help UI will be presented. These coordinates are screen-relative 
     * (ie: (0,0) is the top left-most screen corner).
     * The platform is responsible for calling this method and supplying the 
     * appropriate location.
     * </p>
     * <p>
     * Ignored if no help UI is available.
     * </p>
     * 
     * @param context the context to display
     * @param x horizontal position
     * @param y verifical position
     * @since 3.0
     */
    public static void displayContext(IContext context, int x, int y) {
    	PlatformUI.getWorkbench().getHelpSystem().displayContext(context, x, y);
    }

    /**
     * Displays help content for the help resource with the given URL.
     * <p>
     * This method is called by the platform to launch the help system UI, displaying
     * the documentation identified by the <code>href</code> parameter.
     * </p> 
     * <p>
     * The help system makes no guarantee that all the help resources can be displayed or how they are displayed.
     * </p>
     * <p>
     * Ignored if no help UI is available.
     * </p>
     * 
     * @param href the URL of the help resource.
     * <p>Valid href are as described in 
     * 	{@link  org.eclipse.help.IHelpResource#getHref() IHelpResource.getHref()}
     * </p>
     * @since 3.0
     */
    public static void displayHelpResource(String href) {
    	PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(href);
    }

    /**
     * Creates a new help listener for the given command. This retrieves the
     * help context ID from the command, and creates an appropriate listener
     * based on this.
     * 
     * @param command
     *            The command for which the listener should be created; must
     *            not be <code>null</code>.
     * @return A help listener; never <code>null</code>.
     */
    public static HelpListener createHelpListener(ICommand command) {
    	return WorkbenchHelpSystem.getInstance().createHelpListener(command);
    }

    /**
     * Calls the help support system to display the given help context id.
     * <p>
     * May only be called from a UI thread.
     * <p>
     *
     * @param contextId the id of the context to display
     * @since 2.0
     */
    public static void displayHelp(String contextId) {
    	PlatformUI.getWorkbench().getHelpSystem().displayHelp(contextId);    	
    }

    /**
     * Displays context-sensitive help for the given context.
     * <p>
     * May only be called from a UI thread.
     * <p>
     *
     * @param context the context to display
     * @since 2.0
     */
    public static void displayHelp(IContext context) {
    	PlatformUI.getWorkbench().getHelpSystem().displayHelp(context);
    }

    /**
     * Returns the help contexts on the given control.
     * <p>
     * Instances of <code>IContextComputer</code> may use this method
     * to obtain the previously registered help contexts of a control.
     * </p>
     *
     * @param control the control on which the contexts are registered
     * @return contexts the contexts to use when F1 help is invoked; a mixed-type
     *   array of context ids (type <code>String</code>) and/or help contexts (type
     *   <code>IContext</code>) or an <code>IContextComputer</code> or
     *   <code>null</code> if no contexts have been set.
     * @deprecated as context computers are no longer supported
     */
    public static Object getHelp(Control control) {
        return control.getData(WorkbenchHelpSystem.HELP_KEY);
    }

    /**
     * Returns the help contexts on the given menu.
     * <p>
     * Instances of <code>IContextComputer</code> may use this method
     * to obtain the previously registered help contexts of a menu.
     * </p>
     *
     * @param menu the menu on which the contexts are registered
     * @return contexts the contexts to use when F1 help is invoked; a mixed-type
     *   array of context ids (type <code>String</code>) and/or help contexts (type
     *   <code>IContext</code>) or an <code>IContextComputer</code> or
     *   <code>null</code> if no contexts have been set.
     * @deprecated as context computers are no longer supported
     */
    public static Object getHelp(Menu menu) {
        return menu.getData(WorkbenchHelpSystem.HELP_KEY);
    }

    /**
     * Returns the help contexts on the given menu item.
     * <p>
     * Instances of <code>IContextComputer</code> may use this method
     * to obtain the previously registered help contexts of a menu.
     * </p>
     *
     * @param menuItem the menu item on which the contexts are registered
     * @return contexts the contexts to use when F1 help is invoked; a mixed-type
     *   array of context ids (type <code>String</code>) and/or help contexts (type
     *   <code>IContext</code>) or an <code>IContextComputer</code> or
     *   <code>null</code> if no contexts have been set.
     * @deprecated as context computers are no longer supported
     */
    public static Object getHelp(MenuItem menuItem) {
        return menuItem.getData(WorkbenchHelpSystem.HELP_KEY);
    }

    /**
     * Returns the help support system for the platform, if available.
     *
     * @return the help support system, or <code>null</code> if none
     * @deprecated Use the static methods on this class and on
     * {@link org.eclipse.help.HelpSystem HelpSystem} instead of the IHelp methods
     * on the object returned by this method.
     */
    public static IHelp getHelpSupport() {
    	return WorkbenchHelpSystem.getInstance().getHelpSupport();
    }

    
    /**
     * Returns whether the context-sensitive help window is currently being
     * displayed. Returns <code>false</code> if the help UI has not been
     * activated yet.
     * 
     * @return <code>true</code> if the context-sensitive help
     * window is currently being displayed, <code>false</code> otherwise
     */
    public static boolean isContextHelpDisplayed() {
    	return PlatformUI.getWorkbench().getHelpSystem().isContextHelpDisplayed();
    }

    /**
     * Sets the given help contexts on the given action.
     * <p>
     * Use this method when the list of help contexts is known in advance.
     * Help contexts can either supplied as a static list, or calculated with a
     * context computer (but not both).
     * </p>
     *
     * @param action the action on which to register the computer
     * @param contexts the contexts to use when F1 help is invoked; a mixed-type
     *   array of context ids (type <code>String</code>) and/or help contexts (type
     *   <code>IContext</code>)
     * @deprecated use setHelp with a single context id parameter
     */
    public static void setHelp(IAction action, final Object[] contexts) {
    	WorkbenchHelpSystem.getInstance().setHelp(action, contexts);
    }

    /**
     * Sets the given help context computer on the given action.
     * <p>
     * Use this method when the help contexts cannot be computed in advance.
     * Help contexts can either supplied as a static list, or calculated with a
     * context computer (but not both).
     * </p>
     *
     * @param action the action on which to register the computer
     * @param computer the computer to determine the help contexts for the control
     *    when F1 help is invoked
     * @deprecated context computers are no longer supported, clients should implement
     *  their own help listener
     */
    public static void setHelp(IAction action, final IContextComputer computer) {
    	WorkbenchHelpSystem.getInstance().setHelp(action, computer);
    }

    /**
     * Sets the given help contexts on the given control.
     * <p>
     * Use this method when the list of help contexts is known in advance.
     * Help contexts can either supplied as a static list, or calculated with a
     * context computer (but not both).
     * </p>
     *
     * @param control the control on which to register the contexts
     * @param contexts the contexts to use when F1 help is invoked; a mixed-type
     *   array of context ids (type <code>String</code>) and/or help contexts (type
     *   <code>IContext</code>)
     * @deprecated use setHelp with single context id parameter
     */
    public static void setHelp(Control control, Object[] contexts) {
    	WorkbenchHelpSystem.getInstance().setHelp(control, contexts);
    }

    /**
     * Sets the given help context computer on the given control.
     * <p>
     * Use this method when the help contexts cannot be computed in advance.
     * Help contexts can either supplied as a static list, or calculated with a
     * context computer (but not both).
     * </p>
     *
     * @param control the control on which to register the computer
     * @param computer the computer to determine the help contexts for the control
     *    when F1 help is invoked
     * @deprecated context computers are no longer supported, clients should implement
     *  their own help listener
     */
    public static void setHelp(Control control, IContextComputer computer) {
    	WorkbenchHelpSystem.getInstance().setHelp(control, computer);
    }

    /**
     * Sets the given help contexts on the given menu.
     * <p>
     * Use this method when the list of help contexts is known in advance.
     * Help contexts can either supplied as a static list, or calculated with a
     * context computer (but not both).
     * </p>
     *
     * @param menu the menu on which to register the context
     * @param contexts the contexts to use when F1 help is invoked; a mixed-type
     *   array of context ids (type <code>String</code>) and/or help contexts (type
     *   <code>IContext</code>)
     * @deprecated use setHelp with single context id parameter
     */
    public static void setHelp(Menu menu, Object[] contexts) {
    	WorkbenchHelpSystem.getInstance().setHelp(menu, contexts);
    }

    /**
     * Sets the given help context computer on the given menu.
     * <p>
     * Use this method when the help contexts cannot be computed in advance.
     * Help contexts can either supplied as a static list, or calculated with a
     * context computer (but not both).
     * </p>
     *
     * @param menu the menu on which to register the computer
     * @param computer the computer to determine the help contexts for the control
     *    when F1 help is invoked
     * @deprecated context computers are no longer supported, clients should implement
     *  their own help listener
     */
    public static void setHelp(Menu menu, IContextComputer computer) {
    	WorkbenchHelpSystem.getInstance().setHelp(menu, computer);
    }

    /**
     * Sets the given help contexts on the given menu item.
     * <p>
     * Use this method when the list of help contexts is known in advance.
     * Help contexts can either supplied as a static list, or calculated with a
     * context computer (but not both).
     * </p>
     *
     * @param item the menu item on which to register the context
     * @param contexts the contexts to use when F1 help is invoked; a mixed-type
     *   array of context ids (type <code>String</code>) and/or help contexts (type
     *   <code>IContext</code>)
     * @deprecated use setHelp with single context id parameter
     */
    public static void setHelp(MenuItem item, Object[] contexts) {
    	WorkbenchHelpSystem.getInstance().setHelp(item, contexts);
    }

    /**
     * Sets the given help context computer on the given menu item.
     * <p>
     * Use this method when the help contexts cannot be computed in advance.
     * Help contexts can either supplied as a static list, or calculated with a
     * context computer (but not both).
     * </p>
     *
     * @param item the menu item on which to register the computer
     * @param computer the computer to determine the help contexts for the control
     *    when F1 help is invoked
     * @deprecated context computers are no longer supported, clients should implement
     *  their own help listener
     */
    public static void setHelp(MenuItem item, IContextComputer computer) {
    	WorkbenchHelpSystem.getInstance().setHelp(item, computer);
    }

    /**
     * Sets the given help context id on the given action.
     *
     * @param action the action on which to register the context id
     * @param contextId the context id to use when F1 help is invoked
     * @since 2.0
     */
    public static void setHelp(IAction action, final String contextId) {
    	PlatformUI.getWorkbench().getHelpSystem().setHelp(action, contextId);
    }

    /**
     * Sets the given help context id on the given control.
     *
     * @param control the control on which to register the context id
     * @param contextId the context id to use when F1 help is invoked
     * @since 2.0
     */
    public static void setHelp(Control control, String contextId) {
    	PlatformUI.getWorkbench().getHelpSystem().setHelp(control, contextId);    	
    }

    /**
     * Sets the given help context id on the given menu.
     *
     * @param menu the menu on which to register the context id
     * @param contextId the context id to use when F1 help is invoked
     * @since 2.0
     */
    public static void setHelp(Menu menu, String contextId) {
    	PlatformUI.getWorkbench().getHelpSystem().setHelp(menu, contextId);
    }

    /**
     * Sets the given help context id on the given menu item.
     *
     * @param item the menu item on which to register the context id
     * @param contextId the context id to use when F1 help is invoked
     * @since 2.0
     */
    public static void setHelp(MenuItem item, String contextId) {
    	PlatformUI.getWorkbench().getHelpSystem().setHelp(item, contextId);
    }
}

Back to the top