From ac90b69d9e29a39645cd17088b82df588c905a08 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Mon, 7 Feb 2011 11:28:32 +0800 Subject: [PATCH] Show busy dialog while button process is running. --- .../webui/apps/BusyDialogTemplate.java | 50 ++++++++ .../webui/component/WListItemRenderer.java | 107 +++++++++++++----- .../webui/panel/AbstractADWindowPanel.java | 28 +++-- 3 files changed, 143 insertions(+), 42 deletions(-) create mode 100644 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/BusyDialogTemplate.java diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/BusyDialogTemplate.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/BusyDialogTemplate.java new file mode 100644 index 0000000000..385e85617a --- /dev/null +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/BusyDialogTemplate.java @@ -0,0 +1,50 @@ +package org.adempiere.webui.apps; + +import org.adempiere.webui.component.Window; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.EventListener; +import org.zkoss.zk.ui.event.Events; + +public class BusyDialogTemplate implements Runnable, EventListener { + + private static final String EVENT_NAME = "onRun"; + + private Runnable runnable; + + private BusyDialog busyDialog; + + public BusyDialogTemplate(Runnable runnable) { + this.runnable = runnable; + } + + private void hideBusyDialog() { + if (busyDialog != null) + { + busyDialog.dispose(); + busyDialog = null; + } + } + + private void showBusyDialog() { + busyDialog = new BusyDialog(); + busyDialog.setAttribute(Window.MODE_KEY, Window.MODE_HIGHLIGHTED); + AEnv.showCenterScreen(busyDialog); + } + + public void onEvent(Event event) throws Exception { + try { + if (event.getName().equals(EVENT_NAME)) { + runnable.run(); + } + } finally { + hideBusyDialog(); + } + } + + public void run() { + showBusyDialog(); + + busyDialog.addEventListener(EVENT_NAME, this); + Events.echoEvent(EVENT_NAME, busyDialog, null); + } +} diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/WListItemRenderer.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/WListItemRenderer.java index 613a5d51e1..870a0addaf 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/WListItemRenderer.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/WListItemRenderer.java @@ -17,7 +17,10 @@ package org.adempiere.webui.component; +import java.io.IOException; import java.math.BigDecimal; +import java.net.MalformedURLException; +import java.net.URL; import java.sql.Timestamp; import java.text.DecimalFormat; import java.text.SimpleDateFormat; @@ -32,15 +35,18 @@ import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.event.TableValueChangeEvent; import org.adempiere.webui.event.TableValueChangeListener; import org.compiere.minigrid.IDColumn; +import org.compiere.model.MImage; import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.MSort; import org.compiere.util.Util; +import org.zkoss.image.AImage; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; import org.zkoss.zul.Decimalbox; +import org.zkoss.zul.Image; import org.zkoss.zul.ListModel; import org.zkoss.zul.Listbox; import org.zkoss.zul.Listcell; @@ -217,29 +223,51 @@ public class WListItemRenderer implements ListitemRenderer, EventListener, Listi } else if (field instanceof Number) { - DecimalFormat format = field instanceof BigDecimal - ? DisplayType.getNumberFormat(DisplayType.Amount, AEnv.getLanguage(Env.getCtx())) - : DisplayType.getNumberFormat(DisplayType.Integer, AEnv.getLanguage(Env.getCtx())); - - // set cell value to allow sorting - listcell.setValue(field.toString()); - - if (isCellEditable) + if (m_tableColumns != null && columnIndex < m_tableColumns.size() + && m_tableColumns.get(columnIndex).getColumnClass().getName().equals(MImage.class.getName()) && field instanceof Integer) { - NumberBox numberbox = new NumberBox(false); - numberbox.setFormat(format); - numberbox.setValue(field); - numberbox.setWidth("100px"); - numberbox.setEnabled(true); - numberbox.setStyle("text-align:right; " - + listcell.getStyle()); - numberbox.addEventListener(Events.ON_CHANGE, this); - listcell.appendChild(numberbox); + MImage mImage = MImage.get(Env.getCtx(), (Integer) field); + AImage img = null; + byte[] data = mImage.getData(); + if (data != null && data.length > 0) { + try { + img = new AImage(null, data); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + Image image = new Image(); + image.setContent(img); + image.setStyle("width: 48px; height: 48px;"); + listcell.appendChild(image); + listcell.setStyle("text-align: center;"); } else { - listcell.setLabel(format.format(((Number)field).doubleValue())); - ZkCssHelper.appendStyle(listcell, "text-align:right"); + DecimalFormat format = field instanceof BigDecimal + ? DisplayType.getNumberFormat(DisplayType.Amount, AEnv.getLanguage(Env.getCtx())) + : DisplayType.getNumberFormat(DisplayType.Integer, AEnv.getLanguage(Env.getCtx())); + + // set cell value to allow sorting + listcell.setValue(field.toString()); + + if (isCellEditable) + { + NumberBox numberbox = new NumberBox(false); + numberbox.setFormat(format); + numberbox.setValue(field); + numberbox.setWidth("100px"); + numberbox.setEnabled(true); + numberbox.setStyle("text-align:right; " + + listcell.getStyle()); + numberbox.addEventListener(Events.ON_CHANGE, this); + listcell.appendChild(numberbox); + } + else + { + listcell.setLabel(format.format(((Number)field).doubleValue())); + ZkCssHelper.appendStyle(listcell, "text-align:right"); + } } } else if (field instanceof Timestamp) @@ -262,17 +290,36 @@ public class WListItemRenderer implements ListitemRenderer, EventListener, Listi } else if (field instanceof String) { - listcell.setValue(field.toString()); - if (isCellEditable) + if (m_tableColumns != null && columnIndex < m_tableColumns.size() && m_tableColumns.get(columnIndex).getColumnClass().getName().equals(MImage.class.getName())) { - Textbox textbox = new Textbox(); - textbox.setValue(field.toString()); - textbox.addEventListener(Events.ON_CHANGE, this); - listcell.appendChild(textbox); + try { + URL url = new URL(field.toString()); + AImage aImage = new AImage(url); + Image image = new Image(); + image.setContent(aImage); + image.setStyle("width: 48px; height: 48px;"); + listcell.appendChild(image); + listcell.setStyle("text-align: center;"); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } } else { - listcell.setLabel(field.toString()); + listcell.setValue(field.toString()); + if (isCellEditable) + { + Textbox textbox = new Textbox(); + textbox.setValue(field.toString()); + textbox.addEventListener(Events.ON_CHANGE, this); + listcell.appendChild(textbox); + } + else + { + listcell.setLabel(field.toString()); + } } } // if ID column make it invisible @@ -386,13 +433,13 @@ public class WListItemRenderer implements ListitemRenderer, EventListener, Listi { Comparator ascComparator = getColumnComparator(true, headerIndex); Comparator dscComparator = getColumnComparator(false, headerIndex); - + header = new ListHeader(headerText); - + header.setSort("auto"); header.setSortAscending(ascComparator); header.setSortDescending(dscComparator); - + int width = headerText.trim().length() * 9; if (width > 300) width = 300; @@ -414,7 +461,7 @@ public class WListItemRenderer implements ListitemRenderer, EventListener, Listi } else if (width > 0 && width < 100) width = 100; - + header.setWidth(width + "px"); } m_headers.add(header); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/AbstractADWindowPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/AbstractADWindowPanel.java index ed2e53011b..ce49e3b1cc 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/AbstractADWindowPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/AbstractADWindowPanel.java @@ -33,6 +33,7 @@ import org.adempiere.webui.WArchive; import org.adempiere.webui.WRequest; import org.adempiere.webui.WZoomAcross; import org.adempiere.webui.apps.AEnv; +import org.adempiere.webui.apps.BusyDialogTemplate; import org.adempiere.webui.apps.ProcessModalDialog; import org.adempiere.webui.apps.WReport; import org.adempiere.webui.apps.form.WCreateFromFactory; @@ -2004,7 +2005,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To if (vp.isInitOK()) // may not be allowed { vp.setVisible(true); - AEnv.showWindow(vp); + AEnv.showCenterScreen(vp); } //vp.dispose(); @@ -2028,7 +2029,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To } else { - AEnv.showWindow(win); + AEnv.showCenterScreen(win); if (!win.isStartProcess()) return; @@ -2178,18 +2179,21 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To * @param event * @see ActionListener#actionPerformed(ActionEvent) */ - public void actionPerformed(ActionEvent event) + public void actionPerformed(final ActionEvent event) { - if (event.getSource() instanceof WButtonEditor) - { - String error = processButtonCallout((WButtonEditor)event.getSource()); - if (error != null && error.trim().length() > 0) - { - statusBar.setStatusLine(error, true); - return; + Runnable runnable = new Runnable() { + public void run() { + String error = processButtonCallout((WButtonEditor)event.getSource()); + if (error != null && error.trim().length() > 0) + { + statusBar.setStatusLine(error, true); + return; + } + actionButton((WButtonEditor)event.getSource()); } - actionButton((WButtonEditor)event.getSource()); - } + }; + BusyDialogTemplate template = new BusyDialogTemplate(runnable); + template.run(); } /**************************************************************************