public int setupGridOrder ( ) { int iErrorCode = DBConstants . NORMAL_RETURN ; boolean bOrder = DBConstants . ASCENDING ; int iKeyOrder = ( int ) ( ( NumberField ) this . getOwner ( ) ) . getValue ( ) ; if ( iKeyOrder == 0 ) return DBConstants . KEY_NOT_FOUND ; if ( iKeyOrder < 0 ) { bOrder = DBConstants . DESCENDING ; iKeyOrder = - iKeyOrder ; } iKeyOrder -- ; // 0 Based if ( iKeyOrder < m_iNextArrayIndex ) { if ( m_recGrid == null ) m_recGrid = ( Record ) m_gridScreen . getMainRecord ( ) ; for ( int i = 0 ; i < m_recGrid . getKeyAreaCount ( ) ; i ++ ) { if ( m_recGrid . getKeyArea ( i ) . getKeyName ( ) . equals ( m_iKeyAreaArray [ iKeyOrder ] ) ) iKeyOrder = i ; // Get key order from internal array } } else { // They chose a column that was was not specified... Get the desc and try to sort it by the field if ( m_gridScreen != null ) { int iColumn = iKeyOrder + 1 + m_gridScreen . getNavCount ( ) ; // grid column ScreenComponent sField = m_gridScreen . getSField ( iColumn ) ; if ( sField . getConverter ( ) != null ) if ( sField . getConverter ( ) . getField ( ) != null ) { Record record = ( Record ) m_gridScreen . getMainRecord ( ) ; iKeyOrder = - 1 ; // No obvious sort order for ( int iKeyArea = 0 ; iKeyArea < record . getKeyAreaCount ( ) ; iKeyArea ++ ) { KeyArea keyArea = record . getKeyArea ( iKeyArea ) ; if ( keyArea . getField ( 0 ) == sField . getConverter ( ) . getField ( ) ) { // Is this field the first field of this key? iKeyOrder = iKeyArea ; // Yes, use this order break ; } } if ( iKeyOrder == - 1 ) if ( m_bCreateSortOrder ) { // Create a key to sort on BaseField field = ( BaseField ) sField . getConverter ( ) . getField ( ) ; KeyArea keyArea = new KeyArea ( record , DBConstants . NOT_UNIQUE , field . getFieldName ( ) + "tempKey" ) ; new KeyField ( keyArea , field , DBConstants . ASCENDING ) ; iKeyOrder = record . getKeyAreaCount ( ) - 1 ; } } } } if ( iKeyOrder < 0 ) return DBConstants . KEY_NOT_FOUND ; KeyArea keyArea = null ; if ( m_recGrid == null ) m_recGrid = ( Record ) m_gridScreen . getMainRecord ( ) ; keyArea = m_recGrid . setKeyArea ( iKeyOrder ) ; if ( keyArea == null ) iErrorCode = DBConstants . KEY_NOT_FOUND ; else { for ( int i = 0 ; i < keyArea . getKeyFields ( ) ; i ++ ) { KeyField keyField = keyArea . getKeyField ( i ) ; keyField . setKeyOrder ( bOrder ) ; } } return iErrorCode ; }
Set the grid order to the value in this field .