01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.editor;
11:
12: import org.eclipse.jface.text.IRegion;
13: import org.eclipse.jface.text.ITextViewer;
14: import org.eclipse.jface.text.hyperlink.IHyperlink;
15: import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
16: import org.eclipse.pde.internal.core.text.IDocumentAttributeNode;
17: import org.eclipse.pde.internal.core.text.IDocumentElementNode;
18: import org.eclipse.pde.internal.core.text.IDocumentRange;
19: import org.eclipse.pde.internal.core.text.IDocumentTextNode;
20: import org.eclipse.pde.internal.ui.editor.text.XMLUtil;
21:
22: /**
23: * PDEHyperlinkDetector
24: *
25: */
26: public abstract class PDEHyperlinkDetector implements
27: IHyperlinkDetector {
28:
29: private PDESourcePage fSourcePage;
30:
31: /**
32: * @param page
33: */
34: public PDEHyperlinkDetector(PDESourcePage page) {
35: fSourcePage = page;
36: }
37:
38: /* (non-Javadoc)
39: * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
40: */
41: public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
42: IRegion region, boolean canShowMultipleHyperlinks) {
43:
44: if (region == null || canShowMultipleHyperlinks)
45: return null;
46:
47: IDocumentRange element = fSourcePage.getRangeElement(region
48: .getOffset(), true);
49: if (!XMLUtil.withinRange(element, region.getOffset()))
50: return null;
51:
52: if (element instanceof IDocumentAttributeNode)
53: return detectAttributeHyperlink((IDocumentAttributeNode) element);
54: if (element instanceof IDocumentElementNode)
55: return detectNodeHyperlink((IDocumentElementNode) element);
56: if (element instanceof IDocumentTextNode)
57: return detectTextNodeHyperlink((IDocumentTextNode) element);
58: return null;
59: }
60:
61: /**
62: * @param attr
63: * @return
64: */
65: protected IHyperlink[] detectAttributeHyperlink(
66: IDocumentAttributeNode attr) {
67: return null;
68: }
69:
70: /**
71: * @param node
72: * @return
73: */
74: protected IHyperlink[] detectNodeHyperlink(IDocumentElementNode node) {
75: return null;
76: }
77:
78: /**
79: * @param node
80: * @return
81: */
82: protected IHyperlink[] detectTextNodeHyperlink(
83: IDocumentTextNode node) {
84: return null;
85: }
86:
87: }
|