The last post about the facade implementation for each extension was just a concept showing what could be done for mapping the extension method calls to the script. But implementing a dedicated facade for each extension is not feasible just because there is an unlimited number of the extension types available.
As the previous post said, a proxy class solution could solve the problem so that I shouldn't write a dedicated facade for each extension. That said, we have a brand new solution in place: the ScriptExtensionProxy class, which implements the following interfaces:
- IExecutableExtension required for extension initial setup in ConfigurationElement#createExecutableExtension() calling IExecutableExtension#setInitializationData()
- IExecutableExtensionFactory required for proxy class construction using IExecutableExtensionFactory#create() call in ConfigurationElement#createExecutableExtension()
- InvocationHandler required to delegate the extension method calls to the script in InvocationHandler#invoke() method.
The declaration of an extension is changed a little bit, as I have to define a proxy class, an extension interface class and a script file in the class attribute in plugin.xml:
It looks a little messy though...
<action class="org.eclipse.soc.yummy.core.ScriptExtensionProxy: \
org.eclipse.ui.IWorkbenchWindowActionDelegate/action.groovy"
icon="icons/sample.gif"
id="ScriptAction"
label="&Sample Action"
menubarPath="sampleMenu/sampleGroup"
toolbarPath="sampleGroup"
tooltip="Hello, Eclipse world">
</action>
Overall, providing the scripting support for developing plug-ins in Groovy requires only three classes at the moment: a proxy, a script execution engine, and a helper class for initialization code that is actually used in the proxy class only. LOC = 355.
Next, I will have to make many examples to see what is missing in ScriptExecutor and to find out which workbench objects should I expose to the script. I still need to refer to Dash for this purpose.
No comments:
Post a Comment