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.cheatsheet.simple;
11:
12: import org.eclipse.core.resources.IResource;
13: import org.eclipse.jface.text.IRegion;
14: import org.eclipse.jface.text.Region;
15: import org.eclipse.jface.text.hyperlink.IHyperlink;
16: import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSConstants;
17: import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModel;
18: import org.eclipse.pde.internal.core.text.IDocumentAttributeNode;
19: import org.eclipse.pde.internal.core.text.IDocumentElementNode;
20: import org.eclipse.pde.internal.core.text.cheatsheet.simple.SimpleCSObject;
21: import org.eclipse.pde.internal.core.util.PDETextHelper;
22: import org.eclipse.pde.internal.ui.editor.PDEHyperlinkDetector;
23: import org.eclipse.pde.internal.ui.editor.PDESourcePage;
24: import org.eclipse.pde.internal.ui.editor.text.ResourceHyperlink;
25:
26: /**
27: * SimpleCSHyperlinkDetector
28: *
29: */
30: public class SimpleCSHyperlinkDetector extends PDEHyperlinkDetector {
31:
32: /**
33: * @param page
34: */
35: public SimpleCSHyperlinkDetector(PDESourcePage page) {
36: super (page);
37: }
38:
39: /* (non-Javadoc)
40: * @see org.eclipse.pde.internal.ui.editor.PDEHyperlinkDetector#detectAttributeHyperlink(org.eclipse.pde.internal.core.text.IDocumentAttributeNode)
41: */
42: protected IHyperlink[] detectAttributeHyperlink(
43: IDocumentAttributeNode attribute) {
44: // Get the attribute value
45: String attributeValue = attribute.getAttributeValue();
46: // Ensure the value is defined
47: if (PDETextHelper.isDefinedAfterTrim(attributeValue) == false) {
48: return null;
49: }
50: // Get attribute parent
51: IDocumentElementNode node = attribute.getEnclosingElement();
52: // Ensure the node is defined
53: if (node == null) {
54: return null;
55: } else if ((node instanceof SimpleCSObject) == false) {
56: return null;
57: }
58: SimpleCSObject csObject = (SimpleCSObject) node;
59: ISimpleCSModel model = csObject.getModel();
60: // Ensure the model is editable
61: if (model.isEditable() == false) {
62: return null;
63: }
64: // Get the underlying model resource
65: IResource resource = model.getUnderlyingResource();
66: // Create the link region
67: IRegion linkRegion = new Region(attribute.getValueOffset(),
68: attribute.getValueLength());
69: // Create the link container
70: IHyperlink[] link = new IHyperlink[1];
71: // Create the appropriate resource hyperlink
72: if (csObject.getType() == ISimpleCSConstants.TYPE_ITEM) {
73: // Item
74: if (attribute.getAttributeName().equals(
75: ISimpleCSConstants.ATTRIBUTE_HREF)) {
76: // Href
77: link[0] = new ResourceHyperlink(linkRegion,
78: attributeValue, resource);
79: }
80: } else if (csObject.getType() == ISimpleCSConstants.TYPE_INTRO) {
81: // Intro
82: if (attribute.getAttributeName().equals(
83: ISimpleCSConstants.ATTRIBUTE_HREF)) {
84: // Href
85: link[0] = new ResourceHyperlink(linkRegion,
86: attributeValue, resource);
87: }
88: }
89: // If the link is defined return it
90: if (link[0] != null) {
91: return link;
92: }
93: return null;
94: }
95:
96: }
|