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) {
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.Serializable;
import java.net.URL;
import java.util.Properties;
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.WPerformanceDetail;
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.panel.HeaderPanel;
import org.adempiere.webui.panel.SidePanel;
import org.adempiere.webui.session.SessionContextListener;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.util.IServerPushCallback;
import org.adempiere.webui.util.ServerPushTemplate;
@ -96,6 +100,8 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
private int noOfWorkflow;
private Tabpanel homeTab;
public DefaultDesktop()
{
super();
@ -153,15 +159,48 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
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;
}
private void createHomeTab()
private void renderHomeTab()
{
Tabpanel homeTab = new Tabpanel();
windowContainer.addWindow(homeTab, Msg.getMsg(Env.getCtx(), "Home").replaceAll("&", ""), false);
homeTab.getChildren().clear();
Portallayout portalLayout = new Portallayout();
portalLayout.setWidth("100%");
@ -196,6 +235,7 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
Panel panel = new Panel();
panel.setStyle("margin-bottom:10px");
panel.setTitle(dp.getName());
panel.setMaximizable(true);
String description = dp.getDescription();
if(description != null)
@ -249,6 +289,7 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
ToolBarButton btn = new ToolBarButton(String.valueOf(AD_Menu_ID));
I_AD_Menu menu = dp.getAD_Menu();
btn.setLabel(menu.getName());
btn.setAttribute("AD_Menu_ID", AD_Menu_ID);
btn.addEventListener(Events.ON_CLICK, this);
content.appendChild(btn);
panelEmpty = false;
@ -318,9 +359,6 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
{
logger.log(Level.WARNING, "Failed to create dashboard content", e);
}
finally
{
}
//
//register as 0
@ -329,11 +367,14 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
if (!portalLayout.getDesktop().isServerPushEnabled())
portalLayout.getDesktop().enableServerPush(true);
dashboardRunnable.refreshDashboard();
if (!dashboardRunnable.isEmpty())
{
dashboardRunnable.refreshDashboard();
dashboardThread = new Thread(dashboardRunnable, "UpdateInfo");
dashboardThread.setDaemon(true);
dashboardThread.start();
dashboardThread = new Thread(dashboardRunnable, "UpdateInfo");
dashboardThread.setDaemon(true);
dashboardThread.start();
}
}
public void onEvent(Event event)
@ -347,16 +388,11 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
{
ToolBarButton btn = (ToolBarButton) comp;
int menuId = 0;
try
if (btn.getAttribute("AD_Menu_ID") != null)
{
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);
}
}
}

View File

@ -20,8 +20,12 @@ import java.io.Serializable;
import java.net.URL;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
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.graph.WGraph;
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.HeaderPanel;
import org.adempiere.webui.panel.SidePanel;
import org.adempiere.webui.session.SessionContextListener;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.util.IServerPushCallback;
import org.adempiere.webui.util.ServerPushTemplate;
@ -97,6 +102,8 @@ public class NavBar2Desktop extends TabbedDesktop implements MenuListener, Seria
private int noOfWorkflow;
private Tabpanel homeTab;
public NavBar2Desktop()
{
super();
@ -191,15 +198,48 @@ public class NavBar2Desktop extends TabbedDesktop implements MenuListener, Seria
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;
}
private void createHomeTab()
private void renderHomeTab()
{
Tabpanel homeTab = new Tabpanel();
windowContainer.addWindow(homeTab, Msg.getMsg(Env.getCtx(), "Home").replaceAll("&", ""), false);
homeTab.getChildren().clear();
Portallayout portalLayout = new Portallayout();
portalLayout.setWidth("100%");

View File

@ -20,8 +20,12 @@ import java.io.Serializable;
import java.net.URL;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
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.graph.WGraph;
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.HeaderPanel;
import org.adempiere.webui.panel.SidePanel;
import org.adempiere.webui.session.SessionContextListener;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.util.IServerPushCallback;
import org.adempiere.webui.util.ServerPushTemplate;
@ -107,6 +112,8 @@ public class NavBarDesktop extends TabbedDesktop implements MenuListener, Serial
private int noOfWorkflow;
private Tabpanel homeTab;
public NavBarDesktop()
{
super();
@ -193,15 +200,48 @@ public class NavBarDesktop extends TabbedDesktop implements MenuListener, Serial
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;
}
private void createHomeTab()
private void renderHomeTab()
{
Tabpanel homeTab = new Tabpanel();
windowContainer.addWindow(homeTab, Msg.getMsg(Env.getCtx(), "Home").replaceAll("&", ""), false);
homeTab.getChildren().clear();
Portallayout portalLayout = new Portallayout();
portalLayout.setWidth("100%");