Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2164875bd0c1249e7719795e224fc86f6c5a1911 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*******************************************************************************
 * Copyright (c) 2007, 2016 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.ui.internal;

import java.util.StringTokenizer;

import org.eclipse.help.HelpSystem;
import org.eclipse.help.IHelpResource;
import org.eclipse.help.ILiveHelpAction;
import org.eclipse.help.IToc;
import org.eclipse.help.ITopic;
import org.eclipse.help.ui.internal.views.AllTopicsPart;
import org.eclipse.help.ui.internal.views.ReusableHelpPart;

public class ShowInTocAction implements ILiveHelpAction {

	private String path;
	
	@Override
	public void setInitializationString(String data) {
		path = data;
	}

	@Override
	public void run() {
		final IHelpResource res = getHelpResource();
		final ReusableHelpPart helpPart = ReusableHelpPart.getLastActiveInstance();
		if (helpPart != null) {
			helpPart.getControl().getDisplay().syncExec(() -> {
				helpPart.showPage(IHelpUIConstants.HV_ALL_TOPICS_PAGE);
				AllTopicsPart part = (AllTopicsPart) helpPart.findPart(IHelpUIConstants.HV_TOPIC_TREE);
				if (part != null) {
					part.selectReveal(res);
				}
			});
		}
	}
	
	private IHelpResource getHelpResource() {
		StringTokenizer tok = new StringTokenizer(path, "_"); //$NON-NLS-1$
		int index = Integer.parseInt(tok.nextToken());
		IToc[] tocs = HelpSystem.getTocs();
		IToc toc = tocs[index];
		if (tok.hasMoreTokens()) {
			ITopic topic = toc.getTopic(null);
			while (tok.hasMoreTokens()) {
				index = Integer.parseInt(tok.nextToken());
				topic = topic.getSubtopics()[index];
			}
			return topic;
		}
		return toc;
	}
}

Back to the top