Extension Functions

Well I am onto something else now and trying to set up extension functions to my component. I dug around the best I could with the docs but couldn’t quite piece it together.

I started with the ExtensionFunctionDescriptor class. Given the guidance at the top of the doc I implemented the ExtensibleComponent interface on the component and added the code snippet shown in the javadoc for the basic implementation. That code is inserted verbatim. Then I added the override to initDesc() in my bean info…

However at this point it is cloudy as to the process to configure the descriptors and how to tie in the ability to call these from my module code. Especially with defining what gets passed into the extension function when presented in the Designer (e.g. custom classes, strings, etc). Likewise, the return value after the script exits.

Seems like the right time of year to ask for some sort of skeleton of this process. :^/

PS> As an aside to this, I implemented a basic actionPerformed event, but can you add arbitrary action handler events (other than ‘mouse’, ‘cell’, etc)? I tried but it did not appear in the scripting customizer on my component.

Ok, I seem to have a lot more luck when I repost with a quippy “can I get a little love here” followup… I’ve been poking at this and just can’t seem to quite get things done in such a way that it yields viable extension functions on my component. I can live with just a quick rundown on which calls need to go where to set up the bean as well as the right calls (and where) to describe my function callbacks. If possible, an example that shows at least two parameters coming into the extension function with a return value (and how does that come back to me in the component code). That would be monumentally helpful! Thanks!

Oh, you know us so well.

Ok, extension functions are great. And they are pretty easy once you have the basic template.

  1. Have your component implement ExtensibleComponent (as you saw, code to do this is in javadocs)

  2. Add each extension function into your bean info. Here's a snippet.

[code]protected void initDesc() {
VisionBeanDescriptor bean = getBeanDescriptor();
bean.setName("Awesome Component");
bean.setDisplayName("Awesome Component");
bean.setShortDescription("It's so great.");

List<ExtensionFunctionDescriptor> extensionFunctionList = new ArrayList<ExtensionFunctionDescriptor>();
extensionFunctionList
	.add(ExtensionFunctionDescriptor
		.newFunction("pleaseCallMe")
		.returns(String.class)
		.description(
			"This is the docstring for the function")
		.arg("arg1",
			"An argument")
		.arg("arg2",
			"An argument")
		.defaultImpl("# Put your code here")
		.build());
// Add more xtn functions to the list if you want
bean.setValue(ExtensionFunctionDescriptor.EXTENSION_FUNCTIONS, extensionFunctionList);

}[/code]

  1. Call the extension function from your component:

ExtensionFunction.invoke( MyAwesomeComponent.this, log, // you must have a LoggerEx from LogUtil "pleaseCallMe", // name of the extension function String.class, // expected return value type. Use Void.class if you don't want a return null, // default return value (used if user hasn't implemented this xtn function) arg1, arg2);

This should get you started. LMK if you have more questions.

Right on. Thanks! That bean.setValue() part is what I think was hosing me. I think I was unclear from the doc where that ExtensionFunctionDescriptor.EXTENSION_FUNCTIONS key had to get added along with the descriptor ArrayList. I’ll give it a shot…