net.sf.jguiraffe.gui.platform.swing.builder.components
Class SwingTableComponentHandler

java.lang.Object
  extended by net.sf.jguiraffe.gui.platform.swing.builder.components.SwingComponentHandler
      extended by net.sf.jguiraffe.gui.platform.swing.builder.components.SwingTableComponentHandler
All Implemented Interfaces:
java.util.EventListener, javax.swing.event.ListSelectionListener, TableHandler, ComponentHandler, SwingEventSource

 class SwingTableComponentHandler
extends SwingComponentHandler
implements TableHandler, javax.swing.event.ListSelectionListener

The Swing-specific implementation of a component handler for a table.

This class wraps a javax.swing.JTable component and implements the methods required for Swing component handlers in a suitable way. The following functionality is provided:

Version:
$Id: SwingTableComponentHandler.java 67 2007-06-09 19:11:01Z oheger $
Author:
Oliver Heger

Constructor Summary
SwingTableComponentHandler(javax.swing.JTable table)
          Creates a new instance of SwingTableComponentHandler and sets the wrapped table.
 
Method Summary
 void clearSelection()
          Clears any information about selected rows.
 java.lang.Object getData()
          Returns the data of the underlying component.
 java.lang.Object getOuterComponent()
          Returns the outer most component.
 int getSelectedIndex()
          Returns the index of the selected row.
 int[] getSelectedIndices()
          Returns an array with the indices of the currently selected rows.
 javax.swing.JTable getTable()
          Returns the table component.
 javax.swing.table.AbstractTableModel getTableModel()
          Returns the table model.
 java.lang.Class getType()
          Returns the type of this component handler.
 boolean isMultiSelection()
          Returns a flag whether the wrapped table supports multi selection.
protected  void registerChangeListener()
          Registers a change listener at the underlying component.
 void rowsDeleted(int startIdx, int endIdx)
          Notifies the table about deleted rows.
 void rowsInserted(int startIdx, int endIdx)
          Notifies the table about inserted rows.
 void rowsUpdated(int startIdx, int endIdx)
          Notifies the table about updated rows.
 void setData(java.lang.Object data)
          Sets the data of this component.
 void setSelectedIndex(int rowIdx)
          Sets the index of the selected row.
 void setSelectedIndices(int[] rowIndices)
          Selects a number of rows.
 void tableDataChanged()
          Notifies the table about an unspecific change of the data of its model.
protected  void unregisterChangeListener()
          Unregisters this handler as change listener from the underlying component.
 void valueChanged(javax.swing.event.ListSelectionEvent e)
          Reacts on changes of the table's selection.
 
Methods inherited from class net.sf.jguiraffe.gui.platform.swing.builder.components.SwingComponentHandler
addActionListener, addChangeListener, addFocusListener, fireChangeEvent, getComponent, getJComponent, isEnabled, removeActionListener, removeChangeListener, removeFocusListener, setEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.jguiraffe.gui.forms.ComponentHandler
getComponent, isEnabled, setEnabled
 

Constructor Detail

SwingTableComponentHandler

public SwingTableComponentHandler(javax.swing.JTable table)
Creates a new instance of SwingTableComponentHandler and sets the wrapped table.

Parameters:
table - the wrapped table component
Method Detail

getTable

public javax.swing.JTable getTable()
Returns the table component.

Returns:
the table

getTableModel

public javax.swing.table.AbstractTableModel getTableModel()
Returns the table model.

Returns:
the table model

isMultiSelection

public boolean isMultiSelection()
Returns a flag whether the wrapped table supports multi selection.

Returns:
the multi selection flag

clearSelection

public void clearSelection()
Clears any information about selected rows.

Specified by:
clearSelection in interface TableHandler

getSelectedIndex

public int getSelectedIndex()
Returns the index of the selected row. This method is intended to be used in single selection mode. If no row is selected, result will be -1.

Specified by:
getSelectedIndex in interface TableHandler
Returns:
the (0-based) index of the selected row

getSelectedIndices

public int[] getSelectedIndices()
Returns an array with the indices of the currently selected rows. This method is intended to be used in multi selection mode. If no rows are selected, an empty array will be returned.

Specified by:
getSelectedIndices in interface TableHandler
Returns:
an array with the (0-based) indices of the selected rows

rowsDeleted

public void rowsDeleted(int startIdx,
                        int endIdx)
Notifies the table about deleted rows. This will cause a redraw if necessary.

Specified by:
rowsDeleted in interface TableHandler
Parameters:
startIdx - the start index of the affected row interval
endIdx - the end index of the affected row interval

rowsInserted

public void rowsInserted(int startIdx,
                         int endIdx)
Notifies the table about inserted rows. This will cause a redraw if necessary.

Specified by:
rowsInserted in interface TableHandler
Parameters:
startIdx - the start index of the affected row interval
endIdx - the end index of the affected row interval
See Also:
TableHandler.tableDataChanged()

rowsUpdated

public void rowsUpdated(int startIdx,
                        int endIdx)
Notifies the table about updated rows. This will cause a redraw if necessary.

Specified by:
rowsUpdated in interface TableHandler
Parameters:
startIdx - the start index of the affected row interval
endIdx - the end index of the affected row interval

setSelectedIndex

public void setSelectedIndex(int rowIdx)
Sets the index of the selected row.

Specified by:
setSelectedIndex in interface TableHandler
Parameters:
rowIdx - the (0-based) index of the row to select

setSelectedIndices

public void setSelectedIndices(int[] rowIndices)
Selects a number of rows. This method is available in multi selection mode.

Specified by:
setSelectedIndices in interface TableHandler
Parameters:
rowIndices - the indices of the rows to be selected

tableDataChanged

public void tableDataChanged()
Notifies the table about an unspecific change of the data of its model. This will cause a redraw.

Specified by:
tableDataChanged in interface TableHandler

getData

public java.lang.Object getData()
Returns the data of the underlying component. This is the table's selection. Depending on the selection mode (single or multi) either a single row index of an array of row indices is returned.

Specified by:
getData in interface ComponentHandler
Returns:
the data of the represented component

getOuterComponent

public java.lang.Object getOuterComponent()
Returns the outer most component. For tables this is the scroll pane the table is embedded.

Specified by:
getOuterComponent in interface ComponentHandler
Overrides:
getOuterComponent in class SwingComponentHandler
Returns:
the outer component

getType

public java.lang.Class getType()
Returns the type of this component handler. The type depends on the table's selection mode.

Specified by:
getType in interface ComponentHandler
Returns:
the type of this handler

setData

public void setData(java.lang.Object data)
Sets the data of this component. Supported are objects of type Number or an array of int values. A value of null is also accepted, it will reset the selection.

Specified by:
setData in interface ComponentHandler
Parameters:
data - the new data for the component
Throws:
java.lang.IllegalArgumentException - if the passed in value is not supported

valueChanged

public void valueChanged(javax.swing.event.ListSelectionEvent e)
Reacts on changes of the table's selection. This will cause registered change listeners to be triggered.

Specified by:
valueChanged in interface javax.swing.event.ListSelectionListener
Parameters:
e - the list selection event

registerChangeListener

protected void registerChangeListener()
Registers a change listener at the underlying component. This implementation registers this object itself as a list selection lister at the wrapped table's row selection model.

Overrides:
registerChangeListener in class SwingComponentHandler

unregisterChangeListener

protected void unregisterChangeListener()
Unregisters this handler as change listener from the underlying component.

Overrides:
unregisterChangeListener in class SwingComponentHandler
See Also:
SwingComponentHandler.registerChangeListener()


Copyright 2007 null. All Rights Reserved.