org.tbee.swing.table
Class ActionEditorImageButton

java.lang.Object
  extended by javax.swing.AbstractCellEditor
      extended by org.tbee.swing.table.ActionEditorImageButton
All Implemented Interfaces:
java.io.Serializable, javax.swing.CellEditor, javax.swing.table.TableCellEditor, UseTableCellEditorAsTableCellRenderer.UseAsRenderer

public class ActionEditorImageButton
extends javax.swing.AbstractCellEditor
implements javax.swing.table.TableCellEditor, UseTableCellEditorAsTableCellRenderer.UseAsRenderer

This class is suited to render a single AbstractAction on multiple row. Usually the action does involve something row-specific, this would mean that you need to provide a separate AbstractAction instance for each row. And each instance must contain all the data it needs to execute it action. Using one instance and updating it upon click does not work because of the random way parts of the table are redrawn. Providing a separate AbstractAction class will work fine with this editor. But this also supports a single instance approach, where the clicked row index is handed over. In the action listener you can use the utility method to fetch a value from the table: private AbstractAction iAddStorageAbstractAction = new AbstractAction(...) { public void actionPerformed(ActionEvent e) { Standversion lStandversion = (Standversion)AbstractActionEditor.getTableModelValue(e, this, COLUMNIDX_STANDVERSION); ... The value must be fetched using TableModel.getValue in order to handle sorting. One practical hint: usually the button is displayed in one column, but you need other data to execute the action. The data in the columns often are not exactly what you need, so additional querying using an alternate key would be needed. But there is no reason why you cannot use negative column indexes (<0) to provide special data that is not shown in the table! The example above does exactly this.

Version:
$Revision: 1.3 $
Author:
$Author: toeukpap $
See Also:
, Serialized Form

Field Summary
static java.lang.String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
static java.lang.String VALUE_ID_TABLE
           
 
Fields inherited from class javax.swing.AbstractCellEditor
changeEvent, listenerList
 
Constructor Summary
ActionEditorImageButton(javax.swing.JTable jtable)
          Initialize the editor
 
Method Summary
 void construct()
          initialize the editor
 java.lang.Object getCellEditorValue()
          Return the value after the editor is done
 java.awt.Component getTableCellEditorComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, int row, int column)
          Return the component that is shown in the cell in the table.
static java.lang.Object getTableModelValue(java.awt.event.ActionEvent e, javax.swing.AbstractAction abstractAction, int col)
          Convenience method to do a get value from the table model
 javax.swing.table.TableCellEditor useAsRenderer()
           
 
Methods inherited from class javax.swing.AbstractCellEditor
addCellEditorListener, cancelCellEditing, fireEditingCanceled, fireEditingStopped, getCellEditorListeners, isCellEditable, removeCellEditorListener, shouldSelectCell, stopCellEditing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.CellEditor
addCellEditorListener, cancelCellEditing, isCellEditable, removeCellEditorListener, shouldSelectCell, stopCellEditing
 

Field Detail

SOURCECODE_VERSION

public static final java.lang.String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values

VALUE_ID_TABLE

public static final java.lang.String VALUE_ID_TABLE
See Also:
Constant Field Values
Constructor Detail

ActionEditorImageButton

public ActionEditorImageButton(javax.swing.JTable jtable)
Initialize the editor

Method Detail

construct

public void construct()
initialize the editor


getCellEditorValue

public java.lang.Object getCellEditorValue()
Return the value after the editor is done

Specified by:
getCellEditorValue in interface javax.swing.CellEditor

getTableCellEditorComponent

public java.awt.Component getTableCellEditorComponent(javax.swing.JTable table,
                                                      java.lang.Object value,
                                                      boolean isSelected,
                                                      int row,
                                                      int column)
Return the component that is shown in the cell in the table.

Specified by:
getTableCellEditorComponent in interface javax.swing.table.TableCellEditor

useAsRenderer

public javax.swing.table.TableCellEditor useAsRenderer()
Specified by:
useAsRenderer in interface UseTableCellEditorAsTableCellRenderer.UseAsRenderer

getTableModelValue

public static java.lang.Object getTableModelValue(java.awt.event.ActionEvent e,
                                                  javax.swing.AbstractAction abstractAction,
                                                  int col)
Convenience method to do a get value from the table model



Copyright © 2010. All Rights Reserved.