use of org.eclipse.swt.browser.ProgressListener in project cubrid-manager by CUBRID.
the class BrowserEditorPart method initBrowser.
private void initBrowser(Composite parent) {
browser = new Browser(parent, SWT.None);
browser.setLayoutData(createGridData(FILL_BOTH, 3, 1, -1, -1));
// Add location change listener
browser.addLocationListener(new LocationListener() {
public void changing(LocationEvent e) {
location.setText(e.location);
}
public void changed(LocationEvent e) {
noOp();
}
});
// Add loading listener
browser.addProgressListener(new ProgressListener() {
// Set stopItem and progress bar status
public void changed(ProgressEvent e) {
if (!stopItem.isEnabled() && e.total != e.current) {
stopItem.setEnabled(true);
}
}
// Set stopItem,backItem,forwardItem and progress bar status
public void completed(ProgressEvent e) {
stopItem.setEnabled(false);
backItem.setEnabled(browser.isBackEnabled());
forwardItem.setEnabled(browser.isForwardEnabled());
}
});
}
use of org.eclipse.swt.browser.ProgressListener in project eclipse.platform.swt by eclipse.
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();
}
use of org.eclipse.swt.browser.ProgressListener 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);
}
use of org.eclipse.swt.browser.ProgressListener in project arduino-eclipse-plugin by Sloeber.
the class PleaseHelp method createContents.
@Override
protected Control createContents(Composite parent) {
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
parent.setLayout(gridLayout);
try {
this.browser = new Browser(parent, SWT.NONE);
} catch (SWTError e) {
// $NON-NLS-1$
System.out.println("Could not instantiate Browser: " + e.getMessage());
}
GridData data = new GridData();
data.horizontalAlignment = GridData.FILL;
data.verticalAlignment = GridData.FILL;
data.horizontalSpan = 3;
data.grabExcessHorizontalSpace = true;
data.grabExcessVerticalSpace = true;
this.browser.setLayoutData(data);
this.browser.addProgressListener(new ProgressListener() {
@Override
public void changed(ProgressEvent event) {
// I'm not interested in change
}
@Override
public void completed(ProgressEvent event) {
PleaseHelp.this.ph.setBlockOnOpen(false);
PleaseHelp.this.ph.open();
}
});
this.buttonBar = createButtonBar(parent);
org.osgi.framework.Version version = FrameworkUtil.getBundle(getClass()).getVersion();
// $NON-NLS-1$
String url = myhelpLocation + "?os=" + Platform.getOS();
// $NON-NLS-1$
url += "&arch=" + Platform.getOSArch();
// $NON-NLS-1$
url += "&majorVersion=" + version.getMajor();
// $NON-NLS-1$
url += "&minorVersion=" + version.getMinor();
// $NON-NLS-1$
url += "µVersion=" + version.getMicro();
// $NON-NLS-1$
url += "&qualifierVersion=" + version.getQualifier();
this.browser.setUrl(url);
return parent;
}
use of org.eclipse.swt.browser.ProgressListener in project BiglyBT by BiglySoftware.
the class BrowserWrapperFake method setUrl.
@Override
public void setUrl(final String _url) {
url = _url;
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
String url_str = _url;
int pos = url_str.indexOf('?');
if (pos != -1) {
url_str = url_str.substring(0, pos);
}
link_label.setText(url_str);
browser.layout();
for (LocationListener l : location_listeners) {
try {
LocationEvent event = new LocationEvent(browser);
event.top = true;
event.location = _url;
l.changed(event);
} catch (Throwable e) {
Debug.out(e);
}
}
for (ProgressListener l : progress_listeners) {
try {
ProgressEvent event = new ProgressEvent(browser);
l.completed(event);
} catch (Throwable e) {
Debug.out(e);
}
}
for (TitleListener l : title_listeners) {
try {
TitleEvent event = new TitleEvent(browser);
event.title = "Browser Disabled";
l.changed(event);
} catch (Throwable e) {
Debug.out(e);
}
}
}
});
}
Aggregations