net.sf.click.extras.panel
Class TabbedPanel

java.lang.Object
  extended bynet.sf.click.control.AbstractControl
      extended bynet.sf.click.control.AbstractContainer
          extended bynet.sf.click.control.Panel
              extended bynet.sf.click.extras.panel.TabbedPanel
All Implemented Interfaces:
Container, Control, Serializable

public class TabbedPanel
extends Panel

Provides a tabbed panel with multiple sub-panels in 'tabs'.

This panel comes with a default template that will render the panels in CSS customizable table tags.

A listener setTabListener(ActionListener) may be attached (similar to the control listeners) that will be called on tab switch. This could be useful to load (or reload) model related information for which ever panel is selected by the user.

The classpath TabbedPanel.htm template is illustrated below:

 <div id='$this.id'>
  <table class="tp_tab">
   <tr class="tp_tab">
    #foreach ($panel in $this.panels)
     #if ($panel.id == $this.activePanel.id)
      <td class="tp_tab_on">
       $panel.label
      </td>
      <td class="tp_tab_space"></td>
     #else
      <td class="tp_tab_off">
       <a href="$this.tabLink.getHref($panel.name)"
          id="$panel.id"
          class="tp_tab_link">$panel.label</a>
      </td>
      <td class="tp_tab_space"></td>
     #end
    #end
   </tr>
  </table>
  <table class="tp_content">
   <tr class="tp_content">
    <td class="tp_content">
     $this.activePanel
    </td>
   </tr>
  </table>
 </div> 
Also, as show above, there are a number of CSS attributes that allow some customization of the output. These CSS attributes are defined in the auto deployed TabbedPanel.css. The TabbedPanel CSS attributes are:
 table.tp_tab {
   border-collapse: collapse;
 }
 tr.tp_tab {
 }
 td.tp_tab_on {
   background: #336699;
   color: #ffffff;
   border-left: 1px solid #336699;
   border-top: 1px solid #336699;
   border-right: 1px solid #336699;
   padding: 5px;
 }
 td.tp_tab_off {
   background: #cccccc;
   color: #000000;
   border-left: 1px solid #336699;
   border-top: 1px solid #336699;
   border-right: 1px solid #336699;
   padding: 5px;
 }
 table.tp_content {
   border: 1px solid #336699;
 }
 tr.tp_content {
 }
 td.tp_content {
   background: #efefef;
 } 

Author:
Phil Barnes, Malcolm Edgar
See Also:
Serialized Form

Field Summary
protected  Panel activePanel
          The currently active panel.
static String HTML_IMPORTS
          The TabbedPanel.css style sheet import link.
protected  ActionLink tabLink
          The tab switch action link.
 
Fields inherited from class net.sf.click.control.Panel
disabled, id, label, model, panels, template
 
Fields inherited from class net.sf.click.control.AbstractContainer
controlMap, controls
 
Fields inherited from class net.sf.click.control.AbstractControl
actionListener, attributes, listener, listenerMethod, messages, name, parent, styles
 
Fields inherited from interface net.sf.click.Control
CONTROL_MESSAGES
 
Constructor Summary
TabbedPanel()
          Create a TabbedPanel with no name or template defined.
TabbedPanel(String name)
          Create a TabbedPanel with the given name.
TabbedPanel(String name, String template)
          Create a Panel with the given name and template path.
TabbedPanel(String name, String template, String id)
          Create a TabbedPanel with the given name, id attribute and template path.
 
Method Summary
 Control add(Control control)
          Add the control to the panel.
 Control addControl(Control control)
           
 Panel getActivePanel()
          Return the currently active panel.
 String getHtmlImports()
          Return the HTML head import statements for the CSS stylesheet file: click/TabbedPanel.css.
 ActionLink getTabLink()
          Return the tab switching action link.
 String getWidth()
          Return the tabbed panel content table HTML width attribute if defined.
protected  void initActivePanel()
          Sets the active panel based on one of the following: If tabPanelIndex request parameter is present, this value will be used to specify the active panel.
 void onDeploy(ServletContext servletContext)
          Deploy the TabbedPanel.css file to the click web directory when the application is initialized.
 void onInit()
          Initialize the child controls contained in the panel.
 boolean onProcess()
          Process the request and invoke the onProcess() method of any child controls.
 void onRender()
          Perform any pre rendering logic and invoke the onRender() method of any child controls.
 void setActionListener(ActionListener actionListener)
          This method will delegate to setTabListener(net.sf.click.ActionListener).
 void setActivePanel(Panel panel)
          Set the currently active panel to the given panel.
 void setListener(Object listener, String listenerMethod)
          This method will delegate to setTabListener(java.lang.Object, java.lang.String).
 void setTabListener(ActionListener actionListener)
          Set the tab switch listener.
 void setTabListener(Object listener, String listenerMethod)
           
 void setWidth(String width)
          Set the tabbed panel content table HTML width attribute if defined.
 
Methods inherited from class net.sf.click.control.Panel
addModel, createTemplateModel, getId, getLabel, getModel, getPanels, getTemplate, isDisabled, remove, removeControl, render, setDisabled, setId, setLabel, setTemplate
 
Methods inherited from class net.sf.click.control.AbstractContainer
contains, getControl, getControlMap, getControls, getControlSizeEst, hasControls, insert, onDestroy, renderChildren, renderContent, renderTagEnd, toString
 
Methods inherited from class net.sf.click.control.AbstractControl
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, getTag, hasAttribute, hasAttributes, hasStyles, registerActionEvent, removeStyleClass, renderTagBegin, setAttribute, setName, setParent, setStyle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.click.Control
getContext, getMessages, getName, getParent, setName, setParent
 

Field Detail

HTML_IMPORTS

public static final String HTML_IMPORTS
The TabbedPanel.css style sheet import link.

See Also:
Constant Field Values

activePanel

protected Panel activePanel
The currently active panel.


tabLink

protected ActionLink tabLink
The tab switch action link.

Constructor Detail

TabbedPanel

public TabbedPanel(String name)
Create a TabbedPanel with the given name.

Parameters:
name - the name of the panel

TabbedPanel

public TabbedPanel(String name,
                   String template)
Create a Panel with the given name and template path.

Parameters:
name - the name of the panel
template - the Velocity template

TabbedPanel

public TabbedPanel(String name,
                   String template,
                   String id)
Create a TabbedPanel with the given name, id attribute and template path.

Parameters:
name - the name of the panel
template - the Velocity template path
id - the id HTML attribute value

TabbedPanel

public TabbedPanel()
Create a TabbedPanel with no name or template defined.

Please note the control's name must be defined before it is valid.

Method Detail

addControl

public Control addControl(Control control)
Parameters:
control - the control to add to the container
Returns:
the control that was added to the container
Throws:
IllegalArgumentException - if the control is null, if the name of the control is not defined or the container already contains a control with the same name
See Also:
add(net.sf.click.Control)

add

public Control add(Control control)
Add the control to the panel.

If the control added is the first panel it will be made the active panel.

Parameters:
control - the control to add to the container
Returns:
the control that was added to the container
Throws:
IllegalArgumentException - if the control is null, if the name of the control is not defined or the container already contains a control with the same name
See Also:
Panel.add(net.sf.click.Control)

getActivePanel

public Panel getActivePanel()
Return the currently active panel.

Returns:
the currently active panel

setActivePanel

public void setActivePanel(Panel panel)
Set the currently active panel to the given panel.

Parameters:
panel - the panel to set as the current active panel

getHtmlImports

public String getHtmlImports()
Return the HTML head import statements for the CSS stylesheet file: click/TabbedPanel.css.

Returns:
the HTML head import statements for the control stylesheet

setListener

public void setListener(Object listener,
                        String listenerMethod)
This method will delegate to setTabListener(java.lang.Object, java.lang.String).

Parameters:
listener - the listener object with the named method to invoke
listenerMethod - the name of the method to invoke

setTabListener

public void setTabListener(Object listener,
                           String listenerMethod)
Parameters:
listener - the listener object with the named method to invoke
listenerMethod - the name of the method to invoke
See Also:
setTabListener(ActionListener)

setActionListener

public void setActionListener(ActionListener actionListener)
This method will delegate to setTabListener(net.sf.click.ActionListener).

Parameters:
actionListener - the control's action listener

setTabListener

public void setTabListener(ActionListener actionListener)
Set the tab switch listener. If the listener and method are non-null, then the listener will be called whenever a request to switch tabs is placed by clicking the link associated with that tab.

The method signature of the listener is:

An example event listener method would be:

 public boolean onClick() {
     System.out.println("onClick called");
     return true;
 } 

Parameters:
actionListener - the control's action listener

getTabLink

public ActionLink getTabLink()
Return the tab switching action link.

Returns:
the tab switching action link

getWidth

public String getWidth()
Return the tabbed panel content table HTML width attribute if defined.

Returns:
the tabbed panel content table HTML width attribute if defined

setWidth

public void setWidth(String width)
Set the tabbed panel content table HTML width attribute if defined.

Parameters:
width - the tabbed panel content table HTML width attribute

onDeploy

public void onDeploy(ServletContext servletContext)
Deploy the TabbedPanel.css file to the click web directory when the application is initialized.

Parameters:
servletContext - the servlet context
See Also:
Control.onDeploy(ServletContext)

onInit

public void onInit()
Initialize the child controls contained in the panel. Note with the child panels only the active panel will be initialized.

If tabPanelIndex request parameter present this value will be used to specify the active panel. The panel index is a zero based integer.

See Also:
Control.onInit()

onProcess

public boolean onProcess()
Process the request and invoke the onProcess() method of any child controls. Note with the child panels only the active panel will be processed.

Returns:
true or false to abort further processing
See Also:
Control.onProcess()

onRender

public void onRender()
Perform any pre rendering logic and invoke the onRender() method of any child controls. Note with the child panels only the active panel will have its onRender() method invoked.

See Also:
Control.onRender()

initActivePanel

protected void initActivePanel()
Sets the active panel based on one of the following: