Search in sources :

Example 21 with LocationListener

use of org.eclipse.swt.browser.LocationListener in project BiglyBT by BiglySoftware.

the class MessageBoxShell method _open.

private void _open() {
    if (instanceID != null) {
        if (mapInstances.containsKey(instanceID)) {
            MessageBoxShell mb = mapInstances.get(instanceID);
            if (mb.shell != null && !mb.shell.isDisposed()) {
                mb.shell.open();
                return;
            }
        }
        mapInstances.put(instanceID, this);
    }
    result = -1;
    boolean ourParent = false;
    if (parent == null || parent.isDisposed()) {
        parent = Utils.findAnyShell();
        ourParent = true;
        if (parent == null || parent.isDisposed()) {
            triggerResultListener(result);
            return;
        }
    }
    final Display display = parent.getDisplay();
    // APPLICATION_MODAL causes some crazy sht to happen on Windows.
    // Example: 5 windows open in APPLICATION MODAL mode,
    // and somehow none of them show until you do a "Window->Bring To Front"
    // which only makes ONE visible
    int shell_style = SWT.DIALOG_TRIM | SWT.RESIZE;
    if (modal) {
        shell_style |= SWT.APPLICATION_MODAL;
    }
    shell = ShellFactory.createShell(parent, shell_style);
    if (title != null) {
        shell.setText(title);
    }
    shell.addListener(SWT.Dispose, new Listener() {

        @Override
        public void handleEvent(Event event) {
            mapInstances.remove(instanceID);
            if (iconImageID != null) {
                ImageLoader.getInstance().releaseImage(iconImageID);
            }
            triggerResultListener(result);
            if (display != null && !display.isDisposed() && filterListener != null) {
                display.removeFilter(SWT.Traverse, filterListener);
            }
            numOpen--;
        }
    });
    GridLayout gridLayout = new GridLayout();
    if (squish) {
        gridLayout.verticalSpacing = 0;
        gridLayout.horizontalSpacing = 0;
        gridLayout.marginLeft = 0;
        gridLayout.marginRight = 0;
        gridLayout.marginTop = 0;
        gridLayout.marginBottom = 0;
        gridLayout.marginWidth = 0;
        gridLayout.marginHeight = 0;
    }
    shell.setLayout(gridLayout);
    Utils.setShellIcon(shell);
    UISkinnableSWTListener[] listeners = UISkinnableManagerSWT.getInstance().getSkinnableListeners(MessageBoxShell.class.toString());
    for (int i = 0; i < listeners.length; i++) {
        listeners[i].skinBeforeComponents(shell, this, relatedObjects);
    }
    FormData formData;
    GridData gridData;
    Composite textComposite = shell;
    if (imgLeft != null) {
        textComposite = new Composite(shell, SWT.NONE);
        textComposite.setForeground(shell.getForeground());
        GridLayout gl = new GridLayout(2, false);
        gl.horizontalSpacing = 10;
        textComposite.setLayout(gl);
        textComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
        Label lblImage = new Label(textComposite, SWT.NONE);
        lblImage.setImage(imgLeft);
        lblImage.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    } else if (!squish) {
        textComposite = new Composite(shell, SWT.NONE);
        GridLayout gl = new GridLayout(2, false);
        gl.marginWidth = 5;
        textComposite.setLayout(gl);
        textComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    }
    Control linkControl;
    if (text != null && text.length() > 0) {
        if (useTextBox()) {
            linkControl = createTextBox(textComposite, text);
        } else {
            linkControl = createLinkLabel(textComposite, text);
        }
    } else {
        linkControl = null;
    }
    if ((html != null && html.length() > 0) || (url != null && url.length() > 0)) {
        try {
            final BrowserWrapper browser = Utils.createSafeBrowser(shell, SWT.NONE);
            if (url != null && url.length() > 0) {
                browser.setUrl(url);
            } else {
                browser.setText(html);
            }
            GridData gd = new GridData(GridData.FILL_BOTH);
            gd.heightHint = 200;
            browser.getControl().setLayoutData(gd);
            browser.addProgressListener(new ProgressListener() {

                @Override
                public void completed(ProgressEvent event) {
                    if (shell == null || shell.isDisposed()) {
                        return;
                    }
                    browser.addLocationListener(new LocationListener() {

                        @Override
                        public void changing(LocationEvent event) {
                            event.doit = browser_follow_links;
                        }

                        @Override
                        public void changed(LocationEvent event) {
                        }
                    });
                    browser.addOpenWindowListener(new BrowserWrapper.OpenWindowListener() {

                        @Override
                        public void open(BrowserWrapper.WindowEvent event) {
                            event.setRequired(true);
                        }
                    });
                }

                @Override
                public void changed(ProgressEvent event) {
                }
            });
            browser.addStatusTextListener(new StatusTextListener() {

                @Override
                public void changed(StatusTextEvent event) {
                    if (STATUS_TEXT_CLOSE.equals(event.text)) {
                        // For some reason disposing the shell / browser in the same Thread makes
                        // ieframe.dll crash on windows.
                        Utils.execSWTThreadLater(0, new Runnable() {

                            @Override
                            public void run() {
                                if (!browser.isDisposed() && !shell.isDisposed()) {
                                    shell.close();
                                }
                            }
                        });
                    }
                }
            });
        } catch (Exception e) {
            Debug.out(e);
            if (html != null) {
                Text text = new Text(shell, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP);
                text.setText(html);
                GridData gd = new GridData(GridData.FILL_BOTH);
                gd.heightHint = 200;
                text.setLayoutData(gd);
            }
        }
        if (linkControl != null) {
            gridData = new GridData(GridData.FILL_HORIZONTAL);
            linkControl.setLayoutData(gridData);
        }
    } else {
        if (linkControl != null) {
            gridData = new GridData(GridData.FILL_BOTH);
            linkControl.setLayoutData(gridData);
        }
    }
    if (!squish && (autoCloseInMS > 0 || rememberID != null || (cbMessageID != null && Utils.getUserMode() >= cbMinUserMode))) {
        Label lblPadding = new Label(shell, SWT.NONE);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.heightHint = 5;
        lblPadding.setLayoutData(gridData);
    }
    // Closing in..
    if (autoCloseInMS > 0) {
        final BufferedLabel lblCloseIn = new BufferedLabel(shell, SWT.WRAP | SWT.DOUBLE_BUFFERED);
        lblCloseIn.setForeground(shell.getForeground());
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        if (!squish) {
            gridData.horizontalIndent = 5;
        }
        lblCloseIn.setText(MessageText.getString("popup.closing.in", new String[] { String.valueOf(autoCloseInMS / 1000) }));
        lblCloseIn.setLayoutData(gridData);
        long endOn = SystemTime.getCurrentTime() + autoCloseInMS;
        lblCloseIn.setData("CloseOn", new Long(endOn));
        SimpleTimer.addPeriodicEvent("autoclose", 500, new TimerEventPerformer() {

            @Override
            public void perform(TimerEvent event) {
                if (shell.isDisposed()) {
                    event.cancel();
                    return;
                }
                Utils.execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        if (!shell.isDisposed()) {
                            boolean bDelayPaused = lblCloseIn.getData("DelayPaused") != null;
                            if (bDelayPaused) {
                                return;
                            }
                            long endOn = ((Long) lblCloseIn.getData("CloseOn")).longValue();
                            if (SystemTime.getCurrentTime() > endOn) {
                                result = defaultButtonPos;
                                autoClosed = true;
                                shell.dispose();
                            } else {
                                String sText = "";
                                if (lblCloseIn.isDisposed())
                                    return;
                                if (!bDelayPaused) {
                                    long delaySecs = (endOn - SystemTime.getCurrentTime()) / 1000;
                                    sText = MessageText.getString("popup.closing.in", new String[] { String.valueOf(delaySecs) });
                                }
                                lblCloseIn.setText(sText);
                            }
                        }
                    }
                });
            }
        });
        SimpleTimer.addPeriodicEvent("OverPopup", 100, new TimerEventPerformer() {

            boolean wasOver = true;

            long lEnterOn = 0;

            @Override
            public void perform(final TimerEvent event) {
                if (shell.isDisposed()) {
                    event.cancel();
                    return;
                }
                Utils.execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        if (shell.isDisposed()) {
                            event.cancel();
                            return;
                        }
                        boolean isOver = shell.getBounds().contains(shell.getDisplay().getCursorLocation());
                        if (isOver != wasOver) {
                            wasOver = isOver;
                            if (isOver) {
                                lblCloseIn.setData("DelayPaused", "");
                                lEnterOn = SystemTime.getCurrentTime();
                                lblCloseIn.setText("");
                            } else {
                                lblCloseIn.setData("DelayPaused", null);
                                if (lEnterOn > 0) {
                                    long diff = SystemTime.getCurrentTime() - lEnterOn;
                                    long endOn = ((Long) lblCloseIn.getData("CloseOn")).longValue() + diff;
                                    lblCloseIn.setData("CloseOn", new Long(endOn));
                                }
                            }
                        }
                    }
                });
            }
        });
    }
    boolean needSpacer = true;
    if (cbMessageID != null && Utils.getUserMode() >= cbMinUserMode) {
        needSpacer = false;
        Button cb = new Button(shell, SWT.CHECK);
        cb.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                cbEnabled = ((Button) e.widget).getSelection();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
        Messages.setLanguageText(cb, cbMessageID);
        cb.setSelection(cbEnabled);
    }
    if (rememberID != null) {
        Button checkRemember = new Button(shell, SWT.CHECK);
        checkRemember.setText(rememberText);
        checkRemember.setSelection(rememberByDefault);
        isRemembered = rememberByDefault;
        checkRemember.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                Button checkRemember = (Button) event.widget;
                isRemembered = checkRemember.getSelection();
            }
        });
        checkRemember.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                Button checkRemember = (Button) e.widget;
                isRemembered = checkRemember != null && checkRemember.getSelection();
                if (rememberID != null && isRemembered && (rememberOnlyIfButtonPos == -1 || rememberOnlyIfButtonPos == result)) {
                    RememberedDecisionsManager.setRemembered(rememberID, getButtonVal(result));
                }
            }
        });
    } else if (supportsApplyToAll) {
        Button appkyToAll = new Button(shell, SWT.CHECK);
        appkyToAll.setText(MessageText.getString("label.apply.to.all"));
        appkyToAll.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                Button button = (Button) event.widget;
                applyToAll = button.getSelection();
            }
        });
    } else if (needSpacer) {
        Button spacer = new Button(shell, SWT.CHECK);
        spacer.setVisible(false);
    }
    if (buttons.length > 0) {
        Canvas line = new Canvas(shell, SWT.NO_BACKGROUND);
        line.addListener(SWT.Paint, new Listener() {

            @Override
            public void handleEvent(Event e) {
                Rectangle clientArea = ((Canvas) e.widget).getClientArea();
                e.gc.setForeground(Colors.getSystemColor(e.display, SWT.COLOR_WIDGET_NORMAL_SHADOW));
                e.gc.drawRectangle(clientArea);
                clientArea.y++;
                e.gc.setForeground(Colors.getSystemColor(e.display, SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
                e.gc.drawRectangle(clientArea);
            }
        });
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.heightHint = 2;
        line.setLayoutData(gridData);
        Composite cButtons = new Composite(shell, SWT.NONE);
        FormLayout layout = new FormLayout();
        cButtons.setLayout(layout);
        gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
        cButtons.setLayoutData(gridData);
        Control lastButton = null;
        Listener buttonListener = new Listener() {

            @Override
            public void handleEvent(Event event) {
                result = ((Integer) event.widget.getData()).intValue();
                shell.dispose();
            }
        };
        int buttonWidth = 0;
        Button[] swtButtons = new Button[buttons.length];
        for (int i = 0; i < buttons.length; i++) {
            Button button = new Button(cButtons, SWT.PUSH);
            swtButtons[i] = button;
            button.setData(Integer.valueOf(i));
            button.setText(buttons[i]);
            button.addListener(SWT.Selection, buttonListener);
            formData = new FormData();
            if (lastButton != null) {
                formData.left = new FormAttachment(lastButton, 5);
            }
            button.setLayoutData(formData);
            Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            if (size.x > buttonWidth) {
                buttonWidth = size.x;
            }
            if (i == defaultButtonPos) {
                button.setFocus();
                shell.setDefaultButton(button);
            }
            lastButton = button;
        }
        if (buttonWidth > 0) {
            if (buttonWidth < MIN_BUTTON_SIZE) {
                buttonWidth = MIN_BUTTON_SIZE;
            }
            for (int i = 0; i < buttons.length; i++) {
                Point size = swtButtons[i].computeSize(buttonWidth, SWT.DEFAULT);
                swtButtons[i].setSize(size);
                formData = (FormData) swtButtons[i].getLayoutData();
                formData.width = buttonWidth;
            }
        }
    }
    shell.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent event) {
            if (event.detail == SWT.TRAVERSE_ESCAPE) {
                shell.dispose();
            }
        }
    });
    filterListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
            if (event.detail == SWT.TRAVERSE_ARROW_NEXT) {
                event.detail = SWT.TRAVERSE_TAB_NEXT;
                event.doit = true;
            } else if (event.detail == SWT.TRAVERSE_ARROW_PREVIOUS) {
                event.detail = SWT.TRAVERSE_TAB_PREVIOUS;
                event.doit = true;
            }
        }
    };
    display.addFilter(SWT.Traverse, filterListener);
    shell.pack();
    Point size = shell.getSize();
    if (size.x < min_size_x) {
        size.x = min_size_x;
        shell.setSize(size);
    } else if (size.x > max_size_x) {
        size = shell.computeSize(max_size_x, SWT.DEFAULT);
        shell.setSize(size);
    }
    if (size.y < min_size_y) {
        size.y = min_size_y;
        shell.setSize(size);
    }
    Shell centerRelativeToShell = parent;
    if (ourParent) {
        Control cursorControl = display.getCursorControl();
        if (cursorControl != null) {
            centerRelativeToShell = cursorControl.getShell();
        }
    }
    Utils.centerWindowRelativeTo(shell, centerRelativeToShell);
    for (int i = 0; i < listeners.length; i++) {
        listeners[i].skinAfterComponents(shell, this, relatedObjects);
    }
    shell.open();
    opened = true;
    numOpen++;
    return;
}
Also used : StatusTextListener(org.eclipse.swt.browser.StatusTextListener) ProgressListener(org.eclipse.swt.browser.ProgressListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) LocationListener(org.eclipse.swt.browser.LocationListener) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) StatusTextListener(org.eclipse.swt.browser.StatusTextListener) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) StatusTextEvent(org.eclipse.swt.browser.StatusTextEvent) LocationListener(org.eclipse.swt.browser.LocationListener) LocationEvent(org.eclipse.swt.browser.LocationEvent) MessageText(com.biglybt.core.internat.MessageText) ProgressListener(org.eclipse.swt.browser.ProgressListener) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) StatusTextEvent(org.eclipse.swt.browser.StatusTextEvent) LocationEvent(org.eclipse.swt.browser.LocationEvent)

Example 22 with LocationListener

use of org.eclipse.swt.browser.LocationListener in project BiglyBT by BiglySoftware.

the class SearchResultsTabAreaBrowser method anotherSearch.

@Override
public void anotherSearch(SearchQuery sq) {
    this.sq = sq;
    String url = Constants.URL_WEBSEARCH.replaceAll("%s", Matcher.quoteReplacement(UrlUtils.encode(sq.term)));
    AEProxyFactory.PluginHTTPProxy proxy = getSearchProxy(this);
    if (proxy != null) {
        url = proxy.proxifyURL(url);
    }
    if (Utils.isThisThreadSWT()) {
        try {
            final AESemaphore sem = new AESemaphore("brwoserWait");
            final BrowserWrapper browser = browserSkinObject.getBrowser();
            browser.addLocationListener(new LocationListener() {

                @Override
                public void changing(LocationEvent event) {
                }

                @Override
                public void changed(LocationEvent event) {
                    browser.removeLocationListener(this);
                    sem.releaseForever();
                }
            });
            browserSkinObject.getBrowser().setUrl("about:blank");
            browserSkinObject.getBrowser().refresh();
            browserSkinObject.getBrowser().update();
            final String finalURL = url;
            Utils.getOffOfSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    sem.reserve(300);
                    browserSkinObject.setURL(finalURL);
                }
            });
        } catch (Throwable t) {
        }
    } else {
        browserSkinObject.setURL(url);
    }
}
Also used : LocationListener(org.eclipse.swt.browser.LocationListener) BrowserWrapper(com.biglybt.ui.swt.BrowserWrapper) AEProxyFactory(com.biglybt.core.proxy.AEProxyFactory) LocationEvent(org.eclipse.swt.browser.LocationEvent)

Example 23 with LocationListener

use of org.eclipse.swt.browser.LocationListener in project statecharts by Yakindu.

the class SelectExamplePage method createDetailsPane.

protected void createDetailsPane(Composite parent) {
    final Composite composite = new Composite(parent, SWT.BORDER);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    composite.setLayout(new FillLayout());
    browser = new Browser(composite, SWT.NONE);
    browser.addLocationListener(new LocationListener() {

        @Override
        public void changing(LocationEvent event) {
            try {
                String loc = event.location;
                URI uri = new URI(loc);
                String scheme = uri.getScheme();
                if (("https".equals(scheme) || "http".equals(scheme)) && !loc.startsWith("https://www.youtube.com/embed/")) {
                    openExternalBrowser(uri.toURL());
                    event.doit = false;
                } else if ("file".equals(scheme)) {
                    String exampleId = parseExampleId(uri);
                    if (exampleId != null) {
                        selectExample(exampleId);
                        event.doit = false;
                    }
                }
            } catch (URISyntaxException | MalformedURLException e) {
                e.printStackTrace();
            }
        }

        private String parseExampleId(URI uri) {
            String query = uri.getQuery();
            if (query == null)
                return null;
            String[] split = query.split("=");
            if (split.length == 2) {
                if (split[0].equals("exampleId")) {
                    return split[1];
                }
            }
            return null;
        }

        @Override
        public void changed(LocationEvent event) {
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) LocationListener(org.eclipse.swt.browser.LocationListener) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) URI(java.net.URI) LocationEvent(org.eclipse.swt.browser.LocationEvent) Browser(org.eclipse.swt.browser.Browser)

Example 24 with LocationListener

use of org.eclipse.swt.browser.LocationListener in project windup-eclipse-plugin by windup.

the class ClassificationDescriptionTab method createBrowser.

private void createBrowser(Composite parent) {
    browser = new Browser(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 150).applyTo(browser);
    browser.addLocationListener(new LocationListener() {

        public void changed(LocationEvent event) {
            event.doit = false;
        }

        public void changing(LocationEvent event) {
            // if it looks like an absolute URL
            if (event.location.matches("([a-zA-Z]{3,8})://?.*")) {
                // $NON-NLS-1$
                // workaround for browser problem (bug 262043)
                // $NON-NLS-1$
                int idxOfSlashHash = event.location.indexOf("/#");
                if (idxOfSlashHash != -1) {
                    // allow javascript-based scrolling to work
                    if (!event.location.startsWith("file:///#")) {
                        // $NON-NLS-1$
                        event.doit = false;
                    }
                    return;
                }
                // workaround end
                event.doit = false;
                try {
                    IWebBrowser webBrowser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser(// $NON-NLS-1$
                    "org.eclipse.ui.browser");
                    webBrowser.openURL(new URL(event.location));
                } catch (Exception e) {
                    new URLHyperlink(new Region(0, 1), event.location).open();
                }
            }
        }
    });
}
Also used : URLHyperlink(org.eclipse.jface.text.hyperlink.URLHyperlink) LocationListener(org.eclipse.swt.browser.LocationListener) Region(org.eclipse.jface.text.Region) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) LocationEvent(org.eclipse.swt.browser.LocationEvent) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) Browser(org.eclipse.swt.browser.Browser)

Example 25 with LocationListener

use of org.eclipse.swt.browser.LocationListener 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

LocationEvent (org.eclipse.swt.browser.LocationEvent)29 LocationListener (org.eclipse.swt.browser.LocationListener)29 Browser (org.eclipse.swt.browser.Browser)18 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)9 ProgressListener (org.eclipse.swt.browser.ProgressListener)9 FillLayout (org.eclipse.swt.layout.FillLayout)9 Shell (org.eclipse.swt.widgets.Shell)9 URL (java.net.URL)7 Display (org.eclipse.swt.widgets.Display)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 SWTException (org.eclipse.swt.SWTException)6 Test (org.junit.Test)6 StatusTextListener (org.eclipse.swt.browser.StatusTextListener)5 TitleListener (org.eclipse.swt.browser.TitleListener)5 Point (org.eclipse.swt.graphics.Point)5 MalformedURLException (java.net.MalformedURLException)4 OpenWindowListener (org.eclipse.swt.browser.OpenWindowListener)4 WindowEvent (org.eclipse.swt.browser.WindowEvent)4 MouseEvent (org.eclipse.swt.events.MouseEvent)4 IOException (java.io.IOException)3