Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2010-01-04 20:36:33 +0000
committerChris Goldthorpe2010-01-04 20:36:33 +0000
commit8cedff70f5ea346872bcea905ce4d1c3d6f0965a (patch)
tree5ad1abdce55a75961d81435676e37d75235af13f /org.eclipse.help
parent5b33a234e0fbf93515e95f39cbe12c1f75e84e6e (diff)
downloadeclipse.platform.ua-8cedff70f5ea346872bcea905ce4d1c3d6f0965a.tar.gz
eclipse.platform.ua-8cedff70f5ea346872bcea905ce4d1c3d6f0965a.tar.xz
eclipse.platform.ua-8cedff70f5ea346872bcea905ce4d1c3d6f0965a.zip
Bug 280357 – [Help][Context] Tools to create, debug, edit context sensitive help (CSH)v20100104
Diffstat (limited to 'org.eclipse.help')
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java20
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/ContextManager.java106
2 files changed, 119 insertions, 7 deletions
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java
index 3897b71d1..037d03f3c 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 IBM Corporation and others.
+ * Copyright (c) 2006, 2010 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
@@ -150,7 +150,7 @@ public class ContextFileProvider extends AbstractContextProvider {
* Returns the context definitions for the given plug-in and locale,
* as a mapping of short IDs to Context objects (shortContextId -> Context).
*/
- private Map[] getPluginContexts(String pluginId, String locale) {
+ public Map[] getPluginContexts(String pluginId, String locale) {
List maps = new ArrayList();
Map associations = getPluginAssociations();
ContextFile[] descriptors = (ContextFile[])associations.get(pluginId);
@@ -213,6 +213,7 @@ public class ContextFileProvider extends AbstractContextProvider {
return null;
}
+
private Map loadContextsFromInputStream(ContextFile descriptor, String locale, InputStream in)
throws Exception {
if (reader == null) {
@@ -240,10 +241,19 @@ public class ContextFileProvider extends AbstractContextProvider {
String id = context.getId();
if (id != null) {
Object existingContext = contexts.get(id);
- if (existingContext != null) {
- ((Context)existingContext).mergeContext(context);
- } else {
+ if (existingContext==null)
contexts.put(id, context);
+ else
+ {
+ ((Context)existingContext).mergeContext(context);
+
+ if (HelpPlugin.DEBUG_CONTEXT)
+ {
+ String error = "Context help ID '"+id+"' is found multiple times in file '"+descriptor.getBundleId()+'/'+descriptor.getFile()+"'\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ " Description 1: "+((Context)existingContext).getText()+'\n'+ //$NON-NLS-1$
+ " Description 2: "+context.getText(); //$NON-NLS-1$
+ System.out.println(error);
+ }
}
}
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextManager.java b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextManager.java
index 312e7d09f..a9bffe727 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextManager.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -12,6 +12,7 @@ package org.eclipse.help.internal.context;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -34,12 +35,21 @@ public class ContextManager {
private static final String ATTRIBUTE_NAME_CLASS = "class"; //$NON-NLS-1$
private Map providersByPluginId;
+ private Map contextIDsByPluginId;
private List globalProviders;
+ public ContextManager()
+ {
+ if (HelpPlugin.DEBUG_CONTEXT)
+ checkContextProviders();
+ }
+
/*
* Returns the Context for the given id and locale.
*/
public IContext getContext(String contextId, String locale) {
+
+
if (HelpPlugin.DEBUG_CONTEXT && contextId != null) {
System.out.println("ContextManager.getContext(\"" + contextId + "\")"); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -66,10 +76,41 @@ public class ContextManager {
HelpPlugin.logError(msg, t);
}
}
- }
+ }
+
if (HelpPlugin.DEBUG_CONTEXT) {
System.out.println("ContextManager.getContext - no context found"); //$NON-NLS-1$
+
+ String id = contextId;
+ ArrayList potentialMatches = new ArrayList();
+ if ((index = contextId.lastIndexOf('.'))>-1)
+ id = contextId.substring(index+1);
+
+ String warning = "Registered Context Provider IDs:\n"; //$NON-NLS-1$
+ Iterator iter = contextIDsByPluginId.keySet().iterator();
+ warning+="--------------------------------\n"; //$NON-NLS-1$
+ while (iter.hasNext())
+ {
+ String pluginID = (String)iter.next();
+ List contextIDList = (List)contextIDsByPluginId.get(pluginID);
+ for (int c=0;c<contextIDList.size();c++)
+ {
+ if (((String)contextIDList.get(c)).equalsIgnoreCase(id))
+ {
+ potentialMatches.add(pluginID+'.'+(String)contextIDList.get(c));
+ break;
+ }
+ }
+
+ warning+=pluginID+' '+contextIDList.toString()+'\n';
+ }
+ warning+="--------------------------------"; //$NON-NLS-1$
+ System.out.println(warning);
+
+ if (!potentialMatches.isEmpty())
+ System.out.println("The ID searched is "+contextId+". Did you mean to call setHelp with:\n"+potentialMatches); //$NON-NLS-1$ //$NON-NLS-2$
}
+
return null;
}
@@ -127,4 +168,65 @@ public class ContextManager {
}
}
}
+
+ /*
+ * Method only called when debugging context
+ * sensitive help.
+ *
+ * Checks to see if there are any duplicate ids
+ *
+ */
+ private void checkContextProviders()
+ {
+ contextIDsByPluginId = new Hashtable();
+ Hashtable contextByContextID = new Hashtable();
+
+ if (providersByPluginId == null) {
+ loadContextProviders();
+ }
+
+ Iterator i = providersByPluginId.keySet().iterator();
+
+ while (i.hasNext())
+ {
+ String pluginID = (String)i.next();
+ ArrayList providers = (ArrayList)providersByPluginId.get(pluginID);
+
+ for (int p=0;p<providers.size();p++)
+ {
+ ContextFileProvider provider = (ContextFileProvider)providers.get(p);
+ Map[] maps = provider.getPluginContexts(pluginID,Platform.getNL());
+
+ for (int m=0;m<maps.length;m++)
+ {
+ Iterator i2 = maps[m].keySet().iterator();
+ while (i2.hasNext())
+ {
+ String contextID = (String)i2.next();
+ String fullID = pluginID+'.'+contextID;
+ Context currentContext = (Context)maps[m].get(contextID);
+
+ if (!contextByContextID.containsKey(fullID))
+ contextByContextID.put(fullID,currentContext);
+ else if (HelpPlugin.DEBUG_CONTEXT)
+ {
+ Context initialContext = (Context)contextByContextID.get(fullID);
+ String error = "Context Help ID '"+contextID+"' is found in multiple context files in plugin '"+pluginID+"'\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ " Description 1: "+initialContext.getText()+'\n'+ //$NON-NLS-1$
+ " Description 2: "+currentContext.getText(); //$NON-NLS-1$
+
+ System.out.println(error);
+ }
+
+ ArrayList list = (ArrayList)contextIDsByPluginId.get(pluginID);
+ if (list==null){
+ list = new ArrayList();
+ contextIDsByPluginId.put(pluginID,list);
+ }
+ list.add(contextID);
+ }
+ }
+ }
+ }
+ }
}

Back to the top