01: package org.eclipse.pde.internal.ui.editor.toc;
02:
03: import org.eclipse.core.resources.IResource;
04: import org.eclipse.jface.text.IRegion;
05: import org.eclipse.jface.text.Region;
06: import org.eclipse.jface.text.hyperlink.IHyperlink;
07: import org.eclipse.pde.internal.core.itoc.ITocConstants;
08: import org.eclipse.pde.internal.core.text.IDocumentAttributeNode;
09: import org.eclipse.pde.internal.core.text.IDocumentElementNode;
10: import org.eclipse.pde.internal.core.text.toc.TocModel;
11: import org.eclipse.pde.internal.core.text.toc.TocObject;
12: import org.eclipse.pde.internal.ui.editor.PDEHyperlinkDetector;
13: import org.eclipse.pde.internal.ui.editor.PDESourcePage;
14: import org.eclipse.pde.internal.ui.editor.text.ResourceHyperlink;
15:
16: public class TocHyperlinkDetector extends PDEHyperlinkDetector {
17:
18: /**
19: * @param editor the editor in which to detect the hyperlink
20: */
21: public TocHyperlinkDetector(PDESourcePage page) {
22: super (page);
23: }
24:
25: protected IHyperlink[] detectAttributeHyperlink(
26: IDocumentAttributeNode attr) {
27: String attrValue = attr.getAttributeValue();
28: if (attrValue.length() == 0)
29: return null;
30:
31: IDocumentElementNode node = attr.getEnclosingElement();
32: if (node == null || !(node instanceof TocObject)
33: || !((TocObject) node).getModel().isEditable()) {
34: return null;
35: }
36:
37: TocObject tocObject = (TocObject) node;
38: TocModel model = tocObject.getModel();
39: IResource res = model.getUnderlyingResource();
40: IRegion linkRegion = new Region(attr.getValueOffset(), attr
41: .getValueLength());
42:
43: IHyperlink[] link = new IHyperlink[1];
44: if (tocObject.getType() == ITocConstants.TYPE_TOC) {
45: if (attr.getAttributeName().equals(
46: ITocConstants.ATTRIBUTE_TOPIC)) {
47: link[0] = new ResourceHyperlink(linkRegion, attrValue,
48: res);
49: }
50: } else if (tocObject.getType() == ITocConstants.TYPE_TOPIC) {
51: if (attr.getAttributeName().equals(
52: ITocConstants.ATTRIBUTE_HREF)) {
53: link[0] = new ResourceHyperlink(linkRegion, attrValue,
54: res);
55: }
56: } else if (tocObject.getType() == ITocConstants.TYPE_LINK) {
57: if (attr.getAttributeName().equals(
58: ITocConstants.ATTRIBUTE_TOC)) {
59: link[0] = new ResourceHyperlink(linkRegion, attrValue,
60: res);
61: }
62: }
63:
64: if (link[0] != null) {
65: return link;
66: }
67:
68: return null;
69: }
70:
71: }
|