Monday, 10 October 2011

Griffon Plugins - docking-frame : Adding new dockables

  • Plugin Name: docking-frame
  • Griffon Plugin Documentation: Here
  • Adapted Library: Docking Frames

I've been playing a little bit with the Docking-Frames plugin for Griffon. The builder is really cool, you can arrange any type of dockables inside a view. For getting started I suggest you to take a look on the plugin page (see above).

Everything was perfect until I realized that I had to add a new dockable to the current view. I wanted every dockable having its own master table data with its own crud control bar.

I didn't find any comment in the Griffon plugin documentation, so I tried with the DockingFrames documentation.

Well, the thing is that DockingFrames is a really powerful framework, and its widely documented, so I found out more than one solution to accomplish that.

The one that I chose (the easy one of course) was to create a new MVC group per each dockable. So my first idea was changing the main view controller:

package invoices

class InvoicesController {

def model
def view

def createDockable = { evt ->
/* Building the MVC group matching the name
* of the trigger */
Map group = buildMVCGroup(
'customers',
dockingControl:view.dockingControl
)
}

def destroyDockable = {evt->
destroyMVCGroup('customers')
}
}



Of course I had to put and id to the dockingControl node on my view:

...
dockingControl(id:'dockingControl',theme: 'eclipse') {
menuBar() {
...


Then inside the mvcGroupInit method of the new MVC group (with id 'customers') I had to initialize the dockable and add it to the docking control passed as a parameter. This is all made inside the new MVC group controller.

package invoices

import javax.swing.*
import bibliothek.gui.dock.common.*

class CustomersController {

def model
def view

def dockingControl
def dockable

void mvcGroupInit(Map args) {
dockingControl = args.dockingControl
dockable =
new DefaultSingleCDockable(
'customers',
'Customers',
view.panel
)
dockable.with{
use(CLocation){
closeable = true
stackable = true
location = dockingControl.contentArea.base().normal()
}
}
dockingControl.addDockable(dockable)
dockable.visible = true
}

void mvcGroupDestroy() {
dockingControl.remove(dockable)
}
}



As you can see once the MVC group starts, the mvcGroupInit method creates a new dockable instance (closeable and stackable). Then the dockable is located in the "normal" area of the docking control (I wanted to build dockables as tabbed panes), and once the dockable is added to the docking control ,we force it to show up.

Finally if we ask the application to destroy de MVC group called 'customers' through destroyMVCGroup('customers') the method mvcGroupDestroy will remove the dockable from the docking control.

No comments:

Post a Comment