Compiere 3.1

org.compiere.model
Class GridTable

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.compiere.model.GridTable
All Implemented Interfaces:
Serializable, TableModel

public class GridTable
extends AbstractTableModel
implements Serializable

Grid Table Model for JDBC access including buffering.

                The following data types are handled
                        Integer         for all IDs
                        BigDecimal      for all Numbers
                        Timestamp       for all Dates
                        String          for all others
  The data is read via r/o resultset and cached in m_buffer. Writes/updates
  are via dynamically constructed SQL INSERT/UPDATE statements. The record
  is re-read via the resultset to get results of triggers.

  
The model maintains and fires the requires TableModelEvent changes, the DataChanged events (loading, changed, etc.) as well as Vetoable Change event "RowChange" (for row changes initiated by moving the row in the table grid).

Version:
$Id: GridTable.java,v 1.9 2006/08/09 16:38:25 jjanke Exp $
Author:
Jorg Janke
See Also:
Serialized Form

Field Summary
static String PROPERTY
          Property of Vetoable Bean support "RowChange"
static char SAVE_ABORT
          Save Abort Error - U
static char SAVE_ACCESS
          Save Access Error - A
static char SAVE_ERROR
          Save Error - E
static char SAVE_MANDATORY
          Save Mandatory Error - M
static char SAVE_OK
          Save OK - O
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
GridTable(Ctx ctx, int AD_Table_ID, String TableName, int WindowNo, int TabNo, boolean withAccessControl)
          JDBC Based Buffered Table
 
Method Summary
 void addDataStatusListener(DataStatusListener l)
          Add Data Status Listener
 void addField(GridField field)
          Add Field to Table
 void addVetoableChangeListener(VetoableChangeListener l)
          Add Vetoable change listener for row changes
 void close(boolean finalCall)
          Close Resultset
 boolean dataDelete(int row)
          Delete Data
 void dataIgnore()
          Ignore changes
 boolean dataNew(int currentRow, boolean copyCurrent)
          New Record after current Row
 void dataRefresh(int row)
          Refresh Row - ignore changes
 void dataRefreshAll()
          Refresh all Rows - ignore changes
 boolean dataRequery(String whereClause)
          Requery with new whereClause
 char dataSave(boolean manualCmd)
          Save unconditional.
 boolean dataSave(int newRow, boolean manualCmd)
          Check if it needs to be saved and save it.
 int findColumn(String columnName)
          Returns a column given its name.
protected  void fireDataStatusEEvent(String AD_Message, String info, boolean isError)
          Create and fire Data Status Error Event
protected  void fireDataStatusEEvent(ValueNamePair errorLog)
          Create and fire Data Status Event (from Error Log)
protected  void fireDataStatusIEvent(String AD_Message, String info)
          Create and fire Data Status Info Event
protected  void fireVetoableChange(PropertyChangeEvent e)
          Fire Vetoable change listener for row changes
 int getColorCode(int row)
          Get ColorCode for Row.
 Class<?> getColumnClass(int index)
          Returns Class of database column/field
 int getColumnCount()
          Get total database column count (displayed and not displayed)
 String getColumnName(int index)
          Returns database column name
 boolean getCompareDB()
          Get Compare DB.
protected  GridField getField(int index)
          Get Column at index
protected  GridField getField(String identifier)
          Return Columns with Indentifier (ColumnName)
 int getFieldCount()
          Get (displayed) field count
 GridField[] getFields()
          Get all Fields
 String getKeyColumnName()
          Get Key ColumnName
 int getKeyID(int row)
          Get Key ID or -1 of none
 Object getOldValue(int row, int col)
          Get Old Value
 String getOrderClause()
          Get Order Clause (w/o the ORDER BY)
 int getRowCount()
          Return number of rows
 String getSelectWhereClause()
          Get record set Where Clause (w/o the WHERE and w/o History)
 String getTableName()
          Get Table Name
 Object getValueAt(int row, int col)
          Get Value in Resultset
 boolean isCellEditable(int row, int col)
          Is Cell Editable.
 boolean isInserting()
          Is inserting
 boolean isLoading()
          Is Loading
 boolean isOpen()
          Is it open?
 boolean isReadOnly()
          Is entire Table Read/Only
 boolean isRowEditable(int row)
          Is Current Row Editable
 void loadComplete()
          Wait until async loader of Table and Lookup Fields is complete Used for performance tests
 boolean needSave()
          Check if the row needs to be saved
 boolean needSave(boolean onlyRealChange)
          Check if the current row needs to be saved.
 boolean needSave(int newRow)
          Check if the row needs to be saved
 boolean needSave(int newRow, boolean onlyRealChange)
          Check if the row needs to be saved
 boolean open(int maxRows)
          Open Database.
 void removeDataStatusListener(DataStatusListener l)
          Remove Data Status Listener
 void removeVetoableChangeListener(VetoableChangeListener l)
          Remove Vetoable change listener for row changes
 void setChanged(boolean changed)
          Indicate that there will be a change
 void setColorColumn(String columnName)
          Set the Column to determine the color of the row
 void setCompareDB(boolean compareDB)
          Set Compare DB.
 void setDeleteable(boolean value)
          Can Table rows be deleted
 void setOrderClause(String newOrderClause)
          Set Order Clause (w/o the ORDER BY)
 void setParameterSELECT(int index, Object parameter)
          Set Select Clause Parameter.
 void setParameterWHERE(int index, Object parameter)
          Set Where Clause Parameter.
 void setReadOnly(boolean value)
          Set entire table as read only
 boolean setSelectWhereClause(String newWhereClause)
          Set Where Clause (w/o the WHERE and w/o History).
 void setTableName(String newTableName)
          Set Table Name
 void setValueAt(Object value, int row, int col)
          Set Value in data and update MField.
 void setValueAt(Object value, int row, int col, boolean force)
          Set Value in data and update MField.
 void sort(int col, boolean ascending)
          Sort Entries by Column.
 String toString()
          toString
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROPERTY

public static final String PROPERTY
Property of Vetoable Bean support "RowChange"

See Also:
Constant Field Values

SAVE_OK

public static final char SAVE_OK
Save OK - O

See Also:
Constant Field Values

SAVE_ERROR

public static final char SAVE_ERROR
Save Error - E

See Also:
Constant Field Values

SAVE_ACCESS

public static final char SAVE_ACCESS
Save Access Error - A

See Also:
Constant Field Values

SAVE_MANDATORY

public static final char SAVE_MANDATORY
Save Mandatory Error - M

See Also:
Constant Field Values

SAVE_ABORT

public static final char SAVE_ABORT
Save Abort Error - U

See Also:
Constant Field Values
Constructor Detail

GridTable

public GridTable(Ctx ctx,
                 int AD_Table_ID,
                 String TableName,
                 int WindowNo,
                 int TabNo,
                 boolean withAccessControl)
JDBC Based Buffered Table

Parameters:
ctx - Properties
AD_Table_ID - table id
TableName - table name
WindowNo - window no
TabNo - tab no
withAccessControl - if true adds AD_Client/Org restrictions
Method Detail

setTableName

public void setTableName(String newTableName)
Set Table Name

Parameters:
newTableName - table name

getTableName

public String getTableName()
Get Table Name

Returns:
table name

setSelectWhereClause

public boolean setSelectWhereClause(String newWhereClause)
Set Where Clause (w/o the WHERE and w/o History).

Parameters:
newWhereClause - sql where clause
Returns:
true if where clause set

getSelectWhereClause

public String getSelectWhereClause()
Get record set Where Clause (w/o the WHERE and w/o History)

Returns:
where clause

setOrderClause

public void setOrderClause(String newOrderClause)
Set Order Clause (w/o the ORDER BY)

Parameters:
newOrderClause - sql order by clause

getOrderClause

public String getOrderClause()
Get Order Clause (w/o the ORDER BY)

Returns:
order by clause

addField

public void addField(GridField field)
Add Field to Table

Parameters:
field - field

getColumnName

public String getColumnName(int index)
Returns database column name

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel
Parameters:
index - the column being queried
Returns:
column name

findColumn

public int findColumn(String columnName)
Returns a column given its name.

Overrides:
findColumn in class AbstractTableModel
Parameters:
columnName - string containing name of column to be located
Returns:
the column index with columnName, or -1 if not found

getColumnClass

public Class<?> getColumnClass(int index)
Returns Class of database column/field

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel
Parameters:
index - the column being queried
Returns:
the class

setParameterSELECT

public void setParameterSELECT(int index,
                               Object parameter)
Set Select Clause Parameter. Assumes that you set parameters starting from index zero

Parameters:
index - index
parameter - parameter

setParameterWHERE

public void setParameterWHERE(int index,
                              Object parameter)
Set Where Clause Parameter. Assumes that you set parameters starting from index zero

Parameters:
index - index
parameter - parameter

getField

protected GridField getField(int index)
Get Column at index

Parameters:
index - index
Returns:
MField

getField

protected GridField getField(String identifier)
Return Columns with Indentifier (ColumnName)

Parameters:
identifier - column name
Returns:
MField

getFields

public GridField[] getFields()
Get all Fields

Returns:
MFields

open

public boolean open(int maxRows)
Open Database. if already opened, data is refreshed

Parameters:
maxRows - maximum number of rows or 0 for all
Returns:
true if success

loadComplete

public void loadComplete()
Wait until async loader of Table and Lookup Fields is complete Used for performance tests


isLoading

public boolean isLoading()
Is Loading

Returns:
true if loading

isOpen

public boolean isOpen()
Is it open?

Returns:
true if opened

close

public void close(boolean finalCall)
Close Resultset

Parameters:
finalCall - final call

getColumnCount

public int getColumnCount()
Get total database column count (displayed and not displayed)

Specified by:
getColumnCount in interface TableModel
Returns:
column count

getFieldCount

public int getFieldCount()
Get (displayed) field count

Returns:
field count

getRowCount

public int getRowCount()
Return number of rows

Specified by:
getRowCount in interface TableModel
Returns:
Number of rows or 0 if not opened

setColorColumn

public void setColorColumn(String columnName)
Set the Column to determine the color of the row

Parameters:
columnName - column name

getColorCode

public int getColorCode(int row)
Get ColorCode for Row.
        If numerical value in compare column is
                negative = -1,
      positive = 1,
      otherwise = 0
  

Parameters:
row - row
Returns:
color code
See Also:
setColorColumn(java.lang.String)

sort

public void sort(int col,
                 boolean ascending)
Sort Entries by Column. actually the rows are not sorted, just the access pointer ArrayList with the same size as m_buffer with MSort entities

Parameters:
col - col
ascending - ascending

getKeyID

public int getKeyID(int row)
Get Key ID or -1 of none

Parameters:
row - row
Returns:
ID or -1

getKeyColumnName

public String getKeyColumnName()
Get Key ColumnName

Returns:
key column name

getValueAt

public Object getValueAt(int row,
                         int col)
Get Value in Resultset

Specified by:
getValueAt in interface TableModel
Parameters:
row - row
col - col
Returns:
Object of that row/column

setChanged

public void setChanged(boolean changed)
Indicate that there will be a change

Parameters:
changed - changed

setValueAt

public final void setValueAt(Object value,
                             int row,
                             int col)
Set Value in data and update MField. (called directly or from JTable.editingStopped())

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel
Parameters:
value - value to assign to cell
row - row index of cell
col - column index of cell

setValueAt

public final void setValueAt(Object value,
                             int row,
                             int col,
                             boolean force)
Set Value in data and update MField. (called directly or from JTable.editingStopped())

Parameters:
value - value to assign to cell
row - row index of cell
col - column index of cell
force - force setting new value

getOldValue

public Object getOldValue(int row,
                          int col)
Get Old Value

Parameters:
row - row
col - col
Returns:
old value

needSave

public boolean needSave(boolean onlyRealChange)
Check if the current row needs to be saved.

Parameters:
onlyRealChange - if true the value of a field was actually changed (e.g. for new records, which have not been changed) - default false
Returns:
true it needs to be saved

needSave

public boolean needSave()
Check if the row needs to be saved. - only if nothing was changed

Returns:
true it needs to be saved

needSave

public boolean needSave(int newRow)
Check if the row needs to be saved. - only when row changed - only if nothing was changed

Parameters:
newRow - to check
Returns:
true it needs to be saved

needSave

public boolean needSave(int newRow,
                        boolean onlyRealChange)
Check if the row needs to be saved. - only when row changed - only if nothing was changed

Parameters:
newRow - to check
onlyRealChange - if true the value of a field was actually changed (e.g. for new records, which have not been changed) - default false
Returns:
true it needs to be saved

dataSave

public boolean dataSave(int newRow,
                        boolean manualCmd)
Check if it needs to be saved and save it.

Parameters:
newRow - row
manualCmd - manual command to save
Returns:
true if not needed to be saved or successful saved

dataSave

public char dataSave(boolean manualCmd)
Save unconditional.

Parameters:
manualCmd - if true, no vetoable PropertyChange will be fired for save confirmation
Returns:
OK Or Error condition Error info (Access*, FillMandatory, SaveErrorNotUnique, SaveErrorRowNotFound, SaveErrorDataChanged) is saved in the log

dataNew

public boolean dataNew(int currentRow,
                       boolean copyCurrent)
New Record after current Row

Parameters:
currentRow - row
copyCurrent - copy
Returns:
true if success - Error info (Access*, AccessCannotInsert) is saved in the log

dataDelete

public boolean dataDelete(int row)
Delete Data

Parameters:
row - row
Returns:
true if success - Error info (Access*, AccessNotDeleteable, DeleteErrorDependent, DeleteError) is saved in the log

dataIgnore

public void dataIgnore()
Ignore changes


dataRefresh

public void dataRefresh(int row)
Refresh Row - ignore changes

Parameters:
row - row

dataRefreshAll

public void dataRefreshAll()
Refresh all Rows - ignore changes


dataRequery

public boolean dataRequery(String whereClause)
Requery with new whereClause

Parameters:
whereClause - sql where clause
onlyCurrentRows - only current rows
onlyCurrentDays - how many days back
Returns:
true if success

isCellEditable

public boolean isCellEditable(int row,
                              int col)
Is Cell Editable. Is queried from JTable before checking VCellEditor.isCellEditable

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel
Parameters:
row - the row index being queried
col - the column index being queried
Returns:
true, if editable

isRowEditable

public boolean isRowEditable(int row)
Is Current Row Editable

Parameters:
row - row
Returns:
true if editable

setReadOnly

public void setReadOnly(boolean value)
Set entire table as read only

Parameters:
value - new read only value

isReadOnly

public boolean isReadOnly()
Is entire Table Read/Only

Returns:
true if read only

isInserting

public boolean isInserting()
Is inserting

Returns:
true if inserting

setCompareDB

public void setCompareDB(boolean compareDB)
Set Compare DB. If Set to false, save overwrites the record, regardless of DB changes. (When a payment is changed in Sales Order, the payment reversal clears the payment id)

Parameters:
compareDB - compare DB - false forces overwrite

getCompareDB

public boolean getCompareDB()
Get Compare DB.

Returns:
false if save overwrites the record, regardless of DB changes (false forces overwrite).

setDeleteable

public void setDeleteable(boolean value)
Can Table rows be deleted

Parameters:
value - new deleteable value

removeDataStatusListener

public void removeDataStatusListener(DataStatusListener l)
Remove Data Status Listener

Parameters:
l - listener

addDataStatusListener

public void addDataStatusListener(DataStatusListener l)
Add Data Status Listener

Parameters:
l - listener

fireDataStatusIEvent

protected void fireDataStatusIEvent(String AD_Message,
                                    String info)
Create and fire Data Status Info Event

Parameters:
AD_Message - message
info - additional info

fireDataStatusEEvent

protected void fireDataStatusEEvent(String AD_Message,
                                    String info,
                                    boolean isError)
Create and fire Data Status Error Event

Parameters:
AD_Message - message
info - info
isError - error

fireDataStatusEEvent

protected void fireDataStatusEEvent(ValueNamePair errorLog)
Create and fire Data Status Event (from Error Log)

Parameters:
errorLog - error log info

removeVetoableChangeListener

public void removeVetoableChangeListener(VetoableChangeListener l)
Remove Vetoable change listener for row changes

Parameters:
l - listener

addVetoableChangeListener

public void addVetoableChangeListener(VetoableChangeListener l)
Add Vetoable change listener for row changes

Parameters:
l - listener

fireVetoableChange

protected void fireVetoableChange(PropertyChangeEvent e)
                           throws PropertyVetoException
Fire Vetoable change listener for row changes

Parameters:
e - event
Throws:
PropertyVetoException

toString

public String toString()
toString

Overrides:
toString in class Object
Returns:
String representation

Compiere 3.1

Compiere® is a registered trademark of ComPiere, Inc. ©2004-2008 HumanFlash.com All rights reserved.