com.partnersoft.workbench.editors
Class TableEditor

java.lang.Object
  extended by com.partnersoft.workbench.model.AbstractWorkbenchFileEditor
      extended by com.partnersoft.workbench.editors.TableEditor
All Implemented Interfaces:
WorkbenchEditor, WorkbenchFileEditor
Direct Known Subclasses:
CsvTableEditor, DbfTableEditor, ShapefileTableEditor

public abstract class TableEditor
extends AbstractWorkbenchFileEditor

Abstract TableEditor class. Defines JTable helper methods. Extending classes need to implement save(), load(), and optionally saveWrapper().

Copyright 2008 Partner Software, Inc.

Version:
$Id$
Author:
Rich Stepanski

Nested Class Summary
 class TableEditor.ComboBoxCellEditor
           
 
Field Summary
protected  javax.swing.JTable table
           
 
Fields inherited from class com.partnersoft.workbench.model.AbstractWorkbenchFileEditor
actionBureau, file, gui, name, workbench
 
Constructor Summary
TableEditor()
          Creates a new TableEditor.
 
Method Summary
 void addBlankRow()
          Adds an empty row to the end of the table.
 void addColumn(java.lang.String name)
          Adds a column.
 void addPicklistColumn(java.lang.String name, java.lang.String... options)
          Adds a column with all cells being combo boxes.
 void addRow(Naming rowData)
          Adds a row to the end of the table.
 void addRow(java.lang.Object... orderedRowData)
          Adds a row to the end of the table.
 void clear()
           
 void deleteRow(int rowIndex)
          Removes specified row from table.
 java.util.List<Naming> getAllData()
          Returns a List, each Naming being the values within a single row.
 java.lang.Object getCellValueAt(int colIndex, int rowIndex)
          Returns object at given table coordinates.
 java.lang.String[] getColumnNames()
          Returns a String[] of all column names in order.
 Naming getRowAt(int rowIndex)
          Returns Naming of column names mapped to column values for specified row.
 java.util.Vector getRowVectorAt(int rowIndex)
          Returns vector of row data for specified row.
 void insertBlankRow(int rowIndex)
          Inserts an empty row at the given index.
 void insertRowAt(int rowIndex, Naming rowData)
          Inserts row at specified index.
 void insertRowAt(int rowIndex, java.lang.Object... orderedRowData)
          Inserts row at specified index.
abstract  void load()
           
 void removeColumn(int colIndex)
          Removes specified column from the table.
 void removeColumn(java.lang.String colName)
          Removes specified column from the table.
abstract  void save()
          Called on every table update through saveWrapper().
 void saveWrapper()
          Wrapper for save() allowing extending classes to handle IOException.
 void setCellValueAt(java.lang.Object value, int colIndex, int rowIndex)
          Sets object at given table coordinates.
 void setColumnCellEditor(int colIndex, javax.swing.table.TableCellEditor editor)
          Sets a column editor for specified column.
 void setColumnCellEditor(java.lang.String colName, javax.swing.table.TableCellEditor editor)
          Sets a column editor for specified column.
 void setColumnCellRenderer(int colIndex, javax.swing.table.TableCellRenderer renderer)
          Sets a column renderer for specified column.
 void setColumnCellRenderer(java.lang.String colName, javax.swing.table.TableCellRenderer renderer)
          Sets a column renderer for specified column.
 void setLine(int line)
           
 void setRowAt(int rowIndex, Naming rowData)
          Sets Row values at specified index to values matching column names in Naming.
 void setRowAt(int rowIndex, java.lang.Object... orderedRowData)
          Sets row values at specified index to values.
 
Methods inherited from class com.partnersoft.workbench.model.AbstractWorkbenchFileEditor
doAction, doAction, getFile, getGui, getName, getWorkbench, loadCog, loadObject, saveCog, saveObject, setFile, setWorkbench
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

table

protected javax.swing.JTable table
Constructor Detail

TableEditor

public TableEditor()
Creates a new TableEditor. Workbench, name, and file are not set in super class.

Internal JTable is generated with a DefaultTableModel, and a TableModelListener passing all tableChanged events to saveWrapper().

Method Detail

getAllData

public java.util.List<Naming> getAllData()
Returns a List, each Naming being the values within a single row.

Returns:
- List of all rows. Empty List if table is empty.

addColumn

public void addColumn(java.lang.String name)
Adds a column.

Parameters:
name -

addPicklistColumn

public void addPicklistColumn(java.lang.String name,
                              java.lang.String... options)
Adds a column with all cells being combo boxes. Sets the cell editor and renderer for the column.

Parameters:
name -
options -

setColumnCellEditor

public void setColumnCellEditor(java.lang.String colName,
                                javax.swing.table.TableCellEditor editor)
Sets a column editor for specified column. Editors handle checking data entry. Calls setColumnCellEditor(int, TableCellEditor).

Parameters:
colName -
editor -

setColumnCellEditor

public void setColumnCellEditor(int colIndex,
                                javax.swing.table.TableCellEditor editor)
Sets a column editor for specified column. Editors handle checking data entry for each cell.

Parameters:
colIndex - - 0 based index of cells.
editor -

setColumnCellRenderer

public void setColumnCellRenderer(java.lang.String colName,
                                  javax.swing.table.TableCellRenderer renderer)
Sets a column renderer for specified column. Handles graphics for each cell in column. Calls setColumnRenderer(int, TableCellRenderer).

Parameters:
colName -
renderer -

setColumnCellRenderer

public void setColumnCellRenderer(int colIndex,
                                  javax.swing.table.TableCellRenderer renderer)
Sets a column renderer for specified column. Handles graphics for each cell in column.

Parameters:
colIndex - - 0 based index of cells.
renderer -

removeColumn

public void removeColumn(java.lang.String colName)
Removes specified column from the table. Deleting all data associated with it.

Parameters:
colName -

removeColumn

public void removeColumn(int colIndex)
Removes specified column from the table. Deleting all data associated with it.

Parameters:
colIndex - - O based column index.

deleteRow

public void deleteRow(int rowIndex)
Removes specified row from table.

Parameters:
rowIndex - - 0 based row index.

getCellValueAt

public java.lang.Object getCellValueAt(int colIndex,
                                       int rowIndex)
Returns object at given table coordinates.

Parameters:
colIndex - - 0 based index of columns.
rowIndex - - 0 based index of rows.
Returns:
Object in given row at given column.

setCellValueAt

public void setCellValueAt(java.lang.Object value,
                           int colIndex,
                           int rowIndex)
Sets object at given table coordinates.

Parameters:
value - - Object to set in cell.
colIndex - - 0 based index of columns.
rowIndex - - 0 based index of rows.

setRowAt

public void setRowAt(int rowIndex,
                     Naming rowData)
Sets Row values at specified index to values matching column names in Naming.

Parameters:
rowIndex - - O based row index.
rowData - - Naming of column names mapped to values.

setRowAt

public void setRowAt(int rowIndex,
                     java.lang.Object... orderedRowData)
Sets row values at specified index to values. Value index is used as column index.

Calls deleteRow(int) and insertRowAt(int,

Parameters:
rowIndex - - 0 based row index.
orderedRowData - - Object[] of column values.

getRowAt

public Naming getRowAt(int rowIndex)
Returns Naming of column names mapped to column values for specified row.

Parameters:
rowIndex - - 0 based row index.
Returns:
- Naming of column names mapped to column values. Empty Naming if row doesn't exit.

getRowVectorAt

public java.util.Vector getRowVectorAt(int rowIndex)
Returns vector of row data for specified row.

Parameters:
rowIndex - - 0 based row index.
Returns:
Vector of row data. Empty vector if index < 0 || index >= rowCount.

insertRowAt

public void insertRowAt(int rowIndex,
                        Naming rowData)
Inserts row at specified index.

Calls insertRowAt(int, Object[])

Parameters:
rowIndex - - 0 based row index.
rowData - - Naming with column names as keys.

insertRowAt

public void insertRowAt(int rowIndex,
                        java.lang.Object... orderedRowData)
Inserts row at specified index.

Parameters:
rowIndex - - 0 based row index
orderedRowData -

addBlankRow

public void addBlankRow()
Adds an empty row to the end of the table.


insertBlankRow

public void insertBlankRow(int rowIndex)
Inserts an empty row at the given index.

Parameters:
rowIndex - - 0 based row index.

addRow

public void addRow(Naming rowData)
Adds a row to the end of the table. Calls insertRowAt( int, Naming )

Parameters:
rowData - - Naming of column names mapped to values.

addRow

public void addRow(java.lang.Object... orderedRowData)
Adds a row to the end of the table. Calls insertRowAt( int, Object[] )

Parameters:
orderedRowData -

getColumnNames

public java.lang.String[] getColumnNames()
Returns a String[] of all column names in order.

Returns:

clear

public void clear()

load

public abstract void load()
                   throws java.io.IOException
Throws:
java.io.IOException

save

public abstract void save()
                   throws java.io.IOException
Called on every table update through saveWrapper().

Throws:
java.io.IOException

saveWrapper

public void saveWrapper()
Wrapper for save() allowing extending classes to handle IOException. Called on every table update, calls save().


setLine

public void setLine(int line)