IDEMPIERE-144 Performance: Remove the use of zk event thread. Refactoring and fixed commit warning message not shown for navigation event.

This commit is contained in:
Heng Sin Low 2012-08-15 11:28:40 +08:00
parent b75d09aff9
commit 7ddd707502
1 changed files with 137 additions and 150 deletions

View File

@ -750,11 +750,15 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
int curInd = adTab.getSelectedIndex(); int curInd = adTab.getSelectedIndex();
if (curInd < maxInd) if (curInd < maxInd)
{ {
setActiveTab(curInd + 1, null); setActiveTab(curInd + 1, new Callback<Boolean>() {
}
@Override
public void onCallback(Boolean result) {
focusToActivePanel(); focusToActivePanel();
} }
});
}
}
/** /**
* @see ToolbarListener#onParentRecord() * @see ToolbarListener#onParentRecord()
@ -764,47 +768,82 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
int curInd = adTab.getSelectedIndex(); int curInd = adTab.getSelectedIndex();
if (curInd > 0) if (curInd > 0)
{ {
setActiveTab(curInd - 1, null); setActiveTab(curInd - 1, new Callback<Boolean>() {
} @Override
public void onCallback(Boolean result) {
focusToActivePanel(); focusToActivePanel();
} }
});
}
}
/** /**
* @see ToolbarListener#onFirst() * @see ToolbarListener#onFirst()
*/ */
public void onFirst() public void onFirst()
{ {
Callback<Boolean> callback = new Callback<Boolean>() {
@Override
public void onCallback(Boolean result) {
if (result) {
curTab.navigate(0); curTab.navigate(0);
focusToActivePanel(); focusToActivePanel();
} }
}
};
saveAndNavigate(callback);
}
/** /**
* @see ToolbarListener#onLast() * @see ToolbarListener#onLast()
*/ */
public void onLast() public void onLast()
{ {
Callback<Boolean> callback = new Callback<Boolean>() {
@Override
public void onCallback(Boolean result) {
if (result) {
curTab.navigate(curTab.getRowCount() - 1); curTab.navigate(curTab.getRowCount() - 1);
focusToActivePanel(); focusToActivePanel();
} }
}
};
onSave(false, true, callback);
}
/** /**
* @see ToolbarListener#onNext() * @see ToolbarListener#onNext()
*/ */
public void onNext() public void onNext()
{ {
Callback<Boolean> callback = new Callback<Boolean>() {
@Override
public void onCallback(Boolean result) {
if (result) {
curTab.navigateRelative(+1); curTab.navigateRelative(+1);
focusToActivePanel(); focusToActivePanel();
} }
}
};
saveAndNavigate(callback);
}
/** /**
* @see ToolbarListener#onPrevious() * @see ToolbarListener#onPrevious()
*/ */
public void onPrevious() public void onPrevious()
{ {
Callback<Boolean> callback = new Callback<Boolean>() {
@Override
public void onCallback(Boolean result) {
if (result) {
curTab.navigateRelative(-1); curTab.navigateRelative(-1);
focusToActivePanel(); focusToActivePanel();
} }
}
};
saveAndNavigate(callback);
}
// Elaine 2008/12/04 // Elaine 2008/12/04
private Menupopup m_popup = null; private Menupopup m_popup = null;
@ -865,9 +904,10 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
if (gridWindow.isTransaction()) if (gridWindow.isTransaction())
{ {
final Runnable runnable = new Runnable() { Callback<Boolean> callback = new Callback<Boolean>() {
@Override @Override
public void run() { public void onCallback(Boolean result) {
if (result) {
final WOnlyCurrentDays ocd = new WOnlyCurrentDays(); final WOnlyCurrentDays ocd = new WOnlyCurrentDays();
ocd.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener<Event>() { ocd.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener<Event>() {
@Override @Override
@ -879,25 +919,9 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
}); });
AEnv.showWindow(ocd); AEnv.showWindow(ocd);
} }
}
}; };
if (curTab.needSave(true, true)) saveAndNavigate(callback);
{
onSave(false, new Callback<Boolean>() {
@Override
public void onCallback(Boolean result)
{
if (result)
{
runnable.run();
}
}
});
}
else
{
runnable.run();
}
} }
} }
@ -1086,87 +1110,49 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
if (callback != null) if (callback != null)
callback.onCallback(true); callback.onCallback(true);
} }
else
{
Callback<Boolean> command = new Callback<Boolean>() {
@Override
public void onCallback(Boolean result) {
if (result) {
setActiveTab0(oldTabIndex, newTabIndex, callback);
} else if (callback != null) {
callback.onCallback(false);
}
}
};
saveAndNavigate(command);
}
}
protected void saveAndNavigate(final Callback<Boolean> callback) {
if (curTab != null) if (curTab != null)
{ {
if (curTab.isSortTab()) if (curTab.isSortTab())
{ {
if (curTabpanel instanceof ADSortTab) onSave(false, true, callback);
{
((ADSortTab)curTabpanel).saveData();
((ADSortTab)curTabpanel).unregisterPanel();
}
setActiveTab0(oldTabIndex, newTabIndex, callback);
} }
else if (curTab.needSave(true, false)) else if (curTab.needSave(true, false))
{ {
if (curTab.needSave(true, true)) if (curTab.needSave(true, true))
{ {
// Automatic Save onSave(false, true, callback);
if (Env.isAutoCommit(ctx, curWindowNo)
&& (curTab.getCommitWarning() == null || curTab.getCommitWarning().trim().length() == 0))
{
if (!curTab.dataSave(true))
{
showLastError();
// there is a problem, stop here
if (callback != null)
callback.onCallback(false);
return;
}
setActiveTab0(oldTabIndex, newTabIndex, callback);
}
// explicitly ask when changing tabs
else
{
FDialog.ask(curWindowNo, this.getComponent(), "SaveChanges?", curTab.getCommitWarning(), new Callback<Boolean>() {
@Override
public void onCallback(Boolean result) {
if (result)
{ // yes we want to save
if (!curTab.dataSave(true))
{
showLastError();
// there is a problem, stop here
if (callback != null)
callback.onCallback(false);
return;
}
setActiveTab0(oldTabIndex, newTabIndex, callback);
}
else // Don't save
{
int newRecord= curTab.getTableModel().getNewRow(); //VOSS COM
if( newRecord == -1)
curTab.dataIgnore();
else
{
if (callback != null)
callback.onCallback(false);
return;
}
setActiveTab0(oldTabIndex, newTabIndex, callback);
}
}
});
}
} }
else else
{ {
// new record, but nothing changed // new record, but nothing changed
curTab.dataIgnore(); curTab.dataIgnore();
setActiveTab0(oldTabIndex, newTabIndex, callback); callback.onCallback(true);
} }
} // there is a change } // there is a change
else else
setActiveTab0(oldTabIndex, newTabIndex, callback); callback.onCallback(true);
} }
else else
setActiveTab0(oldTabIndex, newTabIndex, callback); callback.onCallback(true);
} }
private void setActiveTab0(int oldTabIndex, int newTabIndex, private void setActiveTab0(int oldTabIndex, int newTabIndex,
@ -1507,7 +1493,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
{ {
if (saveCurrentRow) if (saveCurrentRow)
{ {
onSave(false, new Callback<Boolean>() { onSave(false, true, new Callback<Boolean>() {
@Override @Override
public void onCallback(Boolean result) { public void onCallback(Boolean result) {
@ -1553,7 +1539,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
return; return;
} }
autoSave(new Callback<Boolean>() { saveAndNavigate(new Callback<Boolean>() {
@Override @Override
public void onCallback(Boolean result) { public void onCallback(Boolean result) {
if (result) if (result)
@ -1581,21 +1567,6 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
}); });
} }
private void autoSave(Callback<Boolean> callback) {
// has anything changed?
if (curTab.needSave(true, false))
{ // do we have real change
if (curTab.needSave(true, true))
{
onSave(false, callback);
}
else // new record, but nothing changed
curTab.dataIgnore();
} // there is a change
if (callback != null)
callback.onCallback(true);
}
// Elaine 2008/11/19 // Elaine 2008/11/19
/** /**
* @see ToolbarListener#onCopy() * @see ToolbarListener#onCopy()
@ -1637,7 +1608,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
if (curTab == null) if (curTab == null)
return; return;
onSave(false, new Callback<Boolean>() { onSave(false, false, new Callback<Boolean>() {
@Override @Override
public void onCallback(Boolean result) { public void onCallback(Boolean result) {
@ -1717,7 +1688,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
*/ */
public void onSave() public void onSave()
{ {
onSave(true, new Callback<Boolean>() { onSave(true, false, new Callback<Boolean>() {
@Override @Override
public void onCallback(Boolean result) public void onCallback(Boolean result)
{ {
@ -1735,22 +1706,29 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
/** /**
* @param onSaveEvent * @param onSaveEvent
*/ */
private void onSave(final boolean onSaveEvent, final Callback<Boolean> callback) private void onSave(final boolean onSaveEvent, final boolean onNavigationEvent, final Callback<Boolean> callback)
{ {
final boolean newRecord = (curTab.getRecord_ID() <= 0); final boolean newRecord = (curTab.getRecord_ID() <= 0);
final boolean wasChanged = toolbar.isSaveEnable(); final boolean wasChanged = toolbar.isSaveEnable();
if (curTab.isSortTab()) if (curTab.isSortTab())
{ {
if (onNavigationEvent)
((ADSortTab)curTabpanel).unregisterPanel();
else
((ADSortTab)curTabpanel).saveData(); ((ADSortTab)curTabpanel).saveData();
if (!onNavigationEvent)
{
toolbar.enableSave(false); // set explicitly toolbar.enableSave(false); // set explicitly
toolbar.enableSaveAndCreate(false); toolbar.enableSaveAndCreate(false);
toolbar.enableIgnore(false); toolbar.enableIgnore(false);
}
if (callback != null) if (callback != null)
callback.onCallback(true); callback.onCallback(true);
} }
else else
{ {
if (onSaveEvent && curTab.getCommitWarning() != null && curTab.getCommitWarning().trim().length() > 0) if ((curTab.getCommitWarning() != null && curTab.getCommitWarning().trim().length() > 0) ||
(!Env.isAutoCommit(ctx, curWindowNo) && onNavigationEvent))
{ {
FDialog.ask(curWindowNo, this.getComponent(), "SaveChanges?", curTab.getCommitWarning(), new Callback<Boolean>() { FDialog.ask(curWindowNo, this.getComponent(), "SaveChanges?", curTab.getCommitWarning(), new Callback<Boolean>() {
@ -1759,20 +1737,25 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
{ {
if (result) if (result)
{ {
doSave(onSaveEvent, newRecord, wasChanged, callback); onSave0(onSaveEvent, onNavigationEvent, newRecord, wasChanged, callback);
}
else
{
if (callback != null)
callback.onCallback(false);
} }
} }
}); });
} }
else else
{ {
doSave(onSaveEvent, newRecord, wasChanged, callback); onSave0(onSaveEvent, onNavigationEvent, newRecord, wasChanged, callback);
} }
} }
} }
private void doSave(boolean onSaveEvent, boolean newRecord, private void onSave0(boolean onSaveEvent, boolean navigationEvent,
boolean wasChanged, Callback<Boolean> callback) { boolean newRecord, boolean wasChanged, Callback<Boolean> callback) {
boolean retValue = curTab.dataSave(onSaveEvent); boolean retValue = curTab.dataSave(onSaveEvent);
if (!retValue) if (!retValue)
@ -1780,12 +1763,15 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
showLastError(); showLastError();
if (callback != null) if (callback != null)
callback.onCallback(false); callback.onCallback(false);
} else if (!onSaveEvent) //need manual refresh } else if (!onSaveEvent && !navigationEvent) //need manual refresh
{ {
curTab.setCurrentRow(curTab.getCurrentRow()); curTab.setCurrentRow(curTab.getCurrentRow());
} }
if (!navigationEvent) {
curTabpanel.dynamicDisplay(0); curTabpanel.dynamicDisplay(0);
curTabpanel.afterSave(onSaveEvent); curTabpanel.afterSave(onSaveEvent);
}
if (wasChanged) { if (wasChanged) {
if (newRecord) { if (newRecord) {
@ -1838,7 +1824,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
*/ */
public void onSaveCreate() public void onSaveCreate()
{ {
onSave(true, new Callback<Boolean>() { onSave(true, true, new Callback<Boolean>() {
@Override @Override
public void onCallback(Boolean result) public void onCallback(Boolean result)
@ -2096,11 +2082,10 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
return; return;
} }
onSave(false, new Callback<Boolean>() { Callback<Boolean> callback = new Callback<Boolean>() {
@Override @Override
public void onCallback(Boolean result) { public void onCallback(Boolean result) {
if (result) { if (result) {
//
int table_ID = curTab.getAD_Table_ID(); int table_ID = curTab.getAD_Table_ID();
int record_ID = curTab.getRecord_ID(); int record_ID = curTab.getRecord_ID();
@ -2112,7 +2097,8 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
} }
} }
} }
}); };
onSave(false, false, callback);
} }
/** /**
@ -2125,18 +2111,19 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
return; return;
} }
onSave(false, new Callback<Boolean>() { Callback<Boolean> callback = new Callback<Boolean>() {
@Override @Override
public void onCallback(Boolean result) { public void onCallback(Boolean result) {
if (result) { if (result) {
doOnReport(); onReport0();
} }
} }
}); };
onSave(false, false, callback);
} }
private void doOnReport() { private void onReport0() {
// Query // Query
MQuery query = new MQuery(curTab.getTableName()); MQuery query = new MQuery(curTab.getTableName());
// Link for detail records // Link for detail records
@ -2304,7 +2291,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
if (curTab.needSave(true, false)) if (curTab.needSave(true, false))
{ {
onSave(false, new Callback<Boolean>() { onSave(false, false, new Callback<Boolean>() {
@Override @Override
public void onCallback(Boolean result) { public void onCallback(Boolean result) {
if (result) { if (result) {
@ -2369,7 +2356,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
public void onEvent(Event event) throws Exception { public void onEvent(Event event) throws Exception {
if (vp.needSave()) if (vp.needSave())
{ {
onSave(false, new Callback<Boolean>() { onSave(false, false, new Callback<Boolean>() {
@Override @Override
public void onCallback(Boolean result) { public void onCallback(Boolean result) {
@ -2537,7 +2524,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
if (curTab.needSave(true, false)) if (curTab.needSave(true, false))
{ {
onSave(false, new Callback<Boolean>() { onSave(false, false, new Callback<Boolean>() {
@Override @Override
public void onCallback(Boolean result) { public void onCallback(Boolean result) {