Package org.compiere.model
Class GridTable
java.lang.Object
javax.swing.table.AbstractTableModel
org.compiere.model.GridTable
- All Implemented Interfaces:
Serializable
,TableModel
Grid Table Model for JDBC table 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, Teo Sarca, SC ARHIPAC SERVICE SRL
- BF [ 1901192 ] LogMigrationScripts: GridTable.dataSave: manual update
- BF [ 1943682 ] Copy Record should not copy IsApproved and IsGenerated
- BF [ 1949543 ] Window freeze if there is a severe exception
- BF [ 1984310 ] GridTable.getClientOrg() doesn't work for AD_Client/AD_Org, victor.perez@e-evolution.com,www.e-evolution.com
- BF [ 2910358 ] Error in context when a field is found in different tabs. https://sourceforge.net/p/adempiere/bugs/2255/
- BF [ 2910368 ] Error in context when IsActive field is found in different https://sourceforge.net/p/adempiere/bugs/2256/
- See Also:
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final int
static final int
static final String
static final String
Property of Vetoable Bean support "RowChange"static final char
Save Abort Error - Ustatic final char
Save Access Error - Astatic final char
Save Error - Estatic final char
Save Mandatory Error - Mstatic final char
Save OK - Oprotected static final String
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
-
Constructor Summary
ConstructorDescriptionGridTable
(Properties ctx, int AD_Table_ID, String TableName, int WindowNo, int TabNo, boolean withAccessControl) JDBC Based Buffered TableGridTable
(Properties ctx, int AD_Table_ID, String TableName, int WindowNo, int TabNo, boolean withAccessControl, boolean virtual) JDBC Based Buffered Table -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add Data Status Listenervoid
Add Field to Tablevoid
Add Vetoable change listener for row changesvoid
close
(boolean finalCall) Close Resultsetboolean
dataDelete
(int row) Delete data at row indexvoid
Ignore/Undo changesboolean
dataNew
(int currentRow, boolean copyCurrent) Append new row after current rowvoid
dataRefresh
(int row) Refresh Row - ignore changesvoid
dataRefresh
(int row, boolean fireStatusEvent) Refresh Row - ignore changesvoid
Refresh all Rows - ignore changesvoid
dataRefreshAll
(boolean fireStatusEvent) Refresh all Rows - ignore changesvoid
dataRefreshAll
(boolean fireStatusEvent, int rowToRetained) Refresh all Rows - ignore changesboolean
dataRequery
(String whereClause, boolean onlyCurrentRows, int onlyCurrentDays) Delegate todataRequery(String, boolean, int, boolean)
with fireEvents=trueboolean
dataRequery
(String whereClause, boolean onlyCurrentRows, int onlyCurrentDays, boolean fireEvents) Re-query with new whereClausechar
dataSave
(boolean manualCmd) Save changes.boolean
dataSave
(int newRow, boolean manualCmd) Check if it needs to be saved and save it.int
findColumn
(String columnName) Find column index via column name.protected void
fireDataStatusEEvent
(String AD_Message, String info, boolean isError) Create and fire Data Status Error Eventprotected void
fireDataStatusEEvent
(ValueNamePair errorLog) Create and fire Data Status Error Event (from Error Log)protected void
fireDataStatusIEvent
(String AD_Message, String info) Create and fire Data Status Info Eventprotected void
Fire Vetoable change listener for row changesint
getColorCode
(int row) Get ColorCode for Row.Class<?>
getColumnClass
(int index) Returns Class of database column/fieldint
Get column countgetColumnName
(int index) Returns database column nameboolean
Deprecated.getField
(int index) Get GridField at indexprotected GridField
Get GridField with ColumnNameint
Get field countGet all Fieldsint
Get Key ColumnNameint
getKeyID
(int row) Get Key ID or -1 of nonegetKeyUUID
(int row) Get Key UUID or null of noneint
getOldValue
(int row, int col) Get Old ValueGet Order By Clause (w/o the ORDER BY keyword)getPO
(int row) Load PO for rowint
Index of change rowint
Return number of rowsGet Where Clause (w/o the WHERE keyword and w/o History)Get Table Nameint
getTabNo()
get Tab NogetUUID
(int row) Get UUID or null of nonegetValueAt
(int row, int col) Get Value at row and columngetWhereClause
(int row) get where clause for rowboolean
hasChanged
(int row) Verify if the record at row has been changed at DB (by other user or process)boolean
isCellEditable
(int row, int col) Is Cell Editable.boolean
boolean
Is insertingboolean
Is Loadingboolean
boolean
Is History displayedboolean
isOpen()
Is it open?boolean
Is entire Table Read/Onlyboolean
isRowEditable
(int row) Is row editablevoid
Wait until asynchronous loading of Table and Lookup Fields is complete.boolean
needSave()
Check ifm_rowChanged
needs to be saved.boolean
needSave
(boolean onlyRealChange) Check ifm_rowChanged
needs to be saved.boolean
needSave
(int newRow) Check if newRow needs to be saved.boolean
needSave
(int newRow, boolean onlyRealChange) Check if the row needs to be savedboolean
open
(int maxRows) Open connection to db and load data from table.void
Remove Data Status Listenervoid
Remove Vetoable change listener for row changesvoid
reset()
reset to emptyvoid
reset the cache sort state ( sort column and sort ascending )void
setChanged
(boolean changed) Indicate that there will be a changevoid
setColorColumn
(String columnName) Set the Column to determine the color of the rowvoid
setCompareDB
(boolean compareDB) Deprecated.protected void
setCurrentRow
(int m_currentRow) set current row of gridtable container (gridtab). use in sort to create dse event with new current row (after sort) datavoid
setDeleteable
(boolean value) Can Table rows be deletedprotected void
setFieldVFormat
(String identifier, String strNewFormat) Feature Request [1707462] Enable runtime change of VFormatvoid
setImportingMode
(boolean importing, String trxName) void
setOrderClause
(String newOrderClause) Set Order Clause (w/o the ORDER BY keyword)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 onlyboolean
setSelectWhereClause
(String newWhereClause, boolean onlyCurrentRows, int onlyCurrentDays) Set Where Clause (w/o the WHERE keyword and w/o History).void
setTableName
(String newTableName) Set Table Namefinal void
setValueAt
(Object value, int row, int col) Set value at row and columnfinal void
setValueAt
(Object value, int row, int col, boolean force) callsetValueAt(Object, int, int, boolean, boolean)
with isInitEdit = falsefinal void
setValueAt
(Object value, int row, int col, boolean force, boolean isInitEdit) Set value in row data and update GridField.void
sort
(int col, boolean ascending) Sort records by Column.toString()
toStringvoid
waitLoading
(long timeout) wait for the loading of datavoid
waitLoadingForRow
(int row) wait for loading of rowMethods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
Field Details
-
SORTED_DSE_EVENT
- See Also:
-
DEFAULT_GRIDTABLE_LOAD_TIMEOUT_IN_SECONDS
public static final int DEFAULT_GRIDTABLE_LOAD_TIMEOUT_IN_SECONDS- See Also:
-
DEFAULT_GRIDTABLE_COUNT_TIMEOUT_IN_SECONDS
public static final int DEFAULT_GRIDTABLE_COUNT_TIMEOUT_IN_SECONDS- See Also:
-
LOAD_TIMEOUT_ERROR_MESSAGE
- See Also:
-
DATA_REFRESH_MESSAGE
- See Also:
-
DATA_UPDATE_COPIED_MESSAGE
- See Also:
-
DATA_INSERTED_MESSAGE
- See Also:
-
DATA_IGNORED_MESSAGE
- See Also:
-
DATA_SAVED_MESSAGE
- See Also:
-
CTX_KeyColumnName
- See Also:
-
PROPERTY
Property of Vetoable Bean support "RowChange"- See Also:
-
SAVE_OK
public static final char SAVE_OKSave OK - O- See Also:
-
SAVE_ERROR
public static final char SAVE_ERRORSave Error - E- See Also:
-
SAVE_ACCESS
public static final char SAVE_ACCESSSave Access Error - A- See Also:
-
SAVE_MANDATORY
public static final char SAVE_MANDATORYSave Mandatory Error - M- See Also:
-
SAVE_ABORT
public static final char SAVE_ABORTSave Abort Error - U- See Also:
-
-
Constructor Details
-
GridTable
public GridTable(Properties ctx, int AD_Table_ID, String TableName, int WindowNo, int TabNo, boolean withAccessControl) JDBC Based Buffered Table- Parameters:
ctx
- PropertiesAD_Table_ID
- table idTableName
- table nameWindowNo
- window noTabNo
- tab nowithAccessControl
- if true adds AD_Client/Org restrictions
-
GridTable
public GridTable(Properties ctx, int AD_Table_ID, String TableName, int WindowNo, int TabNo, boolean withAccessControl, boolean virtual) JDBC Based Buffered Table- Parameters:
ctx
- PropertiesAD_Table_ID
- table idTableName
- table nameWindowNo
- window noTabNo
- tab nowithAccessControl
- if true adds AD_Client/Org restrictuinsvirtual
- use virtual table mode if table is mark as high volume
-
-
Method Details
-
setTableName
Set Table Name- Parameters:
newTableName
- table name
-
getTableName
Get Table Name- Returns:
- table name
-
setSelectWhereClause
public boolean setSelectWhereClause(String newWhereClause, boolean onlyCurrentRows, int onlyCurrentDays) Set Where Clause (w/o the WHERE keyword and w/o History).- Parameters:
newWhereClause
- sql where clauseonlyCurrentRows
- only current rowsonlyCurrentDays
- how many days back for current- Returns:
- true if where clase set
-
getSelectWhereClause
Get Where Clause (w/o the WHERE keyword and w/o History)- Returns:
- where clause
-
isOnlyCurrentRowsDisplayed
public boolean isOnlyCurrentRowsDisplayed()Is History displayed- Returns:
- true if history displayed
-
setOrderClause
Set Order Clause (w/o the ORDER BY keyword)- Parameters:
newOrderClause
- sql order by clause
-
getOrderClause
Get Order By Clause (w/o the ORDER BY keyword)- Returns:
- order by clause
-
addField
Add Field to Table- Parameters:
field
- field
-
getColumnName
Returns database column name- Specified by:
getColumnName
in interfaceTableModel
- Overrides:
getColumnName
in classAbstractTableModel
- Parameters:
index
- column index- Returns:
- column name or empty string (if index is invalid)
-
findColumn
Find column index via column name.- Overrides:
findColumn
in classAbstractTableModel
- Parameters:
columnName
- string containing name of column to be located- Returns:
- the column index with
columnName
, or -1 if not found
-
getColumnClass
Returns Class of database column/field- Specified by:
getColumnClass
in interfaceTableModel
- Overrides:
getColumnClass
in classAbstractTableModel
- Parameters:
index
- column index- Returns:
- Java class for column
-
setParameterSELECT
Set Select Clause Parameter. Assumes that you set parameters starting from index zero- Parameters:
index
- indexparameter
- parameter
-
setParameterWHERE
Set Where Clause Parameter. Assumes that you set parameters starting from index zero- Parameters:
index
- indexparameter
- parameter
-
getField
Get GridField at index- Parameters:
index
- index- Returns:
- GridField
-
getField
Get GridField with ColumnName- Parameters:
identifier
- column name- Returns:
- GridField or null
-
getFields
Get all Fields- Returns:
- GridField[]
-
open
public boolean open(int maxRows) Open connection to db and load data from table. If already opened, data is refreshed.
Loading of data is perform asynchronously in background thread.- Parameters:
maxRows
- maximum number of rows or 0 for all- Returns:
- true if success
-
loadComplete
public void loadComplete()Wait until asynchronous loading of Table and Lookup Fields is complete. -
isLoading
public boolean isLoading()Is Loading- Returns:
- true if loading is in progress
-
waitLoading
public void waitLoading(long timeout) throws InterruptedException, ExecutionException, TimeoutException wait for the loading of data- Parameters:
timeout
- timeout in milisecond. pass 0 or negative value for infinite wait- Throws:
InterruptedException
ExecutionException
TimeoutException
-
isOpen
public boolean isOpen()Is it open?- Returns:
- true if opened
-
close
public void close(boolean finalCall) Close Resultset- Parameters:
finalCall
- true for final call and perform clean up
-
getColumnCount
public int getColumnCount()Get column count- Specified by:
getColumnCount
in interfaceTableModel
- Returns:
- column count
-
getFieldCount
public int getFieldCount()Get field count- Returns:
- field count
-
getRowCount
public int getRowCount()Return number of rows- Specified by:
getRowCount
in interfaceTableModel
- Returns:
- Number of rows or 0 if not opened
-
setColorColumn
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:
-
sort
public void sort(int col, boolean ascending) Sort records by Column.Actually the rows are not sorted, just the access pointer ArrayList with the same size as m_buffer (
m_sort
).- Parameters:
col
- colascending
- ascending
-
getKeyID
public int getKeyID(int row) Get Key ID or -1 of none- Parameters:
row
- row index- Returns:
- ID or -1
-
getKeyUUID
Get Key UUID or null of none- Parameters:
row
- row index- Returns:
- UUID or null
-
getUUID
Get UUID or null of none- Parameters:
row
- row index- Returns:
- UUID or null
-
getKeyColumnName
Get Key ColumnName- Returns:
- key column name
-
getValueAt
Get Value at row and column- Specified by:
getValueAt
in interfaceTableModel
- Parameters:
row
- rowcol
- col- Returns:
- Value at row/column
-
waitLoadingForRow
public void waitLoadingForRow(int row) wait for loading of row- Parameters:
row
-
-
setChanged
public void setChanged(boolean changed) Indicate that there will be a change- Parameters:
changed
- changed
-
setValueAt
Set value at row and column- Specified by:
setValueAt
in interfaceTableModel
- Overrides:
setValueAt
in classAbstractTableModel
- Parameters:
value
- value to assign to cellrow
- row index of cellcol
- column index of cell
-
setValueAt
callsetValueAt(Object, int, int, boolean, boolean)
with isInitEdit = false- Parameters:
value
- value to assign to cellrow
- row index of cellcol
- column index of cellforce
- force setting new value
-
setValueAt
Set value in row data and update GridField.- Parameters:
value
- value to assign to cellrow
- row index of cellcol
- column index of cellforce
- force setting new valueisInitEdit
- indicate event rise by start edit a field. just want change status to edit, don't change anything else
-
getOldValue
Get Old Value- Parameters:
row
- rowcol
- col- Returns:
- old value
-
needSave
public boolean needSave(boolean onlyRealChange) Check ifm_rowChanged
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 if needs to be saved
-
needSave
public boolean needSave()Check ifm_rowChanged
needs to be saved.- Returns:
- true if needs to be saved
-
needSave
public boolean needSave(int newRow) Check if newRow needs to be saved.- Parameters:
newRow
- to check- Returns:
- true if 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 checkonlyRealChange
- if true, only if the value of a field was actually changed (e.g. for new record with default value, 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 indexmanualCmd
- true if initiated from user action- Returns:
- true if not needed to be saved or successful saved
-
dataSave
public char dataSave(boolean manualCmd) Save changes.- Parameters:
manualCmd
- if true (i.e initiated from user action), 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
-
isNeedSaveAndMandatoryFill
public boolean isNeedSaveAndMandatoryFill()- Returns:
- true if need save and all mandatory field has value
-
dataNew
public boolean dataNew(int currentRow, boolean copyCurrent) Append new row after current row- Parameters:
currentRow
- rowcopyCurrent
- true to copy value from current row- Returns:
- true if success - Error info (Access*, AccessCannotInsert) is saved in the log
-
dataDelete
public boolean dataDelete(int row) Delete data at row index- Parameters:
row
- row index- Returns:
- true if success - Error info (Access*, AccessNotDeleteable, DeleteErrorDependent, DeleteError) is saved in the log
-
dataIgnore
public void dataIgnore()Ignore/Undo changes -
dataRefresh
public void dataRefresh(int row) Refresh Row - ignore changes- Parameters:
row
- row
-
getWhereClause
get where clause for row- Parameters:
row
-- Returns:
- where clause
-
dataRefresh
public void dataRefresh(int row, boolean fireStatusEvent) Refresh Row - ignore changes- Parameters:
row
- rowfireStatusEvent
-
-
dataRefreshAll
public void dataRefreshAll()Refresh all Rows - ignore changes -
dataRefreshAll
public void dataRefreshAll(boolean fireStatusEvent) Refresh all Rows - ignore changes- Parameters:
fireStatusEvent
-
-
dataRefreshAll
public void dataRefreshAll(boolean fireStatusEvent, int rowToRetained) Refresh all Rows - ignore changes- Parameters:
fireStatusEvent
-rowToRetained
-
-
dataRequery
public boolean dataRequery(String whereClause, boolean onlyCurrentRows, int onlyCurrentDays, boolean fireEvents) Re-query with new whereClause- Parameters:
whereClause
- sql where clauseonlyCurrentRows
- only current rowsonlyCurrentDays
- how many days backfireEvents
- if tabledatachanged and datastatusievent must be fired- Returns:
- true if success
-
dataRequery
Delegate todataRequery(String, boolean, int, boolean)
with fireEvents=true- Parameters:
whereClause
-onlyCurrentRows
-onlyCurrentDays
-- Returns:
- true if success
-
isCellEditable
public boolean isCellEditable(int row, int col) Is Cell Editable.- Specified by:
isCellEditable
in interfaceTableModel
- Overrides:
isCellEditable
in classAbstractTableModel
- Parameters:
row
- row indexcol
- column index- Returns:
- true, if editable
-
isRowEditable
public boolean isRowEditable(int row) Is row editable- Parameters:
row
- row index- 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
Deprecated.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
Deprecated.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
Remove Data Status Listener- Parameters:
l
- listener
-
addDataStatusListener
Add Data Status Listener- Parameters:
l
- listener
-
fireDataStatusIEvent
Create and fire Data Status Info Event- Parameters:
AD_Message
- messageinfo
- additional info
-
fireDataStatusEEvent
Create and fire Data Status Error Event- Parameters:
AD_Message
- messageinfo
- infoisError
- error
-
fireDataStatusEEvent
Create and fire Data Status Error Event (from Error Log)- Parameters:
errorLog
- error log info
-
removeVetoableChangeListener
Remove Vetoable change listener for row changes- Parameters:
l
- listener
-
addVetoableChangeListener
Add Vetoable change listener for row changes- Parameters:
l
- listener
-
fireVetoableChange
Fire Vetoable change listener for row changes- Parameters:
e
- event- Throws:
PropertyVetoException
-
toString
toString -
getNewRow
public int getNewRow()- Returns:
- new row added
-
setFieldVFormat
Feature Request [1707462] Enable runtime change of VFormat- Parameters:
identifier
- column namestrNewFormat
- new input mask author fer_luck
-
hasChanged
public boolean hasChanged(int row) Verify if the record at row has been changed at DB (by other user or process)- Parameters:
row
- row index- Returns:
- true if record at row has been changed at DB
-
getTabNo
public int getTabNo()get Tab No- Returns:
- Tab No
-
getPO
Load PO for row- Parameters:
row
- row index- Returns:
- PO
-
setImportingMode
- Parameters:
importing
- import modetrxName
- optional trx name
-
isImporting
public boolean isImporting()- Returns:
- true if it is in import mode
-
get_TrxName
- Returns:
- trx name
-
resetCacheSortState
public void resetCacheSortState()reset the cache sort state ( sort column and sort ascending ) -
getKeyColumnIndex
public int getKeyColumnIndex()- Returns:
- index of primary key column
-
getRowChanged
public int getRowChanged()Index of change row -
reset
public void reset()reset to empty -
setCurrentRow
protected void setCurrentRow(int m_currentRow) set current row of gridtable container (gridtab). use in sort to create dse event with new current row (after sort) data- Parameters:
m_currentRow
-
-