Search in sources :

Example 26 with LocationListener

use of org.eclipse.swt.browser.LocationListener in project spotbugs by spotbugs.

the class BugInfoView method createBrowser.

private void createBrowser(Composite parent) {
    GridData data = new GridData(GridData.FILL_BOTH);
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    try {
        browser = new Browser(parent, SWT.NONE);
        browser.setLayoutData(data);
        browser.setBackground(parent.getBackground());
        browser.addOpenWindowListener(new OpenWindowListener() {

            @Override
            public void open(WindowEvent event) {
                // Cancel opening of new windows
                event.required = true;
            }
        });
        browser.addLocationListener(new LocationListener() {

            @Override
            public void changed(LocationEvent event) {
            // ignore
            }

            @Override
            public void changing(LocationEvent event) {
                // set any non-null url. We ignore this url
                if (allowUrlChange || "about:blank".equals(event.location)) {
                    return;
                }
                // disallow changing of property view content
                event.doit = false;
                // for any external url clicked by user we should leave
                // property view
                openBrowserInEditor(event);
            }
        });
    } catch (SWTError e) {
        FindbugsPlugin plugin = FindbugsPlugin.getDefault();
        plugin.logException(new RuntimeException(e.getMessage(), e), "Could not create org.eclipse.swt.widgets.Composite.Browser");
    }
}
Also used : SWTError(org.eclipse.swt.SWTError) WindowEvent(org.eclipse.swt.browser.WindowEvent) LocationListener(org.eclipse.swt.browser.LocationListener) GridData(org.eclipse.swt.layout.GridData) FindbugsPlugin(de.tobject.findbugs.FindbugsPlugin) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener) LocationEvent(org.eclipse.swt.browser.LocationEvent) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) Browser(org.eclipse.swt.browser.Browser)

Example 27 with LocationListener

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

the class Test_org_eclipse_swt_browser_Browser method test_LocationListener_changingAndOnlyThenChanged.

@Test
public void test_LocationListener_changingAndOnlyThenChanged() {
    // Test proper order of events.
    // Check that 'changed' is only fired after 'changing' has fired at least once.
    AtomicBoolean changingFired = new AtomicBoolean(false);
    AtomicBoolean changedFired = new AtomicBoolean(false);
    AtomicBoolean changedFiredTooEarly = new AtomicBoolean(false);
    AtomicBoolean finished = new AtomicBoolean(false);
    browser.addLocationListener(new LocationListener() {

        @Override
        public void changing(LocationEvent event) {
            // Multiple changing events can occur during a load.
            changingFired.set(true);
        }

        @Override
        public void changed(LocationEvent event) {
            if (!changingFired.get())
                changedFiredTooEarly.set(true);
            changedFired.set(true);
            finished.set(true);
        }
    });
    shell.open();
    browser.setText("Hello world");
    waitForPassCondition(finished::get);
    if (finished.get() && changingFired.get() && changedFired.get() && !changedFiredTooEarly.get()) {
        // pass
        return;
    } else if (!finished.get()) {
        fail("Test timed out. 'changed()' never fired");
    } else {
        if (changedFiredTooEarly.get())
            fail("changed() was fired before changing(). Wrong signal order");
        else if (!changingFired.get())
            fail("changing() was never fired");
        else {
            fail("LocationListener test failed. changing():" + changingFired.get() + "  changed():" + changedFired.get() + " changedFiredTooEarly:" + changedFiredTooEarly.get());
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LocationListener(org.eclipse.swt.browser.LocationListener) LocationEvent(org.eclipse.swt.browser.LocationEvent) Test(org.junit.Test)

Example 28 with LocationListener

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

the class Bug510183_javadocHang method main.

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Button button = new Button(shell, SWT.PUSH);
    final Browser browser = new Browser(shell, SWT.NONE);
    button.setText("Click to increase count.");
    button.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent e) {
        }

        @Override
        public void mouseDown(MouseEvent e) {
            shell.setText("Count: " + count++);
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
        }
    });
    browser.setText("<html><title>Snippet</title><body><a href=\"https://eclipse.org/\">Eclipse.org  Disposing on link change causes hang</a></body></html>");
    browser.addProgressListener(new ProgressListener() {

        @Override
        public void completed(ProgressEvent event) {
            browser.addLocationListener(new LocationListener() {

                @Override
                public void changing(LocationEvent event) {
                    browser.dispose();
                // System.out.println("KILLING OF THE BROWSER");
                // 
                // String value = (String)widget.browser.evaluate("return 'hello'");
                // System.out.println("Returned: " + value);
                // 
                // String script = "document.body.style.backgroundColor = 'red'";
                // widget.browser.execute(script);
                }

                @Override
                public void changed(LocationEvent event) {
                }
            });
        }

        @Override
        public void changed(ProgressEvent event) {
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) ProgressListener(org.eclipse.swt.browser.ProgressListener) Button(org.eclipse.swt.widgets.Button) LocationListener(org.eclipse.swt.browser.LocationListener) FillLayout(org.eclipse.swt.layout.FillLayout) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) LocationEvent(org.eclipse.swt.browser.LocationEvent) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser)

Example 29 with LocationListener

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

the class Bug509615_auto_LocationChangeListener method main.

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final Browser browser = new Browser(shell, SWT.NONE);
    browser.addLocationListener(new LocationListener() {

        @Override
        public void changing(LocationEvent event) {
            System.out.println("Changing ....");
            browser.evaluate("return 123");
        }

        @Override
        public void changed(LocationEvent event) {
            System.out.println("Changed !!!!");
            browser.evaluate("return 123");
        }
    });
    browser.addProgressListener(new ProgressListener() {

        @Override
        public void completed(ProgressEvent event) {
            System.out.println("Progress Completed !!!! ");
        }

        @Override
        public void changed(ProgressEvent event) {
            System.out.println("Progress Changing ....");
        }
    });
    browser.setText("Hello world");
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProgressListener(org.eclipse.swt.browser.ProgressListener) LocationListener(org.eclipse.swt.browser.LocationListener) FillLayout(org.eclipse.swt.layout.FillLayout) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) LocationEvent(org.eclipse.swt.browser.LocationEvent) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser)

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