Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2009-11-30 21:24:30 +0000
committerChris Goldthorpe2009-11-30 21:24:30 +0000
commit4e84d864163b6e36de5bcaa5708ea42669bf1849 (patch)
tree8123c7b1db55936abea6c758c11d1d3adf93d06b /org.eclipse.help
parentc39c32c8fe53ee81f0571c212ecb4882d6fb7e27 (diff)
downloadeclipse.platform.ua-4e84d864163b6e36de5bcaa5708ea42669bf1849.tar.gz
eclipse.platform.ua-4e84d864163b6e36de5bcaa5708ea42669bf1849.tar.xz
eclipse.platform.ua-4e84d864163b6e36de5bcaa5708ea42669bf1849.zip
Bug 280354 – [Help] Action for doc plugins that reside locally and remotely:v20091130
Diffstat (limited to 'org.eclipse.help')
-rw-r--r--org.eclipse.help/src/org/eclipse/help/AbstractTocProvider.java27
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileProvider.java7
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocManager.java10
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocProviderComparator.java32
4 files changed, 71 insertions, 5 deletions
diff --git a/org.eclipse.help/src/org/eclipse/help/AbstractTocProvider.java b/org.eclipse.help/src/org/eclipse/help/AbstractTocProvider.java
index 34f58aa24..3f28e0577 100644
--- a/org.eclipse.help/src/org/eclipse/help/AbstractTocProvider.java
+++ b/org.eclipse.help/src/org/eclipse/help/AbstractTocProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 IBM Corporation and others.
+ * Copyright (c) 2006, 2009 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
@@ -20,7 +20,7 @@ import org.eclipse.help.internal.HelpPlugin;
* @since 3.3
*/
public abstract class AbstractTocProvider {
-
+
/**
* Returns all toc contributions for this provider. Providers
* are free to provide any number of contributions (zero or more).
@@ -39,4 +39,27 @@ public abstract class AbstractTocProvider {
// will force a reload next time around
HelpPlugin.getTocManager().clearCache();
}
+
+ /**
+ * Default priority for toc providers that do not override getPriority()
+ * @since 3.5
+ */
+ public static final int DEFAULT_PRIORITY=10;
+
+ /**
+ * Priority for toc files read from the local file system
+ * @since 3.5
+ */
+ public static final int TOC_FILE_PRIORITY=20;
+
+ /**
+ * If two toc contributions have the same id, the one with higher priority will be shown.
+ * For example, a provider with priority 1 will take precedence over a provider with priority 2.
+ * @return the priority of this provider
+ * @since 3.5
+ */
+ public int getPriority()
+ {
+ return DEFAULT_PRIORITY;
+ }
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileProvider.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileProvider.java
index b05c6760d..b4e13feca 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileProvider.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileProvider.java
@@ -87,4 +87,11 @@ public class TocFileProvider extends AbstractTocProvider {
}
return (TocFile[])tocFiles.toArray(new TocFile[tocFiles.size()]);
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.AbstractTocProvider#getPriority()
+ */
+ public int getPriority() {
+ return TOC_FILE_PRIORITY;
+ }
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocManager.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocManager.java
index 56f7fac27..f911f2a94 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocManager.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocManager.java
@@ -13,6 +13,7 @@ package org.eclipse.help.internal.toc;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -201,7 +202,7 @@ public class TocManager {
private synchronized TocContribution[] getAndCacheTocContributions(String locale, Map contributionsByLocale) {
TocContribution[] cached = (TocContribution[])contributionsByLocale.get(locale);
if (cached == null) {
- List contributions = new ArrayList();
+ HashMap contributions = new HashMap();
AbstractTocProvider[] providers = getTocProviders();
for (int i=0;i<providers.length;++i) {
ITocContribution[] contrib;
@@ -219,7 +220,8 @@ public class TocManager {
Toc t = toc instanceof Toc ? (Toc)toc : (Toc)UAElementFactory.newElement(toc);
t.setLinkTo(contrib[j].getLinkTo());
contribution.setToc(t);
- contributions.add(contribution);
+ if(!contributions.containsKey(contrib[j].getId()))
+ contributions.put(contrib[j].getId(), contribution);
}
}
catch (Throwable t) {
@@ -230,7 +232,7 @@ public class TocManager {
}
}
- cached = (TocContribution[])contributions.toArray(new TocContribution[contributions.size()]);
+ cached = (TocContribution[])contributions.values().toArray(new TocContribution[contributions.size()]);
contributionsByLocale.put(locale, cached);
}
return cached;
@@ -246,6 +248,7 @@ public class TocManager {
tocsByLocale.clear();
tocsById.clear();
tocsByTopic = null;
+ tocProviders=null;
}
/*
@@ -270,6 +273,7 @@ public class TocManager {
}
}
}
+ Collections.sort(providers, new TocProviderComparator());
tocProviders = (AbstractTocProvider[])providers.toArray(new AbstractTocProvider[providers.size()]);
}
return tocProviders;
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocProviderComparator.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocProviderComparator.java
new file mode 100644
index 000000000..9b1eeca42
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocProviderComparator.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.help.internal.toc;
+
+import java.util.Comparator;
+
+import org.eclipse.help.AbstractTocProvider;
+
+
+public class TocProviderComparator implements Comparator{
+
+ public int compare(Object obj1,Object obj2)
+ {
+ AbstractTocProvider provider1 = (AbstractTocProvider)obj1;
+ AbstractTocProvider provider2 = (AbstractTocProvider)obj2;
+
+ if(provider1.getPriority()<provider2.getPriority())
+ return -1;
+ else if(provider1.getPriority()>provider2.getPriority())
+ return 1;
+ else
+ return 0;
+ }
+}

Back to the top