IDEMPIERE-5630 - Multiple Drill Assistants Opening from Dashboard (#1737)

* IDEMPIERE-5630 - Multiple Drill Assistants Opening from Dashboard

* IDEMPIERE-5630 - fix bad merge

* IDEMPIERE-5630 - pr1737 patch
This commit is contained in:
Peter Takács 2023-03-20 11:45:01 +01:00 committed by GitHub
parent b11b7bcf95
commit d9225a2caa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 67 deletions

View File

@ -27,6 +27,7 @@ import org.adempiere.webui.part.AbstractUIPart;
import org.compiere.model.MMenu; import org.compiere.model.MMenu;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Session; import org.zkoss.zk.ui.Session;
@ -155,6 +156,25 @@ public abstract class AbstractDesktop extends AbstractUIPart implements IDesktop
return null; return null;
} }
@Override
public int findWindowNo(Component component) {
if (component == null)
return -1;
List<Object> windows = getWindows();
if (windows != null) {
if (windows.contains(component))
return windows.indexOf(component);
Component parent = component.getParent();
while (parent != null) {
if (windows.contains(parent))
return windows.indexOf(parent);
parent = parent.getParent();
}
}
return -1;
}
/** /**
* @param win * @param win
*/ */

View File

@ -38,6 +38,7 @@ import org.adempiere.webui.Extensions;
import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.LayoutUtils;
import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.apps.BusyDialog; import org.adempiere.webui.apps.BusyDialog;
import org.adempiere.webui.apps.WReport;
import org.adempiere.webui.apps.graph.IChartRendererService; import org.adempiere.webui.apps.graph.IChartRendererService;
import org.adempiere.webui.apps.graph.WGraph; import org.adempiere.webui.apps.graph.WGraph;
import org.adempiere.webui.apps.graph.WPAWidget; import org.adempiere.webui.apps.graph.WPAWidget;
@ -48,6 +49,7 @@ import org.adempiere.webui.component.ToolBarButton;
import org.adempiere.webui.dashboard.DashboardPanel; import org.adempiere.webui.dashboard.DashboardPanel;
import org.adempiere.webui.dashboard.DashboardRunnable; import org.adempiere.webui.dashboard.DashboardRunnable;
import org.adempiere.webui.event.DrillEvent; import org.adempiere.webui.event.DrillEvent;
import org.adempiere.webui.event.ZoomEvent;
import org.adempiere.webui.event.DrillEvent.DrillData; import org.adempiere.webui.event.DrillEvent.DrillData;
import org.adempiere.webui.report.HTMLExtension; import org.adempiere.webui.report.HTMLExtension;
import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.session.SessionManager;
@ -55,6 +57,7 @@ import org.adempiere.webui.theme.ThemeManager;
import org.adempiere.webui.util.ServerPushTemplate; import org.adempiere.webui.util.ServerPushTemplate;
import org.adempiere.webui.util.ZKUpdateUtil; import org.adempiere.webui.util.ZKUpdateUtil;
import org.adempiere.webui.util.ZkContextRunnable; import org.adempiere.webui.util.ZkContextRunnable;
import org.adempiere.webui.window.Dialog;
import org.adempiere.webui.window.ZkReportViewerProvider; import org.adempiere.webui.window.ZkReportViewerProvider;
import org.compiere.Adempiere; import org.compiere.Adempiere;
import org.compiere.model.I_AD_Menu; import org.compiere.model.I_AD_Menu;
@ -71,6 +74,8 @@ import org.compiere.model.MPInstance;
import org.compiere.model.MPInstancePara; import org.compiere.model.MPInstancePara;
import org.compiere.model.MProcess; import org.compiere.model.MProcess;
import org.compiere.model.MProcessPara; import org.compiere.model.MProcessPara;
import org.compiere.model.MQuery;
import org.compiere.model.MRole;
import org.compiere.model.MStatusLine; import org.compiere.model.MStatusLine;
import org.compiere.model.MSysConfig; import org.compiere.model.MSysConfig;
import org.compiere.model.MTable; import org.compiere.model.MTable;
@ -284,7 +289,6 @@ public class DashboardController implements EventListener<Event> {
if (!update) { if (!update) {
final Panel fp = panel; final Panel fp = panel;
ServerPushTemplate spt = new ServerPushTemplate(dashboardLayout.getDesktop()); ServerPushTemplate spt = new ServerPushTemplate(dashboardLayout.getDesktop());
IDesktop appDesktop = SessionManager.getAppDesktop();
String contextPath = Executions.getCurrent().getContextPath(); String contextPath = Executions.getCurrent().getContextPath();
Panelchildren panelChildren = new Panelchildren(); Panelchildren panelChildren = new Panelchildren();
fp.appendChild(panelChildren); fp.appendChild(panelChildren);
@ -305,7 +309,7 @@ public class DashboardController implements EventListener<Event> {
@Override @Override
protected void doRun() { protected void doRun() {
try { try {
asyncRenderGadgetPanel(spt, dc, fp, appDesktop, contextPath, panelChildren, zulComponent); asyncRenderGadgetPanel(spt, dc, fp, contextPath, panelChildren, zulComponent);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -431,16 +435,15 @@ public class DashboardController implements EventListener<Event> {
* @param spt * @param spt
* @param dashboardContent * @param dashboardContent
* @param panel * @param panel
* @param appDesktop
* @param contextPath * @param contextPath
* @param panelChildren * @param panelChildren
* @param zulComponent * @param zulComponent
* @throws Exception * @throws Exception
*/ */
private void asyncRenderGadgetPanel(ServerPushTemplate spt, MDashboardContent dashboardContent, Panel panel, IDesktop appDesktop, String contextPath, private void asyncRenderGadgetPanel(ServerPushTemplate spt, MDashboardContent dashboardContent, Panel panel, String contextPath,
Panelchildren panelChildren, Component zulComponent) throws Exception { Panelchildren panelChildren, Component zulComponent) throws Exception {
List<Component> components = new ArrayList<>(); List<Component> components = new ArrayList<>();
asyncRenderComponents(dashboardContent, dashboardRunnable, appDesktop, contextPath, panelChildren, components, zulComponent, spt); asyncRenderComponents(dashboardContent, dashboardRunnable, contextPath, panelChildren, components, zulComponent, spt);
if (components.size() > 0) { if (components.size() > 0) {
for(Component c : components) { for(Component c : components) {
if (c.getParent() != panelChildren) { if (c.getParent() != panelChildren) {
@ -589,7 +592,6 @@ public class DashboardController implements EventListener<Event> {
if (!update) { if (!update) {
final Panel fp = panel; final Panel fp = panel;
ServerPushTemplate spt = new ServerPushTemplate(dashboardLayout.getDesktop()); ServerPushTemplate spt = new ServerPushTemplate(dashboardLayout.getDesktop());
IDesktop appDesktop = SessionManager.getAppDesktop();
String contextPath = Executions.getCurrent().getContextPath(); String contextPath = Executions.getCurrent().getContextPath();
Panelchildren panelChildren = new Panelchildren(); Panelchildren panelChildren = new Panelchildren();
fp.appendChild(panelChildren); fp.appendChild(panelChildren);
@ -610,7 +612,7 @@ public class DashboardController implements EventListener<Event> {
@Override @Override
protected void doRun() { protected void doRun() {
try { try {
asyncRenderGadgetPanel(spt, dc, fp, appDesktop, contextPath, panelChildren, zulComponent); asyncRenderGadgetPanel(spt, dc, fp, contextPath, panelChildren, zulComponent);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -693,7 +695,6 @@ public class DashboardController implements EventListener<Event> {
* Create gadget components in background thread * Create gadget components in background thread
* @param dashboardContent * @param dashboardContent
* @param dashboardRunnable * @param dashboardRunnable
* @param appDesktop
* @param contextPath * @param contextPath
* @param parentComponent * @param parentComponent
* @param components * @param components
@ -701,7 +702,7 @@ public class DashboardController implements EventListener<Event> {
* @param spt * @param spt
* @throws Exception * @throws Exception
*/ */
private void asyncRenderComponents(MDashboardContent dashboardContent, DashboardRunnable dashboardRunnable, IDesktop appDesktop, String contextPath, private void asyncRenderComponents(MDashboardContent dashboardContent, DashboardRunnable dashboardRunnable, String contextPath,
HtmlBasedComponent parentComponent, List<Component> components, Component zulComponent, ServerPushTemplate spt) throws Exception { HtmlBasedComponent parentComponent, List<Component> components, Component zulComponent, ServerPushTemplate spt) throws Exception {
// HTML content // HTML content
String htmlContent = dashboardContent.get_ID() > 0 ? dashboardContent.get_Translation(MDashboardContent.COLUMNNAME_HTML) : null; String htmlContent = dashboardContent.get_ID() > 0 ? dashboardContent.get_Translation(MDashboardContent.COLUMNNAME_HTML) : null;
@ -777,7 +778,7 @@ public class DashboardController implements EventListener<Event> {
if (dashboardContent.isEmbedReportContent()) if (dashboardContent.isEmbedReportContent())
{ {
addDrillAcrossEventListener(AD_Process_ID, appDesktop); addDrillAcrossEventListener(AD_Process_ID, parentComponent);
String processParameters = dashboardContent.getProcessParameters(); String processParameters = dashboardContent.getProcessParameters();
Div layout = new Div(); Div layout = new Div();
@ -787,7 +788,7 @@ public class DashboardController implements EventListener<Event> {
Iframe iframe = new Iframe(); Iframe iframe = new Iframe();
iframe.setSclass("dashboard-report-iframe"); iframe.setSclass("dashboard-report-iframe");
iframe.setStyle("flex-grow: 1;"); iframe.setStyle("flex-grow: 1;");
iframe.setContent(generateReport(AD_Process_ID, dashboardContent.getAD_PrintFormat_ID(), processParameters, appDesktop, contextPath)); iframe.setContent(generateReport(AD_Process_ID, dashboardContent.getAD_PrintFormat_ID(), processParameters, parentComponent, contextPath));
if(iframe.getContent() != null) if(iframe.getContent() != null)
layout.appendChild(iframe); layout.appendChild(iframe);
else else
@ -816,7 +817,7 @@ public class DashboardController implements EventListener<Event> {
else else
btn.setImage(ThemeManager.getThemeResource("images/Refresh16.png")); btn.setImage(ThemeManager.getThemeResource("images/Refresh16.png"));
btn.addEventListener(Events.ON_CLICK, e -> iframe.setContent(generateReport(AD_Process_ID, dashboardContent.getAD_PrintFormat_ID(), processParameters, appDesktop, contextPath))); btn.addEventListener(Events.ON_CLICK, e -> iframe.setContent(generateReport(AD_Process_ID, dashboardContent.getAD_PrintFormat_ID(), processParameters, parentComponent, contextPath)));
toolbar.appendChild(btn); toolbar.appendChild(btn);
} }
else else
@ -949,7 +950,7 @@ public class DashboardController implements EventListener<Event> {
} }
ServerPushTemplate spt = new ServerPushTemplate(content.getDesktop()); ServerPushTemplate spt = new ServerPushTemplate(content.getDesktop());
HtmlBasedComponent parentComponent = (HtmlBasedComponent) content; HtmlBasedComponent parentComponent = (HtmlBasedComponent) content;
asyncRenderComponents(dashboardContent, dashboardRunnable, SessionManager.getAppDesktop(), Executions.getCurrent().getContextPath(), parentComponent, components, asyncRenderComponents(dashboardContent, dashboardRunnable, Executions.getCurrent().getContextPath(), parentComponent, components,
zulComponent, spt); zulComponent, spt);
boolean empty = components.isEmpty(); boolean empty = components.isEmpty();
for(Component c : components) { for(Component c : components) {
@ -975,8 +976,8 @@ public class DashboardController implements EventListener<Event> {
* Add Drill Across Event Listener to Border Layout * Add Drill Across Event Listener to Border Layout
* @param processID * @param processID
*/ */
private void addDrillAcrossEventListener(int processID, IDesktop appDesktop) { private void addDrillAcrossEventListener(int processID, Component component) {
appDesktop.getComponent().addEventListener(DrillEvent.ON_DRILL_ACROSS, new EventListener<Event>() { component.addEventListener(DrillEvent.ON_DRILL_ACROSS, new EventListener<Event>() {
public void onEvent(Event event) throws Exception { public void onEvent(Event event) throws Exception {
if (event instanceof DrillEvent) { if (event instanceof DrillEvent) {
Clients.clearBusy(); Clients.clearBusy();
@ -988,12 +989,50 @@ public class DashboardController implements EventListener<Event> {
if(jsonData.indexOf(String.valueOf(processID)) < 0) if(jsonData.indexOf(String.valueOf(processID)) < 0)
return; return;
} }
AEnv.actionDrill(data, 0, processID); // WindowNo of Home tab is always 0 AEnv.actionDrill(data, SessionManager.getAppDesktop().findWindowNo(component), processID);
} }
} }
} }
}); });
component.addEventListener("onZoom", event -> {
Clients.clearBusy();
if (event instanceof ZoomEvent) {
ZoomEvent ze = (ZoomEvent) event;
if (ze.getData() != null && ze.getData() instanceof MQuery) {
AEnv.zoom((MQuery) ze.getData());
} }
}
});
component.addEventListener(DrillEvent.ON_DRILL_DOWN, event -> {
Clients.clearBusy();
if (event instanceof DrillEvent) {
DrillEvent de = (DrillEvent) event;
if (de.getData() != null && de.getData() instanceof DrillData) {
DrillData data = (DrillData) de.getData();
MQuery query = data.getQuery();
executeDrill(query);
}
}
});
}
/**
* Execute Drill to Query
* @param query query
*/
private void executeDrill (MQuery query)
{
int AD_Table_ID = MTable.getTable_ID(query.getTableName());
if (!MRole.getDefault().isCanReport(AD_Table_ID))
{
Dialog.error(0, "AccessCannotReport", query.getTableName());
return;
}
if (AD_Table_ID != 0)
new WReport(AD_Table_ID, query);
} // executeDrill
@Override @Override
public void onEvent(Event event) throws Exception { public void onEvent(Event event) throws Exception {
@ -1506,13 +1545,13 @@ public class DashboardController implements EventListener<Event> {
} }
private AMedia generateReport(int AD_Process_ID, int AD_PrintFormat_ID, String parameters, IDesktop appDesktop, String contextPath) throws Exception { private AMedia generateReport(int AD_Process_ID, int AD_PrintFormat_ID, String parameters, Component component, String contextPath) throws Exception {
ReportEngine re = runReport(AD_Process_ID, AD_PrintFormat_ID, parameters); ReportEngine re = runReport(AD_Process_ID, AD_PrintFormat_ID, parameters);
if(re == null) if(re == null)
return null; return null;
File file = FileUtil.createTempFile(re.getName(), ".html"); File file = FileUtil.createTempFile(re.getName(), ".html");
re.createHTML(file, false, AEnv.getLanguage(Env.getCtx()), new HTMLExtension(contextPath, "rp", re.createHTML(file, false, AEnv.getLanguage(Env.getCtx()), new HTMLExtension(contextPath, "rp",
appDesktop.getComponent().getUuid(), String.valueOf(AD_Process_ID))); component.getUuid(), String.valueOf(AD_Process_ID)));
return new AMedia(re.getName(), "html", "text/html", file, false); return new AMedia(re.getName(), "html", "text/html", file, false);
} }

View File

@ -37,16 +37,13 @@ import org.adempiere.webui.adwindow.ADWindow;
import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.apps.BusyDialog; import org.adempiere.webui.apps.BusyDialog;
import org.adempiere.webui.apps.ProcessDialog; import org.adempiere.webui.apps.ProcessDialog;
import org.adempiere.webui.apps.WReport;
import org.adempiere.webui.component.Tab; import org.adempiere.webui.component.Tab;
import org.adempiere.webui.component.Tabpanel; import org.adempiere.webui.component.Tabpanel;
import org.adempiere.webui.component.ToolBar; import org.adempiere.webui.component.ToolBar;
import org.adempiere.webui.component.ToolBarButton; import org.adempiere.webui.component.ToolBarButton;
import org.adempiere.webui.component.Window; import org.adempiere.webui.component.Window;
import org.adempiere.webui.event.DrillEvent;
import org.adempiere.webui.event.MenuListener; import org.adempiere.webui.event.MenuListener;
import org.adempiere.webui.event.ZKBroadCastManager; import org.adempiere.webui.event.ZKBroadCastManager;
import org.adempiere.webui.event.ZoomEvent;
import org.adempiere.webui.panel.ADForm; import org.adempiere.webui.panel.ADForm;
import org.adempiere.webui.panel.BroadcastMessageWindow; import org.adempiere.webui.panel.BroadcastMessageWindow;
import org.adempiere.webui.panel.HeaderPanel; import org.adempiere.webui.panel.HeaderPanel;
@ -56,13 +53,11 @@ import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.theme.ThemeManager; import org.adempiere.webui.theme.ThemeManager;
import org.adempiere.webui.util.UserPreference; import org.adempiere.webui.util.UserPreference;
import org.adempiere.webui.util.ZKUpdateUtil; import org.adempiere.webui.util.ZKUpdateUtil;
import org.adempiere.webui.window.Dialog;
import org.compiere.model.GridField; import org.compiere.model.GridField;
import org.compiere.model.GridTab; import org.compiere.model.GridTab;
import org.compiere.model.I_AD_Preference; import org.compiere.model.I_AD_Preference;
import org.compiere.model.MMenu; import org.compiere.model.MMenu;
import org.compiere.model.MPreference; import org.compiere.model.MPreference;
import org.compiere.model.MQuery;
import org.compiere.model.MRole; import org.compiere.model.MRole;
import org.compiere.model.MTable; import org.compiere.model.MTable;
import org.compiere.model.MTreeFavorite; import org.compiere.model.MTreeFavorite;
@ -205,9 +200,6 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
headerContainer = page.getFellow("northBody"); headerContainer = page.getFellow("northBody");
pnlHead = (HeaderPanel) headerContainer.getFellow("header"); pnlHead = (HeaderPanel) headerContainer.getFellow("header");
layout.addEventListener("onZoom", this);
layout.addEventListener(DrillEvent.ON_DRILL_DOWN, this);
West w = layout.getWest(); West w = layout.getWest();
w.addEventListener(Events.ON_OPEN, new EventListener<Event>() { w.addEventListener(Events.ON_OPEN, new EventListener<Event>() {
@Override @Override
@ -703,24 +695,6 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
if (change) if (change)
updateUI(); updateUI();
} }
else if (event instanceof ZoomEvent)
{
Clients.clearBusy();
ZoomEvent ze = (ZoomEvent) event;
if (ze.getData() != null && ze.getData() instanceof MQuery) {
AEnv.zoom((MQuery) ze.getData());
}
}
else if (event instanceof DrillEvent)
{
Clients.clearBusy();
DrillEvent de = (DrillEvent) event;
if (de.getData() != null && de.getData() instanceof MQuery) {
MQuery query = (MQuery) de.getData();
executeDrill(query);
}
}
} }
protected void restoreHeader() { protected void restoreHeader() {
@ -764,22 +738,6 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
updateHeaderCollapsedPreference(true); updateHeaderCollapsedPreference(true);
} }
/**
* Execute Drill to Query
* @param query query
*/
private void executeDrill (MQuery query)
{
int AD_Table_ID = MTable.getTable_ID(query.getTableName());
if (!MRole.getDefault().isCanReport(AD_Table_ID))
{
Dialog.error(0, "AccessCannotReport", query.getTableName());
return;
}
if (AD_Table_ID != 0)
new WReport(AD_Table_ID, query);
} // executeDrill
/** /**
* *
* @param page * @param page

View File

@ -63,6 +63,12 @@ public interface IDesktop extends UIPart {
*/ */
public Object findWindow(int WindowNo); public Object findWindow(int WindowNo);
/**
* @param component
* @return register window no or -1 if not found
*/
public int findWindowNo(Component component);
/** /**
* close active window * close active window
* @return boolean * @return boolean