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