Currently, I am attempting to retrieve the return value from a JavaScript function that I have created. Although I can achieve this using a complex method involving listeners, I am interested in utilizing Eclipse's Browser.evaluate method.
For practice purposes, I have included the following code in a Java file:
Object result = this.browser.evaluate("new String(\"Hello World\")");
where this.browser is instantiated in a class that extends org.eclipse.ui.part.EditorPart
within the overridden function createPartControl
:
public void createPartControl(Composite parent) {
// Create the browser instance and set it up
this.browser = new Browser(parent, SWT.NONE);
this.browser.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
SomeEditor.this.getSite().getPage().activate(SomeEditor.this);
}
});
new ErrorReporter(this.browser);
this.browser.setUrl(Activator.getResourceURL("html/java-shim.html").toString());
...additional details omitted...
}
However, instead of result
containing the string "Hello World", it appears to be null
. Is there a mistake in my implementation of this method, or is it possibly malfunctioning?