use of org.eclipse.swt.browser.LocationEvent 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.LocationEvent in project archi by archimatetool.
the class BrowserEditor method createBrowser.
/**
* Create the Browser if possible
*/
protected Browser createBrowser(Composite parent) {
Browser browser = null;
try {
browser = new Browser(parent, SWT.NONE);
browser.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
// Don't allow external hosts if set
browser.addLocationListener(new LocationAdapter() {
@Override
public void changing(LocationEvent e) {
if (getEditorInput() != null && !getEditorInput().getExternalHostsEnabled()) {
e.doit = e.location != null && (// $NON-NLS-1$
e.location.startsWith("file:") || // $NON-NLS-1$
e.location.startsWith("data:") || // $NON-NLS-1$
e.location.startsWith("about:"));
}
}
});
} catch (SWTError error) {
error.printStackTrace();
// Remove junk child controls that might be created with failed load
for (Control child : parent.getChildren()) {
child.dispose();
}
}
return browser;
}
use of org.eclipse.swt.browser.LocationEvent in project archi by archimatetool.
the class HintsView method createBrowser.
/**
* Create the Browser if possible
*/
private Browser createBrowser(Composite parent) {
Browser browser = null;
try {
browser = new Browser(parent, SWT.NONE);
// Don't allow external hosts if set
browser.addLocationListener(new LocationAdapter() {
@Override
public void changing(LocationEvent e) {
if (!ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.HINTS_BROWSER_EXTERNAL_HOSTS_ENABLED)) {
e.doit = e.location != null && (// $NON-NLS-1$
e.location.startsWith("file:") || // $NON-NLS-1$
e.location.startsWith("data:") || // $NON-NLS-1$
e.location.startsWith("about:"));
}
}
});
} catch (SWTError error) {
error.printStackTrace();
// Remove junk child controls that might be created with failed load
for (Control child : parent.getChildren()) {
if (child != fTitleLabel) {
child.dispose();
}
}
}
return browser;
}
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_evaluateInCallback.
/**
* This test replicates what happens internally
* if you click on a link in a javadoc popup hoverbox.
* I.e, in a location listener, evaluation() is performed.
*
* The goal of this test is to ensure there are no 'Freezes'/deadlocks if
* javascript evaluation is invoked inside an SWT listener.
*
* At time of writing, it also highlights that evaluation inside SWT listeners
* is not consistent across browsers.
*/
@Test
public void test_LocationListener_evaluateInCallback() {
assumeTrue(isWebkit2 || SwtTestUtil.isCocoa || SwtTestUtil.isWindows);
// On Webki1 this test works, but is prone to crashes. See Bug 509411
AtomicBoolean changingFinished = new AtomicBoolean(false);
AtomicBoolean changedFinished = new AtomicBoolean(false);
browser.addLocationListener(new LocationListener() {
@Override
public void changing(LocationEvent event) {
// Broken on Webkit1. I.e evaluate() in a 'changing()' signal doesn't do anything.
browser.evaluate("SWTchanging = true");
changingFinished.set(true);
}
@Override
public void changed(LocationEvent event) {
browser.evaluate("SWTchanged = true");
changedFinished.set(true);
}
});
browser.setText("<body>Hello <b>World</b></body>");
// Wait till both listeners were fired.
if (SwtTestUtil.isWindows) {
// Windows doesn't reach changedFinished.get();
waitForPassCondition(changingFinished::get);
} else
waitForPassCondition(() -> (changingFinished.get() && changedFinished.get()));
// Inspect if evaluate() was executed correctly.
Boolean changed = false;
try {
changed = (Boolean) browser.evaluate("return SWTchanged");
} catch (SWTException e) {
}
Boolean changing = false;
try {
changing = (Boolean) browser.evaluate("return SWTchanging");
} catch (SWTException e) {
}
String errMsg = "\n changing: fired:" + changingFinished.get() + " evaluated:" + changing + "\n changed: fired:" + changedFinished.get() + " evaluated:" + changed;
boolean passed = false;
if (isWebkit2) {
// Evaluation works in all cases.
passed = changingFinished.get() && changedFinished.get() && changed && changing;
} else if (isWebkit1) {
// On Webkit1, evaluation in 'changing' fails.
// && changing (broken)
passed = changingFinished.get() && changedFinished.get() && changed;
} else if (SwtTestUtil.isCocoa) {
// On Cocoa, evaluation in 'changing' fails.
// && changing (broken)
passed = changingFinished.get() && changedFinished.get() && changed;
} else if (SwtTestUtil.isWindows) {
// On Windows, evaluation inside SWT listeners fails altogether.
// Further, only 'changing' is fired if evaluation is invoked inside listeners.
passed = changingFinished.get();
}
assertTrue(errMsg, passed);
}
use of org.eclipse.swt.browser.LocationEvent in project BiglyBT by BiglySoftware.
the class SearchResultsTabAreaBrowser method anotherSearch.
@Override
public void anotherSearch(SearchQuery sq) {
this.sq = sq;
String url = Constants.URL_WEBSEARCH.replaceAll("%s", UrlUtils.encode(sq.term));
AEProxyFactory.PluginHTTPProxy proxy = getSearchProxy(this);
if (proxy != null) {
url = proxy.proxifyURL(url);
}
if (Utils.isThisThreadSWT()) {
try {
final AESemaphore sem = new AESemaphore("brwoserWait");
final BrowserWrapper browser = browserSkinObject.getBrowser();
browser.addLocationListener(new LocationListener() {
@Override
public void changing(LocationEvent event) {
}
@Override
public void changed(LocationEvent event) {
browser.removeLocationListener(this);
sem.releaseForever();
}
});
browserSkinObject.getBrowser().setUrl("about:blank");
browserSkinObject.getBrowser().refresh();
browserSkinObject.getBrowser().update();
final String finalURL = url;
Utils.getOffOfSWTThread(new AERunnable() {
@Override
public void runSupport() {
sem.reserve(300);
browserSkinObject.setURL(finalURL);
}
});
} catch (Throwable t) {
}
} else {
browserSkinObject.setURL(url);
}
}
Aggregations