Class 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, 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:
    Serialized Form
    • Constructor Detail

      • 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 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,
                                            boolean onlyCurrentRows,
                                            int onlyCurrentDays)
        Set Where Clause (w/o the WHERE 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 record set Where Clause (w/o the WHERE 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)
        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
      • 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
      • 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 Column at index
        Parameters:
        index - index
        Returns:
        GridField
      • getField

        protected GridField getField​(String identifier)
        Return Columns with Identifier (ColumnName)
        Parameters:
        identifier - column name
        Returns:
        GridField
      • getFields

        public GridField[] getFields()
        Get all Fields
        Returns:
        GridFields
      • 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
      • getUUID

        public UUID getUUID​(int row)
        Get UUID or null of none
        Parameters:
        row - row
        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 in Resultset
        Specified by:
        getValueAt in interface TableModel
        Parameters:
        row - row
        col - col
        Returns:
        Object of that row/column
      • waitLoadingForRow

        public void waitLoadingForRow​(int 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 in data and update GridField. (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)
        call setValueAt(Object, int, int, boolean, boolean) with isInitEdit = false (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
      • setValueAt

        public final void setValueAt​(Object value,
                                     int row,
                                     int col,
                                     boolean force,
                                     boolean isInitEdit)
        Set Value in data and update GridField. (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
        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 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
      • 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 -
      • dataRequery

        public boolean dataRequery​(String whereClause,
                                   boolean onlyCurrentRows,
                                   int onlyCurrentDays,
                                   boolean fireEvents)
        Requery 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)
      • 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
      • toString

        public String toString()
        toString
        Overrides:
        toString in class Object
        Returns:
        String representation
      • getNewRow

        public int getNewRow()
      • setFieldVFormat

        protected void setFieldVFormat​(String identifier,
                                       String strNewFormat)
        Feature Request [1707462] Enable runtime change of VFormat
        Parameters:
        identifier - field ident
        strNewFormat - new mask author fer_luck
      • hasChanged

        public boolean hasChanged​(int row)
      • getTabNo

        public int getTabNo()
        get Tab No
        Returns:
        Tab No
      • getPO

        public PO getPO​(int row)
      • setImportingMode

        public void setImportingMode​(boolean importing,
                                     String trxName)
      • isImporting

        public boolean isImporting()
      • get_TrxName

        public String get_TrxName()
      • resetCacheSortState

        public void resetCacheSortState()
        reset the cache sort state ( sort column and sort ascending )
      • getKeyColumnIndex

        public int getKeyColumnIndex()
      • getRowChanged

        public int getRowChanged()
        Index of updated row's
      • 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 -