getLength(File file)
method for our ScriptHelper.
import org.xul.script.scripts.AbstractXULScriptHelper; import java.io.File; public class MyXULScriptHelper extends AbstractXULScriptHelper { MyXULScriptContext context; public MyXULScriptHelper(MyXULScriptContext context) { this.context = context; } public MyXULScriptContext getContext() { return context; } public long getLength(File file) { return file.length(); } }This helper class will only be available if it is returned by the
getHelper
meyhod of the corresponding ScriptContext. Let's override the AbstractXULScriptContext class: import org.xul.script.scripts.AbstractXULScriptContext; public class MyXULScriptContext extends AbstractXULScriptContext { MyXULScriptHelper helper = null; public MyXULScriptContext() { this.helper = new MyXULScriptHelper(); } public MyXULScriptHelper getHelper() { return file.length(); } }
manager.setScriptContext(new MyXULScriptContext());
getLength(File file)
in our scripts. For example in Groovy:FilePicker filepicker = new FilePicker(); picker.init(null, "openMode"); int ret = picker.show(); if (ret == FilePicker.RETURN_OK) { long length = helper.getLength(picker.getFile()); context.echo(length); }
Copyright 2008-2020 Herve Girod. All Rights Reserved. Documentation and source under the LGPL licence