From 93bc73c257083cc872cc34d3eb911ef5091a113b Mon Sep 17 00:00:00 2001 From: hengsin Date: Tue, 6 Jul 2021 02:37:28 +0800 Subject: [PATCH] IDEMPIERE-4865 Find window enhancements (#766) --- .../oracle/202107051142_IDEMPIERE-4865.sql | 10 + .../202107051142_IDEMPIERE-4865.sql | 7 + .../src/org/compiere/model/MSysConfig.java | 1 + .../adempiere/webui/window/FindWindow.java | 179 +++++++++++++----- 4 files changed, 149 insertions(+), 48 deletions(-) create mode 100644 migration/i8.2z/oracle/202107051142_IDEMPIERE-4865.sql create mode 100644 migration/i8.2z/postgresql/202107051142_IDEMPIERE-4865.sql diff --git a/migration/i8.2z/oracle/202107051142_IDEMPIERE-4865.sql b/migration/i8.2z/oracle/202107051142_IDEMPIERE-4865.sql new file mode 100644 index 0000000000..8c00adbd6d --- /dev/null +++ b/migration/i8.2z/oracle/202107051142_IDEMPIERE-4865.sql @@ -0,0 +1,10 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Jul 5, 2021, 7:38:10 PM MYT +INSERT INTO AD_SysConfig (AD_SysConfig_ID,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive,Name,Value,Description,EntityType,ConfigurationLevel,AD_SysConfig_UU) VALUES (200176,0,0,TO_DATE('2021-07-05 19:38:10','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2021-07-05 19:38:10','YYYY-MM-DD HH24:MI:SS'),100,100,'Y','ZK_ADVANCE_FIND_FILTER_COLUMN_LIST','N','Y/N - Define if the advance find column list is filter by user input','D','C','cc532902-6f11-40e5-962a-e8af896544e0') +; + +SELECT Register_Migration_Script ('202107051142_IDEMPIERE-4865.sql') FROM DUAL +; + diff --git a/migration/i8.2z/postgresql/202107051142_IDEMPIERE-4865.sql b/migration/i8.2z/postgresql/202107051142_IDEMPIERE-4865.sql new file mode 100644 index 0000000000..87c5accce0 --- /dev/null +++ b/migration/i8.2z/postgresql/202107051142_IDEMPIERE-4865.sql @@ -0,0 +1,7 @@ +-- Jul 5, 2021, 7:38:11 PM MYT +INSERT INTO AD_SysConfig (AD_SysConfig_ID,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive,Name,Value,Description,EntityType,ConfigurationLevel,AD_SysConfig_UU) VALUES (200176,0,0,TO_TIMESTAMP('2021-07-05 19:38:10','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2021-07-05 19:38:10','YYYY-MM-DD HH24:MI:SS'),100,100,'Y','ZK_ADVANCE_FIND_FILTER_COLUMN_LIST','N','Y/N - Define if the advance find column list is filter by user input','D','C','cc532902-6f11-40e5-962a-e8af896544e0') +; + +SELECT Register_Migration_Script ('202107051142_IDEMPIERE-4865.sql') FROM DUAL +; + diff --git a/org.adempiere.base/src/org/compiere/model/MSysConfig.java b/org.adempiere.base/src/org/compiere/model/MSysConfig.java index f4ee1f5156..23dbb41e93 100644 --- a/org.adempiere.base/src/org/compiere/model/MSysConfig.java +++ b/org.adempiere.base/src/org/compiere/model/MSysConfig.java @@ -168,6 +168,7 @@ public class MSysConfig extends X_AD_SysConfig public static final String USER_PASSWORD_HASH = "USER_PASSWORD_HASH"; public static final String VALIDATE_MATCHING_TO_ORDERED_QTY = "VALIDATE_MATCHING_TO_ORDERED_QTY"; public static final String WEBUI_LOGOURL = "WEBUI_LOGOURL"; + public static final String ZK_ADVANCE_FIND_FILTER_COLUMN_LIST = "ZK_ADVANCE_FIND_FILTER_COLUMN_LIST"; public static final String ZK_BROWSER_ICON = "ZK_BROWSER_ICON"; public static final String ZK_BROWSER_TITLE = "ZK_BROWSER_TITLE"; public static final String ZK_BUTTON_STYLE = "ZK_BUTTON_STYLE"; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java index 597132a4bd..051e4ffa20 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java @@ -44,6 +44,7 @@ import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.component.Button; import org.adempiere.webui.component.Column; import org.adempiere.webui.component.Columns; +import org.adempiere.webui.component.ComboItem; import org.adempiere.webui.component.Combobox; import org.adempiere.webui.component.ConfirmPanel; import org.adempiere.webui.component.DatetimeBox; @@ -109,6 +110,7 @@ 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.util.Clients; +import org.zkoss.zul.AbstractListModel; import org.zkoss.zul.Borderlayout; import org.zkoss.zul.Cell; import org.zkoss.zul.Center; @@ -116,8 +118,10 @@ import org.zkoss.zul.Comboitem; import org.zkoss.zul.Datebox; import org.zkoss.zul.Div; import org.zkoss.zul.Hbox; +import org.zkoss.zul.ListModelList; import org.zkoss.zul.North; import org.zkoss.zul.Separator; +import org.zkoss.zul.SimpleListModel; import org.zkoss.zul.South; import org.zkoss.zul.Space; import org.zkoss.zul.Tab; @@ -306,6 +310,8 @@ public class FindWindow extends Window implements EventListener, ValueCha this.setWidgetAttribute(AdempiereWebUI.WIDGET_INSTANCE_NAME, "findWindow"); this.setId("findWindow_"+targetWindowNo); LayoutUtils.addSclass("find-window", this); + + addEventListener(Events.ON_CANCEL, e -> onCancel()); } public boolean initialize() @@ -982,21 +988,32 @@ public class FindWindow extends Window implements EventListener, ValueCha ListItem listItem = new ListItem(); listItem.setId("Row"+ rowCount++); - Listbox listColumn = new Listbox(); + Combobox listColumn = new Combobox(); listColumn.setId("listColumn"+listItem.getId()); listColumn.setName("listColumn"); - listColumn.setMold("select"); - listColumn.setRows(0); listColumn.addEventListener(Events.ON_SELECT,this); ZKUpdateUtil.setHflex(listColumn, "true"); + listColumn.setAutodrop(true); + listColumn.setAutocomplete(true); + listColumn.setInstantSelect(false); + listColumn.addEventListener(Events.ON_BLUR, e -> { + if (listColumn.getSelectedItem() == null) { + listColumn.setValue(null); + } + }); - Listbox listOperator = new Listbox(); + Combobox listOperator = new Combobox(); listOperator.setId("listOperator"+listItem.getId()); listOperator.setName("listOperator"); - listOperator.setMold("select"); - listOperator.setRows(0); listOperator.addEventListener(Events.ON_SELECT,this); ZKUpdateUtil.setHflex(listOperator, "true"); + listOperator.setInstantSelect(false); + listOperator.setAutocomplete(true); + listOperator.addEventListener(Events.ON_BLUR, e -> { + if (listOperator.getSelectedItem() == null) { + listOperator.setSelectedIndex(0); + } + }); Listbox listAndOr = new Listbox(); listAndOr.setId("listAndOr"+listItem.getId()); @@ -1115,7 +1132,8 @@ public class FindWindow extends Window implements EventListener, ValueCha if (fields != null){ // QueryFrom - String columnName = listColumn.getSelectedItem().getValue().toString(); + ValueNamePair selected = listColumn.getSelectedItem().getValue(); + String columnName = selected.getValue(); if (columnName == null || columnName == "") return; String value = fields.length > INDEX_VALUE ? fields[INDEX_VALUE] : ""; @@ -1172,10 +1190,11 @@ public class FindWindow extends Window implements EventListener, ValueCha } // createFields - private void setValues(Listbox listColumn, Listbox listOperator, String[] fields) + private void setValues(Combobox listColumn, Combobox listOperator, String[] fields) { // 0 = Columns ArrayList items = new ArrayList(); + items.add(new ValueNamePair("", "")); for (int c = 0; c < m_findFields.length; c++) { GridField field = m_findFields[c]; @@ -1206,15 +1225,42 @@ public class FindWindow extends Window implements EventListener, ValueCha Arrays.sort(cols); // sort alpha ValueNamePair[] op = MQuery.OPERATORS; + AbstractListModel columnListModel = null; + if (isFilterColumnList()) { + columnListModel = new SimpleListModel(cols, true) { + private static final long serialVersionUID = -8319240524315831047L; + + @Override + protected boolean inSubModel(Object key, Object value) { + if (key == null) { + return true; + } else if (key instanceof String) { + if (((String) key).length() == 0) + return true; + } + return value.toString().toLowerCase().startsWith(key.toString().toLowerCase()); + } + + protected int getMaxNumberInSubModel(int nRows) { + return Integer.MAX_VALUE; + } + + }; + } else { + columnListModel = new ListModelList(cols); + } + listColumn.setModel(columnListModel); + if (!isFilterColumnList()) { + String script = "var id='#'+this.uuid+'-pp .z-comboitem-selected';var selected=zk($(id));if(selected.jq.length==1)selected.scrollIntoView();"; + listColumn.setWidgetListener("onKeyUp", script); + } + Events.sendEvent("onInitRender", listColumn, null); if(fields == null) { - listColumn.appendItem("","" ); - for (ValueNamePair item: cols) - listColumn.appendItem(item.getName(), item.getValue()); listColumn.setSelectedIndex(0); for (ValueNamePair item: op) - listOperator.appendItem(Msg.getMsg(Env.getCtx(), item.getName()), item.getValue()); + listOperator.appendItem(Msg.getMsg(Env.getCtx(), item.getName()).trim(), item.getValue()); listOperator.setSelectedIndex(0); } else @@ -1223,15 +1269,14 @@ public class FindWindow extends Window implements EventListener, ValueCha String operator = fields.length > INDEX_OPERATOR ? fields[INDEX_OPERATOR] : ""; boolean selected = false; - listColumn.appendItem("",""); - ListItem liCol = null; + Comboitem liCol = null; for (int i = 0; i < cols.length; i++) { ValueNamePair item = cols[i]; - ListItem li = listColumn.appendItem(item.getName(), item.getValue()); if(item.getValue().equals(columnName)) { - listColumn.setSelectedItem(li); + listColumn.setSelectedIndex(i); + Comboitem li = listColumn.getItemAtIndex(i); selected = true; liCol = li; } @@ -1245,7 +1290,8 @@ public class FindWindow extends Window implements EventListener, ValueCha for (int i = 0; i < op.length; i++) { ValueNamePair item = op[i]; - ListItem li = listOperator.appendItem(Msg.getMsg(Env.getCtx(), item.getName()), item.getValue()); + ComboItem li = new ComboItem(Msg.getMsg(Env.getCtx(), item.getName()), item.getValue()); + listOperator.appendChild(li); if(item.getValue().equals(operator)) { listOperator.setSelectedItem(li); @@ -1256,7 +1302,11 @@ public class FindWindow extends Window implements EventListener, ValueCha } } // setValues - /** + private boolean isFilterColumnList() { + return MSysConfig.getBooleanValue(MSysConfig.ZK_ADVANCE_FIND_FILTER_COLUMN_LIST, false, Env.getAD_Client_ID(Env.getCtx())); + } + + /** * Add Selection Column to first Tab * @param mField field **/ @@ -1392,19 +1442,23 @@ public class FindWindow extends Window implements EventListener, ValueCha } else if (Events.ON_SELECT.equals(event.getName())) { - if (event.getTarget() instanceof Listbox) + if (event.getTarget() == fQueryName) + { + onSelectedQueryChanged(); + } + else if (event.getTarget() instanceof Combobox) { ListItem row = (ListItem)(event.getTarget().getParent().getParent()); - Listbox listbox = (Listbox)event.getTarget(); + Combobox listbox = (Combobox)event.getTarget(); advancedPanel.setSelectedItem(row); - Listbox listColumn = (Listbox)row.getFellow("listColumn"+row.getId()); - Listbox listOperator = (Listbox)row.getFellow("listOperator"+row.getId()); + Combobox listColumn = (Combobox)row.getFellow("listColumn"+row.getId()); + Combobox listOperator = (Combobox)row.getFellow("listOperator"+row.getId()); if (listbox.getId().equals(listColumn.getId()) || listbox.getId().equals(listOperator.getId())) { if (listbox.getId().equals(listColumn.getId())) { - ListItem column = listColumn.getSelectedItem(); + Comboitem column = listColumn.getSelectedItem(); if (column != null && column.getValue().toString().length() > 0) { addOperators(column, listOperator); @@ -1415,8 +1469,8 @@ public class FindWindow extends Window implements EventListener, ValueCha componentFrom.setId("searchFieldFrom"+row.getId()); Component componentTo = getEditorCompQueryTo(row); componentTo.setId("searchFieldTo"+row.getId()); - Listbox listOp = (Listbox) row.getFellow("listOperator"+row.getId()); - String betweenValue = listOp.getSelectedItem().getValue().toString(); + Combobox listOp = (Combobox) row.getFellow("listOperator"+row.getId()); + String betweenValue = listOp.getSelectedItem() != null ? listOp.getSelectedItem().getValue().toString() : ""; if(betweenValue.equals(MQuery.NULL) || betweenValue.equals(MQuery.NOT_NULL)) { @@ -1430,10 +1484,6 @@ public class FindWindow extends Window implements EventListener, ValueCha addRowEditor(componentTo,(ListCell)row.getFellow("cellQueryTo"+row.getId())); } } - else if (event.getTarget() == fQueryName) - { - onSelectedQueryChanged(); - } else if (event.getTarget() instanceof Tab) { if (winMain.getComponent().getSelectedIndex() == 1) { onAdvanceTabSelected(); @@ -1452,6 +1502,7 @@ public class FindWindow extends Window implements EventListener, ValueCha if ("btnNewAdv".equals(button.getAttribute("name").toString())) { createFields(); + focusToLastAdvanceRow(); } else if ("btnDeleteAdv".equals(button.getAttribute("name").toString())) @@ -1462,6 +1513,7 @@ public class FindWindow extends Window implements EventListener, ValueCha advancedPanel.getSelectedItem().detach(); advancedPanel.setSelectedIndex(--index); } + focusToLastAdvanceRow(); } else if ("btnSaveAdv".equals(button.getAttribute("name").toString()) @@ -1493,8 +1545,7 @@ public class FindWindow extends Window implements EventListener, ValueCha } else if("btnCancel".equals(btn.getName())) { - m_isCancel = true; - dispose(); + onCancel(); } else if ("btnNew".equals(btn.getName())) { @@ -1548,7 +1599,12 @@ public class FindWindow extends Window implements EventListener, ValueCha } } // onEvent - + + private void onCancel() { + m_isCancel = true; + dispose(); + } + public void onSelectedQueryChanged() { m_whereUserQuery = null; showAdvanced(); @@ -1583,6 +1639,8 @@ public class FindWindow extends Window implements EventListener, ValueCha private void onSimpleTabSelected() { historyCombo.setDisabled(false); + if (m_sEditors.size() > 0) + Clients.response(new AuFocus(m_sEditors.get(0).getComponent())); } private void onAdvanceTabSelected() { @@ -1590,6 +1648,15 @@ public class FindWindow extends Window implements EventListener, ValueCha if (advancedPanel.getItems().size() == 0) { createFields(); } + focusToLastAdvanceRow(); + } + + private void focusToLastAdvanceRow() { + if (advancedPanel.getItemCount() > 0) { + ListItem li = advancedPanel.getItemAtIndex(advancedPanel.getItemCount()-1); + Combobox combo = (Combobox) li.getFellow("listColumn"+li.getId()); + combo.focus(); + } } private void parseUserQuery(MUserQuery userQuery) @@ -1706,8 +1773,8 @@ public class FindWindow extends Window implements EventListener, ValueCha editor.addValueChangeListener(this); boolean between = false; - Listbox listOp = (Listbox) listItem.getFellow("listOperator"+listItem.getId()); - String betweenValue = listOp.getSelectedItem().getValue().toString(); + Combobox listOp = (Combobox) listItem.getFellow("listOperator"+listItem.getId()); + String betweenValue = listOp.getSelectedItem() != null ? listOp.getSelectedItem().getValue().toString() : null; String opValue = MQuery.OPERATORS[MQuery.BETWEEN_INDEX].getValue(); if (to && betweenValue != null && betweenValue.equals(opValue)) @@ -1746,10 +1813,16 @@ public class FindWindow extends Window implements EventListener, ValueCha { // Column ListItem row = (ListItem)rowList.get(rowIndex); - Listbox column = (Listbox)row.getFellow("listColumn"+row.getId()); + Combobox column = (Combobox)row.getFellow("listColumn"+row.getId()); if (column == null) continue; - String ColumnName = column.getSelectedItem().getValue().toString(); + if (column.getSelectedItem() == null) + { + column.setSelectedIndex(0); + continue; + } + ValueNamePair vnp = column.getSelectedItem().getValue(); + String ColumnName = vnp.getValue(); String infoName = column.toString(); // GridField field = getTargetMField(ColumnName); @@ -1777,10 +1850,10 @@ public class FindWindow extends Window implements EventListener, ValueCha and = !"OR".equals(andOr); } // Op - Listbox op = (Listbox)row.getFellow("listOperator"+row.getId()); + Combobox op = (Combobox)row.getFellow("listOperator"+row.getId()); if (op == null) continue; - String Operator = op.getSelectedItem().getValue().toString(); + String Operator = op.getSelectedItem() != null ? op.getSelectedItem().getValue().toString() : ""; // Value ****** ListCell cellQueryFrom = (ListCell)row.getFellow("cellQueryFrom"+row.getId()); @@ -2119,8 +2192,13 @@ public class FindWindow extends Window implements EventListener, ValueCha **/ private String getColumnName(ListItem row) { - Listbox listColumn = (Listbox)row.getFellow("listColumn"+row.getId()); - String columnName = listColumn.getSelectedItem().getValue().toString(); + Combobox listColumn = (Combobox)row.getFellow("listColumn"+row.getId()); + String columnName = ""; + if (listColumn.getSelectedItem() != null) + { + ValueNamePair vnp = listColumn.getSelectedItem().getValue(); + columnName = vnp.getValue(); + } return columnName; @@ -2165,9 +2243,10 @@ public class FindWindow extends Window implements EventListener, ValueCha * and add them to the selection * @param column Column field selected **/ - private void addOperators(ListItem column, Listbox listOperator) + private void addOperators(Comboitem column, Combobox listOperator) { - String columnName = column.getValue().toString(); + ValueNamePair pair = column.getValue(); + String columnName = pair.getValue(); int referenceType = -1; boolean isEncrypted = false; if (columnName != null) { @@ -2213,13 +2292,13 @@ public class FindWindow extends Window implements EventListener, ValueCha * add Operators * @param op array of operators **/ - private void addOperators(ValueNamePair[] op, Listbox listOperator) + private void addOperators(ValueNamePair[] op, Combobox listOperator) { List itemList = listOperator.getChildren(); itemList.clear(); for (ValueNamePair item: op) { - listOperator.appendItem(Msg.getMsg(Env.getCtx(), item.getName()), item.getValue()); + listOperator.appendItem(Msg.getMsg(Env.getCtx(), item.getName()).trim(), item.getValue()); } listOperator.setSelectedIndex(0); } // addOperators @@ -2233,8 +2312,8 @@ public class FindWindow extends Window implements EventListener, ValueCha { String columnName = getColumnName(row); boolean between = false; - Listbox listOp = (Listbox) row.getFellow("listOperator"+row.getId()); - String betweenValue = listOp.getSelectedItem().getValue().toString(); + Combobox listOp = (Combobox) row.getFellow("listOperator"+row.getId()); + String betweenValue = listOp.getSelectedItem() != null ? listOp.getSelectedItem().getValue().toString() : null; String opValue = MQuery.OPERATORS[MQuery.BETWEEN_INDEX].getValue(); if (to && betweenValue != null && betweenValue.equals(opValue)) @@ -2831,8 +2910,12 @@ public class FindWindow extends Window implements EventListener, ValueCha public void OnPostVisible() { removeAttribute(ON_POST_VISIBLE_ATTR); - if (m_sEditors.size() > 0) - Clients.response(new AuFocus(m_sEditors.get(0).getComponent())); + if (winMain.getComponent().getSelectedIndex() == 0) { + if (m_sEditors.size() > 0) + Clients.response(new AuFocus(m_sEditors.get(0).getComponent())); + } else { + focusToLastAdvanceRow(); + } } /**