1 11 package org.eclipse.pde.internal.ui.editor.plugin; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.jface.text.IRegion; 15 import org.eclipse.jface.text.ITextViewer; 16 import org.eclipse.jface.text.Region; 17 import org.eclipse.jface.text.hyperlink.IHyperlink; 18 import org.eclipse.jface.text.hyperlink.IHyperlinkDetector; 19 import org.eclipse.pde.core.plugin.IPluginExtension; 20 import org.eclipse.pde.core.plugin.IPluginExtensionPoint; 21 import org.eclipse.pde.core.plugin.IPluginModelBase; 22 import org.eclipse.pde.core.plugin.IPluginObject; 23 import org.eclipse.pde.internal.core.ischema.IMetaAttribute; 24 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute; 25 import org.eclipse.pde.internal.core.schema.SchemaRootElement; 26 import org.eclipse.pde.internal.core.text.IDocumentAttribute; 27 import org.eclipse.pde.internal.core.text.IDocumentNode; 28 import org.eclipse.pde.internal.core.text.IDocumentRange; 29 import org.eclipse.pde.internal.core.text.IDocumentTextNode; 30 import org.eclipse.pde.internal.ui.editor.PDESourcePage; 31 import org.eclipse.pde.internal.ui.editor.text.JavaHyperlink; 32 import org.eclipse.pde.internal.ui.editor.text.ResourceHyperlink; 33 import org.eclipse.pde.internal.ui.editor.text.SchemaHyperlink; 34 import org.eclipse.pde.internal.ui.editor.text.TranslationHyperlink; 35 import org.eclipse.pde.internal.ui.editor.text.XMLUtil; 36 37 public class ManifestHyperlinkDetector implements IHyperlinkDetector { 38 39 private PDESourcePage fSourcePage; 40 41 44 public ManifestHyperlinkDetector(PDESourcePage page) { 45 fSourcePage = page; 46 } 47 48 public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) { 49 if (region == null || canShowMultipleHyperlinks) 50 return null; 51 52 IDocumentRange element = fSourcePage.getRangeElement(region.getOffset(), true); 53 if (!XMLUtil.withinRange(element, region.getOffset())) 54 return null; 55 56 if (element instanceof IDocumentAttribute) 57 return detectAttributeHyperlink((IDocumentAttribute)element); 58 if (element instanceof IDocumentNode) 59 return detectNodeHyperlink((IDocumentNode)element); 60 if (element instanceof IDocumentTextNode) 61 return detectTextNodeHyperlink((IDocumentTextNode)element); 62 return null; 63 } 64 65 private IHyperlink[] detectAttributeHyperlink(IDocumentAttribute attr) { 66 String attrValue = attr.getAttributeValue(); 67 if (attrValue.length() == 0) 68 return null; 69 70 IPluginObject node = XMLUtil.getTopLevelParent((IDocumentNode)attr); 71 if (node == null || !node.getModel().isEditable()) 72 return null; 73 74 IPluginModelBase base = node.getPluginModel(); 75 IResource res = base.getUnderlyingResource(); 76 IRegion linkRegion = new Region(attr.getValueOffset(), attr.getValueLength()); 77 78 IHyperlink[] link = new IHyperlink[1]; 79 if (node instanceof IPluginExtensionPoint) { 80 if (attr.getAttributeName().equals(IPluginExtensionPoint.P_SCHEMA)) 81 link[0] = new SchemaHyperlink(linkRegion, attrValue, res); 82 else if (attr.getAttributeName().equals(IPluginObject.P_NAME)) 83 if (attrValue.charAt(0) == '%') 84 link[0] = new TranslationHyperlink(linkRegion, attrValue, base); 85 86 } else if (node instanceof IPluginExtension) { 87 ISchemaAttribute sAttr = XMLUtil.getSchemaAttribute(attr, ((IPluginExtension)node).getPoint()); 88 if (sAttr == null) 89 return null; 90 91 if (sAttr.getKind() == IMetaAttribute.JAVA) { 92 link[0] = new JavaHyperlink(linkRegion, attrValue, res); 93 } else if (sAttr.getKind() == IMetaAttribute.RESOURCE) { 94 link[0] = new ResourceHyperlink(linkRegion, attrValue, res); 95 } else if (sAttr.getParent() instanceof SchemaRootElement) { 96 if (attr.getAttributeName().equals(IPluginExtension.P_POINT)) 97 link[0] = new ExtensionHyperLink(linkRegion, attrValue); 98 } else if (sAttr.isTranslatable()) { 99 if (attrValue.charAt(0) == '%') 100 link[0] = new TranslationHyperlink(linkRegion, attrValue, base); 101 } 102 } 103 104 if (link[0] != null) 105 return link; 106 return null; 107 } 108 109 private IHyperlink[] detectNodeHyperlink(IDocumentNode node) { 110 129 return null; 130 } 131 132 private IHyperlink[] detectTextNodeHyperlink(IDocumentTextNode node) { 133 IDocumentNode enclosing = node.getEnclosingElement(); 134 if (!(enclosing instanceof IPluginObject)) 135 return null; 136 IPluginModelBase base = ((IPluginObject)enclosing).getPluginModel(); 137 if (node.getText().charAt(0) == '%') 138 return new IHyperlink[] { 139 new TranslationHyperlink( 140 new Region(node.getOffset(), node.getLength()), node.getText(), base)}; 141 return null; 142 } 143 } 144 | Popular Tags |