diff --git a/base/src/org/compiere/model/GridTab.java b/base/src/org/compiere/model/GridTab.java index d625ecd5d1..7e4b054177 100644 --- a/base/src/org/compiere/model/GridTab.java +++ b/base/src/org/compiere/model/GridTab.java @@ -900,10 +900,18 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable if (isDetail() && m_parentNeedSave) return false; - boolean retValue = m_mTable.dataNew (m_currentRow, copy); + /** + * temporary set currentrow to point to the new row to ensure even cause by m_mTable.dataNew + * is handle properly. + */ + int oldCurrentRow = m_currentRow; + m_currentRow = m_currentRow + 1; + boolean retValue = m_mTable.dataNew (oldCurrentRow, copy); + m_currentRow = oldCurrentRow; if (!retValue) return retValue; setCurrentRow(m_currentRow + 1, true); + // process all Callouts (no dependency check - assumed that settings are valid) for (int i = 0; i < getFieldCount(); i++) processCallout(getField(i)); @@ -2668,6 +2676,6 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable m_mTable.sort(lineCol, true); } navigate(to); - } + } } // MTab diff --git a/base/src/org/compiere/model/GridTable.java b/base/src/org/compiere/model/GridTable.java index 71dfbd2403..27e1a8d696 100644 --- a/base/src/org/compiere/model/GridTable.java +++ b/base/src/org/compiere/model/GridTable.java @@ -2115,10 +2115,27 @@ public class GridTable extends AbstractTableModel m_inserting = true; - // Create default data + + // Setup the buffer first so that event will be handle properly + // Create default data int size = m_fields.size(); m_rowData = new Object[size]; // "original" data Object[] rowData = new Object[size]; + + m_changed = true; + m_compareDB = true; + m_newRow = currentRow + 1; + // if there is no record, the current row could be 0 (and not -1) + if (m_buffer.size() < m_newRow) + m_newRow = m_buffer.size(); + + // add Data at end of buffer + MSort newSort = new MSort(m_buffer.size(), null); // index + m_buffer.add(rowData); + // add Sort pointer + m_sort.add(m_newRow, newSort); + m_rowCount++; + // fill data if (copyCurrent) { @@ -2164,20 +2181,8 @@ public class GridTable extends AbstractTableModel field.setValue(rowData[i], m_inserting); } } - m_changed = true; - m_compareDB = true; + m_rowChanged = -1; // only changed in setValueAt - m_newRow = currentRow + 1; - // if there is no record, the current row could be 0 (and not -1) - if (m_buffer.size() < m_newRow) - m_newRow = m_buffer.size(); - - // add Data at end of buffer - MSort sort = new MSort(m_buffer.size(), null); // index - m_buffer.add(rowData); - // add Sort pointer - m_sort.add(m_newRow, sort); - m_rowCount++; // inform log.fine("Current=" + currentRow + ", New=" + m_newRow);