Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 296042 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/help/WorkbenchHelpSystem.java (-1 / +52 lines)
Lines 11-17 Link Here
11
package org.eclipse.ui.internal.help;
11
package org.eclipse.ui.internal.help;
12
12
13
import java.net.URL;
13
import java.net.URL;
14
14
import java.util.Hashtable;
15
import org.eclipse.core.runtime.Assert;
15
import org.eclipse.core.runtime.Assert;
16
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IConfigurationElement;
17
import org.eclipse.core.runtime.IConfigurationElement;
Lines 160-165 Link Here
160
	private String desiredHelpSystemId;
160
	private String desiredHelpSystemId;
161
161
162
	/**
162
	/**
163
	 * Table for tracing registered context ids. This is used only for debugging
164
	 * purposes.
165
	 * 
166
	 */
167
	private Hashtable registeredIDTable;
168
169
	/**
163
	 * Handles dynamic removal of the help system.
170
	 * Handles dynamic removal of the help system.
164
	 * 
171
	 * 
165
	 * @since 3.1
172
	 * @since 3.1
Lines 959-964 Link Here
959
	 *      java.lang.String)
966
	 *      java.lang.String)
960
	 */
967
	 */
961
	public void setHelp(final IAction action, final String contextId) {
968
	public void setHelp(final IAction action, final String contextId) {
969
		if (WorkbenchPlugin.DEBUG)
970
			setHelpTrace(contextId);
962
		action.setHelpListener(new HelpListener() {
971
		action.setHelpListener(new HelpListener() {
963
			public void helpRequested(HelpEvent event) {
972
			public void helpRequested(HelpEvent event) {
964
				if (getHelpUI() != null) {
973
				if (getHelpUI() != null) {
Lines 981-986 Link Here
981
	 *      java.lang.String)
990
	 *      java.lang.String)
982
	 */
991
	 */
983
	public void setHelp(Control control, String contextId) {
992
	public void setHelp(Control control, String contextId) {
993
		if (WorkbenchPlugin.DEBUG)
994
			setHelpTrace(contextId);
984
		control.setData(HELP_KEY, contextId);
995
		control.setData(HELP_KEY, contextId);
985
		// ensure that the listener is only registered once
996
		// ensure that the listener is only registered once
986
		control.removeHelpListener(getHelpListener());
997
		control.removeHelpListener(getHelpListener());
Lines 994-999 Link Here
994
	 *      java.lang.String)
1005
	 *      java.lang.String)
995
	 */
1006
	 */
996
	public void setHelp(Menu menu, String contextId) {
1007
	public void setHelp(Menu menu, String contextId) {
1008
		if (WorkbenchPlugin.DEBUG)
1009
			setHelpTrace(contextId);
997
		menu.setData(HELP_KEY, contextId);
1010
		menu.setData(HELP_KEY, contextId);
998
		// ensure that the listener is only registered once
1011
		// ensure that the listener is only registered once
999
		menu.removeHelpListener(getHelpListener());
1012
		menu.removeHelpListener(getHelpListener());
Lines 1007-1018 Link Here
1007
	 *      java.lang.String)
1020
	 *      java.lang.String)
1008
	 */
1021
	 */
1009
	public void setHelp(MenuItem item, String contextId) {
1022
	public void setHelp(MenuItem item, String contextId) {
1023
1024
		if (WorkbenchPlugin.DEBUG)
1025
			setHelpTrace(contextId);
1026
1010
		item.setData(HELP_KEY, contextId);
1027
		item.setData(HELP_KEY, contextId);
1011
		// ensure that the listener is only registered once
1028
		// ensure that the listener is only registered once
1012
		item.removeHelpListener(getHelpListener());
1029
		item.removeHelpListener(getHelpListener());
1013
		item.addHelpListener(getHelpListener());
1030
		item.addHelpListener(getHelpListener());
1014
	}
1031
	}
1015
1032
1033
	/*
1034
	 * (non-Javadoc)
1035
	 * 
1036
	 * Traces all calls to the setHelp method in an attempt to find and report
1037
	 * duplicated context IDs.
1038
	 */
1039
	private void setHelpTrace(String contextId) {
1040
1041
		StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
1042
		StackTraceElement currentElement = null;
1043
		for (int s = 0; s < stackTrace.length; s++) {
1044
			if (stackTrace[s].getMethodName().equals("setHelp") && s + 1 < stackTrace.length) //$NON-NLS-1$
1045
			{
1046
				currentElement = stackTrace[s + 1];
1047
				break;
1048
			}
1049
		}
1050
1051
		if (registeredIDTable == null)
1052
			registeredIDTable = new Hashtable();
1053
1054
		if (!registeredIDTable.containsKey(contextId))
1055
			registeredIDTable.put(contextId, currentElement);
1056
		else if (!registeredIDTable.get(contextId).equals(currentElement)) {
1057
			StackTraceElement initialElement = (StackTraceElement) registeredIDTable
1058
					.get(contextId);
1059
			String error = "UI Duplicate Context ID found: '" + contextId + "'\n" + //$NON-NLS-1$ //$NON-NLS-2$
1060
					" 1 at " + initialElement + '\n' + //$NON-NLS-1$
1061
					" 2 at " + currentElement; //$NON-NLS-1$
1062
1063
			System.out.println(error);
1064
		}
1065
	}
1066
1016
	/* (non-Javadoc)
1067
	/* (non-Javadoc)
1017
	 * @see org.eclipse.ui.help.IWorkbenchHelpSystem#hasHelpUI()
1068
	 * @see org.eclipse.ui.help.IWorkbenchHelpSystem#hasHelpUI()
1018
	 */
1069
	 */

Return to bug 296042