Search in sources :

Example 1 with BrowserViewer

use of org.eclipse.ui.internal.browser.BrowserViewer in project yamcs-studio by yamcs.

the class WebBrowserFigure method createSWTWidget.

@Override
protected BrowserViewer createSWTWidget(Composite parent, int style) {
    try {
        browserViewer = new BrowserViewer(parent, style);
        browserViewer.setLayoutData(null);
        browser = browserViewer.getBrowser();
    } catch (Exception e) {
        errorMassage = "Failed to create web browser widget.\n" + "It may not available on your platform.\n" + e;
        ErrorHandlerUtil.handleError(errorMassage, e);
    }
    return browserViewer;
}
Also used : BrowserViewer(org.eclipse.ui.internal.browser.BrowserViewer)

Example 2 with BrowserViewer

use of org.eclipse.ui.internal.browser.BrowserViewer in project knime-core by knime.

the class AbstractInjector method findIntroPageBrowser.

/**
 * Looks for the open intro page editor (and HTML editor) and returns the Browser instance. This (unfortunately)
 * involves some heavy reflection stuff as there is no other way to attach a listener otherwise. If the intro page
 * editor cannot be found then <code>null</code> is returned.
 *
 * @param introPageFile the temporary intro page file
 * @return the browser instance showing the intro page or <code>null</code>
 */
@SuppressWarnings("restriction")
static Browser findIntroPageBrowser(final File introPageFile) {
    for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
        for (IWorkbenchPage page : window.getPages()) {
            for (IEditorReference ref : page.getEditorReferences()) {
                try {
                    if (isIntroPageEditor(ref, introPageFile)) {
                        IEditorPart part = ref.getEditor(false);
                        if (part instanceof WebBrowserEditor) {
                            WebBrowserEditor editor = (WebBrowserEditor) part;
                            Field webBrowser = editor.getClass().getDeclaredField("webBrowser");
                            webBrowser.setAccessible(true);
                            BrowserViewer viewer = (BrowserViewer) webBrowser.get(editor);
                            Field browserField = viewer.getClass().getDeclaredField("browser");
                            browserField.setAccessible(true);
                            return (Browser) browserField.get(viewer);
                        }
                    }
                } catch (PartInitException ex) {
                    NodeLogger.getLogger(AbstractInjector.class).error("Could not open web browser with intro page: " + ex.getMessage(), ex);
                } catch (SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {
                    NodeLogger.getLogger(AbstractInjector.class).error("Could not attach location listener to web browser: " + ex.getMessage(), ex);
                }
            }
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WebBrowserEditor(org.eclipse.ui.internal.browser.WebBrowserEditor) IEditorPart(org.eclipse.ui.IEditorPart) Field(java.lang.reflect.Field) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) BrowserViewer(org.eclipse.ui.internal.browser.BrowserViewer) PartInitException(org.eclipse.ui.PartInitException) Browser(org.eclipse.swt.browser.Browser)

Aggregations

BrowserViewer (org.eclipse.ui.internal.browser.BrowserViewer)2 Field (java.lang.reflect.Field)1 Browser (org.eclipse.swt.browser.Browser)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IEditorReference (org.eclipse.ui.IEditorReference)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 PartInitException (org.eclipse.ui.PartInitException)1 WebBrowserEditor (org.eclipse.ui.internal.browser.WebBrowserEditor)1