Affects Version/s: 0.9.3-beta-2
Fix Version/s: 0.9.4
Number of attachments :
Most of the times a View script defines a single node. This node is set as the return value of the script, which is useful for composing secondary Views by calling the build() method on the primary View.
However, there may be times where the "root" node is not the last expression evaluated in the script (due to additional configuration like bindings or setting up listeners for example). In this case the developer must set a reference to the top node and make an explicit return at the end of the script.
It would be better if Views were capable of identifying the root node by convention, so that View composition would be DRYer.
Add a root() method to AbstractGriffonView and AbstractGriffonViewScript with three variants:
- root(JComponent c) - identifies the passed in argument as the root node, will compute an unique identifier based on the script's and component's classes
- root(String id, JComponent c) - identifies the passed in argument as the root node using a developer supplied id
- root() - returns the root component as set with either of the two previous methods.
This a secondary View script may look like the following one
which can be reused in a primary View like this
where MyContent.root() returns the panel built in the secondary View instead of a List (noparent creates a List for those who didn't know the trick