Class GridTable

All Implemented Interfaces:
Serializable, TableModel

public class GridTable extends AbstractTableModel implements Serializable
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:
    • Field Details

    • 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 - Properties
        AD_Table_ID - table id
        TableName - table name
        WindowNo - window no
        TabNo - tab no
        withAccessControl - 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 - Properties
        AD_Table_ID - table id
        TableName - table name
        WindowNo - window no
        TabNo - tab no
        withAccessControl - if true adds AD_Client/Org restrictuins
        virtual - use virtual table mode if table is mark as high volume
    • Method Details

      • 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, boolean onlyCurrentRows, int onlyCurrentDays)
        Set Where Clause (w/o the WHERE keyword and w/o History).
        Parameters:
        newWhereClause - sql where clause
        onlyCurrentRows - only current rows
        onlyCurrentDays - how many days back for current
        Returns:
        true if where clase set
      • getSelectWhereClause

        public String 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

        public void setOrderClause(String newOrderClause)
        Set Order Clause (w/o the ORDER BY keyword)
        Parameters:
        newOrderClause - sql order by clause
      • getOrderClause

        public String getOrderClause()
        Get Order By Clause (w/o the ORDER BY keyword)
        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 - column index
        Returns:
        column name or empty string (if index is invalid)
      • findColumn

        public int findColumn(String columnName)
        Find column index via column 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 - column index
        Returns:
        Java class for column
      • 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

        public GridField getField(int index)
        Get GridField at index
        Parameters:
        index - index
        Returns:
        GridField
      • getField

        protected GridField getField(String identifier)
        Get GridField with ColumnName
        Parameters:
        identifier - column name
        Returns:
        GridField
      • getFields

        public GridField[] 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 interface TableModel
        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 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:
      • 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 - col
        ascending - ascending
      • getKeyID

        public int getKeyID(int row)
        Get Key ID or -1 of none
        Parameters:
        row - row index
        Returns:
        ID or -1
      • getKeyUUID

        public String getKeyUUID(int row)
        Get Key UUID or null of none
        Parameters:
        row - row index
        Returns:
        UUID or null
      • getUUID

        public UUID getUUID(int row)
        Get UUID or null of none
        Parameters:
        row - row index
        Returns:
        UUID or null
      • getKeyColumnName

        public String getKeyColumnName()
        Get Key ColumnName
        Returns:
        key column name
      • getValueAt

        public Object getValueAt(int row, int col)
        Get Value at row and column
        Specified by:
        getValueAt in interface TableModel
        Parameters:
        row - row
        col - 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

        public final void setValueAt(Object value, int row, int col)
        Set value at row and column
        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)
        Parameters:
        value - value to assign to cell
        row - row index of cell
        col - column index of cell
        force - force setting new value
      • setValueAt

        public final void setValueAt(Object value, int row, int col, boolean force, boolean isInitEdit)
        Set value in row data and update GridField.
        Parameters:
        value - value to assign to cell
        row - row index of cell
        col - column index of cell
        force - force setting new value
        isInitEdit - indicate event rise by start edit a field. just want change status to edit, don't change anything else
      • 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 m_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 if m_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 check
        onlyRealChange - 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 index
        manualCmd - 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 - row
        copyCurrent - 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

        public String getWhereClause(int row)
        get where clause for row
        Parameters:
        row -
        Returns:
        where clause
      • dataRefresh

        public void dataRefresh(int row, boolean fireStatusEvent)
        Refresh Row - ignore changes
        Parameters:
        row - row
        fireStatusEvent -
      • 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 clause
        onlyCurrentRows - only current rows
        onlyCurrentDays - how many days back
        fireEvents - if tabledatachanged and datastatusievent must be fired
        Returns:
        true if success
      • dataRequery

        public boolean dataRequery(String whereClause, boolean onlyCurrentRows, int onlyCurrentDays)
        Delegate to dataRequery(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 interface TableModel
        Overrides:
        isCellEditable in class AbstractTableModel
        Parameters:
        row - row index
        col - 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 public void setCompareDB(boolean compareDB)
        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 public boolean 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

        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 Error 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
      • getNewRow

        public int getNewRow()
        Returns:
        new row added
      • setFieldVFormat

        protected void setFieldVFormat(String identifier, String strNewFormat)
        Feature Request [1707462] Enable runtime change of VFormat
        Parameters:
        identifier - column name
        strNewFormat - 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

        public PO getPO(int row)
        Load PO for row
        Parameters:
        row - row index
        Returns:
        PO
      • setImportingMode

        public void setImportingMode(boolean importing, String trxName)
        Parameters:
        importing - import mode
        trxName - optional trx name
      • isImporting

        public boolean isImporting()
        Returns:
        true if it is in import mode
      • get_TrxName

        public String 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 -