From a27e86f006448bb88e050200b6b1d49487498e3c Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Tue, 10 Mar 2009 01:53:54 +0000 Subject: [PATCH] [ 2486831 ] Dashboard auto refresh performance issue - Regression: context not correct after first auto refresh --- .../webui/dashboard/DPActivities.java | 10 +++++++++- .../webui/dashboard/DashboardRunnable.java | 20 ++++++++++++++++++- .../webui/util/ServerPushTemplate.java | 9 +++++++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/dashboard/DPActivities.java b/zkwebui/WEB-INF/src/org/adempiere/webui/dashboard/DPActivities.java index 29241c04b0..deada23103 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/dashboard/DPActivities.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/dashboard/DPActivities.java @@ -99,6 +99,7 @@ public class DPActivities extends DashboardPanel implements EventListener { String sql = "SELECT COUNT(1) FROM AD_Note " + "WHERE AD_Client_ID=? AND AD_User_ID IN (0,?)" + " AND Processed='N'"; + int retValue = DB.getSQLValue(null, sql, Env.getAD_Client_ID(Env.getCtx()), Env.getAD_User_ID(Env.getCtx())); return retValue; } @@ -171,7 +172,7 @@ public class DPActivities extends DashboardPanel implements EventListener { @Override public void refresh(ServerPushTemplate template) - { + { noOfNotice = getNoticeCount(); noOfRequest = getRequestCount(); noOfWorkflow = getWorkflowCount(); @@ -181,6 +182,13 @@ public class DPActivities extends DashboardPanel implements EventListener { @Override public void updateUI() { + //don't update if not visible + Component c = this.getParent(); + while (c != null) { + if (!c.isVisible()) + return; + c = c.getParent(); + } btnNotice.setLabel("Notice : " + noOfNotice); btnRequest.setLabel("Request : " + noOfRequest); btnWorkflow.setLabel("Workflow Activities : " + noOfWorkflow); diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/dashboard/DashboardRunnable.java b/zkwebui/WEB-INF/src/org/adempiere/webui/dashboard/DashboardRunnable.java index e5fd043641..f3616e14cf 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/dashboard/DashboardRunnable.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/dashboard/DashboardRunnable.java @@ -17,10 +17,13 @@ import java.util.ArrayList; import java.util.List; import org.adempiere.webui.desktop.IDesktop; +import org.adempiere.webui.session.ServerContext; +import org.adempiere.webui.session.SessionContextListener; import org.adempiere.webui.util.ServerPushTemplate; import org.compiere.model.MSysConfig; import org.compiere.util.CLogger; import org.zkoss.zk.ui.Desktop; +import org.zkoss.zk.ui.Executions; /** * @@ -74,10 +77,25 @@ public class DashboardRunnable implements Runnable { */ public void refreshDashboard() { + ServerPushTemplate template = new ServerPushTemplate(desktop); - for(int i = 0; i < dashboardPanels.size(); i++) + for(int i = 0; i < dashboardPanels.size(); i++) + { + //make sure context is correct + ServerContext ctx = (ServerContext)template.getDesktop().getSession().getAttribute(SessionContextListener.SESSION_CTX); + if (ctx != null && ServerContext.getCurrentInstance() != ctx) + { + ServerContext.setCurrentInstance(ctx); + } dashboardPanels.get(i).refresh(template); + } + //make sure context is correct + ServerContext ctx = (ServerContext)template.getDesktop().getSession().getAttribute(SessionContextListener.SESSION_CTX); + if (ctx != null && ServerContext.getCurrentInstance() != ctx) + { + ServerContext.setCurrentInstance(ctx); + } appDesktop.onServerPush(template); } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/util/ServerPushTemplate.java b/zkwebui/WEB-INF/src/org/adempiere/webui/util/ServerPushTemplate.java index 7845176225..25d3ec7378 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/util/ServerPushTemplate.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/util/ServerPushTemplate.java @@ -45,17 +45,22 @@ public class ServerPushTemplate { */ public void execute(IServerPushCallback callback) { boolean inUIThread = Executions.getCurrent() != null; + boolean desktopActivated = false; try { if (!inUIThread) { //1 second timeout - Executions.activate(desktop, 1000); + if (Executions.activate(desktop, 1000)) { + desktopActivated = true; + } else { + return; + } } callback.updateUI(); } catch (Exception e) { logger.log(Level.WARNING, "Server push error="+e.getLocalizedMessage(), e); } finally { - if (!inUIThread) { + if (!inUIThread && desktopActivated) { Executions.deactivate(desktop); } }