use of org.eclipse.swt.browser.LocationListener 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.LocationListener in project pentaho-kettle by pentaho.
the class Spoon method showDocumentMap.
public void showDocumentMap() {
try {
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) {
System.out.println("Changed to: " + event.location);
}
};
URL url = new URL(DOCUMENTATION_URL);
HelpUtils.openHelpDialog(shell, STRING_DOCUMENT_TAB_NAME, url.toString(), listener);
} catch (MalformedURLException e1) {
log.logError(Const.getStackTracker(e1));
}
}
use of org.eclipse.swt.browser.LocationListener in project pentaho-kettle by pentaho.
the class Spoon method showWelcomePage.
public void showWelcomePage() {
try {
LocationListener listener = new LocationListener() {
@Override
public void changing(LocationEvent event) {
if (event.location.endsWith(".pdf")) {
Program.launch(event.location);
event.doit = false;
} else if (event.location.contains("samples/transformations") || event.location.contains("samples/jobs") || event.location.contains("samples/mapping")) {
try {
FileObject fileObject = KettleVFS.getFileObject(event.location);
if (fileObject.exists()) {
if (event.location.endsWith(".ktr") || event.location.endsWith(".kjb")) {
openFile(event.location, false);
} else {
lastDirOpened = KettleVFS.getFilename(fileObject);
openFile(true);
}
event.doit = false;
}
} catch (Exception e) {
log.logError("Error handling samples location: " + event.location, e);
}
}
}
@Override
public void changed(LocationEvent event) {
// System.out.println("Changed to: " + event.location);
}
};
// create callback functions for welcome
Runnable openFileFunction = new Runnable() {
public void run() {
Spoon.this.openFile();
}
};
Runnable newTransFunction = new Runnable() {
public void run() {
Spoon.this.newTransFile();
}
};
Runnable newJobFunction = new Runnable() {
public void run() {
Spoon.this.newJobFile();
}
};
HashMap<String, Runnable> functions = new HashMap<String, Runnable>();
functions.put("openFileFunction", openFileFunction);
functions.put("newTransFunction", newTransFunction);
functions.put("newJobFunction", newJobFunction);
// see if we are in webstart mode
String webstartRoot = System.getProperty("spoon.webstartroot");
if (webstartRoot != null) {
URL url = new URL(webstartRoot + '/' + FILE_WELCOME_PAGE);
// ./docs/English/tips/index.htm
addSpoonBrowser(STRING_WELCOME_TAB_NAME, url.toString(), true, listener, functions, false);
} else {
// see if we can find the welcome file on the file system
File file = new File(FILE_WELCOME_PAGE);
if (file.exists()) {
// ./docs/English/tips/index.htm
addSpoonBrowser(STRING_WELCOME_TAB_NAME, file.toURI().toURL().toString(), true, listener, functions, false);
}
}
} catch (MalformedURLException e1) {
log.logError(Const.getStackTracker(e1));
}
}
use of org.eclipse.swt.browser.LocationListener 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.LocationListener 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());
}
}
}
Aggregations