This class is responsible for holding the configuration of all MVC groups no matter how they were defined, which can be either in Application.groovy
or in an addon descriptor.During the startup sequence an instance of MVCGroupManager
will be created and initialized. Later the application will instruct this instance to create all startup groups as required. MVCGroupManager
has a handful set of methods that deal with MVC group configuration alone; however those that deal with group instantiation come in 3 versions, with 2 flavors each (one Groovy, the other Java friendly).Locating a group configuration is easily done by specifying the name you're interested in findingdef configuration = app.mvcGroupManager.findConfiguration('foo')
Once you have a configuration reference you can instantiate a group with it by calling any of the variants of the create
methoddef configuration = app.mvcGroupManager.findConfiguration('foo')
def group1 = configuration.create('foo1')
def group2 = configuration.create('foo2', [someKey: 'someValue'])
// the following will make the group's id match its name
def group3 = configuration.create()
def group4 = configuration.create(someKey: 'someValue')
Be careful that creating groups with the same name is usually not a good idea. The default MVCGroupManager will complain when this happens and will automatically spit out an exception. This behavior may be changed by setting a configuration key in Config.groovy
griffon.mvcid.collision = 'warning' // accepted values are 'warning', 'exception' (default)
The manager will log a warning and destroy the previously existing group before instantiating the new one when 'warning' is the preferred strategyNow, even though you can create group instances based on their configurations the preferred way is to call any of createMVCGroup, buildMVCGroup or withMVCGroup methods. These methods are available to the app property every GriffonArtifact has, which points to the currently running application. Griffon artifacts also inherit these methods as part of their default contract. Finally, any class annotated with the MVCAware AST transformation will also gain access to these methods.Groups will be available by id regardless of how they were instantiated. You can ask the mvcGroupManager for a particular group at any time, for exampledef g1 = app.mvcGroupManager.groups.foo1
def g2 = app.mvcGroupManager.findGroup('foo1')
def g3 = app.mvcGroupManager.foo1
assert g1 == g2
assert g1 == g3
It's also possible to query all models, views, controllers and builders on their own. Say you'd want to inspect all currently instantiated models, this is how it can be doneapp.mvcGroupManager.models.each { model ->
// do something with model
}