diff --git a/base/src/org/compiere/model/GridTab.java b/base/src/org/compiere/model/GridTab.java index 7e4b054177..5780fc2600 100644 --- a/base/src/org/compiere/model/GridTab.java +++ b/base/src/org/compiere/model/GridTab.java @@ -789,6 +789,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable } } setCurrentRow(m_currentRow, true); + fireStateChangeEvent(new StateChangeEvent(this, StateChangeEvent.DATA_REFRESH_ALL)); } // dataRefreshAll /** @@ -808,6 +809,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable log.fine("#" + m_vo.TabNo + " - row=" + row); m_mTable.dataRefresh(row); setCurrentRow(row, true); + fireStateChangeEvent(new StateChangeEvent(this, StateChangeEvent.DATA_REFRESH)); } // dataRefresh @@ -824,6 +826,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable boolean retValue = (m_mTable.dataSave(manualCmd) == GridTable.SAVE_OK); if (manualCmd) setCurrentRow(m_currentRow, false); + fireStateChangeEvent(new StateChangeEvent(this, StateChangeEvent.DATA_SAVE)); return retValue; } catch (Exception e) @@ -864,6 +867,8 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable log.fine("#" + m_vo.TabNo); m_mTable.dataIgnore(); setCurrentRow(m_currentRow, false); // re-load data + + fireStateChangeEvent(new StateChangeEvent(this, StateChangeEvent.DATA_IGNORE)); log.fine("#" + m_vo.TabNo + "- fini"); } // dataIgnore @@ -922,6 +927,8 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable getField(i).validateValue(); } m_mTable.setChanged(false); + + fireStateChangeEvent(new StateChangeEvent(this, StateChangeEvent.DATA_NEW)); return retValue; } // dataNew @@ -934,6 +941,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable log.fine("#" + m_vo.TabNo + " - row=" + m_currentRow); boolean retValue = m_mTable.dataDelete(m_currentRow); setCurrentRow(m_currentRow, true); + fireStateChangeEvent(new StateChangeEvent(this, StateChangeEvent.DATA_DELETE)); return retValue; } // dataDelete @@ -2590,7 +2598,23 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable { m_listenerList.add(DataStatusListener.class, l); } + + /** + * @param l + */ + public synchronized void addStateChangeListener(StateChangeListener l) + { + m_listenerList.add(StateChangeListener.class, l); + } + /** + * @param l + */ + public synchronized void removeStateChangeListener(StateChangeListener l) + { + m_listenerList.remove(StateChangeListener.class, l); + } + /** * Feature Request [1707462] * Enable runtime change of VFormat @@ -2677,5 +2701,16 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable } navigate(to); } + + private void fireStateChangeEvent(StateChangeEvent e) + { + StateChangeListener[] listeners = m_listenerList.getListeners(StateChangeListener.class); + if (listeners.length == 0) + return; + for(int i = 0; i < listeners.length; i++) { + listeners[i].stateChange(e); + } + + } } // MTab diff --git a/base/src/org/compiere/model/GridTable.java b/base/src/org/compiere/model/GridTable.java index 27e1a8d696..2aa3e6dc14 100644 --- a/base/src/org/compiere/model/GridTable.java +++ b/base/src/org/compiere/model/GridTable.java @@ -502,6 +502,7 @@ public class GridTable extends AbstractTableModel // m_changed = false; m_rowChanged = -1; + m_inserting = false; return true; } // open diff --git a/base/src/org/compiere/model/StateChangeEvent.java b/base/src/org/compiere/model/StateChangeEvent.java new file mode 100644 index 0000000000..c9b07e82c1 --- /dev/null +++ b/base/src/org/compiere/model/StateChangeEvent.java @@ -0,0 +1,26 @@ +package org.compiere.model; + +import java.util.EventObject; + +/** + * + * @author Low Heng Sin + * + */ +public class StateChangeEvent extends EventObject { + + private int eventType; + + public StateChangeEvent(Object source, int eventType) { + super(source); + this.eventType = eventType; + } + + public final static int DATA_REFRESH_ALL = 0; + public final static int DATA_REFRESH = 1; + public final static int DATA_NEW = 2; + public final static int DATA_DELETE = 3; + public final static int DATA_SAVE = 4; + public final static int DATA_IGNORE = 5; + +} diff --git a/base/src/org/compiere/model/StateChangeListener.java b/base/src/org/compiere/model/StateChangeListener.java new file mode 100644 index 0000000000..241774a1e6 --- /dev/null +++ b/base/src/org/compiere/model/StateChangeListener.java @@ -0,0 +1,14 @@ +package org.compiere.model; + +import java.util.EventListener; + +/** + * + * @author Low Heng Sin + * + */ +public interface StateChangeListener extends EventListener { + + public void stateChange(StateChangeEvent event); + +}