KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > ShowInTocAction


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.ui.internal;
12
13 import java.util.StringTokenizer JavaDoc;
14
15 import org.eclipse.help.HelpSystem;
16 import org.eclipse.help.IHelpResource;
17 import org.eclipse.help.ILiveHelpAction;
18 import org.eclipse.help.IToc;
19 import org.eclipse.help.ITopic;
20 import org.eclipse.help.ui.internal.views.AllTopicsPart;
21 import org.eclipse.help.ui.internal.views.ReusableHelpPart;
22
23 public class ShowInTocAction implements ILiveHelpAction {
24
25     private String JavaDoc path;
26     
27     public void setInitializationString(String JavaDoc data) {
28         path = data;
29     }
30
31     public void run() {
32         final IHelpResource res = getHelpResource();
33         final ReusableHelpPart helpPart = ReusableHelpPart.getLastActiveInstance();
34         if (helpPart != null) {
35             helpPart.getControl().getDisplay().syncExec(new Runnable JavaDoc() {
36                 public void run() {
37                     helpPart.showPage(IHelpUIConstants.HV_ALL_TOPICS_PAGE);
38                     AllTopicsPart part = (AllTopicsPart)helpPart.findPart(IHelpUIConstants.HV_TOPIC_TREE);
39                     if (part != null) {
40                         part.selectReveal(res);
41                     }
42                 }
43             });
44         }
45     }
46     
47     private IHelpResource getHelpResource() {
48         StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(path, "_"); //$NON-NLS-1$
49
int index = Integer.parseInt(tok.nextToken());
50         IToc[] tocs = HelpSystem.getTocs();
51         IToc toc = tocs[index];
52         if (tok.hasMoreTokens()) {
53             ITopic topic = toc.getTopic(null);
54             while (tok.hasMoreTokens()) {
55                 index = Integer.parseInt(tok.nextToken());
56                 topic = topic.getSubtopics()[index];
57             }
58             return topic;
59         }
60         return toc;
61     }
62 }
Popular Tags