Custom form enhancement:

* Use custom progress dialog with adempiere localization support
* Cleanup eclipse editor warnings
* Remove use of background thread ( serverpush ) to reduce resource usage and for slight performance improvement
* Use zk's native WrongValueException for mandatory field error

Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2979740
This commit is contained in:
Heng Sin Low 2010-03-31 03:28:30 +00:00
parent ec3939024f
commit 7fc78215a4
5 changed files with 94 additions and 130 deletions

View File

@ -25,7 +25,6 @@ import java.util.logging.Level;
import org.adempiere.webui.component.Button;
import org.adempiere.webui.component.Checkbox;
import org.adempiere.webui.component.Column;
import org.adempiere.webui.component.ConfirmPanel;
import org.adempiere.webui.component.Grid;
import org.adempiere.webui.component.GridFactory;
@ -46,6 +45,7 @@ import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.Util;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
@ -80,13 +80,9 @@ public class WCharge extends Charge implements IFormController, EventListener
/** Logger. */
private static CLogger log = CLogger.getCLogger(WCharge.class);
private ListModelTable model;
// new panel
/** Grid for components for creating a new charge account. */
private Grid m_grdNew = GridFactory.newGridLayout();
/** Title of new charge account grid. */
private Column m_clmNewTitle = new Column();
/** Value (key) field label. */
private Label m_lblValue = new Label();
/** Field for specifying value (key) of new account. */
@ -103,8 +99,6 @@ public class WCharge extends Charge implements IFormController, EventListener
// account panel
/** Grid for components for creating a charge form a selected account. **/
private Panel m_pnlAccount = new Panel();
/** Title of account grid. */
private Column m_clmAccountTitle = new Column();
/** Button to create charge from selected account. */
private Button m_btnAccount = new Button();
/** Table to hold data of accounts. */
@ -386,7 +380,6 @@ public class WCharge extends Charge implements IFormController, EventListener
*/
private void createNew()
{
final String backgroundColorStyle = "background-color:";
String value;
String name;
@ -395,17 +388,13 @@ public class WCharge extends Charge implements IFormController, EventListener
value = m_txbValueField.getValue();
if (value.length() == 0)
{
/* m_txbValueField.setStyle(backgroundColorStyle
+ ZkCssHelper.createHexColorString(AdempierePLAF.getFieldBackground_Error()));*/
return;
throw new WrongValueException(m_txbValueField, Msg.getMsg(Env.getCtx(), "FillMandatory") + m_lblValue.getValue());
}
name = m_txbNameField.getText();
if (name.length() == 0)
{
/* m_txbNameField.setStyle(backgroundColorStyle
+ ZkCssHelper.createHexColorString(AdempierePLAF.getFieldBackground_Error()));*/
return;
throw new WrongValueException(m_txbNameField, Msg.getMsg(Env.getCtx(), "FillMandatory") + m_lblName.getValue());
}
// Create Element

View File

@ -21,6 +21,7 @@ import java.util.logging.Level;
import org.adempiere.webui.LayoutUtils;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.apps.BusyDialog;
import org.adempiere.webui.component.ConfirmPanel;
import org.adempiere.webui.component.DesktopTabpanel;
import org.adempiere.webui.component.Grid;
@ -52,8 +53,6 @@ import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.zkoss.zk.au.out.AuEcho;
import org.zkoss.zk.ui.DesktopUnavailableException;
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;
@ -84,14 +83,13 @@ public class WGenForm extends ADForm implements EventListener, WTableModelListen
private Tabbox tabbedPane = new Tabbox();
private Borderlayout selPanel = new Borderlayout();
private Grid selNorthPanel = GridFactory.newGridLayout();
// private FlowLayout northPanelLayout = new FlowLayout();
private ConfirmPanel confirmPanelSel = new ConfirmPanel(true);
private ConfirmPanel confirmPanelGen = new ConfirmPanel(false, true, false, false, false, false, false);
private StatusBarPanel statusBar = new StatusBarPanel();
private Borderlayout genPanel = new Borderlayout();
private Html info = new Html();
// private JScrollPane scrollPane = new JScrollPane();
private WListbox miniTable = ListboxFactory.newDataTable();
private BusyDialog progressWindow;
private int[] m_ids;
@ -284,36 +282,23 @@ public class WGenForm extends ADForm implements EventListener, WTableModelListen
{
info.setContent(genForm.generate());
// Execute Process
if (!getDesktop().isServerPushEnabled())
getDesktop().enableServerPush(true);
this.lockUI();
final ProcessCtl worker = new ProcessCtl(null, getWindowNo(), genForm.getProcessInfo(), genForm.getTrx());
Runnable runnable = new Runnable() {
public void run() {
//get full control of desktop
org.zkoss.zk.ui.Desktop desktop = WGenForm.this.getDesktop();
try {
Executions.activate(desktop);
try {
worker.run(); // complete tasks in unlockUI / generateShipments_complete
} finally{
unlockUI();
//release full control of desktop
Executions.deactivate(desktop);
}
} catch (DesktopUnavailableException e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
} catch (InterruptedException e) {
log.log(Level.WARNING, e.getLocalizedMessage(), e);
}
}
};
new Thread(runnable).start();
//
Clients.response(new AuEcho(this, "runProcess", null));
} // generate
/**
* Internal use, don't call this directly
*/
public void runProcess()
{
final ProcessCtl worker = new ProcessCtl(null, getWindowNo(), genForm.getProcessInfo(), genForm.getTrx());
try {
worker.run(); // complete tasks in unlockUI / generateShipments_complete
} finally{
unlockUI();
}
}
/**
* Complete generating shipments.
* Called from Unlock UI
@ -321,7 +306,10 @@ public class WGenForm extends ADForm implements EventListener, WTableModelListen
*/
private void generateComplete ()
{
Clients.showBusy(null, false);
if (progressWindow != null) {
progressWindow.dispose();
progressWindow = null;
}
// Switch Tabs
tabbedPane.setSelectedIndex(1);
@ -415,7 +403,9 @@ public class WGenForm extends ADForm implements EventListener, WTableModelListen
*/
public void lockUI ()
{
Clients.showBusy("Processing...", true);
progressWindow = new BusyDialog();
progressWindow.setPage(this.getPage());
progressWindow.doHighlighted();
} // lockUI
/**

View File

@ -17,9 +17,6 @@
package org.adempiere.webui.apps.form;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.logging.Level;
@ -51,9 +48,7 @@ import org.compiere.apps.form.Match;
import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn;
import org.compiere.model.MMatchPO;
import org.compiere.model.MRole;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
@ -105,15 +100,7 @@ public class WMatch extends Match
LayoutUtils.addSclass("status-border", statusBar);
//
new Thread()
{
public void run()
{
log.info("Starting ...");
MMatchPO.consolidate(Env.getCtx());
log.info("... Done");
}
}.start();
MMatchPO.consolidate(Env.getCtx());
cmd_matchTo();
}
catch(Exception e)
@ -149,8 +136,6 @@ public class WMatch extends Match
private static final int I_MATCHED = 7;
private StringBuffer m_sql = null;
private String m_groupBy = "";
private BigDecimal m_xMatched = Env.ZERO;
private BigDecimal m_xMatchedTo = Env.ZERO;
@ -186,17 +171,14 @@ public class WMatch extends Match
private Button bProcess = new Button();
private Panel centerPanel = new Panel();
private Borderlayout centerLayout = new Borderlayout();
// private JScrollPane xMatchedScrollPane = new JScrollPane();
private Label xMatchedBorder = new Label("xMatched");
private WListbox xMatchedTable = ListboxFactory.newDataTable();
// private JScrollPane xMatchedToScrollPane = new JScrollPane();
private Label xMatchedToBorder = new Label("xMatchedTo");
private WListbox xMatchedToTable = ListboxFactory.newDataTable();
private Panel xPanel = new Panel();
private Checkbox sameProduct = new Checkbox();
private Checkbox sameBPartner = new Checkbox();
private Checkbox sameQty = new Checkbox();
// private FlowLayout xLayout = new FlowLayout(FlowLayout.CENTER, 10, 0);
/**
* Static Init.
@ -233,17 +215,12 @@ public class WMatch extends Match
differenceLabel.setText(Msg.translate(Env.getCtx(), "Difference"));
bProcess.setLabel(Msg.translate(Env.getCtx(), "Process"));
centerPanel.appendChild(centerLayout);
// xMatchedScrollPane.setBorder(xMatchedBorder);
// xMatchedScrollPane.setPreferredSize(new Dimension(450, 200));
// xMatchedToScrollPane.setBorder(xMatchedToBorder);
// xMatchedToScrollPane.setPreferredSize(new Dimension(450, 200));
sameProduct.setSelected(true);
sameProduct.setText(Msg.translate(Env.getCtx(), "SameProduct"));
sameBPartner.setSelected(true);
sameBPartner.setText(Msg.translate(Env.getCtx(), "SameBPartner"));
sameQty.setSelected(false);
sameQty.setText(Msg.translate(Env.getCtx(), "SameQty"));
// xPanel.setLayout(xLayout);
North north = new North();
mainLayout.appendChild(north);
@ -558,31 +535,6 @@ public class WMatch extends Match
} // tableChanged
/**
* Fill the table using m_sql
* @param table table
*/
private void tableLoad (WListbox table)
{
// log.finest(m_sql + " - " + m_groupBy);
String sql = MRole.getDefault().addAccessSQL(
m_sql.toString(), "hdr", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO)
+ m_groupBy;
log.finest(sql);
try
{
Statement stmt = DB.createStatement();
ResultSet rs = stmt.executeQuery(sql);
table.loadTable(rs);
stmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
} // tableLoad
public ADForm getForm() {
return form;
}

View File

@ -18,6 +18,7 @@ package org.adempiere.webui.apps.form;
import java.util.logging.Level;
import org.adempiere.webui.apps.BusyDialog;
import org.adempiere.webui.component.ConfirmPanel;
import org.adempiere.webui.component.Grid;
import org.adempiere.webui.component.GridFactory;
@ -29,7 +30,6 @@ import org.adempiere.webui.editor.WEditor;
import org.adempiere.webui.editor.WSearchEditor;
import org.adempiere.webui.editor.WTableDirEditor;
import org.adempiere.webui.panel.ADForm;
import org.adempiere.webui.panel.CustomForm;
import org.adempiere.webui.panel.IFormController;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.window.FDialog;
@ -40,9 +40,6 @@ import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.zkoss.zk.au.out.AuEcho;
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.DesktopUnavailableException;
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.util.Clients;
@ -64,7 +61,7 @@ public class WMerge extends Merge implements IFormController, EventListener
*/
private static final long serialVersionUID = 5797395051958101596L;
private CustomForm form = new CustomForm();
private WMergeUI form;
private Label[] m_label = null;
private WEditor[] m_from = null;
@ -78,6 +75,9 @@ public class WMerge extends Merge implements IFormController, EventListener
private ConfirmPanel confirmPanel = new ConfirmPanel(true);
private String m_msg;
private boolean m_success;
private BusyDialog progressWindow;
private MergeRunnable runnable;
/**
* Initialize Panel
@ -88,7 +88,7 @@ public class WMerge extends Merge implements IFormController, EventListener
try
{
preInit();
jbInit ();
zkInit ();
}
catch (Exception ex)
{
@ -144,8 +144,9 @@ public class WMerge extends Merge implements IFormController, EventListener
* Static init
* @throws java.lang.Exception
*/
void jbInit () throws Exception
void zkInit () throws Exception
{
form = new WMergeUI(this);
form.appendChild (mainLayout);
mainLayout.setHeight("100%");
mainLayout.setWidth("100%");
@ -242,48 +243,39 @@ public class WMerge extends Merge implements IFormController, EventListener
updateDeleteTable(columnName);
Clients.showBusy("Processing...", true);
progressWindow = new BusyDialog();
progressWindow.setPage(form.getPage());
progressWindow.doHighlighted();
if (!form.getDesktop().isServerPushEnabled())
form.getDesktop().enableServerPush(true);
MergeRunnable runnable = new MergeRunnable(columnName, from_ID, to_ID, form.getDesktop());
new Thread(runnable).start();
runnable = new MergeRunnable(columnName, from_ID, to_ID);
Clients.response(new AuEcho(form, "runProcess", null));
} // actionPerformed
class MergeRunnable implements Runnable {
private int to_ID;
private int from_ID;
private String columnName;
private Desktop desktop;
private MergeRunnable(String columnName, int from_ID, int to_ID, Desktop desktop) {
private MergeRunnable(String columnName, int from_ID, int to_ID) {
this.columnName = columnName;
this.from_ID = from_ID;
this.to_ID = to_ID;
this.desktop = desktop;
}
public void run() {
//get full control of desktop
try {
Executions.activate(desktop);
try {
m_success = merge (columnName, from_ID, to_ID);
postMerge(columnName, to_ID);
} finally{
Clients.showBusy(null, false);
Clients.response(new AuEcho(form, "onAfterProcess", null));
//release full control of desktop
Executions.deactivate(desktop);
}
} catch (DesktopUnavailableException e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
} catch (InterruptedException e) {
log.log(Level.WARNING, e.getLocalizedMessage(), e);
}
try {
m_success = merge (columnName, from_ID, to_ID);
postMerge(columnName, to_ID);
} finally{
Clients.showBusy(null, false);
Clients.response(new AuEcho(form, "onAfterProcess", null));
}
}
}
public void runProcess()
{
runnable.run();
}
public void onAfterProcess()
{
if (m_success)

View File

@ -0,0 +1,41 @@
/******************************************************************************
* Copyright (C) 2010 Low Heng Sin *
* Copyright (C) 2010 Idalica Corporation *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.adempiere.webui.apps.form;
import org.adempiere.webui.panel.CustomForm;
/**
*
* @author hengsin
*
*/
public class WMergeUI extends CustomForm {
private static final long serialVersionUID = -8576926702378868806L;
private WMerge m_merge;
public WMergeUI(WMerge merge) {
super();
m_merge = merge;
}
public void runProcess() {
m_merge.runProcess();
}
public void onAfterProcess() {
m_merge.onAfterProcess();
}
}