Show busy dialog while button process is running.

This commit is contained in:
Heng Sin Low 2011-02-07 11:28:32 +08:00
parent 0a0f56134e
commit ac90b69d9e
3 changed files with 143 additions and 42 deletions

View File

@ -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);
}
}

View File

@ -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;
@ -216,6 +222,27 @@ public class WListItemRenderer implements ListitemRenderer, EventListener, Listi
ZkCssHelper.appendStyle(listcell, "text-align:center");
}
else if (field instanceof Number)
{
if (m_tableColumns != null && columnIndex < m_tableColumns.size()
&& m_tableColumns.get(columnIndex).getColumnClass().getName().equals(MImage.class.getName()) && field instanceof Integer)
{
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
{
DecimalFormat format = field instanceof BigDecimal
? DisplayType.getNumberFormat(DisplayType.Amount, AEnv.getLanguage(Env.getCtx()))
@ -242,6 +269,7 @@ public class WListItemRenderer implements ListitemRenderer, EventListener, Listi
ZkCssHelper.appendStyle(listcell, "text-align:right");
}
}
}
else if (field instanceof Timestamp)
{
@ -261,6 +289,24 @@ public class WListItemRenderer implements ListitemRenderer, EventListener, Listi
}
}
else if (field instanceof String)
{
if (m_tableColumns != null && columnIndex < m_tableColumns.size() && m_tableColumns.get(columnIndex).getColumnClass().getName().equals(MImage.class.getName()))
{
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.setValue(field.toString());
if (isCellEditable)
@ -275,6 +321,7 @@ public class WListItemRenderer implements ListitemRenderer, EventListener, Listi
listcell.setLabel(field.toString());
}
}
}
// if ID column make it invisible
else if (field instanceof IDColumn)
{

View File

@ -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,10 +2179,10 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
* @param event
* @see ActionListener#actionPerformed(ActionEvent)
*/
public void actionPerformed(ActionEvent event)
{
if (event.getSource() instanceof WButtonEditor)
public void actionPerformed(final ActionEvent event)
{
Runnable runnable = new Runnable() {
public void run() {
String error = processButtonCallout((WButtonEditor)event.getSource());
if (error != null && error.trim().length() > 0)
{
@ -2190,6 +2191,9 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
}
actionButton((WButtonEditor)event.getSource());
}
};
BusyDialogTemplate template = new BusyDialogTemplate(runnable);
template.run();
}
/**************************************************************************