IDEMPIERE-1248 Performance Optimization: Eliminate the fire and processing of duplicate event.

This commit is contained in:
Heng Sin Low 2013-08-05 11:04:00 +08:00
parent a128d9b302
commit 6819bbc720
4 changed files with 71 additions and 12 deletions

View File

@ -127,6 +127,10 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
public static final String ON_DYNAMIC_DISPLAY_EVENT = "onDynamicDisplay"; public static final String ON_DYNAMIC_DISPLAY_EVENT = "onDynamicDisplay";
public static final String ON_DEFER_DYNAMIC_DISPLAY_EVENT = "onDeferDynamicDisplay";
public static final String ON_DEFER_DYNAMIC_DISPLAY_EVENT_ATTR = "onDeferDynamicDisplay.Event.Posted";
/** /**
* *
*/ */
@ -134,6 +138,8 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
private static final String ON_DEFER_SET_SELECTED_NODE = "onDeferSetSelectedNode"; private static final String ON_DEFER_SET_SELECTED_NODE = "onDeferSetSelectedNode";
private static final String ON_DEFER_SET_SELECTED_NODE_ATTR = "onDeferSetSelectedNode.Event.Posted";
private static final CLogger logger; private static final CLogger logger;
static static
@ -217,6 +223,7 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
}); });
addEventListener(ON_POST_INIT_EVENT, this); addEventListener(ON_POST_INIT_EVENT, this);
addEventListener(ON_SAVE_OPEN_PREFERENCE_EVENT, this); addEventListener(ON_SAVE_OPEN_PREFERENCE_EVENT, this);
addEventListener(ON_DEFER_DYNAMIC_DISPLAY_EVENT, this);
} }
private void initComponents() private void initComponents()
@ -654,8 +661,21 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
* @param col * @param col
*/ */
@Override @Override
public void dynamicDisplay (int col) public void dynamicDisplay (int col)
{
//0 and -1 is same
if (col < 0)
col = 0;
if (getAttribute(ON_DEFER_DYNAMIC_DISPLAY_EVENT_ATTR+"_"+col) == null)
{
setAttribute(ON_DEFER_DYNAMIC_DISPLAY_EVENT_ATTR+"_"+col, Boolean.TRUE);
Events.postEvent(ON_DEFER_DYNAMIC_DISPLAY_EVENT, this, col);
}
}
private void onDeferDynamicDisplay (int col)
{ {
removeAttribute(ON_DEFER_DYNAMIC_DISPLAY_EVENT_ATTR+"_"+col);
if (!gridTab.isOpen()) if (!gridTab.isOpen())
{ {
return; return;
@ -796,10 +816,17 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
} }
Events.sendEvent(this, new Event(ON_DYNAMIC_DISPLAY_EVENT, this)); Events.sendEvent(this, new Event(ON_DYNAMIC_DISPLAY_EVENT, this));
Events.echoEvent(ON_DEFER_SET_SELECTED_NODE, this, null); echoDeferSetSelectedNodeEvent();
if (logger.isLoggable(Level.CONFIG)) logger.config(gridTab.toString() + " - fini - " + (col<=0 ? "complete" : "seletive")); if (logger.isLoggable(Level.CONFIG)) logger.config(gridTab.toString() + " - fini - " + (col<=0 ? "complete" : "seletive"));
} // dynamicDisplay } // dynamicDisplay
private void echoDeferSetSelectedNodeEvent() {
if (getAttribute(ON_DEFER_SET_SELECTED_NODE_ATTR) == null) {
setAttribute(ON_DEFER_SET_SELECTED_NODE_ATTR, Boolean.TRUE);
Events.echoEvent(ON_DEFER_SET_SELECTED_NODE, this, null);
}
}
/** /**
* @return String * @return String
*/ */
@ -957,7 +984,7 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
} }
if (gridTab.getRecord_ID() > 0 && gridTab.isTreeTab() && treePanel != null) { if (gridTab.getRecord_ID() > 0 && gridTab.isTreeTab() && treePanel != null) {
Events.echoEvent(ON_DEFER_SET_SELECTED_NODE, this, null); echoDeferSetSelectedNodeEvent();
} }
Event event = new Event(ON_ACTIVATE_EVENT, this, activate); Event event = new Event(ON_ACTIVATE_EVENT, this, activate);
@ -1006,6 +1033,7 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
navigateTo((DefaultTreeNode<MTreeNode>)item.getValue()); navigateTo((DefaultTreeNode<MTreeNode>)item.getValue());
} }
else if (ON_DEFER_SET_SELECTED_NODE.equals(event.getName())) { else if (ON_DEFER_SET_SELECTED_NODE.equals(event.getName())) {
removeAttribute(ON_DEFER_SET_SELECTED_NODE_ATTR);
if (gridTab.getRecord_ID() >= 0 && gridTab.isTreeTab() && treePanel != null) { if (gridTab.getRecord_ID() >= 0 && gridTab.isTreeTab() && treePanel != null) {
setSelectedNode(gridTab.getRecord_ID()); setSelectedNode(gridTab.getRecord_ID());
} }
@ -1052,6 +1080,10 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
Env.getCtx().setProperty("P"+windowId+"|"+adTabId+"|DetailPane.IsOpen", value ? "Y" : "N"); Env.getCtx().setProperty("P"+windowId+"|"+adTabId+"|DetailPane.IsOpen", value ? "Y" : "N");
} }
} }
else if (event.getName().equals(ON_DEFER_DYNAMIC_DISPLAY_EVENT)) {
Integer col = (Integer) event.getData();
onDeferDynamicDisplay(col);
}
} }
private void onSouthEvent(SouthEvent event) { private void onSouthEvent(SouthEvent event) {
@ -1197,7 +1229,7 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
if (AD_Tree_ID != 0) if (AD_Tree_ID != 0)
{ {
if (treePanel.initTree(AD_Tree_ID, windowNo)) if (treePanel.initTree(AD_Tree_ID, windowNo))
Events.echoEvent(ON_DEFER_SET_SELECTED_NODE, this, null); echoDeferSetSelectedNodeEvent();
else else
setSelectedNode(gridTab.getRecord_ID()); setSelectedNode(gridTab.getRecord_ID());
@ -1282,7 +1314,7 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
int[] path = model.getPath(treeNode); int[] path = model.getPath(treeNode);
Treeitem ti = treePanel.getTree().renderItemByPath(path); Treeitem ti = treePanel.getTree().renderItemByPath(path);
if (ti.getPage() == null) { if (ti.getPage() == null) {
Events.echoEvent(ON_DEFER_SET_SELECTED_NODE, this, null); echoDeferSetSelectedNodeEvent();
} }
boolean changed = false; boolean changed = false;

View File

@ -29,6 +29,7 @@ import org.zkoss.zk.ui.util.Clients;
*/ */
public class DPPerformance extends DashboardPanel { public class DPPerformance extends DashboardPanel {
private static final String ON_POST_RENDER_ATTR = "onPostRender.Event.Posted";
/** /**
* *
*/ */
@ -53,22 +54,31 @@ public class DPPerformance extends DashboardPanel {
public void refresh(ServerPushTemplate template) { public void refresh(ServerPushTemplate template) {
super.refresh(template); super.refresh(template);
if (Executions.getCurrent() != null) if (Executions.getCurrent() != null) {
Events.echoEvent("onPostRender", this, null); if (this.getAttribute(ON_POST_RENDER_ATTR) == null) {
setAttribute(ON_POST_RENDER_ATTR, Boolean.TRUE);
Events.echoEvent("onPostRender", this, null);
}
}
} }
@Override @Override
public void onPageAttached(Page newpage, Page oldpage) { public void onPageAttached(Page newpage, Page oldpage) {
super.onPageAttached(newpage, oldpage); super.onPageAttached(newpage, oldpage);
if (newpage != null) { if (newpage != null) {
if (Executions.getCurrent() != null) if (Executions.getCurrent() != null) {
Events.echoEvent("onPostRender", this, null); if (this.getAttribute(ON_POST_RENDER_ATTR) == null) {
setAttribute(ON_POST_RENDER_ATTR, Boolean.TRUE);
Events.echoEvent("onPostRender", this, null);
}
}
} }
} }
//adjust window height to match grid height //adjust window height to match grid height
public void onPostRender() public void onPostRender()
{ {
removeAttribute(ON_POST_RENDER_ATTR);
if (this.getFirstChild() != null) if (this.getFirstChild() != null)
{ {
Component grid = this.getFirstChild().getFirstChild(); Component grid = this.getFirstChild().getFirstChild();

View File

@ -3,6 +3,8 @@
*/ */
package org.adempiere.webui.util; package org.adempiere.webui.util;
import org.zkoss.zk.ui.Execution;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.util.EventInterceptor; import org.zkoss.zk.ui.util.EventInterceptor;
@ -35,8 +37,18 @@ public class LogEventInterceptor implements EventInterceptor {
*/ */
@Override @Override
public Event beforeProcessEvent(Event event) { public Event beforeProcessEvent(Event event) {
String locator = event.getTarget() != null ? event.getTarget().getWidgetAttribute("_zk_locator") : ""; if (event.getTarget() != null) {
System.out.println("beforeProcessEvent, event="+event.getName()+",target="+event.getTarget()+",locator="+locator); Execution execution = Executions.getCurrent();
String uuid = event.getTarget().getUuid();
String key = uuid + event.getName();
if (execution.getAttribute(key) != null) {
System.out.println("Duplicate Event., event="+event.getName()+",target="+event.getTarget());
} else {
execution.setAttribute(key, Boolean.TRUE);
String locator = event.getTarget() != null ? event.getTarget().getWidgetAttribute("_zk_locator") : "";
System.out.println("beforeProcessEvent, event="+event.getName()+",target="+event.getTarget()+",locator="+locator);
}
}
return event; return event;
} }

View File

@ -206,6 +206,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
private Properties m_findCtx; private Properties m_findCtx;
private static final String ON_POST_VISIBLE_ATTR = "onPostVisible.Event.Posted";
/** /**
* FindPanel Constructor * FindPanel Constructor
@ -2157,6 +2158,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
} }
public void OnPostVisible() { public void OnPostVisible() {
removeAttribute(ON_POST_VISIBLE_ATTR);
if (m_sEditors.size() > 0) if (m_sEditors.size() > 0)
Clients.response(new AuFocus(m_sEditors.get(0).getComponent())); Clients.response(new AuFocus(m_sEditors.get(0).getComponent()));
} }
@ -2180,7 +2182,10 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
public boolean setVisible(boolean visible) { public boolean setVisible(boolean visible) {
boolean ret = super.setVisible(visible); boolean ret = super.setVisible(visible);
if (visible) { if (visible) {
Events.echoEvent("OnPostVisible", this, null); if (getAttribute(ON_POST_VISIBLE_ATTR) == null) {
setAttribute(ON_POST_VISIBLE_ATTR, Boolean.TRUE);
Events.echoEvent("OnPostVisible", this, null);
}
} else { } else {
//auto detach //auto detach
detach(); detach();