IDEMPIERE-3194:prepare data of perfomance gadget should do on thread

just work-around better complete implement IDEMPIERE-348.
This commit is contained in:
hieplq 2016-09-19 20:35:19 +07:00
parent 123e2074c8
commit 79f3e4e8f4
3 changed files with 58 additions and 26 deletions

View File

@ -16,27 +16,21 @@ import org.zkoss.zul.Label;
public class WPAPanel extends Panel implements EventListener<Event>
{
/**
*
*/
private static final long serialVersionUID = -6491684272848160726L;
public static WPAPanel get()
{
return get((WPerformanceIndicator.Options)null);
}
private static final long serialVersionUID = -6367672112341229048L;
/**
* Get Panel if User has Performance Goals
* @return panel pr null
*/
public static WPAPanel get(WPerformanceIndicator.Options options)
public static MGoal[] loadGoal()
{
int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
MGoal[] goals = MGoal.getUserGoals(Env.getCtx(), AD_User_ID);
if (goals.length == 0)
return null;
return new WPAPanel(goals, options);
return goals;
}
/**************************************************************************
@ -44,9 +38,12 @@ public class WPAPanel extends Panel implements EventListener<Event>
* @param goals
* @param options
*/
private WPAPanel (MGoal[] goals, Options options)
public WPAPanel ()
{
super ();
}
public void setGoals (MGoal[] goals, Options options){
m_goals = goals;
init(options);
}

View File

@ -1,6 +1,7 @@
package org.adempiere.webui.apps.graph;
import org.adempiere.webui.panel.ADForm;
import org.compiere.model.MGoal;
public class WViewPI extends ADForm {
@ -13,8 +14,13 @@ public class WViewPI extends ADForm {
protected void initForm() {
this.setSclass("window-view-pi");
WPerformanceIndicator.Options options = new WPerformanceIndicator.Options();
WPAPanel paPanel = WPAPanel.get(options);
if (paPanel != null)
WPAPanel paPanel = new WPAPanel();
MGoal [] data = WPAPanel.loadGoal();
if (data != null && data.length > 0){
paPanel.setGoals (data, options);
appendChild(paPanel);
}
}
}

View File

@ -13,8 +13,14 @@
*****************************************************************************/
package org.adempiere.webui.dashboard;
import org.adempiere.util.ContextRunnable;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.apps.DesktopRunnable;
import org.adempiere.webui.apps.graph.WPAPanel;
import org.adempiere.webui.apps.graph.WPerformanceIndicator.Options;
import org.adempiere.webui.util.ServerPushTemplate;
import org.compiere.Adempiere;
import org.compiere.model.MGoal;
import org.compiere.model.MSysConfig;
import org.compiere.util.Env;
import org.zkoss.zk.au.out.AuScript;
@ -37,27 +43,50 @@ public class DPPerformance extends DashboardPanel {
*/
private static final long serialVersionUID = -8878665031716441912L;
private WPAPanel paPanel;
public DPPerformance()
{
super();
setSclass("performance-widget");
WPAPanel paPanel = createPAPanel();
if (paPanel != null)
{
this.appendChild(paPanel);
}
// have to add at least a child component, other it will be remove from DashboardController
// and can't update when finish load data
paPanel = new WPAPanel();
appendChild(paPanel);
Adempiere.getThreadPoolExecutor().submit(new DesktopRunnable(new LoadPerfomanceData(this), Executions.getCurrent().getDesktop()));
}
static class LoadPerfomanceData extends ContextRunnable{
private DPPerformance parentCtr;
public LoadPerfomanceData (DPPerformance parentCtr){
this.parentCtr = parentCtr;
}
@Override
protected void doRun() {
MGoal [] performanceData = WPAPanel.loadGoal();
AEnv.executeAsyncDesktopTask(new Runnable() {
@Override
public void run() {
if (performanceData != null && performanceData.length > 0){
parentCtr.paPanel.setGoals(performanceData, (Options)null);
if (parentCtr.getAttribute(ON_POST_RENDER_ATTR) == null) {
parentCtr.setAttribute(ON_POST_RENDER_ATTR, Boolean.TRUE);
Events.echoEvent("onPostRender", parentCtr, null);
}
}
}
});
}
protected WPAPanel createPAPanel() {
WPAPanel paPanel = WPAPanel.get();
return paPanel;
}
public void refresh(ServerPushTemplate template) {
super.refresh(template);
if (Executions.getCurrent() != null) {
if (this.getAttribute(ON_POST_RENDER_ATTR) == null) {
if (this.getAttribute(ON_POST_RENDER_ATTR) == null && paPanel.getChildren().size() > 0) {
setAttribute(ON_POST_RENDER_ATTR, Boolean.TRUE);
Events.echoEvent("onPostRender", this, null);
}
@ -69,7 +98,7 @@ public class DPPerformance extends DashboardPanel {
super.onPageAttached(newpage, oldpage);
if (newpage != null) {
if (Executions.getCurrent() != null) {
if (this.getAttribute(ON_POST_RENDER_ATTR) == null) {
if (this.getAttribute(ON_POST_RENDER_ATTR) == null && paPanel.getChildren().size() > 0) {
setAttribute(ON_POST_RENDER_ATTR, Boolean.TRUE);
Events.echoEvent("onPostRender", this, null);
}