blob: e59fdfe718b2946c3a9ed1a7a37abc7ffaf4e13d (
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
|
/*******************************************************************************
* Copyright (c) 2000, 2008 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 java.util.ArrayList;
import org.eclipse.core.runtime.Assert;
import org.eclipse.help.IContext;
import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.swt.events.HelpEvent;
import org.eclipse.swt.widgets.Control;
/**
* For determining the help context for controls in a dialog page.
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
* @deprecated nested contexts are no longer supported by the help support system
* @noextend This class is not intended to be subclassed by clients.
*/
public class DialogPageContextComputer implements IContextComputer {
private IDialogPage page;
private ArrayList contextList;
private Object context;
/**
* Creates a new context computer for the given dialog page and help context.
*
* @param page the dialog page
* @param helpContext a single help context id (type <code>String</code>) or
* help context object (type <code>IContext</code>)
*/
public DialogPageContextComputer(IDialogPage page, Object helpContext) {
Assert.isTrue(helpContext instanceof String
|| helpContext instanceof IContext);
this.page = page;
context = helpContext;
}
/**
* Add the contexts to the context list.
*
* @param object the contexts (<code>Object[]</code> or <code>IContextComputer</code>)
* @param event the help event
*/
private void addContexts(Object object, HelpEvent event) {
Assert.isTrue(object instanceof Object[]
|| object instanceof IContextComputer
|| object instanceof String);
if (object instanceof String) {
contextList.add(object);
return;
}
Object[] contexts;
if (object instanceof IContextComputer) {
// get local contexts
contexts = ((IContextComputer) object).getLocalContexts(event);
} else {
contexts = (Object[]) object;
}
// copy the contexts into our list
for (int i = 0; i < contexts.length; i++) {
contextList.add(contexts[i]);
}
}
/**
* Add the contexts for the given control to the context list.
*
* @param control the control from which to obtain the contexts
* @param event the help event
*/
private void addContextsForControl(Control control, HelpEvent event) {
// See if there is are help contexts on the control
Object object = WorkbenchHelp.getHelp(control);
if (object == null || object == this) {
// We need to check for this in order to avoid recursion
return;
}
addContexts(object, event);
}
/* (non-Javadoc)
* Method declared on IContextComputer.
*/
public Object[] computeContexts(HelpEvent event) {
contextList = new ArrayList();
// Add the local context
contextList.add(context);
// Add the contexts for the page
addContextsForControl(page.getControl(), event);
// Add the contexts for the container shell
addContextsForControl(page.getControl().getShell(), event);
// Return the contexts
return contextList.toArray();
}
/* (non-Javadoc)
* Method declared on IContextComputer.
*/
public Object[] getLocalContexts(HelpEvent event) {
return new Object[] { context };
}
}
|