Search in sources :

Example 1 with JavadocView

use of org.eclipse.jdt.internal.ui.infoviews.JavadocView in project windup-eclipse-plugin by windup.

the class ControlInformationSupport method addLinkListener.

private static void addLinkListener(final BrowserInformationControl control) {
    control.addLocationListener(JavaElementLinks.createLocationListener(new JavaElementLinks.ILinkHandler() {

        @Override
        public void handleJavadocViewLink(IJavaElement linkTarget) {
            control.notifyDelayedInputChange(null);
            control.setVisible(false);
            control.dispose();
            try {
                JavadocView view = (JavadocView) JavaPlugin.getActivePage().showView(JavaUI.ID_JAVADOC_VIEW);
                view.setInput(linkTarget);
            } catch (PartInitException e) {
                JavaPlugin.log(e);
            }
        }

        @Override
        public void handleInlineJavadocLink(IJavaElement linkTarget) {
            JavadocBrowserInformationControlInput hoverInfo = JavadocHover.getHoverInfo(new IJavaElement[] { linkTarget }, null, null, (JavadocBrowserInformationControlInput) control.getInput());
            if (control.hasDelayedInputChangeListener())
                control.notifyDelayedInputChange(hoverInfo);
            else
                control.setInput(hoverInfo);
        }

        @Override
        public void handleDeclarationLink(IJavaElement linkTarget) {
            control.notifyDelayedInputChange(null);
            control.dispose();
        // TODO: ME
        /*try {
					//FIXME: add hover location to editor navigation history?
					openDeclaration(linkTarget);
				} catch (PartInitException e) {
					JavaPlugin.log(e);
				} catch (JavaModelException e) {
					JavaPlugin.log(e);
				}*/
        }

        @Override
        public boolean handleExternalLink(URL url, Display display) {
            control.notifyDelayedInputChange(null);
            control.dispose();
            // Open attached Javadoc links
            OpenBrowserUtil.open(url, display);
            return true;
        }

        @Override
        public void handleTextSet() {
        }
    }));
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) JavadocBrowserInformationControlInput(org.eclipse.jdt.internal.ui.text.java.hover.JavadocBrowserInformationControlInput) JavadocView(org.eclipse.jdt.internal.ui.infoviews.JavadocView) PartInitException(org.eclipse.ui.PartInitException) URL(java.net.URL) Display(org.eclipse.swt.widgets.Display)

Example 2 with JavadocView

use of org.eclipse.jdt.internal.ui.infoviews.JavadocView in project jbosstools-base by jbosstools.

the class ELInfoHover method addLinkListener.

private static void addLinkListener(final BrowserInformationControl control) {
    control.addLocationListener(new LocationListener() {

        @Override
        public void changing(LocationEvent event) {
            String loc = event.location;
            if ("about:blank".equals(loc)) {
                // $NON-NLS-1$
                return;
            }
            event.doit = false;
            if (loc.startsWith("about:")) {
                // If no base is available, links just won't work.
                return;
            }
            URI uri = null;
            try {
                uri = new URI(loc);
            } catch (URISyntaxException e) {
                ElUiPlugin.getDefault().logError(e);
                return;
            }
            String scheme = uri == null ? null : uri.getScheme();
            if (JavaElementLinks.JAVADOC_VIEW_SCHEME.equals(scheme)) {
                IJavaElement linkTarget = JavaElementLinks.parseURI(uri);
                if (linkTarget == null)
                    return;
                handleJavadocViewLink(linkTarget);
            } else if (JavaElementLinks.JAVADOC_SCHEME.equals(scheme)) {
                IJavaElement linkTarget = JavaElementLinks.parseURI(uri);
                if (linkTarget == null)
                    return;
                handleInlineJavadocLink(linkTarget);
            } else if (JavaElementLinks.OPEN_LINK_SCHEME.equals(scheme)) {
                IJavaElement linkTarget = JavaElementLinks.parseURI(uri);
                if (linkTarget == null)
                    return;
                handleDeclarationLink(linkTarget);
            } else if (scheme != null && (// $NON-NLS-1$
            scheme.toLowerCase().equalsIgnoreCase("http") || scheme.toLowerCase().equalsIgnoreCase("https"))) {
                // $NON-NLS-1$
                try {
                    if (handleExternalLink(new URL(loc), event.display, true))
                        return;
                    event.doit = true;
                } catch (MalformedURLException e) {
                    ElUiPlugin.getDefault().logError(e);
                }
            }
        }

        /* (non-Javadoc)
			 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks.ILinkHandler#handleJavadocViewLink(org.eclipse.jdt.core.IJavaElement)
			 */
        public void handleJavadocViewLink(IJavaElement linkTarget) {
            control.notifyDelayedInputChange(null);
            control.setVisible(false);
            control.dispose();
            try {
                JavadocView view = (JavadocView) JavaPlugin.getActivePage().showView(JavaUI.ID_JAVADOC_VIEW);
                view.setInput(linkTarget);
            } catch (PartInitException e) {
                ElUiPlugin.getDefault().logError(e);
            }
        }

        /* (non-Javadoc)
			 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks.ILinkHandler#handleInlineJavadocLink(org.eclipse.jdt.core.IJavaElement)
			 */
        public void handleInlineJavadocLink(IJavaElement linkTarget) {
            JavadocBrowserInformationControlInput hoverInfo = JavadocHover.getHoverInfo(new IJavaElement[] { linkTarget }, null, null, (JavadocBrowserInformationControlInput) control.getInput());
            if (control.hasDelayedInputChangeListener())
                control.notifyDelayedInputChange(hoverInfo);
            else
                control.setInput(hoverInfo);
        }

        /* (non-Javadoc)
			 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks.ILinkHandler#handleDeclarationLink(org.eclipse.jdt.core.IJavaElement)
			 */
        public void handleDeclarationLink(IJavaElement linkTarget) {
            control.notifyDelayedInputChange(null);
            // FIXME: should have protocol to hide, rather than dispose
            control.dispose();
            try {
                JavadocHover.openDeclaration(linkTarget);
            } catch (PartInitException e) {
                ElUiPlugin.getDefault().logError(e);
            } catch (JavaModelException e) {
                ElUiPlugin.getDefault().logError(e);
            }
        }

        boolean handleExternalLink(URL url, Display display, boolean openInExternalBrowser) {
            control.notifyDelayedInputChange(null);
            control.dispose();
            // Open attached Javadoc links
            if (openInExternalBrowser)
                OpenBrowserUtil.openExternal(url, display);
            else
                OpenBrowserUtil.open(url, display);
            return true;
        }

        public void changed(LocationEvent event) {
        }
    });
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) MalformedURLException(java.net.MalformedURLException) JavaModelException(org.eclipse.jdt.core.JavaModelException) JavadocBrowserInformationControlInput(org.eclipse.jdt.internal.ui.text.java.hover.JavadocBrowserInformationControlInput) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) LocationListener(org.eclipse.swt.browser.LocationListener) JavadocView(org.eclipse.jdt.internal.ui.infoviews.JavadocView) PartInitException(org.eclipse.ui.PartInitException) LocationEvent(org.eclipse.swt.browser.LocationEvent) Display(org.eclipse.swt.widgets.Display)

Aggregations

URL (java.net.URL)2 IJavaElement (org.eclipse.jdt.core.IJavaElement)2 JavadocView (org.eclipse.jdt.internal.ui.infoviews.JavadocView)2 JavadocBrowserInformationControlInput (org.eclipse.jdt.internal.ui.text.java.hover.JavadocBrowserInformationControlInput)2 Display (org.eclipse.swt.widgets.Display)2 PartInitException (org.eclipse.ui.PartInitException)2 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 LocationEvent (org.eclipse.swt.browser.LocationEvent)1 LocationListener (org.eclipse.swt.browser.LocationListener)1