Skip to content
This repository was archived by the owner on Jun 7, 2024. It is now read-only.

Adding tabs

mlist edited this page Apr 12, 2013 · 1 revision

Tabs are content modules that will be rendered at the bottom of the main panel.

Show view of a gene in OLF

This kind of content module is slightly more complicated than a menu module, because it is more flexible. Tabs can be rendered for all or only for specific domain objects. Furthermore, different templates can be defined for different domain objects. Like all content modules the class has to be placed under grails-app/modules. Tabs, as well as operations content modules need to implement the interface Module and the class name needs to end in Module.

Let's look at an example:

package org.openlab.module.operations

import org.openlab.module.*;
import org.openlab.genetracker.*;

class GeneOperationsModule implements Module{

    //returns the name of the grails-plug-in, e.g. the name of your OLF module. 
    //this information is used to locate the templates to be rendered later on.
    def getPluginName() 
    {
        "gene-tracker"
    }

    //returns the name of the template for a given domainClass name
    //allows in this way to render different templates where necessary
    def getTemplateForDomainClass(def domainClass)
    {
	if(domainClass.startsWith("cellLineData")) return "antibioticsTab"
        else return null
    }

    //returns a template to render for mobile view. 
    @Override
    def getMobileTemplateForDomainClass(Object domainClass) {
        return null
    }

    //returns a boolean if the module offers a template for a given domain class and type (either "tab" or "operations"
    def isInterestedIn(def domainClass, def type)
    {
	if((type == "tab") && domainClass.startsWith("cellLineData")) return true
	return false
    }
		
    //it is possible to create a model for rendering the templates.
    def getModelForDomainClass(def domainClass, def id)
    {
	if(domainClass.startsWith("cellLineData"))
	{
		def cellLineData = CellLineData.get(id)
		def antibioticsWithConc = AntibioticsWithConcentration.findAllByCellLineData(cellLineData)
                def antibioticsList = Antibiotics.list()

            [cellLineData: cellLineData, antibioticsList: antibioticsList, antibioticsWithConc: antibioticsWithConc]
	}
    }

    //should return true only if a mobile template is available.
    @Override
    def isMobile() 
    {
        return false
    }
}

However, this is only half of the story. It is equally important to provide the view templates. Their implementation follows the same rules as normal GSP views. View templates for tabs have to be placed under a dedicated folder "grails-app/views/tabs". Note that grails view templates are indicated by an underscore in the name, e.g. "_antibioticsTab.gsp".

Clone this wiki locally