KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > help > DialogPageContextComputer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.help;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.help.IContext;
17 import org.eclipse.jface.dialogs.IDialogPage;
18 import org.eclipse.swt.events.HelpEvent;
19 import org.eclipse.swt.widgets.Control;
20
21 /**
22  * For determining the help context for controls in a dialog page.
23  * <p>
24  * This class may be instantiated; it is not intended to be subclassed.
25  * </p>
26  * @deprecated nested contexts are no longer supported by the help support system
27  */

28 public class DialogPageContextComputer implements IContextComputer {
29     private IDialogPage page;
30
31     private ArrayList JavaDoc contextList;
32
33     private Object JavaDoc context;
34
35     /**
36      * Creates a new context computer for the given dialog page and help context.
37      *
38      * @param page the dialog page
39      * @param helpContext a single help context id (type <code>String</code>) or
40      * help context object (type <code>IContext</code>)
41      */

42     public DialogPageContextComputer(IDialogPage page, Object JavaDoc helpContext) {
43         Assert.isTrue(helpContext instanceof String JavaDoc
44                 || helpContext instanceof IContext);
45         this.page = page;
46         context = helpContext;
47     }
48
49     /**
50      * Add the contexts to the context list.
51      *
52      * @param object the contexts (<code>Object[]</code> or <code>IContextComputer</code>)
53      * @param event the help event
54      */

55     private void addContexts(Object JavaDoc object, HelpEvent event) {
56         Assert.isTrue(object instanceof Object JavaDoc[]
57                 || object instanceof IContextComputer
58                 || object instanceof String JavaDoc);
59
60         if (object instanceof String JavaDoc) {
61             contextList.add(object);
62             return;
63         }
64
65         Object JavaDoc[] contexts;
66         if (object instanceof IContextComputer) {
67             // get local contexts
68
contexts = ((IContextComputer) object).getLocalContexts(event);
69         } else {
70             contexts = (Object JavaDoc[]) object;
71         }
72
73         // copy the contexts into our list
74
for (int i = 0; i < contexts.length; i++) {
75             contextList.add(contexts[i]);
76         }
77     }
78
79     /**
80      * Add the contexts for the given control to the context list.
81      *
82      * @param control the control from which to obtain the contexts
83      * @param event the help event
84      */

85     private void addContextsForControl(Control control, HelpEvent event) {
86         // See if there is are help contexts on the control
87
Object JavaDoc object = WorkbenchHelp.getHelp(control);
88
89         if (object == null || object == this) {
90             // We need to check for this in order to avoid recursion
91
return;
92         }
93
94         addContexts(object, event);
95     }
96
97     /* (non-Javadoc)
98      * Method declared on IContextComputer.
99      */

100     public Object JavaDoc[] computeContexts(HelpEvent event) {
101         contextList = new ArrayList JavaDoc();
102
103         // Add the local context
104
contextList.add(context);
105
106         // Add the contexts for the page
107
addContextsForControl(page.getControl(), event);
108
109         // Add the contexts for the container shell
110
addContextsForControl(page.getControl().getShell(), event);
111
112         // Return the contexts
113
return contextList.toArray();
114     }
115
116     /* (non-Javadoc)
117      * Method declared on IContextComputer.
118      */

119     public Object JavaDoc[] getLocalContexts(HelpEvent event) {
120         return new Object JavaDoc[] { context };
121     }
122 }
123
Popular Tags