Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2009-06-23 21:00:26 +0000
committerChris Goldthorpe2009-06-23 21:00:26 +0000
commit039a7fe0df957563c310c507b897bb1e1118fcd7 (patch)
tree024829f8bcad3f6f0c32ecb7a8877c940801c543 /org.eclipse.help
parentd74fea377c672738f114c8594ab37a51a05b5c4d (diff)
downloadeclipse.platform.ua-039a7fe0df957563c310c507b897bb1e1118fcd7.tar.gz
eclipse.platform.ua-039a7fe0df957563c310c507b897bb1e1118fcd7.tar.xz
eclipse.platform.ua-039a7fe0df957563c310c507b897bb1e1118fcd7.zip
Bug 38052 – [Help] Add alphabetical ordering attribute to TOC DTD
Diffstat (limited to 'org.eclipse.help')
-rw-r--r--org.eclipse.help/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.help/schema/toc.exsd66
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/Topic.java8
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/Toc.java9
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocManager.java4
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TopicSorter.java85
6 files changed, 142 insertions, 32 deletions
diff --git a/org.eclipse.help/META-INF/MANIFEST.MF b/org.eclipse.help/META-INF/MANIFEST.MF
index e1ed481b6..f84ae5de1 100644
--- a/org.eclipse.help/META-INF/MANIFEST.MF
+++ b/org.eclipse.help/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %help_plugin_name
Bundle-SymbolicName: org.eclipse.help; singleton:=true
-Bundle-Version: 3.4.0.qualifier
+Bundle-Version: 3.5.0.qualifier
Bundle-Activator: org.eclipse.help.internal.HelpPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/org.eclipse.help/schema/toc.exsd b/org.eclipse.help/schema/toc.exsd
index 10c0d7704..2c72d2627 100644
--- a/org.eclipse.help/schema/toc.exsd
+++ b/org.eclipse.help/schema/toc.exsd
@@ -2,9 +2,9 @@
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.help" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
- <appinfo>
+ <appInfo>
<meta.schema plugin="org.eclipse.help" id="toc" name="Table of Contents (TOC)"/>
- </appinfo>
+ </appInfo>
<documentation>
For registering an online help contribution for an individual plug-in.
@@ -26,9 +26,9 @@ point and specify TOC file(s).&lt;/li&gt;
<element name="extension">
<annotation>
- <appinfo>
+ <appInfo>
<meta.element />
- </appinfo>
+ </appInfo>
</annotation>
<complexType>
<choice minOccurs="1" maxOccurs="unbounded">
@@ -56,9 +56,9 @@ point and specify TOC file(s).&lt;/li&gt;
<documentation>
</documentation>
- <appinfo>
+ <appInfo>
<meta.attribute translatable="true"/>
- </appinfo>
+ </appInfo>
</annotation>
</attribute>
</complexType>
@@ -81,10 +81,14 @@ point and specify TOC file(s).&lt;/li&gt;
&lt;br&gt;&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ATTLIST toc link_to CDATA #IMPLIED &gt;&lt;/tt&gt;
&lt;br&gt;&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ATTLIST toc label CDATA #REQUIRED &gt;&lt;/tt&gt;
&lt;br&gt;&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ATTLIST toc topic CDATA #IMPLIED &gt;&lt;/tt&gt;
+&lt;br&gt;&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ATTLIST toc sort CDATA #IMPLIED &gt;&lt;/tt&gt;
+&lt;br&gt;&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ATTLIST toc icon CDATA #IMPLIED &gt;&lt;/tt&gt;
&lt;p&gt;&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ELEMENT topic (topic | anchor | link )*
&gt;&lt;/tt&gt;
&lt;br&gt;&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ATTLIST topic label CDATA #REQUIRED &gt;&lt;/tt&gt;
&lt;br&gt;&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ATTLIST topic href CDATA #IMPLIED &gt;&lt;/tt&gt;
+&lt;br&gt;&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ATTLIST topic sort CDATA #IMPLIED &gt;&lt;/tt&gt;
+&lt;br&gt;&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ATTLIST topic icon CDATA #IMPLIED &gt;&lt;/tt&gt;
&lt;p&gt;&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ELEMENT anchor EMPTY &gt;&lt;/tt&gt;
&lt;br&gt;&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ATTLIST anchor id ID&amp;nbsp; #REQUIRED &gt;&lt;/tt&gt;
&lt;p&gt;&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!ELEMENT link EMPTY &gt;&lt;/tt&gt;
@@ -121,6 +125,9 @@ file as well.
/&gt;&lt;/tt&gt;
&lt;br&gt;&lt;tt&gt;&amp;nbsp; ...&lt;/tt&gt;
&lt;br&gt;&lt;tt&gt;&amp;lt;/topic&gt;&lt;/tt&gt;
+&lt;p&gt; If the sort attribute is true child topics will be sorted alphabetically.&lt;/p&gt;&lt;p&gt; The
+optional icon attribute allows the use of a different icon as defined by a
+&amp;lt; tocIcon &amp;gt; element in an org.eclipse.help.toc extension.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;The link element&lt;/b&gt;
&lt;p&gt;The link element allows to link Table of Contents defined in another
toc file.&amp;nbsp; All the topics from the toc file specified in the toc attribute
@@ -145,8 +152,11 @@ an anchor as follows:
&lt;p&gt;&lt;b&gt;The toc element&lt;/b&gt;
&lt;p&gt;The toc element is a Table of Contents that groups topics and other
elements defined in this file.&amp;nbsp; The label identifies the table of
-contents to the user, when it is displayed to the user.&amp;nbsp; The optional topic
-attribute is the path to a topic file describing the TOC.&amp;nbsp; The optional
+contents to the user, when it is displayed to the user.&amp;nbsp;&lt;/p&gt;&lt;p&gt; The optional topic
+attribute is the path to a topic file describing the TOC.&amp;nbsp; &lt;/p&gt;
+&lt;p&gt; If the sort attribute is true child topics will be sorted alphabetically.&lt;/p&gt;&lt;p&gt; The
+optional icon attribute allows the use of a different icon as defined by a
+&amp;lt; tocIcon &amp;gt; element in an org.eclipse.help.toc extension.&lt;/p&gt;&lt;p&gt;The optional
link_to attribute allows for linking toc from this file into another toc
file being higher in the navigation hierarchy.&amp;nbsp; The value of the link_to
attribute must specify an anchor in another toc file. To link toc from
@@ -163,9 +173,9 @@ API&quot;/&gt;&lt;/tt&gt;
&lt;/p&gt;
&lt;br&gt;
</documentation>
- <appinfo>
+ <appInfo>
<meta.attribute kind="resource"/>
- </appinfo>
+ </appInfo>
</annotation>
</attribute>
<attribute name="primary" type="boolean" use="default" value="false">
@@ -205,9 +215,9 @@ or not primary and intended to be integrated into another table of contents.
<documentation>
the implementation class for the toc provider. This class must implement the &lt;samp&gt;org.eclipse.help.AbstractTocProvider&lt;/samp&gt; interface.
</documentation>
- <appinfo>
+ <appInfo>
<meta.attribute kind="java" basedOn="org.eclipse.help.AbstractTocProvider"/>
- </appinfo>
+ </appInfo>
</annotation>
</attribute>
</complexType>
@@ -249,9 +259,9 @@ or not primary and intended to be integrated into another table of contents.
<documentation>
The path of an icon to be used for a toc or topic whose chidren have been expanded.
</documentation>
- <appinfo>
+ <appInfo>
<meta.attribute kind="resource"/>
- </appinfo>
+ </appInfo>
</annotation>
</attribute>
<attribute name="closedIcon" type="string">
@@ -259,9 +269,9 @@ or not primary and intended to be integrated into another table of contents.
<documentation>
The path of an icon to be used for a toc or topic whose chidren have been expanded. If no provided openIcon will be used.
</documentation>
- <appinfo>
+ <appInfo>
<meta.attribute kind="resource"/>
- </appinfo>
+ </appInfo>
</annotation>
</attribute>
<attribute name="leafIcon" type="string">
@@ -269,9 +279,9 @@ or not primary and intended to be integrated into another table of contents.
<documentation>
The path of an icon to be used for a toc or topic without children. If not provided openIcon will be used.
</documentation>
- <appinfo>
+ <appInfo>
<meta.attribute kind="resource"/>
- </appinfo>
+ </appInfo>
</annotation>
</attribute>
<attribute name="altText" type="string">
@@ -279,18 +289,18 @@ or not primary and intended to be integrated into another table of contents.
<documentation>
Text that will be used in the &quot;alt&quot; attribute for the img tag in the web presentation.
</documentation>
- <appinfo>
+ <appInfo>
<meta.attribute translatable="true"/>
- </appinfo>
+ </appInfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
- <appinfo>
+ <appInfo>
<meta.section type="examples"/>
- </appinfo>
+ </appInfo>
<documentation>
The following is an example of using the &lt;samp&gt;toc&lt;/samp&gt; extension point.
@@ -378,9 +388,9 @@ to plugin directory.
</annotation>
<annotation>
- <appinfo>
+ <appInfo>
<meta.section type="apiInfo"/>
- </appinfo>
+ </appInfo>
<documentation>
An implementation of &lt;samp&gt;org.eclipse.help.AbstractTocProvider&lt;/samp&gt; must be supplied if a &lt;samp&gt;tocProvider&lt;/samp&gt; is used.
</documentation>
@@ -388,18 +398,18 @@ to plugin directory.
<annotation>
- <appinfo>
+ <appInfo>
<meta.section type="implementation"/>
- </appinfo>
+ </appInfo>
<documentation>
The default implementation of the help system UI supplied with the Eclipse platform fully supports this extension point.
</documentation>
</annotation>
<annotation>
- <appinfo>
+ <appInfo>
<meta.section type="copyright"/>
- </appinfo>
+ </appInfo>
<documentation>
Copyright (c) 2000, 2006 IBM Corporation and others.&lt;br&gt;
All rights reserved. This program and the accompanying materials are made
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/Topic.java b/org.eclipse.help/src/org/eclipse/help/internal/Topic.java
index 1e6125e83..df3e34ad5 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/Topic.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/Topic.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 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
@@ -19,6 +19,7 @@ public class Topic extends UAElement implements ITopic {
public static final String ATTRIBUTE_HREF = "href"; //$NON-NLS-1$
public static final String ATTRIBUTE_LABEL = "label"; //$NON-NLS-1$
public static final String ATTRIBUTE_ICON = "icon"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_SORT= "sort"; //$NON-NLS-1$
public Topic() {
super(NAME);
@@ -30,10 +31,15 @@ public class Topic extends UAElement implements ITopic {
setLabel(src.getLabel());
appendChildren(src.getChildren());
}
+
public String getIcon(){
return getAttribute(ATTRIBUTE_ICON);
}
+ public boolean isSorted(){
+ return "true".equalsIgnoreCase(getAttribute(ATTRIBUTE_SORT)); //$NON-NLS-1$
+ }
+
public Topic(Element src) {
super(src);
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/Toc.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/Toc.java
index 8ccd34378..e1df434c2 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/Toc.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/Toc.java
@@ -30,6 +30,7 @@ public class Toc extends UAElement implements IToc {
public static final String ATTRIBUTE_LINK_TO = "link_to"; //$NON-NLS-1$
public static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
public static final String ATTRIBUTE_ICON= "icon"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_SORT= "sort"; //$NON-NLS-1$
private ITocContribution contribution;
private ITopic topic;
@@ -98,6 +99,10 @@ public class Toc extends UAElement implements IToc {
public String getIcon(){
return getAttribute(ATTRIBUTE_ICON);
}
+
+ public boolean isSorted(){
+ return "true".equalsIgnoreCase(getAttribute(ATTRIBUTE_SORT)); //$NON-NLS-1$
+ }
/*
* Returns a mapping of all topic hrefs to ITopics.
@@ -135,10 +140,10 @@ public class Toc extends UAElement implements IToc {
return getTopics();
}
public boolean isEnabled(IEvaluationContext context) {
- return isEnabled(context);
+ return Toc.this.isEnabled(context);
}
public IUAElement[] getChildren() {
- return getChildren();
+ return new IUAElement[0];
}
};
}
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 34424363b..56f7fac27 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
@@ -81,6 +81,10 @@ public class TocManager {
}
}
tocs = (Toc[])orderedTocs.toArray(new Toc[orderedTocs.size()]);
+ TopicSorter topicSorter = new TopicSorter();
+ for (int i = 0; i < tocs.length; i++) {
+ topicSorter.sortChildren(tocs[i]);
+ }
tocsByLocale.put(locale, tocs);
long stop = System.currentTimeMillis();
if (HelpPlugin.DEBUG_TOC) {
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TopicSorter.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TopicSorter.java
new file mode 100644
index 000000000..5d90ec301
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/TopicSorter.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * 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.Arrays;
+import java.util.Comparator;
+
+import org.eclipse.help.ITopic;
+import org.eclipse.help.internal.Topic;
+import org.eclipse.help.internal.UAElement;
+
+import com.ibm.icu.text.Collator;
+
+/*
+ * Handles the "sort" attribute on topics and tocs
+ */
+public class TopicSorter {
+
+ private Comparator comparator;
+
+ public void sortChildren(Toc toc) {
+ if (comparator == null) {
+ comparator = new TopicComparator();
+ }
+ if (toc.isSorted()) {
+ sort(toc, toc.getTopics());
+ }
+ ITopic[] childTopics = toc.getTopics();
+ for (int i = 0; i < childTopics.length; i++) {
+ sortChildren((Topic)childTopics[i]);
+ }
+ }
+
+ private void sortChildren(Topic topic) {
+ if (topic.isSorted()) {
+ sort(topic, topic.getSubtopics());
+ }
+ ITopic[] childTopics = topic.getSubtopics();
+ for (int i = 0; i < childTopics.length; i++) {
+ sortChildren((Topic)childTopics[i]);
+ }
+ }
+
+ private class TopicComparator implements Comparator {
+ Collator collator = Collator.getInstance();
+
+ public int compare(Object o1, Object o2) {
+ String label1 = ((ITopic)o1).getLabel();
+ String label2 = ((ITopic)o2).getLabel();
+ return collator.compare(label1, label2);
+ }
+ }
+
+ /*
+ * Sort the given node's descendants recursively using the given
+ * Comparator.
+ */
+ private void sort(UAElement element, ITopic[] children) {
+ // sort children
+ if (children.length > 1) {
+ for (int i=0;i<children.length;++i) {
+ element.removeChild((UAElement)children[i]);
+ }
+ Arrays.sort(children, comparator);
+ for (int i=0;i<children.length;++i) {
+ element.appendChild((UAElement)children[i]);
+ }
+ }
+ // sort children's children
+ for (int i=0; i< children.length;++i) {
+ ITopic child = children[i];
+ sort((UAElement)children[i], child.getSubtopics());
+ }
+ }
+}
+
+ \ No newline at end of file

Back to the top