use of org.eclipse.swt.browser.LocationEvent 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.LocationEvent in project azure-tools-for-java by Microsoft.
the class LoginDialog method createDlgBody.
private void createDlgBody(Composite container) {
final Browser browser = new Browser(container, SWT.NONE);
browser.addLocationListener(new LocationAdapter() {
@Override
public void changing(LocationEvent locationEvent) {
System.out.println("\t--> locationEvent.location: " + locationEvent.location);
if (locationEvent.location.startsWith(redirectUriStr)) {
setResult(locationEvent.location);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
//Browser.clearSessions();
close();
}
});
}
}
});
// String[] headers = new String[] {
// "User-Agent: SwtBrowser"
// };
// browser.setUrl(requestUriStr, null, headers);
browser.setUrl(requestUriStr);
}
use of org.eclipse.swt.browser.LocationEvent in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_browser_Browser method test_LocationListener_ProgressListener_cancledLoad.
@Test
public /**
* "event.doit = false" in Location.changing() should stop 'Loction.changed & progress.completed' from getting fired.
*/
void test_LocationListener_ProgressListener_cancledLoad() {
AtomicBoolean locationChanging = new AtomicBoolean(false);
AtomicBoolean unexpectedLocationChanged = new AtomicBoolean(false);
AtomicBoolean unexpectedProgressCompleted = new AtomicBoolean(false);
browser.addLocationListener(new LocationListener() {
@Override
public void changing(LocationEvent event) {
event.doit = false;
locationChanging.set(true);
}
@Override
public void changed(LocationEvent event) {
if (event.location.length() != 0) {
// See footnote 1
unexpectedLocationChanged.set(true);
}
}
});
browser.addProgressListener(completedAdapter(event -> {
String location = browser.getUrl();
if (location.length() != 0) {
// See footnote 1
unexpectedProgressCompleted.set(true);
}
}));
shell.open();
browser.setText("You should not see this message.");
// We must wait for events *not* to fire.
// On Gtk, Quadcore (Intel i7-4870HQ pci-e SSD, all events fire after ~80ms.
// For stability, wait 1000 ms.
waitForMilliseconds(1000);
boolean passed = locationChanging.get() && !unexpectedLocationChanged.get() && !unexpectedProgressCompleted.get();
String errMsg = "\nUnexpected event fired. \n" + "LocationChanging (should be true): " + locationChanging.get() + "\n" + "LocationChanged unexpectedly (should be false): " + unexpectedLocationChanged.get() + "\n" + "ProgressChanged unexpectedly (should be false): " + unexpectedProgressCompleted.get() + "\n";
assertTrue(errMsg, passed);
/* FOOTNOTE 1
*
* Feature on Internet Explorer. If there is no current location, IE still fires a DocumentComplete
* following the BeforeNavigate2 cancel event. This DocumentComplete event contains an empty URL
* since the URL in BeforeNavigate2 was correctly cancelled.
* The test considers it is OK to send a Location.changed and a Progress.completed events after
* a Location.changing cancel true - at the condition that the current location is empty,
* otherwise it is considered that the location was not successfully cancelled.
*/
}
use of org.eclipse.swt.browser.LocationEvent in project eclipse.platform.swt by eclipse.
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.LocationEvent in project pentaho-kettle by pentaho.
the class ShowHelpDialog method addProgressAndLocationListener.
private void addProgressAndLocationListener() {
ProgressListener progressListener = new ProgressListener() {
@Override
public void changed(ProgressEvent event) {
}
@Override
public void completed(ProgressEvent event) {
if (fromPrint) {
wBrowser.execute(PRINT_SCRIPT);
fromPrint = false;
}
setForwardBackEnable();
}
};
LocationListener listener = new LocationListener() {
@Override
public void changing(LocationEvent event) {
if (event.location.endsWith(".pdf")) {
Program.launch(event.location);
event.doit = false;
}
}
@Override
public void changed(LocationEvent event) {
textURL.setText(event.location);
}
};
wBrowser.addProgressListener(progressListener);
wBrowser.addLocationListener(listener);
}
Aggregations