Render user home page in background thread.

This commit is contained in:
Heng Sin Low 2011-02-07 18:00:37 +08:00
parent ba9cc04439
commit 14242ef8b6
4 changed files with 156 additions and 33 deletions

View File

@ -197,4 +197,11 @@ public class DashboardRunnable implements Runnable, Serializable
public void add(DashboardPanel dashboardPanel) { public void add(DashboardPanel dashboardPanel) {
dashboardPanels.add(dashboardPanel); dashboardPanels.add(dashboardPanel);
} }
/**
* @return boolean
*/
public boolean isEmpty() {
return dashboardPanels == null || dashboardPanels.isEmpty() ? true : false;
}
} }

View File

@ -22,8 +22,11 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Serializable; import java.io.Serializable;
import java.net.URL; import java.net.URL;
import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.util.ServerContext;
import org.adempiere.webui.apps.BusyDialog;
import org.adempiere.webui.apps.graph.WGraph; import org.adempiere.webui.apps.graph.WGraph;
import org.adempiere.webui.apps.graph.WPerformanceDetail; import org.adempiere.webui.apps.graph.WPerformanceDetail;
import org.adempiere.webui.component.Tabpanel; import org.adempiere.webui.component.Tabpanel;
@ -34,6 +37,7 @@ import org.adempiere.webui.dashboard.DashboardRunnable;
import org.adempiere.webui.event.MenuListener; import org.adempiere.webui.event.MenuListener;
import org.adempiere.webui.panel.HeaderPanel; import org.adempiere.webui.panel.HeaderPanel;
import org.adempiere.webui.panel.SidePanel; import org.adempiere.webui.panel.SidePanel;
import org.adempiere.webui.session.SessionContextListener;
import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.util.IServerPushCallback; import org.adempiere.webui.util.IServerPushCallback;
import org.adempiere.webui.util.ServerPushTemplate; import org.adempiere.webui.util.ServerPushTemplate;
@ -76,7 +80,7 @@ import org.zkoss.zul.Toolbarbutton;
public class DefaultDesktop extends TabbedDesktop implements MenuListener, Serializable, EventListener, IServerPushCallback public class DefaultDesktop extends TabbedDesktop implements MenuListener, Serializable, EventListener, IServerPushCallback
{ {
/** /**
* generated serial version ID * generated serial version ID
*/ */
private static final long serialVersionUID = -8203958978173990301L; private static final long serialVersionUID = -8203958978173990301L;
@ -96,6 +100,8 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
private int noOfWorkflow; private int noOfWorkflow;
private Tabpanel homeTab;
public DefaultDesktop() public DefaultDesktop()
{ {
super(); super();
@ -133,7 +139,7 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
w.setSplittable(true); w.setSplittable(true);
w.setTitle("Menu"); w.setTitle("Menu");
w.setFlex(true); w.setFlex(true);
w.addEventListener(Events.ON_OPEN, new EventListener() { w.addEventListener(Events.ON_OPEN, new EventListener() {
@Override @Override
public void onEvent(Event event) throws Exception { public void onEvent(Event event) throws Exception {
OpenEvent oe = (OpenEvent) event; OpenEvent oe = (OpenEvent) event;
@ -153,15 +159,48 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
windowContainer.createPart(windowArea); windowContainer.createPart(windowArea);
createHomeTab(); homeTab = new Tabpanel();
windowContainer.addWindow(homeTab, Msg.getMsg(Env.getCtx(), "Home").replaceAll("&", ""), false);
BusyDialog busyDialog = new BusyDialog();
busyDialog.setShadow(false);
homeTab.appendChild(busyDialog);
if (!layout.getDesktop().isServerPushEnabled())
{
layout.getDesktop().enableServerPush(true);
}
Runnable runnable = new Runnable() {
public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
IServerPushCallback callback = new IServerPushCallback() {
public void updateUI() {
Properties ctx = (Properties)layout.getDesktop().getSession().getAttribute(SessionContextListener.SESSION_CTX);
try {
ServerContext.setCurrentInstance(ctx);
renderHomeTab();
} finally {
ServerContext.dispose();
}
}
};
ServerPushTemplate template = new ServerPushTemplate(layout.getDesktop());
template.execute(callback);
}
};
Thread thread = new Thread(runnable);
thread.start();
return layout; return layout;
} }
private void createHomeTab() private void renderHomeTab()
{ {
Tabpanel homeTab = new Tabpanel(); homeTab.getChildren().clear();
windowContainer.addWindow(homeTab, Msg.getMsg(Env.getCtx(), "Home").replaceAll("&", ""), false);
Portallayout portalLayout = new Portallayout(); Portallayout portalLayout = new Portallayout();
portalLayout.setWidth("100%"); portalLayout.setWidth("100%");
@ -196,6 +235,7 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
Panel panel = new Panel(); Panel panel = new Panel();
panel.setStyle("margin-bottom:10px"); panel.setStyle("margin-bottom:10px");
panel.setTitle(dp.getName()); panel.setTitle(dp.getName());
panel.setMaximizable(true);
String description = dp.getDescription(); String description = dp.getDescription();
if(description != null) if(description != null)
@ -249,6 +289,7 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
ToolBarButton btn = new ToolBarButton(String.valueOf(AD_Menu_ID)); ToolBarButton btn = new ToolBarButton(String.valueOf(AD_Menu_ID));
I_AD_Menu menu = dp.getAD_Menu(); I_AD_Menu menu = dp.getAD_Menu();
btn.setLabel(menu.getName()); btn.setLabel(menu.getName());
btn.setAttribute("AD_Menu_ID", AD_Menu_ID);
btn.addEventListener(Events.ON_CLICK, this); btn.addEventListener(Events.ON_CLICK, this);
content.appendChild(btn); content.appendChild(btn);
panelEmpty = false; panelEmpty = false;
@ -275,7 +316,7 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
String goalDisplay = dp.getGoalDisplay(); String goalDisplay = dp.getGoalDisplay();
MGoal goal = new MGoal(Env.getCtx(), PA_Goal_ID, null); MGoal goal = new MGoal(Env.getCtx(), PA_Goal_ID, null);
WGraph graph = new WGraph(goal, 55, false, true, WGraph graph = new WGraph(goal, 55, false, true,
!(X_PA_DashboardContent.GOALDISPLAY_Chart.equals(goalDisplay)), !(X_PA_DashboardContent.GOALDISPLAY_Chart.equals(goalDisplay)),
X_PA_DashboardContent.GOALDISPLAY_Chart.equals(goalDisplay)); X_PA_DashboardContent.GOALDISPLAY_Chart.equals(goalDisplay));
content.appendChild(graph); content.appendChild(graph);
@ -318,9 +359,6 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
{ {
logger.log(Level.WARNING, "Failed to create dashboard content", e); logger.log(Level.WARNING, "Failed to create dashboard content", e);
} }
finally
{
}
// //
//register as 0 //register as 0
@ -329,11 +367,14 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
if (!portalLayout.getDesktop().isServerPushEnabled()) if (!portalLayout.getDesktop().isServerPushEnabled())
portalLayout.getDesktop().enableServerPush(true); portalLayout.getDesktop().enableServerPush(true);
dashboardRunnable.refreshDashboard(); if (!dashboardRunnable.isEmpty())
{
dashboardRunnable.refreshDashboard();
dashboardThread = new Thread(dashboardRunnable, "UpdateInfo"); dashboardThread = new Thread(dashboardRunnable, "UpdateInfo");
dashboardThread.setDaemon(true); dashboardThread.setDaemon(true);
dashboardThread.start(); dashboardThread.start();
}
} }
public void onEvent(Event event) public void onEvent(Event event)
@ -347,16 +388,11 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
{ {
ToolBarButton btn = (ToolBarButton) comp; ToolBarButton btn = (ToolBarButton) comp;
int menuId = 0; if (btn.getAttribute("AD_Menu_ID") != null)
try
{ {
menuId = Integer.valueOf(btn.getName()); int menuId = (Integer)btn.getAttribute("AD_Menu_ID");
if(menuId > 0) onMenuSelected(menuId);
} }
catch (Exception e) {
}
if(menuId > 0) onMenuSelected(menuId);
} }
} }
} }
@ -414,7 +450,7 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
+ ", " + Msg.translate(Env.getCtx(), "R_Request_ID") + " : " + noOfRequest + ", " + Msg.translate(Env.getCtx(), "R_Request_ID") + " : " + noOfRequest
+ ", " + Msg.getMsg (Env.getCtx(), "WorkflowActivities") + " : " + noOfWorkflow); + ", " + Msg.getMsg (Env.getCtx(), "WorkflowActivities") + " : " + noOfWorkflow);
} }
private void autoHideMenu() { private void autoHideMenu() {
if (layout.getWest().isCollapsible() && !layout.getWest().isOpen()) if (layout.getWest().isCollapsible() && !layout.getWest().isOpen())
{ {
@ -431,8 +467,8 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
} }
@Override @Override
protected void preOpenNewTab() protected void preOpenNewTab()
{ {
autoHideMenu(); autoHideMenu();
} }
} }

View File

@ -20,8 +20,12 @@ import java.io.Serializable;
import java.net.URL; import java.net.URL;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.util.ServerContext;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.apps.BusyDialog;
import org.adempiere.webui.apps.ProcessDialog; import org.adempiere.webui.apps.ProcessDialog;
import org.adempiere.webui.apps.graph.WGraph; import org.adempiere.webui.apps.graph.WGraph;
import org.adempiere.webui.component.Accordion; import org.adempiere.webui.component.Accordion;
@ -34,6 +38,7 @@ import org.adempiere.webui.event.MenuListener;
import org.adempiere.webui.panel.ADForm; import org.adempiere.webui.panel.ADForm;
import org.adempiere.webui.panel.HeaderPanel; import org.adempiere.webui.panel.HeaderPanel;
import org.adempiere.webui.panel.SidePanel; import org.adempiere.webui.panel.SidePanel;
import org.adempiere.webui.session.SessionContextListener;
import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.util.IServerPushCallback; import org.adempiere.webui.util.IServerPushCallback;
import org.adempiere.webui.util.ServerPushTemplate; import org.adempiere.webui.util.ServerPushTemplate;
@ -97,6 +102,8 @@ public class NavBar2Desktop extends TabbedDesktop implements MenuListener, Seria
private int noOfWorkflow; private int noOfWorkflow;
private Tabpanel homeTab;
public NavBar2Desktop() public NavBar2Desktop()
{ {
super(); super();
@ -191,15 +198,48 @@ public class NavBar2Desktop extends TabbedDesktop implements MenuListener, Seria
windowContainer.createPart(windowArea); windowContainer.createPart(windowArea);
createHomeTab(); homeTab = new Tabpanel();
windowContainer.addWindow(homeTab, Msg.getMsg(Env.getCtx(), "Home").replaceAll("&", ""), false);
BusyDialog busyDialog = new BusyDialog();
busyDialog.setShadow(false);
homeTab.appendChild(busyDialog);
if (!layout.getDesktop().isServerPushEnabled())
{
layout.getDesktop().enableServerPush(true);
}
Runnable runnable = new Runnable() {
public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
IServerPushCallback callback = new IServerPushCallback() {
public void updateUI() {
Properties ctx = (Properties)layout.getDesktop().getSession().getAttribute(SessionContextListener.SESSION_CTX);
try {
ServerContext.setCurrentInstance(ctx);
renderHomeTab();
} finally {
ServerContext.dispose();
}
}
};
ServerPushTemplate template = new ServerPushTemplate(layout.getDesktop());
template.execute(callback);
}
};
Thread thread = new Thread(runnable);
thread.start();
return layout; return layout;
} }
private void createHomeTab() private void renderHomeTab()
{ {
Tabpanel homeTab = new Tabpanel(); homeTab.getChildren().clear();
windowContainer.addWindow(homeTab, Msg.getMsg(Env.getCtx(), "Home").replaceAll("&", ""), false);
Portallayout portalLayout = new Portallayout(); Portallayout portalLayout = new Portallayout();
portalLayout.setWidth("100%"); portalLayout.setWidth("100%");

View File

@ -20,8 +20,12 @@ import java.io.Serializable;
import java.net.URL; import java.net.URL;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.util.ServerContext;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.apps.BusyDialog;
import org.adempiere.webui.apps.ProcessDialog; import org.adempiere.webui.apps.ProcessDialog;
import org.adempiere.webui.apps.graph.WGraph; import org.adempiere.webui.apps.graph.WGraph;
import org.adempiere.webui.component.Accordion; import org.adempiere.webui.component.Accordion;
@ -35,6 +39,7 @@ import org.adempiere.webui.event.MenuListener;
import org.adempiere.webui.panel.ADForm; import org.adempiere.webui.panel.ADForm;
import org.adempiere.webui.panel.HeaderPanel; import org.adempiere.webui.panel.HeaderPanel;
import org.adempiere.webui.panel.SidePanel; import org.adempiere.webui.panel.SidePanel;
import org.adempiere.webui.session.SessionContextListener;
import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.util.IServerPushCallback; import org.adempiere.webui.util.IServerPushCallback;
import org.adempiere.webui.util.ServerPushTemplate; import org.adempiere.webui.util.ServerPushTemplate;
@ -107,6 +112,8 @@ public class NavBarDesktop extends TabbedDesktop implements MenuListener, Serial
private int noOfWorkflow; private int noOfWorkflow;
private Tabpanel homeTab;
public NavBarDesktop() public NavBarDesktop()
{ {
super(); super();
@ -193,15 +200,48 @@ public class NavBarDesktop extends TabbedDesktop implements MenuListener, Serial
windowContainer.createPart(windowArea); windowContainer.createPart(windowArea);
createHomeTab(); homeTab = new Tabpanel();
windowContainer.addWindow(homeTab, Msg.getMsg(Env.getCtx(), "Home").replaceAll("&", ""), false);
BusyDialog busyDialog = new BusyDialog();
busyDialog.setShadow(false);
homeTab.appendChild(busyDialog);
if (!layout.getDesktop().isServerPushEnabled())
{
layout.getDesktop().enableServerPush(true);
}
Runnable runnable = new Runnable() {
public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
IServerPushCallback callback = new IServerPushCallback() {
public void updateUI() {
Properties ctx = (Properties)layout.getDesktop().getSession().getAttribute(SessionContextListener.SESSION_CTX);
try {
ServerContext.setCurrentInstance(ctx);
renderHomeTab();
} finally {
ServerContext.dispose();
}
}
};
ServerPushTemplate template = new ServerPushTemplate(layout.getDesktop());
template.execute(callback);
}
};
Thread thread = new Thread(runnable);
thread.start();
return layout; return layout;
} }
private void createHomeTab() private void renderHomeTab()
{ {
Tabpanel homeTab = new Tabpanel(); homeTab.getChildren().clear();
windowContainer.addWindow(homeTab, Msg.getMsg(Env.getCtx(), "Home").replaceAll("&", ""), false);
Portallayout portalLayout = new Portallayout(); Portallayout portalLayout = new Portallayout();
portalLayout.setWidth("100%"); portalLayout.setWidth("100%");