1 11 package org.eclipse.help.internal.workingset; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.help.*; 17 import org.eclipse.help.internal.util.*; 18 import org.w3c.dom.*; 19 20 23 public class AdaptableTopic extends AdaptableHelpResource { 24 27 private Map topicMap; 28 29 32 AdaptableTopic(ITopic element) { 33 super(element); 34 } 35 36 39 public Object getAdapter(Class adapter) { 40 if (adapter == ITopic.class) 41 return element; 42 return super.getAdapter(adapter); 43 } 44 45 public AdaptableHelpResource[] getChildren() { 46 ITopic[] topics = this.getSubtopics(); 47 AdaptableHelpResource[] adaptableTopic = new AdaptableTopic[topics.length]; 48 for (int i = 0; i < topics.length; i++) { 49 adaptableTopic[i] = new AdaptableTopic(topics[i]); 50 } 51 return adaptableTopic; 52 } 53 54 57 public ITopic[] getSubtopics() { 58 return ((ITopic) element).getSubtopics(); 59 } 60 61 69 public ITopic getTopic(String href) { 70 if (href == null) 71 return null; 72 73 if (topicMap == null) { 74 topicMap = new HashMap (); 76 topicMap.put(getHref(), element); 77 FastStack stack = new FastStack(); 78 ITopic[] topics = getSubtopics(); 79 for (int i = 0; i < topics.length; i++) 80 stack.push(topics[i]); 81 while (!stack.isEmpty()) { 82 ITopic topic = (ITopic) stack.pop(); 83 if (topic != null) { 84 String topicHref = topic.getHref(); 85 if (topicHref != null) { 86 topicMap.put(topicHref, topic); 87 } 88 ITopic[] subtopics = topic.getSubtopics(); 89 for (int i = 0; i < subtopics.length; i++) 90 stack.push(subtopics[i]); 91 } 92 } 93 } 94 return (ITopic) topicMap.get(href); 95 } 96 97 public void saveState(Element element) { 98 AdaptableToc toc = (AdaptableToc) getParent(); 99 toc.saveState(element); 100 AdaptableHelpResource[] topics = toc.getChildren(); 101 for (int i = 0; i < topics.length; i++) 102 if (topics[i] == this) 103 element.setAttribute("topic", String.valueOf(i)); } 105 } 106 | Popular Tags |