001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.help;
011:
012: import java.util.ArrayList;
013:
014: import org.eclipse.core.runtime.Assert;
015: import org.eclipse.help.IContext;
016: import org.eclipse.jface.dialogs.IDialogPage;
017: import org.eclipse.swt.events.HelpEvent;
018: import org.eclipse.swt.widgets.Control;
019:
020: /**
021: * For determining the help context for controls in a dialog page.
022: * <p>
023: * This class may be instantiated; it is not intended to be subclassed.
024: * </p>
025: * @deprecated nested contexts are no longer supported by the help support system
026: */
027: public class DialogPageContextComputer implements IContextComputer {
028: private IDialogPage page;
029:
030: private ArrayList contextList;
031:
032: private Object context;
033:
034: /**
035: * Creates a new context computer for the given dialog page and help context.
036: *
037: * @param page the dialog page
038: * @param helpContext a single help context id (type <code>String</code>) or
039: * help context object (type <code>IContext</code>)
040: */
041: public DialogPageContextComputer(IDialogPage page,
042: Object helpContext) {
043: Assert.isTrue(helpContext instanceof String
044: || helpContext instanceof IContext);
045: this .page = page;
046: context = helpContext;
047: }
048:
049: /**
050: * Add the contexts to the context list.
051: *
052: * @param object the contexts (<code>Object[]</code> or <code>IContextComputer</code>)
053: * @param event the help event
054: */
055: private void addContexts(Object object, HelpEvent event) {
056: Assert.isTrue(object instanceof Object[]
057: || object instanceof IContextComputer
058: || object instanceof String);
059:
060: if (object instanceof String) {
061: contextList.add(object);
062: return;
063: }
064:
065: Object[] contexts;
066: if (object instanceof IContextComputer) {
067: // get local contexts
068: contexts = ((IContextComputer) object)
069: .getLocalContexts(event);
070: } else {
071: contexts = (Object[]) object;
072: }
073:
074: // copy the contexts into our list
075: for (int i = 0; i < contexts.length; i++) {
076: contextList.add(contexts[i]);
077: }
078: }
079:
080: /**
081: * Add the contexts for the given control to the context list.
082: *
083: * @param control the control from which to obtain the contexts
084: * @param event the help event
085: */
086: private void addContextsForControl(Control control, HelpEvent event) {
087: // See if there is are help contexts on the control
088: Object object = WorkbenchHelp.getHelp(control);
089:
090: if (object == null || object == this ) {
091: // We need to check for this in order to avoid recursion
092: return;
093: }
094:
095: addContexts(object, event);
096: }
097:
098: /* (non-Javadoc)
099: * Method declared on IContextComputer.
100: */
101: public Object[] computeContexts(HelpEvent event) {
102: contextList = new ArrayList();
103:
104: // Add the local context
105: contextList.add(context);
106:
107: // Add the contexts for the page
108: addContextsForControl(page.getControl(), event);
109:
110: // Add the contexts for the container shell
111: addContextsForControl(page.getControl().getShell(), event);
112:
113: // Return the contexts
114: return contextList.toArray();
115: }
116:
117: /* (non-Javadoc)
118: * Method declared on IContextComputer.
119: */
120: public Object[] getLocalContexts(HelpEvent event) {
121: return new Object[] { context };
122: }
123: }
|