org.tbee.swing.table
Class ActionEditorJButton

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

public class ActionEditorJButton
extends AbstractCellEditor
implements 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.2 $
Author:
$Author: toeukpap $
See Also:
, Serialized Form

Field Summary
static String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
static String VALUE_ID_TABLE
           
 
Fields inherited from class javax.swing.AbstractCellEditor
changeEvent, listenerList
 
Constructor Summary
ActionEditorJButton(JTable jtable)
          Initialize the editor
 
Method Summary
 void construct()
          initialize the editor
 Object getCellEditorValue()
          Return the value after the editor is done
 Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
          Return the component that is shown in the cell in the table.
static Object getTableModelValue(ActionEvent e, AbstractAction abstractAction, int col)
          Convenience method to do a get value from the table model
 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 String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values

VALUE_ID_TABLE

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

ActionEditorJButton

public ActionEditorJButton(JTable jtable)
Initialize the editor

Method Detail

construct

public void construct()
initialize the editor


getCellEditorValue

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

Specified by:
getCellEditorValue in interface CellEditor

getTableCellEditorComponent

public Component getTableCellEditorComponent(JTable table,
                                             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 TableCellEditor

useAsRenderer

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

getTableModelValue

public static Object getTableModelValue(ActionEvent e,
                                        AbstractAction abstractAction,
                                        int col)
Convenience method to do a get value from the table model



Copyright © 2012 KnowledgePlaza. All Rights Reserved.