diff options
author | Chris Goldthorpe | 2008-10-10 18:26:23 +0000 |
---|---|---|
committer | Chris Goldthorpe | 2008-10-10 18:26:23 +0000 |
commit | 13765e21030fc2e7773347e47ab36328f2b03eda (patch) | |
tree | 0b53805bd8b0ed294f05daf3f6465fddb1467531 /org.eclipse.help.webapp | |
parent | d2277f662fc52b2bfa8c7cdea8696e3c6bb76349 (diff) | |
download | eclipse.platform.ua-13765e21030fc2e7773347e47ab36328f2b03eda.tar.gz eclipse.platform.ua-13765e21030fc2e7773347e47ab36328f2b03eda.tar.xz eclipse.platform.ua-13765e21030fc2e7773347e47ab36328f2b03eda.zip |
Bug 27343 [Help] TOC tag does not support icon="Myimage.gif" - Webapp work
Diffstat (limited to 'org.eclipse.help.webapp')
4 files changed, 249 insertions, 28 deletions
diff --git a/org.eclipse.help.webapp/advanced/helptreechildren.js b/org.eclipse.help.webapp/advanced/helptreechildren.js index 6722d9149..1cda71957 100644 --- a/org.eclipse.help.webapp/advanced/helptreechildren.js +++ b/org.eclipse.help.webapp/advanced/helptreechildren.js @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * Copyright (c) 2006, 2008 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 @@ -77,9 +77,22 @@ function mergeChildren(treeItem, nodes) { var title = node.getAttribute("title"); var isLeaf = node.getAttribute("is_leaf"); var href = node.getAttribute("href"); - var image = node.getAttribute("image"); var id = node.getAttribute("id"); - var childItem = mergeChild(childContainer, id, title, href, image, isLeaf); + var openImage = null; + var closedImage = null; + var imageAltText = ""; + if (node.getAttribute("openImage")) { + openImage = "../topic" + node.getAttribute("openImage"); + imageAltText = node.getAttribute("imageAlt"); + } else { + openImage = node.getAttribute("image"); + imageAltText = getAltText(openImage); + openImage = imagesDirectory + "/" + openImage + ".gif"; + } + if (node.getAttribute("closedImage")) { + closedImage = "../topic" + node.getAttribute("closedImage"); + } + var childItem = mergeChild(childContainer, id, title, href, openImage, closedImage, imageAltText, isLeaf); var isSelected = node.getAttribute("is_selected"); if (!isLeaf) { mergeChildren(childItem, node.childNodes); @@ -106,7 +119,7 @@ function mergeChildren(treeItem, nodes) { } // Create a child if one with this if does not exist -function mergeChild(treeItem, id, name, href, image, isLeaf) { +function mergeChild(treeItem, id, name, href, image, closedImage, imageAltText, isLeaf) { var children = treeItem.childNodes; if (children !== null) { for (var i = 0; i < children.length; i++) { @@ -134,8 +147,16 @@ function mergeChild(treeItem, id, name, href, image, isLeaf) { var topicImage; if (image) { topicImage = document.createElement("IMG"); - setImage(topicImage, image); - } + //setImage(topicImage, image); + if (closedImage) { + topicImage.src = closedImage; + topicImage.openImage = image; + topicImage.closedImage = closedImage; + } else { + topicImage.src = image; + } + topicImage.alt = imageAltText; + } var topicName=document.createTextNode(name); diff --git a/org.eclipse.help.webapp/advanced/tocTree.js b/org.eclipse.help.webapp/advanced/tocTree.js index 108e71b66..ffddf9676 100644 --- a/org.eclipse.help.webapp/advanced/tocTree.js +++ b/org.eclipse.help.webapp/advanced/tocTree.js @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * Copyright (c) 2006, 2008 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 @@ -104,36 +104,44 @@ function setShowAll(isShowAll, href) { function setImage(imageNode, image) { var imageFile = imagesDirectory + "/" + image + ".gif"; imageNode.src = imageFile; + imageNode.alt = getAltText(image); +} + +function getAltText(image) { if (image == "plus") { - imageNode.alt = altPlus; + return altPlus; } else if (image == "minus") { - imageNode.alt = altMinus; + return altMinus; } else if (image == "toc_open") { - imageNode.alt = altBookOpen; + return altBookOpen; } else if (image == "toc_closed") { - imageNode.alt = altBookClosed; + return altBookClosed; } else if (image == "container_obj") { - imageNode.alt = altContainer; + return altContainer; } else if (image == "container_topic") { - imageNode.alt = altContainerTopic; + return altContainerTopic; } else if (image == "topic") { - imageNode.alt = altTopic; + return altTopic; } else { - imageNode.alt = ""; + return ""; } } function updateImage(imageNode, isExpanded) { var src = imageNode.src; - if (isExpanded) { - if (src.match( /toc_closed.gif$/)) { + if (isExpanded) { + if (imageNode.openImage) { + imageNode.src = imageNode.openImage; + } else if (src.match( /toc_closed.gif$/)) { setImage(imageNode, "toc_open"); } - } else { - if (src.match( /toc_open.gif$/)) { + } else { + if (imageNode.closedImage) { + imageNode.src = imageNode.closedImage; + } else if (src.match( /toc_open.gif$/)) { setImage(imageNode, "toc_closed"); } - } + } } function loadChildren(treeItem) { diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/IconFinder.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/IconFinder.java new file mode 100644 index 000000000..165aa5bf6 --- /dev/null +++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/IconFinder.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (c) 2008 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.webapp.data; + +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.Platform; + +public class IconFinder { + + private static final String LEAF = "_leaf"; //$NON-NLS-1$ + private static final String CLOSED = "_closed"; //$NON-NLS-1$ + private static final String OPEN = "_open"; //$NON-NLS-1$ + private static final String TOOLTIP = "_tooltip"; //$NON-NLS-1$ + private static final String EXT_PT = "org.eclipse.help.toc"; //$NON-NLS-1$ + private static final String TOC_ICON_ELEMENT = "tocIcon"; //$NON-NLS-1$ + private static final String TOC_ICON_ID = "id"; //$NON-NLS-1$ + private static final String OPEN_ICON_PATH = "openIcon"; //$NON-NLS-1$ + private static final String CLOSED_ICON_PATH = "closedIcon"; //$NON-NLS-1$ + private static final String LEAF_ICON_PATH = "leafIcon"; //$NON-NLS-1$ + private static final String ICON_TOOLTIP = "tooltip"; //$NON-NLS-1$ + private static final String PATH_SEPARATOR = "/"; //$NON-NLS-1$ + private static boolean iconsInitialized = false; + public static int TYPEICON_OPEN = 0; + public static int TYPEICON_CLOSED = 1; + public static int TYPEICON_LEAF = 2; + + + private static Map IconPathMap = null; // hash table + + public static void addIconPath(String IconKey, String IconPath) { + if (IconPathMap == null) { + IconPathMap = new HashMap(); + IconPathMap = new TreeMap(); // sorted map + } + IconPathMap.put(IconKey, IconPath); + } + public static String getIconPath(String IconKey) { + return getEntry(IconKey); + } + + public static String getIconTooltip(String IconKey) { + return getEntry(IconKey); + } + + private static String getEntry(String IconKey) { + if (IconPathMap == null) + return null; + Object key = IconPathMap.get(IconKey); + return (String) key; + } + + public static Map getInfoCenterMap() { + return IconPathMap; + } + + public static void setIconImagePath(String bundleId, String path, String key) { + String iconPath = IconFinder.getIconPath(key); + if(iconPath == null){ + iconPath = bundleId + PATH_SEPARATOR + path; + IconFinder.addIconPath(key, iconPath); + } + } + public static void setIconTooltip(String value, String key) { + IconFinder.addIconPath(key, value); + } + public static String getImagePathFromId(String iconId, int type) { + if (iconId == null) { + return null; + } + initializeTocIcons(); + String suffix; + + switch(type){ + case 0:suffix = OPEN;break; + case 1:suffix = CLOSED;break; + case 2:suffix = LEAF;break; + default: suffix = OPEN; break; + } + String result = lookupImagePath(iconId + suffix); + if (result != null) { + return result; + } + return lookupImagePath(iconId + OPEN); + } + + public static String getIconTooltipFromId(String iconId) { + if (iconId == null) { + return null; + } + initializeTocIcons(); + return getIconTooltip(iconId + TOOLTIP); + } + + private static String lookupImagePath(String name) { + return getIconPath(name); + } + private static void initializeTocIcons() { + if (iconsInitialized) { + return; + } + iconsInitialized = true; + // Get extension points that contribute products + IExtension[] extensionsFound = Platform.getExtensionRegistry() + .getExtensionPoint(EXT_PT).getExtensions(); + + for (int i = 0; i < extensionsFound.length; i++) { + + IConfigurationElement[] configElements = extensionsFound[i] + .getConfigurationElements(); + for (int j = 0; j < configElements.length; j++) { + if (configElements[j].getName().equals(TOC_ICON_ELEMENT)) { + IConfigurationElement iconElem = configElements[j]; + String attrs[] = iconElem.getAttributeNames(); + String contributorID = iconElem.getContributor().getName(); + + for (int k = 0; k < attrs.length; k++) { + if (attrs[k].equals(OPEN_ICON_PATH)) + IconFinder.setIconImagePath(contributorID, iconElem.getAttribute(OPEN_ICON_PATH),iconElem.getAttribute(TOC_ICON_ID) + OPEN); + if (attrs[k].equals(CLOSED_ICON_PATH)) + IconFinder.setIconImagePath(contributorID,iconElem.getAttribute(CLOSED_ICON_PATH),iconElem.getAttribute(TOC_ICON_ID)+ CLOSED); + if (attrs[k].equals(LEAF_ICON_PATH)) + IconFinder.setIconImagePath(contributorID, iconElem.getAttribute(LEAF_ICON_PATH),iconElem.getAttribute(TOC_ICON_ID) + LEAF); + if (attrs[k].equals(ICON_TOOLTIP)) + IconFinder.setIconTooltip(iconElem.getAttribute(ICON_TOOLTIP),iconElem.getAttribute(TOC_ICON_ID) + TOOLTIP); + } + } + } + } + } +} diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/TocFragmentServlet.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/TocFragmentServlet.java index 8f2869a4d..5c1a422e4 100644 --- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/TocFragmentServlet.java +++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/TocFragmentServlet.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * Copyright (c) 2006, 2008 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 @@ -22,8 +22,11 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.help.IToc; import org.eclipse.help.ITopic; +import org.eclipse.help.internal.Topic; +import org.eclipse.help.internal.toc.Toc; import org.eclipse.help.internal.webapp.WebappResources; import org.eclipse.help.internal.webapp.data.EnabledTopicUtils; +import org.eclipse.help.internal.webapp.data.IconFinder; import org.eclipse.help.internal.webapp.data.TocData; import org.eclipse.help.internal.webapp.data.UrlUtil; @@ -188,7 +191,7 @@ public class TocFragmentServlet extends HttpServlet { } buf.append('\n' + " href=\"" + XMLGenerator.xmlEscape(UrlUtil.getHelpURL(href)) + "\""); //$NON-NLS-1$ //$NON-NLS-2$ - buf.append('\n' + " image=\"toc_closed\""); //$NON-NLS-1$ + buf.append(createTocImageTag(toc)); boolean serializeChildren = true; if (requestKind == REQUEST_SHOW_TOCS) { @@ -252,7 +255,56 @@ public class TocFragmentServlet extends HttpServlet { buf.append('\n' + " is_selected=\"true\"" ); //$NON-NLS-1$ buf.append('\n' + " is_highlighted=\"true\"" ); //$NON-NLS-1$ } - String icon; + String imageTags = createTopicImageTags(topic, isLeaf); + buf.append(imageTags); + + buf.append(">\n"); //$NON-NLS-1$ + serializeChildTopics(subtopics, topicPath, parentPath, isSelected); + buf.append("</node>\n"); //$NON-NLS-1$ + } + + private String createTocImageTag(IToc toc) { + if (toc instanceof Toc) { + String icon = ((Toc) toc).getIcon(); + + if (icon != null && icon.length() > 0) { + + String imageTags = '\n' + " openImage=\"/"+ IconFinder.getImagePathFromId(icon, IconFinder.TYPEICON_OPEN) + "\""; //$NON-NLS-1$ //$NON-NLS-2$ + imageTags += '\n' + " closedImage=\"/" + IconFinder.getImagePathFromId(icon, IconFinder.TYPEICON_CLOSED) + "\""; //$NON-NLS-1$ //$NON-NLS-2$ + String tooltip = IconFinder.getIconTooltipFromId(icon); + if(tooltip != null) { + imageTags += '\n' + " imageAlt=\""+ tooltip + "\""; //$NON-NLS-1$ //$NON-NLS-2$ + } + return imageTags; + } + } + return '\n' + " image=\"toc_closed\""; //$NON-NLS-1$ + } + + private String createTopicImageTags(ITopic topic, boolean isLeaf) { + if (topic instanceof Topic) { + String icon = ((Topic) topic).getIcon(); + String tooltip = IconFinder.getIconTooltipFromId(icon); + + if (icon != null && icon.length() > 0) { + String imageTags; + if (isLeaf) { + imageTags = '\n' + " openImage=\"/" +IconFinder.getImagePathFromId(icon, IconFinder.TYPEICON_LEAF) + "\""; //$NON-NLS-1$//$NON-NLS-2$ + if(tooltip != null) + imageTags += '\n' + " tooltip=\""+ tooltip + "\""; //$NON-NLS-1$ //$NON-NLS-2$ + } else { + imageTags = '\n' + " openImage=\"/" + IconFinder.getImagePathFromId(icon, IconFinder.TYPEICON_OPEN)+ "\""; //$NON-NLS-1$ //$NON-NLS-2$ + imageTags += '\n' + " closedImage=\"/" + IconFinder.getImagePathFromId(icon, IconFinder.TYPEICON_CLOSED) + "\""; //$NON-NLS-1$ //$NON-NLS-2$ + if(tooltip != null) + imageTags += '\n' + " tooltip=\""+ tooltip + "\""; //$NON-NLS-1$ //$NON-NLS-2$ + } + if(tooltip != null) { + imageTags += '\n' + " imageAlt=\""+ tooltip + "\""; //$NON-NLS-1$ //$NON-NLS-2$ + } + return imageTags; + } + } + String icon; if (isLeaf) { icon = "topic"; //$NON-NLS-1$ } else if (topic.getHref() == null) { @@ -260,11 +312,8 @@ public class TocFragmentServlet extends HttpServlet { } else { icon = "container_topic"; //$NON-NLS-1$ } - buf.append('\n' + " image=\"" + icon + "\""); //$NON-NLS-1$ //$NON-NLS-2$ - - buf.append(">\n"); //$NON-NLS-1$ - serializeChildTopics(subtopics, topicPath, parentPath, isSelected); - buf.append("</node>\n"); //$NON-NLS-1$ + String imageTags = '\n' + " image=\"" + icon + "\""; //$NON-NLS-1$ //$NON-NLS-2$ + return imageTags; } private void serializeChildTopics(ITopic[] childTopics, ITopic[] topicPath, String parentPath, boolean parentIsSelected) { |