org.apache.click.extras.panel
Class TabbedPanel

java.lang.Object
  extended by org.apache.click.control.AbstractControl
      extended by org.apache.click.control.AbstractContainer
          extended by org.apache.click.control.Panel
              extended by org.apache.click.extras.panel.TabbedPanel
All Implemented Interfaces:
Serializable, Control, Container, Stateful

public class TabbedPanel
extends Panel
implements Stateful

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.link.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 shown 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;
 } 

CSS and JavaScript resources

The TabbedPanel makes use of the following resources (which Click automatically deploys to the application directory, /click/): To import these TabbedPanel files simply reference the variables $headElements and $jsElements in the page template. For example:
 <html>
 <head>
 $headElements
 </head>
 <body>

 $panel

 $jsElements
 </body>
 </html> 

See Also:
Serialized Form

Field Summary
protected  Panel activePanel
          The currently active panel.
protected  ActionLink tabLink
          The tab switch action link.
 
Fields inherited from class org.apache.click.control.Panel
active, disabled, id, label, model, panels, template
 
Fields inherited from class org.apache.click.control.AbstractContainer
controlMap, controls
 
Fields inherited from class org.apache.click.control.AbstractControl
actionListener, attributes, behaviors, headElements, listener, listenerMethod, messages, name, parent, styles
 
Fields inherited from interface org.apache.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
 Panel getActivePanel()
          Return the currently active panel.
 List<Element> getHeadElements()
          Return the TabbedPanel HTML HEAD elements for the following resource: click/TabbedPanel.css Additionally all controls HEAD elements are also returned.
 Object getState()
          Return the TabbedPanel state.
 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.
 Control insert(Control control, int index)
          Add the control to the panel.
 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 removeState(Context context)
          Remove the TabbedPanel state from the session for the given request context.
 Control replace(Control currentControl, Control newControl)
          Replace the current control with the new control.
 void restoreState(Context context)
          Restore the TabbedPanel state from the session for the given request context.
 void saveState(Context context)
          Save the TabbedPanel state to the session for the given request context.
 void setActionListener(ActionListener actionListener)
          This method will delegate to setTabListener(org.apache.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 setName(String name)
           
 void setState(Object state)
          Set the TabbedPanel state.
 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 org.apache.click.control.Panel
addControl, addModel, createTemplateModel, getId, getLabel, getModel, getPanels, getTemplate, isActive, isDisabled, remove, removeControl, render, setActive, setDisabled, setId, setLabel, setTemplate
 
Methods inherited from class org.apache.click.control.AbstractContainer
add, contains, getControl, getControlMap, getControls, getControlSizeEst, hasControls, onDestroy, renderChildren, renderContent, renderTagEnd, toString
 
Methods inherited from class org.apache.click.control.AbstractControl
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getHtmlImports, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, getTag, hasAttribute, hasAttributes, hasBehaviors, hasStyles, isAjaxTarget, onDeploy, removeBehavior, removeStyleClass, renderTagBegin, setAttribute, setParent, setStyle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.click.Control
getBehaviors, getContext, getMessages, getName, getParent, hasBehaviors, isAjaxTarget, onDeploy, setParent
 

Field Detail

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

insert

public Control insert(Control control,
                      int index)
Add the control to the panel.

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

Specified by:
insert in interface Container
Overrides:
insert in class 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:
AbstractContainer.add(org.apache.click.Control)

replace

public Control replace(Control currentControl,
                       Control newControl)
Replace the current control with the new control.

Specified by:
replace in interface Container
Overrides:
replace in class Panel
Parameters:
currentControl - the current control container in the panel
newControl - the control to replace the current control
Returns:
the new control that replaced the current control
Throws:
IllegalArgumentException - if the currentControl or newControl is null
IllegalStateException - if the currentControl is not contained in the panel

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. In addition the given panel's active property will be set to true, while the previous active panel will be deactivated.

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

getHeadElements

public List<Element> getHeadElements()
Return the TabbedPanel HTML HEAD elements for the following resource: Additionally all controls HEAD elements are also returned.

Specified by:
getHeadElements in interface Control
Overrides:
getHeadElements in class AbstractControl
Returns:
the HTML HEAD elements for the control
See Also:
Control.getHeadElements()

setListener

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

Specified by:
setListener in interface Control
Overrides:
setListener in class AbstractControl
Parameters:
listener - the listener object with the named method to invoke
listenerMethod - the name of the method to invoke

setName

public void setName(String name)
Specified by:
setName in interface Control
Overrides:
setName in class AbstractControl
Parameters:
name - of the control
Throws:
IllegalArgumentException - if the name is null
See Also:
Control.setName(String)

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(org.apache.click.ActionListener).

Overrides:
setActionListener in class AbstractControl
Parameters:
actionListener - the control's action listener

getState

public Object getState()
Return the TabbedPanel state. The following state is returned:

Specified by:
getState in interface Stateful
Returns:
the TabbedPanel state

setState

public void setState(Object state)
Set the TabbedPanel state.

Specified by:
setState in interface Stateful
Parameters:
state - the tabbedPanel state to set

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:

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

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 is present, this value will be used to specify the active panel. The panel index is a zero based integer.

If multiple TabbedPanels are present on a form, use tabPanelIndex-<panel-name> to target a specific panel, for example: tabPanelIndex-myTabbedPanel.

Specified by:
onInit in interface Control
Overrides:
onInit in class Panel
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.

Specified by:
onProcess in interface Control
Overrides:
onProcess in class Panel
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.

Specified by:
onRender in interface Control
Overrides:
onRender in class Panel
See Also:
Control.onRender()

removeState

public void removeState(Context context)
Remove the TabbedPanel state from the session for the given request context.

Parameters:
context - the request context
See Also:
saveState(org.apache.click.Context), restoreState(org.apache.click.Context)

restoreState

public void restoreState(Context context)
Restore the TabbedPanel state from the session for the given request context.

This method delegates to setState(java.lang.Object) to set the panel's restored state.

Parameters:
context - the request context
See Also:
saveState(org.apache.click.Context), removeState(org.apache.click.Context)

saveState

public void saveState(Context context)
Save the TabbedPanel state to the session for the given request context.

* This method delegates to getState() to retrieve the panel's state to save.

Parameters:
context - the request context
See Also:
restoreState(org.apache.click.Context), removeState(org.apache.click.Context)

initActivePanel

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