diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java index 4a25bdabd0..5d6cd5296b 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java @@ -34,14 +34,20 @@ import java.util.logging.Level; import javax.servlet.ServletRequest; import org.adempiere.webui.ClientInfo; +import org.adempiere.webui.ISupportMask; +import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.adwindow.ADWindow; +import org.adempiere.webui.component.Mask; import org.adempiere.webui.component.Window; import org.adempiere.webui.editor.WTableDirEditor; +import org.adempiere.webui.event.DialogEvents; +import org.adempiere.webui.event.DrillEvent.DrillData; import org.adempiere.webui.info.InfoWindow; import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.theme.ThemeManager; import org.adempiere.webui.util.IServerPushCallback; import org.adempiere.webui.util.ServerPushTemplate; +import org.adempiere.webui.window.Dialog; import org.compiere.acct.Doc; import org.compiere.model.GridWindowVO; import org.compiere.model.I_AD_Window; @@ -52,6 +58,7 @@ import org.compiere.model.MLookup; import org.compiere.model.MLookupFactory; import org.compiere.model.MQuery; import org.compiere.model.MReference; +import org.compiere.model.MRole; import org.compiere.model.MSession; import org.compiere.model.MSysConfig; import org.compiere.model.MTable; @@ -71,6 +78,8 @@ import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Execution; import org.zkoss.zk.ui.Executions; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.EventListener; import com.lowagie.text.DocumentException; @@ -429,6 +438,47 @@ public final class AEnv } } + /** + * Opens the Drill Assistant + * @param data query + * @param component + */ + public static void actionDrill(DrillData data, int windowNo) { + int AD_Table_ID = MTable.getTable_ID(data.getQuery().getTableName()); + if (!MRole.getDefault().isCanReport(AD_Table_ID)) + { + Dialog.error(windowNo, "AccessCannotReport", data.getQuery().getTableName()); + return; + } + if (AD_Table_ID > 0) { + WDrillReport drillReport = new WDrillReport(data, windowNo); + + Object window = SessionManager.getAppDesktop().findWindow(windowNo); + if (window != null && window instanceof Component && window instanceof ISupportMask){ + final ISupportMask parent = LayoutUtils.showWindowWithMask(drillReport, (Component)window, LayoutUtils.OVERLAP_PARENT); + drillReport.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + parent.hideMask(); + } + }); + }else if (window != null && window instanceof Component){ + final Mask mask = LayoutUtils.showWindowWithMask(drillReport, (Component)window, null); + drillReport.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + mask.hideMask(); + } + }); + }else{ + drillReport.setAttribute(Window.MODE_KEY, Window.MODE_HIGHLIGHTED); + AEnv.showWindow(drillReport); + } + } + else + log.warning("No Table found for " + data.getQuery().getWhereClause(true)); + } + /** * open zoom window with query * @param AD_Window_ID diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/WDrillReport.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/WDrillReport.java index 7b9886992f..f8f5ea1e80 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/WDrillReport.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/WDrillReport.java @@ -62,7 +62,6 @@ import org.zkoss.zhtml.Table; import org.zkoss.zhtml.Td; import org.zkoss.zhtml.Text; import org.zkoss.zhtml.Tr; -import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.HtmlNativeComponent; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; @@ -100,10 +99,9 @@ public class WDrillReport extends Window implements EventListener { /** * * @param data - * @param parent * @param WindowNo */ - public WDrillReport(DrillData data, Component parent, int WindowNo) { + public WDrillReport(DrillData data, int WindowNo) { super(); this.windowNo = WindowNo; drillReportCtl = new DrillReportCtl(data.getQuery().getTableName(), data.getQuery(), data.getColumnName(), data.getValue(), data.getDisplayValue(), WindowNo); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WEditorPopupMenu.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WEditorPopupMenu.java index 86532ba6b4..52169c9fe5 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WEditorPopupMenu.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WEditorPopupMenu.java @@ -64,6 +64,7 @@ public class WEditorPopupMenu extends Menupopup implements EventListener public static final String EDITOR_EVENT = "EDITOR"; public static final String RESET_EVENT = "RESET"; public static final String ASSISTANT_EVENT = "ASSISTANT"; + public static final String DRILL_EVENT = "DRILL"; private boolean newEnabled = true; private boolean updateEnabled = true; // Elaine 2009/02/16 - update record @@ -71,6 +72,7 @@ public class WEditorPopupMenu extends Menupopup implements EventListener private boolean requeryEnabled = true; private boolean preferencesEnabled = true; private boolean showLocation = true; + private boolean drillEnabled = true; private Menuitem zoomItem; private Menuitem requeryItem; @@ -78,12 +80,13 @@ public class WEditorPopupMenu extends Menupopup implements EventListener private Menuitem newItem; private Menuitem updateItem; // Elaine 2009/02/16 - update record private Menuitem showLocationItem; + private Menuitem drillItem; private ArrayList menuListeners = new ArrayList(); public WEditorPopupMenu(boolean zoom, boolean requery, boolean preferences) { - this(zoom, requery, preferences, false, false, false, null); // no check zoom + this(zoom, requery, preferences, false, false, false, false, null); // no check zoom } @Deprecated @@ -104,6 +107,11 @@ public class WEditorPopupMenu extends Menupopup implements EventListener this(zoom, requery, preferences, newRecord, updateRecord, false, null); } + public WEditorPopupMenu(boolean zoom, boolean requery, boolean preferences, boolean newRecord, boolean updateRecord, boolean showLocation, Lookup lookup) + { + this(zoom, requery, preferences, newRecord, updateRecord, showLocation, false, lookup); + } + /** * @param zoom - enable zoom in menu - disabled if the lookup cannot zoom * @param requery - enable requery in menu @@ -113,7 +121,7 @@ public class WEditorPopupMenu extends Menupopup implements EventListener * @param showLocation - enable show location in menu * @param lookup - when this parameter is received then new and update are calculated based on the zoom and quickentry */ - public WEditorPopupMenu(boolean zoom, boolean requery, boolean preferences, boolean newRecord, boolean updateRecord, boolean showLocation, Lookup lookup) + public WEditorPopupMenu(boolean zoom, boolean requery, boolean preferences, boolean newRecord, boolean updateRecord, boolean showLocation, boolean drillEnabled, Lookup lookup) { super(); this.zoomEnabled = zoom; @@ -122,6 +130,7 @@ public class WEditorPopupMenu extends Menupopup implements EventListener this.newEnabled = newRecord; this.updateEnabled = updateRecord; // Elaine 2009/02/16 - update record this.showLocation = showLocation; + this.drillEnabled = drillEnabled; String tableName = null; if (lookup != null && lookup.getColumnName() != null) @@ -274,6 +283,18 @@ public class WEditorPopupMenu extends Menupopup implements EventListener this.appendChild(showLocationItem); } + if(drillEnabled) + { + drillItem = new Menuitem(); + drillItem.setAttribute(EVENT_ATTRIBUTE, DRILL_EVENT); + drillItem.setLabel(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "DrillAssistant")).intern()); + if (ThemeManager.isUseFontIconForImage()) + drillItem.setIconSclass("z-icon-Window"); + else + drillItem.setImage(ThemeManager.getThemeResource("images/Window16.png")); + drillItem.addEventListener(Events.ON_CLICK, this); + this.appendChild(drillItem); + } } public void addMenuListener(ContextMenuListener listener) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WSearchEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WSearchEditor.java index 6d18f4cf59..6455b96988 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WSearchEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WSearchEditor.java @@ -35,6 +35,7 @@ import org.adempiere.webui.component.ComboEditorBox; import org.adempiere.webui.event.ContextMenuEvent; import org.adempiere.webui.event.ContextMenuListener; import org.adempiere.webui.event.DialogEvents; +import org.adempiere.webui.event.DrillEvent.DrillData; import org.adempiere.webui.event.ValueChangeEvent; import org.adempiere.webui.event.ValueChangeListener; import org.adempiere.webui.factory.InfoManager; @@ -50,6 +51,7 @@ import org.compiere.model.Lookup; import org.compiere.model.MColumn; import org.compiere.model.MLookup; import org.compiere.model.MLookupFactory; +import org.compiere.model.MQuery; import org.compiere.model.MRole; import org.compiere.model.MSysConfig; import org.compiere.model.MTable; @@ -196,9 +198,14 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value if (Util.isEmpty(m_tableName)) setTableAndKeyColumn(); + boolean enableDrill = false; + if(getGridField() != null && getGridField().getGridTab() != null && getGridField().getColumnName().endsWith("_ID") + && MRole.getDefault().isCanReport(getGridField().getGridTab().getAD_Table_ID())) + enableDrill = true; + if (m_tableName.equals("C_BPartner")) { - popupMenu = new WEditorPopupMenu(true, true, isShowPreference(), true, true, false, lookup); + popupMenu = new WEditorPopupMenu(true, true, isShowPreference(), true, true, false, enableDrill, lookup); if (ThemeManager.isUseFontIconForImage()) imageUrl = "z-icon-BPartner"; else @@ -206,7 +213,7 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value } else if (m_tableName.equals("M_Product")) { - popupMenu = new WEditorPopupMenu(true, true, isShowPreference(), false, false, false, lookup); + popupMenu = new WEditorPopupMenu(true, true, isShowPreference(), false, false, false, enableDrill, lookup); if (ThemeManager.isUseFontIconForImage()) imageUrl = "z-icon-Product"; else @@ -214,7 +221,7 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value } else { - popupMenu = new WEditorPopupMenu(true, true, isShowPreference(), false, false, false, lookup); + popupMenu = new WEditorPopupMenu(true, true, isShowPreference(), false, false, false, enableDrill, lookup); if (ThemeManager.isUseFontIconForImage()) imageUrl = "z-icon-More"; else @@ -434,6 +441,10 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value { WFieldRecordInfo.start(gridField); } + else if (WEditorPopupMenu.DRILL_EVENT.equals(evt.getContextEvent())) + { + actionDrill(); + } // } @@ -493,7 +504,20 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value resetButtonState(); } // actionText - + protected void actionDrill() { + if(getGridField() == null || getGridField().getGridTab() == null) + return; + + if(!m_keyColumnName.endsWith("_ID")) + return; + MQuery query = new MQuery(m_tableName); + query.addRestriction(m_keyColumnName, MQuery.EQUAL, value); + int windowNo = getGridField().getGridTab().getWindowNo(); + DrillData data = new DrillData(query, m_keyColumnName, value, null, null); + + AEnv.actionDrill(data, windowNo); + } + protected void resetButtonState() { getComponent().getButton().setEnabled(true); if (ThemeManager.isUseFontIconForImage()) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WTableDirEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WTableDirEditor.java index b37255d06d..af3b7f18a7 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WTableDirEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WTableDirEditor.java @@ -37,6 +37,7 @@ import org.adempiere.webui.component.Combobox; import org.adempiere.webui.event.ContextMenuEvent; import org.adempiere.webui.event.ContextMenuListener; import org.adempiere.webui.event.DialogEvents; +import org.adempiere.webui.event.DrillEvent.DrillData; import org.adempiere.webui.event.ValueChangeEvent; import org.adempiere.webui.grid.AbstractWQuickEntry; import org.adempiere.webui.theme.ThemeManager; @@ -51,6 +52,7 @@ import org.compiere.model.MColumn; import org.compiere.model.MLocation; import org.compiere.model.MLocator; import org.compiere.model.MLookup; +import org.compiere.model.MQuery; import org.compiere.model.MRole; import org.compiere.model.MSysConfig; import org.compiere.model.MTable; @@ -108,6 +110,8 @@ ContextMenuListener, IZoomableEditor private Lookup lookup; private Object oldValue; + private String m_tableName = null; + private String m_keyColumnName = null; public static final String SHORT_LIST_EVENT = "SHORT_LIST"; // IDEMPIERE 90 protected boolean onlyShortListItems; // IDEMPIERE 90 @@ -249,11 +253,15 @@ ContextMenuListener, IZoomableEditor int posPoint = tableName_temp.indexOf("."); String tableName = tableName_temp.substring(0, posPoint); + boolean enableDrill = false; + if(getGridField() != null && getGridField().getGridTab() != null && getGridField().getColumnName().endsWith("_ID") + && MRole.getDefault().isCanReport(getGridField().getGridTab().getAD_Table_ID())) + enableDrill = true; if (tableName.toUpperCase().equals("C_BPARTNER_LOCATION")) { - popupMenu = new WEditorPopupMenu(true, true, isShowPreference(), false, false, true, lookup); + popupMenu = new WEditorPopupMenu(true, true, isShowPreference(), false, false, true, enableDrill, lookup); } else { - popupMenu = new WEditorPopupMenu(zoom, true, isShowPreference(), false, false, false, lookup); + popupMenu = new WEditorPopupMenu(zoom, true, isShowPreference(), false, false, false, enableDrill, lookup); } addChangeLogMenu(popupMenu); @@ -655,6 +663,49 @@ ContextMenuListener, IZoomableEditor return lookup; } + protected void actionDrill() { + if(getGridField() == null || getGridField().getGridTab() == null) + return; + if(m_tableName == null) + setTableAndKeyColumn(); + if(m_keyColumnName == null) + m_keyColumnName = getGridField().getColumnName(); + if(!m_keyColumnName.endsWith("_ID")) + return; + MQuery query = new MQuery(m_tableName); + query.addRestriction(m_keyColumnName, MQuery.EQUAL, oldValue); + int windowNo = getGridField().getGridTab().getWindowNo(); + DrillData data = new DrillData(query, m_keyColumnName, oldValue, null, null); + + AEnv.actionDrill(data, windowNo); + } + + /** + * Sets m_tableName and m_keyColumnName + */ + private void setTableAndKeyColumn() { + if (lookup != null && lookup instanceof MLookup) { + // foreign table defined in lookup + m_keyColumnName = ((MLookup)lookup).getColumnName(); + if (m_keyColumnName.contains(".")) { + m_tableName = m_keyColumnName.substring(0, m_keyColumnName.indexOf(".")); + m_keyColumnName = m_keyColumnName.substring(m_keyColumnName.indexOf(".")+1); + } else { + m_tableName = m_keyColumnName.substring(0, m_keyColumnName.length()-3); + } + } else if (getGridField() != null && getGridField().getGridTab() != null && getGridField().getAD_Column_ID() > 0) { + // field - this editor comes from a window, when it comes from process parameter it doesn't have a gridtab + MColumn column = MColumn.get(Env.getCtx(), getGridField().getAD_Column_ID()); + m_tableName = column.getReferenceTableName(); + MTable table = MTable.get(Env.getCtx(), m_tableName); + m_keyColumnName = table.getKeyColumns()[0]; + } else { + // no field - the search editor is defined programatically + m_keyColumnName = getColumnName(); + m_tableName = m_keyColumnName.substring(0, m_keyColumnName.length()-3); + } + } + /** * Action - Special Quick Entry Screen * @param newRecord true if new record should be created @@ -775,6 +826,10 @@ ContextMenuListener, IZoomableEditor getLabel().setText(">" + champ + "<"); } } + else if (WEditorPopupMenu.DRILL_EVENT.equals(evt.getContextEvent())) + { + actionDrill(); + } // IDEMPIERE 90 } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java index 6fb154bd48..dd568f218f 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java @@ -41,12 +41,10 @@ import org.adempiere.util.Callback; import org.adempiere.util.ContextRunnable; import org.adempiere.webui.ClientInfo; import org.adempiere.webui.Extensions; -import org.adempiere.webui.ISupportMask; import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.apps.BusyDialog; import org.adempiere.webui.apps.ProcessModalDialog; -import org.adempiere.webui.apps.WDrillReport; import org.adempiere.webui.apps.WReport; import org.adempiere.webui.apps.form.WReportCustomization; import org.adempiere.webui.component.Checkbox; @@ -816,7 +814,7 @@ public class ZkReportViewer extends Window implements EventListener, ITab DrillEvent de = (DrillEvent) event; if (de.getData() != null && de.getData() instanceof DrillData) { DrillData data = (DrillData) de.getData(); - executeDrill(data, event.getTarget()); + AEnv.actionDrill(data, m_WindowNo); } } @@ -1247,52 +1245,6 @@ public class ZkReportViewer extends Window implements EventListener, ITab private void cmd_render() { postRenderReportEvent(); } - - /** - * Execute Drill to Query - * @param data query - * @param component - */ - private void executeDrill (DrillData data, Component component) - { - int AD_Table_ID = MTable.getTable_ID(data.getQuery().getTableName()); - if (!MRole.getDefault().isCanReport(AD_Table_ID)) - { - Dialog.error(m_WindowNo, "AccessCannotReport", data.getQuery().getTableName()); - return; - } - if (AD_Table_ID != 0) { - WDrillReport drillReport = new WDrillReport(data, component, m_WindowNo); - - Object window = SessionManager.getAppDesktop().findWindow(m_WindowNo); - if (window != null && window instanceof Component && window instanceof ISupportMask){ - final ISupportMask parent = LayoutUtils.showWindowWithMask(drillReport, (Component)window, LayoutUtils.OVERLAP_PARENT); - drillReport.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { - @Override - public void onEvent(Event event) throws Exception { - parent.hideMask(); - } - }); - }else if (window != null && window instanceof Component){ - final Mask mask = LayoutUtils.showWindowWithMask(drillReport, (Component)window, null); - drillReport.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { - @Override - public void onEvent(Event event) throws Exception { - mask.hideMask(); - } - }); - }else{ - // Add proper width width - int width = SessionManager.getAppDesktop().getClientInfo().screenWidth * 42 / 100; - drillReport.setWidth(width + "px"); - drillReport.setPosition("center"); - drillReport.setAttribute(Window.MODE_KEY, Window.MODE_MODAL); - AEnv.showWindow(drillReport); - } - } - else - log.warning("No Table found for " + data.getQuery().getWhereClause(true)); - } // executeDrill /** * Execute Drill to Query @@ -1584,7 +1536,7 @@ public class ZkReportViewer extends Window implements EventListener, ITab } // cmd_reRun protected void setLanguage (){ - if (MClient.get(m_ctx).isMultiLingualDocument() && wLanguage.getValue() != null){ + if (MClient.get(m_ctx).isMultiLingualDocument() && wLanguage != null && wLanguage.getValue() != null){ MLanguage language = new MLanguage (m_ctx, (int)wLanguage.getValue(), null); Language lang = new Language(language.getName(), language.getAD_Language(), language.getLocale()); m_reportEngine.setLanguageID(language.getAD_Language_ID()); diff --git a/org.adempiere.ui/src/org/compiere/print/DrillReportCtl.java b/org.adempiere.ui/src/org/compiere/print/DrillReportCtl.java index 7ee38fcc83..30431a9597 100644 --- a/org.adempiere.ui/src/org/compiere/print/DrillReportCtl.java +++ b/org.adempiere.ui/src/org/compiere/print/DrillReportCtl.java @@ -370,10 +370,11 @@ public class DrillReportCtl { if (m_Query.getColumnName(0).equals(m_Query.getTableName()+"_ID")) { Object vrec = m_Query.getCode(0); if (vrec instanceof Integer) { - Record_ID = ((Integer)m_Query.getCode(0)).intValue(); + Record_ID = ((Integer)vrec).intValue(); } else { try { - Record_ID = Integer.parseInt(m_Query.getCode(0).toString()); + if(vrec != null) + Record_ID = Integer.parseInt(m_Query.getCode(0).toString()); } catch (NumberFormatException e) { log.info(e.getMessage()); }