001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.plugin;
011:
012: import org.eclipse.core.resources.IResource;
013: import org.eclipse.jface.text.IRegion;
014: import org.eclipse.jface.text.Region;
015: import org.eclipse.jface.text.hyperlink.IHyperlink;
016: import org.eclipse.pde.core.plugin.IPluginExtension;
017: import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
018: import org.eclipse.pde.core.plugin.IPluginModelBase;
019: import org.eclipse.pde.core.plugin.IPluginObject;
020: import org.eclipse.pde.internal.core.ischema.IMetaAttribute;
021: import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
022: import org.eclipse.pde.internal.core.schema.SchemaRootElement;
023: import org.eclipse.pde.internal.core.text.IDocumentAttributeNode;
024: import org.eclipse.pde.internal.core.text.IDocumentElementNode;
025: import org.eclipse.pde.internal.core.text.IDocumentTextNode;
026: import org.eclipse.pde.internal.ui.editor.PDEHyperlinkDetector;
027: import org.eclipse.pde.internal.ui.editor.PDESourcePage;
028: import org.eclipse.pde.internal.ui.editor.text.JavaHyperlink;
029: import org.eclipse.pde.internal.ui.editor.text.ResourceHyperlink;
030: import org.eclipse.pde.internal.ui.editor.text.SchemaHyperlink;
031: import org.eclipse.pde.internal.ui.editor.text.TranslationHyperlink;
032: import org.eclipse.pde.internal.ui.editor.text.XMLUtil;
033:
034: public class ManifestHyperlinkDetector extends PDEHyperlinkDetector {
035:
036: /**
037: * @param editor the editor in which to detect the hyperlink
038: */
039: public ManifestHyperlinkDetector(PDESourcePage page) {
040: super (page);
041: }
042:
043: protected IHyperlink[] detectAttributeHyperlink(
044: IDocumentAttributeNode attr) {
045: String attrValue = attr.getAttributeValue();
046: if (attrValue.length() == 0)
047: return null;
048:
049: IPluginObject node = XMLUtil.getTopLevelParent(attr);
050: if (node == null || !node.getModel().isEditable())
051: return null;
052:
053: IPluginModelBase base = node.getPluginModel();
054: IResource res = base.getUnderlyingResource();
055: IRegion linkRegion = new Region(attr.getValueOffset(), attr
056: .getValueLength());
057:
058: IHyperlink[] link = new IHyperlink[1];
059: if (node instanceof IPluginExtensionPoint) {
060: if (attr.getAttributeName().equals(
061: IPluginExtensionPoint.P_SCHEMA))
062: link[0] = new SchemaHyperlink(linkRegion, attrValue,
063: res);
064: else if (attr.getAttributeName().equals(
065: IPluginObject.P_NAME))
066: if (attrValue.charAt(0) == '%')
067: link[0] = new TranslationHyperlink(linkRegion,
068: attrValue, base);
069:
070: } else if (node instanceof IPluginExtension) {
071: ISchemaAttribute sAttr = XMLUtil.getSchemaAttribute(attr,
072: ((IPluginExtension) node).getPoint());
073: if (sAttr == null)
074: return null;
075:
076: if (sAttr.getKind() == IMetaAttribute.JAVA) {
077: link[0] = new JavaHyperlink(linkRegion, attrValue, res);
078: } else if (sAttr.getKind() == IMetaAttribute.RESOURCE) {
079: link[0] = new ResourceHyperlink(linkRegion, attrValue,
080: res);
081: } else if (sAttr.getParent() instanceof SchemaRootElement) {
082: if (attr.getAttributeName().equals(
083: IPluginExtension.P_POINT))
084: link[0] = new ExtensionHyperLink(linkRegion,
085: attrValue);
086: } else if (sAttr.isTranslatable()) {
087: if (attrValue.charAt(0) == '%')
088: link[0] = new TranslationHyperlink(linkRegion,
089: attrValue, base);
090: }
091: }
092:
093: if (link[0] != null)
094: return link;
095: return null;
096: }
097:
098: protected IHyperlink[] detectNodeHyperlink(IDocumentElementNode node) {
099: // TODO what can we do here?
100: // suggestions:
101: // - use SchemaEditor.openToElement(IPath path, ISchemaElement element)
102: // to directly highlight this particular element in a schema editor
103: // ? too fancy ?
104: /*
105: IPluginObject parent = XMLUtil.getTopLevelParent(node);
106: if (parent == null || !parent.getModel().isEditable())
107: return null;
108:
109: if (parent instanceof IPluginExtension) {
110: ISchemaElement sElement = XMLUtil.getSchemaElement(node, ((IPluginExtension)parent).getPoint());
111: if (sElement == null)
112: return null;
113: URL url = sElement.getSchema().getURL();
114: // only have access to URL now - extend SchemaEditor?
115: SchemaEditor.openToElement(url, sElement);
116: }
117: */
118: return null;
119: }
120:
121: protected IHyperlink[] detectTextNodeHyperlink(
122: IDocumentTextNode node) {
123: IDocumentElementNode enclosing = node.getEnclosingElement();
124: if (!(enclosing instanceof IPluginObject))
125: return null;
126: IPluginModelBase base = ((IPluginObject) enclosing)
127: .getPluginModel();
128: if (node.getText().charAt(0) == '%')
129: return new IHyperlink[] { new TranslationHyperlink(
130: new Region(node.getOffset(), node.getLength()),
131: node.getText(), base) };
132: return null;
133: }
134: }
|