Search in sources :

Example 16 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.

the class Bug510905_Browser_JsConsole method main.

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(500, 600);
    GridLayout gridLayout = new GridLayout();
    shell.setLayout(gridLayout);
    final Text jsConsole = new Text(shell, SWT.BORDER);
    // jsConsole.setText("document.body.innerHTML = theJavaFunction(123, 'hello', null, true)");
    // Case where there are no paramaters.
    jsConsole.setText("document.body.innerHTML = theJavaFunction()");
    jsConsole.setSelection(jsConsole.getText().length());
    GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    jsConsole.setLayoutData(data);
    final Browser browser = new Browser(shell, SWT.NONE);
    browser.setText("hello <b>world!</b>");
    data = new GridData(SWT.FILL, SWT.FILL, true, true);
    browser.setLayoutData(data);
    jsConsole.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == 13) {
                // 13 = Enter
                browser.execute(jsConsole.getText());
            }
        }
    });
    Button loadNewPage = new Button(shell, SWT.PUSH);
    loadNewPage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    loadNewPage.setText("Load new Page");
    loadNewPage.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            browser.setText("New page!" + count++);
        }
    });
    // BrowserFunction Code
    @SuppressWarnings("unused") final BrowserFunction function = new CustomFunction(browser, "theJavaFunction");
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) KeyEvent(org.eclipse.swt.events.KeyEvent) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) BrowserFunction(org.eclipse.swt.browser.BrowserFunction) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser)

Example 17 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.

the class Bug510905_Browser_TwoJsConsoles method makeBrowserWithConsole.

/**
 * @param leftBrowser
 * @return
 */
private static Browser makeBrowserWithConsole(Composite leftBrowser, String funcName) {
    GridLayout gridLayout = new GridLayout();
    leftBrowser.setLayout(gridLayout);
    final Text jsConsole = new Text(leftBrowser, SWT.BORDER);
    // Case where there are no paramaters.
    jsConsole.setText("document.body.innerHTML = " + funcName + "(123)");
    jsConsole.setSelection(jsConsole.getText().length());
    GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    jsConsole.setLayoutData(data);
    final Browser browser = new Browser(leftBrowser, SWT.NONE);
    browser.setText("hello <b>world!</b>");
    data = new GridData(SWT.FILL, SWT.FILL, true, true);
    browser.setLayoutData(data);
    jsConsole.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == 13) {
                // 13 = Enter
                browser.execute(jsConsole.getText());
            }
        }
    });
    Button loadNewPage = new Button(leftBrowser, SWT.PUSH);
    loadNewPage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    loadNewPage.setText("Load new Page");
    loadNewPage.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            browser.setText("New page!" + count++);
        }
    });
    return browser;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Text(org.eclipse.swt.widgets.Text) Browser(org.eclipse.swt.browser.Browser)

Example 18 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.

the class Bug525946_DownloadFunction method main.

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setBounds(10, 10, 400, 400);
    shell.setLayout(new FillLayout());
    final Browser browser = new Browser(shell, SWT.NONE);
    browser.setUrl("http://download.eclipse.org/tools/orbit/downloads/drops/R20170516192513/orbit-buildrepo-R20170516192513.zip");
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    shell.dispose();
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) FillLayout(org.eclipse.swt.layout.FillLayout) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser)

Example 19 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_browser_Browser method test_VisibilityWindowListener_newAdapter_closeShell.

@Test
public void test_VisibilityWindowListener_newAdapter_closeShell() {
    Display display = Display.getCurrent();
    Shell shell = new Shell(display);
    Browser browser = new Browser(shell, SWT.NONE);
    browser.addVisibilityWindowListener(new VisibilityWindowAdapter() {
    });
    shell.close();
}
Also used : VisibilityWindowAdapter(org.eclipse.swt.browser.VisibilityWindowAdapter) Shell(org.eclipse.swt.widgets.Shell) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser) Test(org.junit.Test)

Example 20 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_browser_Browser method test_setUrl_remote_with_post.

/**
 * This test requires working Internet connection
 */
@Test
public void test_setUrl_remote_with_post() {
    // Fails on webkit1 but likely not going to try to support it.
    assumeFalse(webkit1SkipMsg(), isWebkit1);
    // This test sometimes times out if build server has a bad connection. Thus for this test we have a longer timeout.
    secondsToWaitTillFail = 35;
    String url = "https://bugs.eclipse.org/bugs/buglist.cgi";
    // Skip this test if we don't have a working Internet connection.
    assumeTrue("Skipping test due to bad internet connection", checkInternet(url));
    testLog.append("checkInternet() passed");
    Runnable browserSetFunc = () -> {
        testLog.append("Setting Browser url to:" + url);
        boolean opSuccess = browser.setUrl(url, "bug_severity=enhancement&bug_status=NEW&email1=rgrunber&emailassigned_to1=1&emailtype1=substring", null);
        assertTrue("Expecting setUrl() to return true", opSuccess);
    };
    final AtomicReference<Boolean> completed = new AtomicReference<>(new Boolean(false));
    browser.addProgressListener(completedAdapter(event -> {
        testLog.append("ProgressListener fired");
        completed.set(true);
    }));
    browserSetFunc.run();
    shell.open();
    boolean hasFinished = waitForPassCondition(() -> completed.get().booleanValue());
    assertTrue("Test timed out. ProgressListener not fired " + testLog.toString(), hasFinished);
    // Even a successful empty query returns about 10000 chars of HTML
    int numChars = browser.getText().length();
    assertTrue("Response data contained " + numChars + " chars.", numChars > 10000);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) StatusTextListener(org.eclipse.swt.browser.StatusTextListener) URL(java.net.URL) Assume.assumeFalse(org.junit.Assume.assumeFalse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) ProgressListener(org.eclipse.swt.browser.ProgressListener) TitleListener(org.eclipse.swt.browser.TitleListener) VisibilityWindowAdapter(org.eclipse.swt.browser.VisibilityWindowAdapter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) Point(org.eclipse.swt.graphics.Point) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) BrowserFunction(org.eclipse.swt.browser.BrowserFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) TestName(org.junit.rules.TestName) LocationListener.changedAdapter(org.eclipse.swt.browser.LocationListener.changedAdapter) VisibilityWindowListener.showAdapter(org.eclipse.swt.browser.VisibilityWindowListener.showAdapter) WindowEvent(org.eclipse.swt.browser.WindowEvent) LocationListener(org.eclipse.swt.browser.LocationListener) ProgressListener.completedAdapter(org.eclipse.swt.browser.ProgressListener.completedAdapter) Assert.fail(org.junit.Assert.fail) SWTException(org.eclipse.swt.SWTException) VisibilityWindowListener(org.eclipse.swt.browser.VisibilityWindowListener) FillLayout(org.eclipse.swt.layout.FillLayout) AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) Before(org.junit.Before) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) Browser(org.eclipse.swt.browser.Browser) Shell(org.eclipse.swt.widgets.Shell) MalformedURLException(java.net.MalformedURLException) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Display(org.eclipse.swt.widgets.Display) Instant(java.time.Instant) LocationListener.changingAdapter(org.eclipse.swt.browser.LocationListener.changingAdapter) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) SWT(org.eclipse.swt.SWT) LocationEvent(org.eclipse.swt.browser.LocationEvent) Assume.assumeTrue(org.junit.Assume.assumeTrue) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Point(org.eclipse.swt.graphics.Point) Test(org.junit.Test)

Aggregations

Browser (org.eclipse.swt.browser.Browser)62 Shell (org.eclipse.swt.widgets.Shell)26 Display (org.eclipse.swt.widgets.Display)25 Test (org.junit.Test)22 FillLayout (org.eclipse.swt.layout.FillLayout)19 GridData (org.eclipse.swt.layout.GridData)16 IOException (java.io.IOException)13 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)13 Composite (org.eclipse.swt.widgets.Composite)13 BrowserFunction (org.eclipse.swt.browser.BrowserFunction)12 LocationEvent (org.eclipse.swt.browser.LocationEvent)12 URL (java.net.URL)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 ProgressListener (org.eclipse.swt.browser.ProgressListener)11 WindowEvent (org.eclipse.swt.browser.WindowEvent)11 GridLayout (org.eclipse.swt.layout.GridLayout)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 LocationAdapter (org.eclipse.swt.browser.LocationAdapter)10 LocationListener (org.eclipse.swt.browser.LocationListener)10 ProgressAdapter (org.eclipse.swt.browser.ProgressAdapter)10