From 4216a8caed3aa0b79d685dbbf744827ba8d3d927 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Mon, 25 Feb 2013 19:45:07 +0800 Subject: [PATCH] IDEMPIERE-664 Zk: Zoom on empty field should goes to create new record mode. --- .../adempiere/webui/adwindow/BreadCrumb.java | 2 + .../adempiere/webui/editor/WSearchEditor.java | 41 +++++++++++++++++- .../webui/editor/WTableDirEditor.java | 42 ++++++++++++++++++- 3 files changed, 82 insertions(+), 3 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/BreadCrumb.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/BreadCrumb.java index 3c1cc1c0d0..be4f37c88c 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/BreadCrumb.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/BreadCrumb.java @@ -460,6 +460,8 @@ public class BreadCrumb extends Div implements EventListener { } else { + if (text.indexOf("-1/0") >= 0) + text = text.replace("-1/0", "0/0"); btnRecordInfo.setLabel(text); } 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 f9b3b5ef76..741a700843 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 @@ -26,7 +26,9 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.logging.Level; +import org.adempiere.util.Callback; import org.adempiere.webui.ValuePreference; +import org.adempiere.webui.adwindow.ADWindow; import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.component.Searchbox; import org.adempiere.webui.event.ContextMenuEvent; @@ -34,19 +36,24 @@ import org.adempiere.webui.event.ContextMenuListener; import org.adempiere.webui.event.DialogEvents; import org.adempiere.webui.event.ValueChangeEvent; import org.adempiere.webui.event.ValueChangeListener; +import org.adempiere.webui.exception.ApplicationException; import org.adempiere.webui.factory.InfoManager; import org.adempiere.webui.grid.WQuickEntry; import org.adempiere.webui.panel.InfoPanel; +import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.window.WFieldRecordInfo; import org.compiere.model.GridField; +import org.compiere.model.GridTab; import org.compiere.model.Lookup; import org.compiere.model.MLookup; import org.compiere.model.MLookupFactory; +import org.compiere.model.MQuery; 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.Util; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Page; import org.zkoss.zk.ui.event.Event; @@ -270,13 +277,45 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value public void actionZoom() { - AEnv.actionZoom(lookup, getValue()); + if (getValue() == null || Util.isEmpty(getValue().toString())) + { + onNewRecord(); + } + else + { + AEnv.actionZoom(lookup, getValue()); + } } private void actionZoom(Object value) { AEnv.actionZoom(lookup, value); } + private void onNewRecord() { + try + { + MQuery query = new MQuery(""); + query.addRestriction("1=2"); + query.setRecordCount(0); + + SessionManager.getAppDesktop().openWindow(lookup.getZoom(query), query, new Callback() { + @Override + public void onCallback(ADWindow result) { + if(result == null) + return; + + GridTab tab = result.getADWindowContent().getActiveGridTab(); + tab.dataNew(false); + } + }); + } + catch (Exception e) + { + throw new ApplicationException(e.getMessage(), e); + } + + } + public void onMenu(ContextMenuEvent evt) { if (WEditorPopupMenu.REQUERY_EVENT.equals(evt.getContextEvent())) 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 68986a0589..cf2349cb4c 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 @@ -22,20 +22,26 @@ import java.beans.PropertyChangeEvent; import javax.swing.event.ListDataEvent; import javax.swing.event.ListDataListener; +import org.adempiere.util.Callback; import org.adempiere.webui.ValuePreference; +import org.adempiere.webui.adwindow.ADWindow; import org.adempiere.webui.apps.AEnv; 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.ValueChangeEvent; +import org.adempiere.webui.exception.ApplicationException; import org.adempiere.webui.grid.WQuickEntry; +import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.window.WFieldRecordInfo; import org.adempiere.webui.window.WLocationDialog; import org.compiere.model.GridField; +import org.compiere.model.GridTab; import org.compiere.model.Lookup; import org.compiere.model.MBPartnerLocation; import org.compiere.model.MLocation; +import org.compiere.model.MQuery; import org.compiere.model.MTable; import org.compiere.util.CLogger; import org.compiere.util.DisplayType; @@ -149,7 +155,7 @@ ContextMenuListener, IZoomableEditor //no need to refresh readonly lookup if (isReadWrite()) lookup.refresh(); - refreshList(); + refreshList(); } if (gridField != null) @@ -422,7 +428,39 @@ ContextMenuListener, IZoomableEditor */ public void actionZoom() { - AEnv.actionZoom(lookup, getValue()); + if (getValue() == null) + { + onNewRecord(); + } + else + { + AEnv.actionZoom(lookup, getValue()); + } + } + + private void onNewRecord() { + try + { + MQuery query = new MQuery(""); + query.addRestriction("1=2"); + query.setRecordCount(0); + + SessionManager.getAppDesktop().openWindow(lookup.getZoom(query), query, new Callback() { + @Override + public void onCallback(ADWindow result) { + if(result == null) + return; + + GridTab tab = result.getADWindowContent().getActiveGridTab(); + tab.dataNew(false); + } + }); + } + catch (Exception e) + { + throw new ApplicationException(e.getMessage(), e); + } + } /**