use of org.springsource.ide.eclipse.commons.browser.IEclipseToBrowserFunction in project eclipse-integration-commons by spring-projects.
the class StsBrowserManager method doCall.
private void doCall(final IEclipseToBrowserFunction function) {
Display.getDefault().asyncExec(() -> {
IEclipseToBrowserFunction provider = function;
if (provider != null) {
String fname = provider.getFunctionName();
try {
Object[] fargs = provider.getArguments();
// System.out.println("doCall "+fname+" "+Arrays.asList(fargs));
String code = "window." + fname + serializeArguments(fargs);
boolean success = browser.execute(code);
// System.out.println("doCall("+fname+") => "+success);
if (!success) {
throw new ExecutionException("Problems executing script: '" + code + "'");
}
} catch (Exception e) {
StatusManager.getManager().handle(new Status(IStatus.ERROR, BrowserPlugin.PLUGIN_ID, "Could not call browser function extension: " + fname, e));
}
}
if (DEBUG) {
printPageHtml();
}
});
}
use of org.springsource.ide.eclipse.commons.browser.IEclipseToBrowserFunction in project eclipse-integration-commons by spring-projects.
the class StsBrowserManager method dispose.
public void dispose() {
disposed = true;
for (IEclipseToBrowserFunction function : onLoadFunctions) {
function.dispose();
}
if (browser_function != null) {
browser_function.dispose();
browser_function = null;
}
}
use of org.springsource.ide.eclipse.commons.browser.IEclipseToBrowserFunction in project eclipse-integration-commons by spring-projects.
the class StsBrowserManager method setClient.
public void setClient(Browser browser) {
this.browser = browser;
browser.execute("window.ide = {\n" + " call: function () {\n" + " return ide_call.apply(this, arguments);\n" + " }\n" + "}");
if (browser_function == null) {
browser_function = new BrowserFunction(browser, "ide_call") {
@Override
public Object function(Object[] arguments) {
call((String) arguments[0], (String) arguments[1]);
return false;
}
};
}
onLoadFunctions = new ArrayList<IEclipseToBrowserFunction>();
String oldUrl = currentUrl;
currentUrl = browser.getUrl();
// System.out.println("oldUrl: "+oldUrl);
// System.out.println("newUrl: "+currentUrl);
// Need to remove any query parameters that might break pattern matching for extensions
currentUrl = StringUtils.substringBeforeLast(currentUrl, "?");
currentUrl = StringUtils.substringBeforeLast(currentUrl, "&");
loadInitialFunctions();
}
use of org.springsource.ide.eclipse.commons.browser.IEclipseToBrowserFunction in project eclipse-integration-commons by spring-projects.
the class StsBrowserManager method callOnBrowser.
/**
* Calls Javascript functions <i>to</i> the browser, refreshing the browser
* after each call
*/
public void callOnBrowser(final Collection<IEclipseToBrowserFunction> functions) {
final Collection<IEclipseToBrowserFunction> waitingFunctions = new CopyOnWriteArrayList<IEclipseToBrowserFunction>();
IEclipseToBrowserFunction.Callback callback = new IEclipseToBrowserFunction.Callback() {
@Override
public void ready(final IEclipseToBrowserFunction function) {
if (waitingFunctions.remove(function)) {
if (!disposed) {
doCall(function);
}
}
}
};
for (IEclipseToBrowserFunction function : functions) {
if (!function.isReady()) {
waitingFunctions.add(function);
function.setCallback(callback);
} else {
doCall(function);
}
}
callback.ready(null);
}
Aggregations