com.arsdigita.bebop.table
Interface TableCellRenderer

All Known Implementing Classes:
DataTable.GlobalizedHeaderCellRenderer, DateTableCellRenderer, DateTimeTableCellRenderer, DefaultTableCellRenderer, PropertySheet.StringLabelCellRenderer

public interface TableCellRenderer

Render one cell in a table. The renderer returns a component whose generateXML method will be called by the table to include the data for the cell in the table's output.

The table uses the returned component only until it calls the cell renderer again, so that cell renderers may reuse the same object in subsequent calls to getComponent.

As an example, consider the following implementation of a table cell renderer, which simply converts the passed in value to a string and encloses it in a label. The cell renderer converts the passed in value to a string and uses that to set the text to display for a label. If the value is selected, the label is bolded. As an added twist, the table cell renderer uses only one label for each thread from which it is accessed (rather than creating a new Label for each call) by storing the label in a ThreadLocal variable.

 public class MyTableCellRenderer implements TableCellRenderer {

   private ThreadLocal m_label;

   public MyTableCellRenderer() {
     m_label = new ThreadLocal() {
  protected Object initialValue() {
    return new Label("");
  }
       };
   }

   public Component getComponent(Table table, PageState state, Object value,
              boolean isSelected, Object key,
              int row, int column) {
     Label l = (Label) m_label.get();
     l.setLabel(value.toString());
     l.setFontWeight( isSelected ? Label.BOLD : null );
     return l;
   }
 }
 

Version:
$Id: //core-platform/dev/src/com/arsdigita/bebop/table/TableCellRenderer.java#9 $
Author:
David Lutterkort
See Also:
Table

Field Summary
static String versionId
           
 
Method Summary
 Component getComponent(Table table, PageState state, Object value, boolean isSelected, Object key, int row, int column)
          Return a component with the visual representation for the passed in key and value.
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Method Detail

getComponent

public Component getComponent(Table table,
                              PageState state,
                              Object value,
                              boolean isSelected,
                              Object key,
                              int row,
                              int column)
Return a component with the visual representation for the passed in key and value.

The table sets the control event prior to calling this method, so that any control link returned as the component will, when clicked, cause the table to fire a TableActionEvent whose getRowKey() and getColumn() return the values of key and column. A simple cell renderer that achieves this would implement this method in the following way:

   public Component getComponent(Table table, PageState state, Object value,
              boolean isSelected, Object key,
              int row, int column) {
     return new ControlLink(value.toString());
   }
 

The column refers to a column in the table's TableColumnModel, i.e. the visual column on the screen, and not the table's representation of the underlying data in the TableModel.

Parameters:
table - the table requesting the rendering.
state - represents the state of the current request.
value - the data element to render as returned by the table model's getElementAt(column).
isSelected - true if this item is selected.
key - the key identifying this row (and possibly column) as returned by the table model's getKeyAt(column)
row - the number of the row in the table, the first row has number 0.
column - the number of the table column.
Returns:
the component that should be used to render the value.
See Also:
TableColumnModel


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC