From 5e3c87abce24f6de7b734e84b36468fa1316685e Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Mon, 16 Apr 2012 14:49:23 +0800 Subject: [PATCH] IDEMPIERE-231 Zk6: Improve the tablet experience. Fixed scrolling for home page and ad window ( form and grid ). Fixed can't click on grid row to select current record at ad window. Added file link at the bottom of report preview window as a workaround for iframe scrolling issue at iPad. --- .../adempiere/webui/component/GridPanel.java | 1 + .../webui/component/GridTabRowRenderer.java | 3 +- .../webui/desktop/DefaultDesktop.java | 12 ++- .../webui/desktop/TabbedDesktop.java | 3 + .../org/adempiere/webui/panel/ADTabpanel.java | 14 +++- .../webui/window/ZkReportViewer.java | 78 +++++++++++++++---- .../theme/default/css/theme.css.dsp | 15 ++++ 7 files changed, 106 insertions(+), 20 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/GridPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/GridPanel.java index 4631d8aa1b..af9b041f85 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/GridPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/GridPanel.java @@ -334,6 +334,7 @@ public class GridPanel extends Borderlayout implements EventListener Center center = new Center(); center.appendChild(listbox); + LayoutUtils.addSclass("mobile-scrolling", center); this.appendChild(center); if (pageSize > 0) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/GridTabRowRenderer.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/GridTabRowRenderer.java index b045a6e35d..b2ffcf0b36 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/GridTabRowRenderer.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/GridTabRowRenderer.java @@ -387,7 +387,7 @@ public class GridTabRowRenderer implements RowRenderer, RowRendererExt colIndex ++; Div div = new Div(); - String divStyle = "border: none; width: 100%; height: 100%;"; + String divStyle = "border: none; width: 100%; height: 100%; cursor: pointer;"; org.zkoss.zul.Column column = (org.zkoss.zul.Column) columns.getChildren().get(colIndex); if (column.isVisible()) { Component component = getDisplayComponent(rowIndex, currentValues[i], gridField[i]); @@ -406,6 +406,7 @@ public class GridTabRowRenderer implements RowRenderer, RowRendererExt div.addEventListener(Events.ON_CLICK, rowListener); div.addEventListener(Events.ON_DOUBLE_CLICK, rowListener); row.addEventListener(Events.ON_CLICK, rowListener); + row.setStyle("cursor:pointer"); row.appendChild(div); } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DefaultDesktop.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DefaultDesktop.java index 4016d89abc..f599144dca 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DefaultDesktop.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DefaultDesktop.java @@ -21,6 +21,7 @@ import java.io.Serializable; import java.util.Properties; import org.adempiere.util.ServerContext; +import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.apps.BusyDialog; import org.adempiere.webui.component.Tabpanel; import org.adempiere.webui.component.ToolBarButton; @@ -181,14 +182,17 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria { homeTab.getChildren().clear(); + homeTab.addEventListener("onAddMobileScrolling", this); //register as 0 registerWindow(homeTab); - dashboardController.render(homeTab, this); + dashboardController.render(homeTab, this); + + Events.echoEvent("onAddMobileScrolling", homeTab, null); } - public void onEvent(Event event) + public void onEvent(Event event) { Component comp = event.getTarget(); String eventName = event.getName(); @@ -206,6 +210,10 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria } } } + else if (eventName.equals("onAddMobileScrolling")) + { + LayoutUtils.addSclass("mobile-scrolling", homeTab); + } } public void onServerPush(ServerPushTemplate template) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/TabbedDesktop.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/TabbedDesktop.java index 34f293d519..3365cd40c6 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/TabbedDesktop.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/TabbedDesktop.java @@ -23,6 +23,7 @@ import org.adempiere.webui.component.Tabpanel; import org.adempiere.webui.component.Window; import org.adempiere.webui.panel.ADForm; import org.adempiere.webui.part.WindowContainer; +import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.window.ADWindow; import org.adempiere.webui.window.WTask; import org.compiere.model.MQuery; @@ -110,6 +111,7 @@ public abstract class TabbedDesktop extends AbstractDesktop { ADWindow adWindow = new ADWindow(Env.getCtx(), windowId); DesktopTabpanel tabPanel = new DesktopTabpanel(); + tabPanel.setPage(SessionManager.getAppDesktop().getComponent().getPage()); if (adWindow.createPart(tabPanel) != null) { preOpenNewTab(); windowContainer.addWindow(tabPanel, adWindow.getTitle(), true); @@ -130,6 +132,7 @@ public abstract class TabbedDesktop extends AbstractDesktop { ADWindow adWindow = new ADWindow(Env.getCtx(), windowId, query); DesktopTabpanel tabPanel = new DesktopTabpanel(); + tabPanel.setPage(SessionManager.getAppDesktop().getComponent().getPage()); if (adWindow.createPart(tabPanel) != null) { preOpenNewTab(); windowContainer.addWindow(tabPanel, adWindow.getTitle(), true); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADTabpanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADTabpanel.java index 9d3c23f1e3..932e752f23 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADTabpanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADTabpanel.java @@ -172,7 +172,7 @@ DataStatusListener, IADTabpanel, VetoableChangeListener grid.setVflex(true); grid.setStyle("margin:0; padding:0; position: absolute"); grid.makeNoStrip(); - + listPanel = new GridPanel(); listPanel.getListbox().addEventListener(Events.ON_DOUBLE_CLICK, this); } @@ -222,11 +222,19 @@ DataStatusListener, IADTabpanel, VetoableChangeListener formComponent = layout; treePanel.getTree().addEventListener(Events.ON_SELECT, this); + + LayoutUtils.addSclass("mobile-scrolling", west); + LayoutUtils.addSclass("mobile-scrolling", center); } else { - this.appendChild(grid); - formComponent = grid; + Div div = new Div(); + div.setStyle("width:100%;height:100%;border:none;margin:none;padding:none"); + div.appendChild(grid); + this.appendChild(div); + formComponent = div; + + LayoutUtils.addSclass("mobile-scrolling", div); } this.appendChild(listPanel); listPanel.setVisible(false); 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 70b2e98084..e99c959f97 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 @@ -26,6 +26,8 @@ import java.util.List; import java.util.Properties; import java.util.logging.Level; +import javax.servlet.http.HttpServletRequest; + import org.adempiere.exceptions.AdempiereException; import org.adempiere.pdf.Document; import org.adempiere.webui.apps.AEnv; @@ -62,11 +64,14 @@ import org.compiere.util.Env; import org.compiere.util.KeyNamePair; import org.compiere.util.Msg; import org.zkoss.util.media.AMedia; +import org.zkoss.util.media.Media; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; +import org.zkoss.zk.ui.ext.render.DynamicMedia; +import org.zkoss.zul.A; import org.zkoss.zul.Borderlayout; import org.zkoss.zul.Center; import org.zkoss.zul.North; @@ -77,10 +82,13 @@ import org.zkoss.zul.Iframe; import org.zkoss.zul.Listitem; import org.zkoss.zul.Menuitem; import org.zkoss.zul.Separator; +import org.zkoss.zul.South; import org.zkoss.zul.Tab; import org.zkoss.zul.Toolbar; import org.zkoss.zul.Toolbarbutton; import org.zkoss.zul.Vbox; +import org.zkoss.zul.impl.Utils; +import org.zkoss.zul.impl.XulElement; /** @@ -100,7 +108,7 @@ import org.zkoss.zul.Vbox; * * @author Low Heng Sin */ -public class ZkReportViewer extends Window implements EventListener, ITabOnCloseHandler { +public class ZkReportViewer extends Window implements EventListener, ITabOnCloseHandler { /** * */ @@ -146,6 +154,11 @@ public class ZkReportViewer extends Window implements EventListener, ITabOnClose private ConfirmPanel confirmPanel = new ConfirmPanel(true); private Listbox cboType = new Listbox(); private Checkbox summary = new Checkbox(); + + private AMedia media; + private int mediaVersion = 0; + +private A reportLink; /** * Static Layout @@ -154,6 +167,8 @@ public class ZkReportViewer extends Window implements EventListener, ITabOnClose public ZkReportViewer(ReportEngine re, String title) { super(); + setPage(SessionManager.getAppDesktop().getComponent().getPage()); + log.info(""); m_WindowNo = SessionManager.getAppDesktop().registerWindow(this); Env.setContext(re.getCtx(), m_WindowNo, "_WinInfo_IsReportViewer", "Y"); @@ -189,6 +204,7 @@ public class ZkReportViewer extends Window implements EventListener, ITabOnClose this.setStyle("width: 100%; height: 100%; position: absolute; border:none; padding:none; margin:none;"); toolBar.setHeight("26px"); + toolBar.setWidth("100%"); previewType.setMold("select"); previewType.appendItem("PDF", "PDF"); @@ -267,19 +283,27 @@ public class ZkReportViewer extends Window implements EventListener, ITabOnClose bRefresh.setTooltiptext(Msg.getMsg(Env.getCtx(), "Refresh")); toolBar.appendChild(bRefresh); bRefresh.addEventListener(Events.ON_CLICK, this); - + North north = new North(); layout.appendChild(north); north.appendChild(toolBar); - + Center center = new Center(); center.setFlex(true); layout.appendChild(center); iframe = new Iframe(); iframe.setId("reportFrame"); - iframe.addEventListener(Events.ON_CLICK, this); - iframe.addEventListener(Events.ON_RIGHT_CLICK, this); center.appendChild(iframe); + + South south = new South(); + south.setHeight("22px"); + layout.appendChild(south); + reportLink = new A(); + reportLink.setTarget("_blank"); + Div linkDiv = new Div(); + linkDiv.setStyle("width:100%; height: 20px"); + linkDiv.appendChild(reportLink); + south.appendChild(linkDiv); try { renderReport(); @@ -291,7 +315,7 @@ public class ZkReportViewer extends Window implements EventListener, ITabOnClose this.setBorder("normal"); - this.addEventListener("onZoom", new EventListener() { + this.addEventListener("onZoom", new EventListener() { public void onEvent(Event event) throws Exception { if (event instanceof ZoomEvent) { @@ -304,7 +328,7 @@ public class ZkReportViewer extends Window implements EventListener, ITabOnClose } }); - this.addEventListener(DrillEvent.ON_DRILL_ACROSS, new EventListener() { + this.addEventListener(DrillEvent.ON_DRILL_ACROSS, new EventListener() { public void onEvent(Event event) throws Exception { if (event instanceof DrillEvent) { @@ -323,7 +347,7 @@ public class ZkReportViewer extends Window implements EventListener, ITabOnClose } }); - this.addEventListener(DrillEvent.ON_DRILL_DOWN, new EventListener() { + this.addEventListener(DrillEvent.ON_DRILL_DOWN, new EventListener() { public void onEvent(Event event) throws Exception { if (event instanceof DrillEvent) { @@ -339,7 +363,7 @@ public class ZkReportViewer extends Window implements EventListener, ITabOnClose } private void renderReport() throws Exception { - AMedia media = null; + media = null; Listitem selected = previewType.getSelectedItem(); if (selected == null || "PDF".equals(selected.getValue())) { String path = System.getProperty("java.io.tmpdir"); @@ -350,7 +374,7 @@ public class ZkReportViewer extends Window implements EventListener, ITabOnClose } File file = File.createTempFile(prefix, ".pdf", new File(path)); m_reportEngine.createPDF(file); - media = new AMedia(getTitle(), "pdf", "application/pdf", file, true); + media = new AMedia(file.getName(), "pdf", "application/pdf", file, true); } else if ("HTML".equals(previewType.getSelectedItem().getValue())) { String path = System.getProperty("java.io.tmpdir"); String prefix = makePrefix(m_reportEngine.getName()); @@ -360,7 +384,7 @@ public class ZkReportViewer extends Window implements EventListener, ITabOnClose } File file = File.createTempFile(prefix, ".html", new File(path)); m_reportEngine.createHTML(file, false, AEnv.getLanguage(Env.getCtx()), new HTMLExtension(Executions.getCurrent().getContextPath(), "rp", this.getUuid())); - media = new AMedia(getTitle(), "html", "text/html", file, false); + media = new AMedia(file.getName(), "html", "text/html", file, false); } else if ("XLS".equals(previewType.getSelectedItem().getValue())) { String path = System.getProperty("java.io.tmpdir"); String prefix = makePrefix(m_reportEngine.getName()); @@ -370,10 +394,21 @@ public class ZkReportViewer extends Window implements EventListener, ITabOnClose } File file = File.createTempFile(prefix, ".xls", new File(path)); m_reportEngine.createXLS(file, AEnv.getLanguage(Env.getCtx())); - media = new AMedia(getTitle(), "xls", "application/vnd.ms-excel", file, true); + media = new AMedia(file.getName(), "xls", "application/vnd.ms-excel", file, true); } + Events.echoEvent("onPreviewReport", this, null); + } + + public void onPreviewReport() { + mediaVersion++; + String url = Utils.getDynamicMediaURI(this, mediaVersion, media.getName(), media.getFormat()); iframe.setContent(media); + HttpServletRequest request = (HttpServletRequest) Executions.getCurrent().getNativeRequest(); + if (url.startsWith(request.getContextPath() + "/")) + url = url.substring((request.getContextPath() + "/").length()); + reportLink.setHref(url); + reportLink.setLabel(media.getName()); } private String makePrefix(String name) { @@ -582,7 +617,7 @@ public class ZkReportViewer extends Window implements EventListener, ITabOnClose { m_reportEngine.setSummary(summary.isSelected()); cmd_report(); - } + } } /************************************************************************** @@ -998,5 +1033,20 @@ public class ZkReportViewer extends Window implements EventListener, ITabOnClose int AD_Window_ID = 240; // hardcoded int AD_PrintFormat_ID = m_reportEngine.getPrintFormat().get_ID(); AEnv.zoom(AD_Window_ID, MQuery.getEqualQuery("AD_PrintFormat_ID", AD_PrintFormat_ID)); - } // cmd_customize + } // cmd_customize + + //-- ComponentCtrl --// + public Object getExtraCtrl() { + return new ExtraCtrl(); + } + /** A utility class to implement {@link #getExtraCtrl}. + * It is used only by component developers. + */ + protected class ExtraCtrl extends XulElement.ExtraCtrl + implements DynamicMedia { + //-- DynamicMedia --// + public Media getMedia(String pathInfo) { + return media; + } + } } diff --git a/org.adempiere.ui.zk/theme/default/css/theme.css.dsp b/org.adempiere.ui.zk/theme/default/css/theme.css.dsp index 6dd78ed549..e6d530ed6c 100644 --- a/org.adempiere.ui.zk/theme/default/css/theme.css.dsp +++ b/org.adempiere.ui.zk/theme/default/css/theme.css.dsp @@ -525,3 +525,18 @@ img.z-group-img-close { background-color: transparent; background-repeat: no-repeat; } + +<%-- Tablet --%> +.mobile-scrolling { + -webkit-overflow-scrolling: touch; +} + +<%-- Tab --%> +.z-tab-close { + top:4px; + margin-right:2px; +} + +.z-tab-hm-close { + padding-right:18px; +}