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,10 +750,14 @@ 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
focusToActivePanel(); public void onCallback(Boolean result) {
focusToActivePanel();
}
});
}
} }
/** /**
@ -764,10 +768,13 @@ 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();
}
});
}
} }
/** /**
@ -775,8 +782,16 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
*/ */
public void onFirst() public void onFirst()
{ {
curTab.navigate(0); Callback<Boolean> callback = new Callback<Boolean>() {
focusToActivePanel(); @Override
public void onCallback(Boolean result) {
if (result) {
curTab.navigate(0);
focusToActivePanel();
}
}
};
saveAndNavigate(callback);
} }
/** /**
@ -784,8 +799,16 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
*/ */
public void onLast() public void onLast()
{ {
curTab.navigate(curTab.getRowCount() - 1); Callback<Boolean> callback = new Callback<Boolean>() {
focusToActivePanel(); @Override
public void onCallback(Boolean result) {
if (result) {
curTab.navigate(curTab.getRowCount() - 1);
focusToActivePanel();
}
}
};
onSave(false, true, callback);
} }
/** /**
@ -793,8 +816,16 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
*/ */
public void onNext() public void onNext()
{ {
curTab.navigateRelative(+1); Callback<Boolean> callback = new Callback<Boolean>() {
focusToActivePanel(); @Override
public void onCallback(Boolean result) {
if (result) {
curTab.navigateRelative(+1);
focusToActivePanel();
}
}
};
saveAndNavigate(callback);
} }
/** /**
@ -802,8 +833,16 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
*/ */
public void onPrevious() public void onPrevious()
{ {
curTab.navigateRelative(-1); Callback<Boolean> callback = new Callback<Boolean>() {
focusToActivePanel(); @Override
public void onCallback(Boolean result) {
if (result) {
curTab.navigateRelative(-1);
focusToActivePanel();
}
}
};
saveAndNavigate(callback);
} }
// Elaine 2008/12/04 // Elaine 2008/12/04
@ -865,39 +904,24 @@ 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) {
final WOnlyCurrentDays ocd = new WOnlyCurrentDays(); if (result) {
ocd.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener<Event>() { final WOnlyCurrentDays ocd = new WOnlyCurrentDays();
@Override ocd.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener<Event>() {
public void onEvent(Event event) throws Exception { @Override
m_onlyCurrentDays = ocd.getCurrentDays(); public void onEvent(Event event) throws Exception {
history(m_onlyCurrentDays); m_onlyCurrentDays = ocd.getCurrentDays();
focusToActivePanel(); history(m_onlyCurrentDays);
} focusToActivePanel();
}); }
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())
{ {
((ADSortTab)curTabpanel).saveData(); if (onNavigationEvent)
toolbar.enableSave(false); // set explicitly ((ADSortTab)curTabpanel).unregisterPanel();
toolbar.enableSaveAndCreate(false); else
toolbar.enableIgnore(false); ((ADSortTab)curTabpanel).saveData();
if (!onNavigationEvent)
{
toolbar.enableSave(false); // set explicitly
toolbar.enableSaveAndCreate(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());
} }
curTabpanel.dynamicDisplay(0);
curTabpanel.afterSave(onSaveEvent); if (!navigationEvent) {
curTabpanel.dynamicDisplay(0);
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) {