14.6 Addons - Reference Documentation
Authors: Andres Almiray
Version: 1.2.0
14.6 Addons
Understanding Addons
Addons are a plugin's best friend. While plugins can only contribute build-time artifacts (such as scripts) and participate on build events, addons may contribute runtime artifacts (such as MVC Groups or services) and participate on application events.Often times whenever you'd like to package a reusable runtime artifact you'd have to create an Addon as well.Addon responsibilities
Addons may contribute any of the following to your application: MVC Groups and application event handlers. They can also contribute the following to the CompositeBuilder: factories, methods, properties and FactoryBuilderSupport delegates (attribute, preInstantiate, postInstantiate, postNodeCompletion).Addons are created using a template that suggests all of the properties and methods you can use configure. The complete list follows:addonInit
- called right after the addon has been loaded but before contributions are taken into accountaddonPostInit
- called after all contributions haven been madeaddonBuilderInit
- called before contributions to the CompositeBuilder are taken into accountaddonBuilderPostInit
- called after all CompositeBuilder contributions haven been madeevents
- Map of additional application event handlersfactories
- Map of additional node factories, added to CompositeBuildermethods
- Map of additional methods, added to CompositeBuilderprops
- Map of additional methods, added to CompositeBuilderattributeDelegates
- List of attributeDelegates (as Closures), added to CompositeBuilderpreInstantiateDelegates
- List of preInstantiateDelegates (as Closures), added to CompositeBuilderpostInstantiateDelegates
- List of postInstantiateDelegates (as Closures), added to CompositeBuilderpostNodeCompletionDelegates
- List of postNodeCompletionDelegates (as Closures), added to CompositeBuilder
Configuring Addons
This task is done automatically for you when you package an addon inside a plugin. The plugin's_Install
and _Uninstall
scripts will make sure that griffon-app/conf/Builder.groovy
stays up to date. When you install a plugin that contains an addon you'll notice that Builder.groovy
may get updated with a line similar to the next oneroot.'CustomGriffonAddon'.addon=true
Builder.groovy
file. You can still apply modifications as explained below.The following snippet shows how to configure an Addon to contribute all of its methods to Controllers, and all of its contributions to Models.root.'CustomGriffonAddon'.controller='*:methods' root.'CustomGriffonAddon'.model='*'
root
) of the addon to something more suitable to your needs. All nodes contributed by the addon will now be accessible using that prefix. Here's an examplenx.'CustomGriffonAddon'.addon=true
CustomGriffonAddon
is defined as followsclass CustomGriffonAddon { def factories = [ button: com.acme.CustomButton ] }
CustomButtom
can be obtained by using nxbutton
, whereas regular instances of JButton
will be accessible with button
.