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();
}
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;
}
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();
}
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();
}
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);
}
Aggregations