Search in sources :

Example 6 with URLHyperlink

use of org.eclipse.jface.text.hyperlink.URLHyperlink in project webtools.sourceediting by eclipse.

the class TaglibHyperlinkDetector method createHyperlink.

/**
 * Create the appropriate hyperlink
 *
 * @param uriString
 * @param hyperlinkRegion
 * @return IHyperlink
 */
private IHyperlink createHyperlink(String uriString, IRegion hyperlinkRegion, IDocument document, Node node) {
    IHyperlink link = null;
    if (uriString != null) {
        String temp = uriString.toLowerCase();
        if (temp.startsWith(HTTP_PROTOCOL)) {
            // this is a URLHyperlink since this is a web address
            link = new URLHyperlink(hyperlinkRegion, uriString);
        } else if (temp.startsWith(JAR_PROTOCOL)) {
            // this is a URLFileHyperlink since this is a local address
            try {
                link = new URLFileRegionHyperlink(hyperlinkRegion, TAG, node.getLocalName(), new URL(uriString)) {

                    public String getHyperlinkText() {
                        return JSPUIMessages.CustomTagHyperlink_hyperlinkText;
                    }
                };
            } catch (MalformedURLException e) {
                Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
            }
        } else {
            // try to locate the file in the workspace
            IPath path = new Path(uriString);
            if (path.segmentCount() > 1) {
                IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
                if (file.getType() == IResource.FILE && file.isAccessible()) {
                    if (node != null) {
                        link = new TLDFileHyperlink(file, TAG, node.getLocalName(), hyperlinkRegion) {

                            public String getHyperlinkText() {
                                return JSPUIMessages.TLDHyperlink_hyperlinkText;
                            }
                        };
                    } else {
                        link = new WorkspaceFileHyperlink(hyperlinkRegion, file) {

                            public String getHyperlinkText() {
                                return JSPUIMessages.TLDHyperlink_hyperlinkText;
                            }
                        };
                    }
                }
            }
        }
        if (link == null) {
            // this is an ExternalFileHyperlink since file does not exist
            // in workspace
            File externalFile = new File(uriString);
            link = new ExternalFileHyperlink(hyperlinkRegion, externalFile) {

                public String getHyperlinkText() {
                    return JSPUIMessages.TLDHyperlink_hyperlinkText;
                }
            };
        }
    }
    return link;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) MalformedURLException(java.net.MalformedURLException) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) URL(java.net.URL) URLHyperlink(org.eclipse.jface.text.hyperlink.URLHyperlink) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 7 with URLHyperlink

use of org.eclipse.jface.text.hyperlink.URLHyperlink in project webtools.sourceediting by eclipse.

the class XMLHyperlinkDetector method createHyperlink.

/**
 * Create the appropriate hyperlink
 *
 * @param uriString
 * @param hyperlinkRegion
 * @return IHyperlink
 */
private IHyperlink createHyperlink(String uriString, IRegion hyperlinkRegion, IDocument document, Node node) {
    IHyperlink link = null;
    if (isHttp(uriString)) {
        link = new URLHyperlink(hyperlinkRegion, uriString);
    } else {
        // try to locate the file in the workspace
        File systemFile = getFileFromUriString(uriString);
        if (systemFile != null) {
            String systemPath = systemFile.getPath();
            IFile file = getFile(systemPath);
            if (file != null) {
                // this is a WorkspaceFileHyperlink since file exists in
                // workspace
                link = new WorkspaceFileHyperlink(hyperlinkRegion, file);
            } else {
                // this is an ExternalFileHyperlink since file does not
                // exist in workspace
                link = new ExternalFileHyperlink(hyperlinkRegion, systemFile);
            }
        }
    }
    return link;
}
Also used : URLHyperlink(org.eclipse.jface.text.hyperlink.URLHyperlink) IFile(org.eclipse.core.resources.IFile) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

URLHyperlink (org.eclipse.jface.text.hyperlink.URLHyperlink)7 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)5 File (java.io.File)2 URL (java.net.URL)2 IFile (org.eclipse.core.resources.IFile)2 Region (org.eclipse.jface.text.Region)2 PartInitException (org.eclipse.ui.PartInitException)2 MalformedURLException (java.net.MalformedURLException)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IRegion (org.eclipse.jface.text.IRegion)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 ProjectionViewer (org.eclipse.jface.text.source.projection.ProjectionViewer)1 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)1 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)1 Viewer (org.eclipse.jface.viewers.Viewer)1 SpecfileEditor (org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileEditor)1 URLHyperlinkWithMacroDetector (org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.URLHyperlinkWithMacroDetector)1