use of org.eclipse.swt.browser.ProgressListener in project aero.minova.rcp by minova-afis.
the class Preview method postConstruct.
@PostConstruct
public void postConstruct(Composite parent, MWindow window) {
window.getContext().set(Preview.class, this);
parent.setLayout(new FillLayout());
browser = new Browser(parent, SWT.NONE);
DisposeListener dl = e -> window.getContext().set(Preview.class, null);
browser.addDisposeListener(dl);
browser.addProgressListener(new ProgressListener() {
@Override
public void completed(ProgressEvent event) {
loading = false;
}
@Override
public void changed(ProgressEvent event) {
loading = true;
}
});
}
use of org.eclipse.swt.browser.ProgressListener in project olca-app by GreenDelta.
the class UI method onLoaded.
/**
* Calls the given function when the browser has loaded the given URL. No
* threads are spawned here. You have to make sure that the given function
* accesses the browser in the UI thread.
*/
public static void onLoaded(Browser browser, String url, Runnable fn) {
if (browser == null || url == null)
return;
browser.addProgressListener(new ProgressListener() {
@Override
public void completed(ProgressEvent event) {
if (fn != null) {
fn.run();
browser.removeProgressListener(this);
}
}
@Override
public void changed(ProgressEvent event) {
}
});
browser.setUrl(url);
}
use of org.eclipse.swt.browser.ProgressListener in project eclipse.platform.swt by eclipse-platform.
the class Test_org_eclipse_swt_browser_Browser method test_BrowserFunction_multiprocess.
@Test
public void test_BrowserFunction_multiprocess() {
// Test that BrowserFunctions work in multiple Browser instances simultaneously.
Browser browser1 = new Browser(shell, SWT.NONE);
Browser browser2 = new Browser(shell, SWT.NONE);
class JavaFunc extends BrowserFunction {
JavaFunc(Browser browser) {
super(browser, "javaFunc");
}
@Override
public Object function(Object[] arguments) {
return arguments[0];
}
}
new JavaFunc(browser1);
new JavaFunc(browser2);
assertEquals("value1", browser1.evaluate("return javaFunc('value1')"));
assertEquals("value2", browser2.evaluate("return javaFunc('value2')"));
// Ensure that navigation to a different page preserves BrowserFunctions.
int[] completed = new int[1];
ProgressListener listener = new ProgressAdapter() {
@Override
public void completed(ProgressEvent event) {
completed[0]++;
}
};
browser1.addProgressListener(listener);
browser2.addProgressListener(listener);
browser1.setText("<body>new_page1");
browser2.setText("<body>new_page2");
waitForPassCondition(() -> completed[0] == 2);
assertEquals("value1", browser1.evaluate("return javaFunc('value1')"));
assertEquals("value2", browser2.evaluate("return javaFunc('value2')"));
browser1.dispose();
browser2.dispose();
}
use of org.eclipse.swt.browser.ProgressListener in project eclipse.platform.swt by eclipse-platform.
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() {
// 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<>(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);
}
use of org.eclipse.swt.browser.ProgressListener in project eclipse.platform.swt by eclipse-platform.
the class BrowserExample method show.
void show(boolean owned, Point location, Point size, boolean addressBar, boolean menuBar, boolean statusBar, boolean toolBar) {
final Shell shell = browser.getShell();
if (owned) {
if (location != null)
shell.setLocation(location);
if (size != null)
shell.setSize(shell.computeSize(size.x, size.y));
}
FormData data = null;
if (toolBar) {
toolbar = new ToolBar(parent, SWT.NONE);
data = new FormData();
data.top = new FormAttachment(0, 5);
toolbar.setLayoutData(data);
itemBack = new ToolItem(toolbar, SWT.PUSH);
itemBack.setText(getResourceString("Back"));
itemForward = new ToolItem(toolbar, SWT.PUSH);
itemForward.setText(getResourceString("Forward"));
final ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH);
itemStop.setText(getResourceString("Stop"));
final ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH);
itemRefresh.setText(getResourceString("Refresh"));
final ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH);
itemGo.setText(getResourceString("Go"));
itemBack.setEnabled(browser.isBackEnabled());
itemForward.setEnabled(browser.isForwardEnabled());
Listener listener = event -> {
ToolItem item = (ToolItem) event.widget;
if (item == itemBack)
browser.back();
else if (item == itemForward)
browser.forward();
else if (item == itemStop)
browser.stop();
else if (item == itemRefresh)
browser.refresh();
else if (item == itemGo)
browser.setUrl(locationBar.getText());
};
itemBack.addListener(SWT.Selection, listener);
itemForward.addListener(SWT.Selection, listener);
itemStop.addListener(SWT.Selection, listener);
itemRefresh.addListener(SWT.Selection, listener);
itemGo.addListener(SWT.Selection, listener);
canvas = new Canvas(parent, SWT.NO_BACKGROUND);
data = new FormData();
data.width = 24;
data.height = 24;
data.top = new FormAttachment(0, 5);
data.right = new FormAttachment(100, -5);
canvas.setLayoutData(data);
final Rectangle rect = images[0].getBounds();
canvas.addListener(SWT.Paint, e -> {
Point pt = ((Canvas) e.widget).getSize();
e.gc.drawImage(images[index], 0, 0, rect.width, rect.height, 0, 0, pt.x, pt.y);
});
canvas.addListener(SWT.MouseDown, e -> browser.setUrl(getResourceString("Startup")));
final Display display = parent.getDisplay();
display.asyncExec(new Runnable() {
@Override
public void run() {
if (canvas.isDisposed())
return;
if (busy) {
index++;
if (index == images.length)
index = 0;
canvas.redraw();
}
display.timerExec(150, this);
}
});
}
if (addressBar) {
locationBar = new Text(parent, SWT.BORDER);
data = new FormData();
if (toolbar != null) {
data.top = new FormAttachment(toolbar, 0, SWT.TOP);
data.left = new FormAttachment(toolbar, 5, SWT.RIGHT);
data.right = new FormAttachment(canvas, -5, SWT.DEFAULT);
} else {
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
}
locationBar.setLayoutData(data);
locationBar.addListener(SWT.DefaultSelection, e -> browser.setUrl(locationBar.getText()));
}
if (statusBar) {
status = new Label(parent, SWT.NONE);
progressBar = new ProgressBar(parent, SWT.NONE);
data = new FormData();
data.left = new FormAttachment(0, 5);
data.right = new FormAttachment(progressBar, 0, SWT.DEFAULT);
data.bottom = new FormAttachment(100, -5);
status.setLayoutData(data);
data = new FormData();
data.right = new FormAttachment(100, -5);
data.bottom = new FormAttachment(100, -5);
progressBar.setLayoutData(data);
browser.addStatusTextListener(event -> status.setText(event.text));
}
parent.setLayout(new FormLayout());
Control aboveBrowser = toolBar ? (Control) canvas : (addressBar ? (Control) locationBar : null);
data = new FormData();
data.left = new FormAttachment(0, 0);
data.top = aboveBrowser != null ? new FormAttachment(aboveBrowser, 5, SWT.DEFAULT) : new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
data.bottom = status != null ? new FormAttachment(status, -5, SWT.DEFAULT) : new FormAttachment(100, 0);
browser.setLayoutData(data);
if (statusBar || toolBar) {
browser.addProgressListener(new ProgressListener() {
@Override
public void changed(ProgressEvent event) {
if (event.total == 0)
return;
int ratio = event.current * 100 / event.total;
if (progressBar != null)
progressBar.setSelection(ratio);
busy = event.current != event.total;
if (!busy) {
index = 0;
if (canvas != null)
canvas.redraw();
}
}
@Override
public void completed(ProgressEvent event) {
if (progressBar != null)
progressBar.setSelection(0);
busy = false;
index = 0;
if (canvas != null) {
itemBack.setEnabled(browser.isBackEnabled());
itemForward.setEnabled(browser.isForwardEnabled());
canvas.redraw();
}
}
});
}
if (addressBar || statusBar || toolBar) {
browser.addLocationListener(LocationListener.changedAdapter(event -> {
busy = true;
if (event.top && locationBar != null)
locationBar.setText(event.location);
}));
}
if (title) {
browser.addTitleListener(event -> shell.setText(event.title + " - " + getResourceString("window.title")));
}
parent.layout(true);
if (owned)
shell.open();
}
Aggregations