From de37b5951b943afc35af865d5642f441cac73ec7 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Thu, 5 Dec 2013 18:31:03 -0500 Subject: [PATCH] hg merge release-1.0c (merge release1 into release2) --- .../adempiere/webui/window/FindWindow.java | 269 +++++++++--------- 1 file changed, 140 insertions(+), 129 deletions(-) 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 504faf0b72..2d8661ca98 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 @@ -534,13 +534,11 @@ public class FindWindow extends Window implements EventListener, ValueCha btnSave.setAttribute("name","btnSaveAdv"); btnSave.setImage(ThemeManager.getThemeResource("images/Save24.png")); btnSave.addEventListener(Events.ON_CLICK, this); - btnSave.setDisabled(true); btnSave.setId("btnSave"); btnSave.setStyle("vertical-align: middle;"); fQueryName = new Combobox(); fQueryName.setTooltiptext(Msg.getMsg(Env.getCtx(),"QueryName")); - fQueryName.setReadonly(true); fQueryName.setId("savedQueryCombo"); //user query @@ -1214,7 +1212,11 @@ public class FindWindow extends Window implements EventListener, ValueCha else if ("btnSaveAdv".equals(button.getAttribute("name").toString())) { - cmd_save(true); + if (winMain.getComponent().getSelectedIndex() == 1) { + cmd_saveAdvanced(true); + } else { + cmd_saveSimple(true); + } } } // Confirm panel actions @@ -1284,14 +1286,10 @@ public class FindWindow extends Window implements EventListener, ValueCha } // onEvent private void onSimpleTabSelected() { - fQueryName.setReadonly(true); - btnSave.setDisabled(true); historyCombo.setDisabled(false); } private void onAdvanceTabSelected() { - fQueryName.setReadonly(false); - btnSave.setDisabled(m_AD_Tab_ID <= 0); historyCombo.setSelectedItem(null); if (advancedPanel.getItems().size() == 0) { createFields(); @@ -1426,7 +1424,7 @@ public class FindWindow extends Window implements EventListener, ValueCha } // parseValue - private void cmd_save(boolean saveQuery) + private void cmd_saveAdvanced(boolean saveQuery) { // m_query = new MQuery(m_tableName); @@ -1502,21 +1500,7 @@ public class FindWindow extends Window implements EventListener, ValueCha { m_query.addRestriction(ColumnSQL, Operator, null, infoName, null, and, openBrackets); - if (code.length() > 0) - code.append(SEGMENT_SEPARATOR); - code.append(ColumnName) - .append(FIELD_SEPARATOR) - .append(Operator) - .append(FIELD_SEPARATOR) - .append("") - .append(FIELD_SEPARATOR) - .append("") - .append(FIELD_SEPARATOR) - .append(andOr) - .append(FIELD_SEPARATOR) - .append(lBrackets) - .append(FIELD_SEPARATOR) - .append(rBrackets); + appendCode(code, ColumnName, Operator, "", "", andOr, lBrackets, rBrackets); } continue; } @@ -1571,22 +1555,35 @@ public class FindWindow extends Window implements EventListener, ValueCha m_query.addRestriction(ColumnSQL, Operator, parsedValue, infoName, infoDisplay, and, openBrackets); - if (code.length() > 0) - code.append(SEGMENT_SEPARATOR); - code.append(ColumnName) - .append(FIELD_SEPARATOR) - .append(Operator) - .append(FIELD_SEPARATOR) - .append(value.toString()) - .append(FIELD_SEPARATOR) - .append(value2 != null ? value2.toString() : "") - .append(FIELD_SEPARATOR) - .append(andOr) - .append(FIELD_SEPARATOR) - .append(lBrackets) - .append(FIELD_SEPARATOR) - .append(rBrackets); + appendCode(code, ColumnName, Operator, value.toString(), value2 != null ? value2.toString() : "", andOr, lBrackets, rBrackets); } + + saveQuery(saveQuery, code); + + } // cmd_saveAdvanced + + private void appendCode(StringBuilder code, String columnName, + String operator, String value1, String value2, String andOr, + String lBrackets, String rBrackets) { + if (code.length() > 0) + code.append(SEGMENT_SEPARATOR); + code.append(columnName) + .append(FIELD_SEPARATOR) + .append(operator) + .append(FIELD_SEPARATOR) + .append(value1) + .append(FIELD_SEPARATOR) + .append(value2) + .append(FIELD_SEPARATOR) + .append(andOr) + .append(FIELD_SEPARATOR) + .append(lBrackets) + .append(FIELD_SEPARATOR) + .append(rBrackets); + } + + private void saveQuery(boolean saveQuery, StringBuilder code) { + String selected = fQueryName.getValue(); if (selected != null) { String name = selected; @@ -1643,8 +1640,108 @@ public class FindWindow extends Window implements EventListener, ValueCha // } + } - } // cmd_save + private void cmd_saveSimple(boolean saveQuery) + { + // Create Query String + m_query = new MQuery(m_tableName); + m_query.addRestriction(Env.parseContext(Env.getCtx(), m_targetWindowNo, m_whereExtended, false)); + StringBuilder code = new StringBuilder(); + // Special Editors + for (int i = 0; i < m_sEditors.size(); i++) + { + WEditor wed = (WEditor)m_sEditors.get(i); + Object value = wed.getValue(); + String ColumnName = wed.getColumnName(); + WEditor wedTo = (WEditor)m_sEditorsTo.get(i); + Object valueTo = null; + if (wedTo != null && wedTo.getComponent().isVisible()) + valueTo = wedTo.getValue(); + if (value != null && value.toString().length() > 0) + { + if (valueTo != null && valueTo.toString().length() > 0) { + // range + StringBuilder msglog = new StringBuilder(ColumnName).append(">=").append(value).append("<=").append(valueTo); + if (log.isLoggable(Level.FINE)) log.fine(msglog.toString()); + + GridField field = getTargetMField(ColumnName); + StringBuilder ColumnSQL = new StringBuilder(field.getColumnSQL(false)); + m_query.addRangeRestriction(ColumnSQL.toString(), value, valueTo, + ColumnName, wed.getDisplay(), wedTo.getDisplay(), true, 0); + appendCode(code, ColumnName, MQuery.BETWEEN, value.toString(), valueTo.toString(), "AND", "", ""); + } else { + StringBuilder msglog = new StringBuilder(ColumnName).append("=").append(value); + if (log.isLoggable(Level.FINE)) log.fine(msglog.toString()); + + // globalqss - Carlos Ruiz - 20060711 + // fix a bug with virtualColumn + isSelectionColumn not yielding results + GridField field = getTargetMField(ColumnName); + // add encryption here if the field is encrypted. + if (field.isEncryptedColumn()) { + value = SecureEngine.encrypt(value, Env.getAD_Client_ID(Env.getCtx())); + } + + boolean isProductCategoryField = isProductCategoryField(field.getColumnName()); + StringBuilder ColumnSQL = new StringBuilder(field.getColumnSQL(false)); + // + // Be more permissive for String columns + if (isSearchLike(field)) + { + StringBuilder valueStr = new StringBuilder(value.toString().toUpperCase()); + if (!valueStr.toString().endsWith("%")) + valueStr.append("%"); + // + ColumnSQL = new StringBuilder("UPPER(").append(ColumnSQL).append(")"); + value = valueStr.toString(); + } + // + if (value.toString().indexOf('%') != -1) { + m_query.addRestriction(ColumnSQL.toString(), MQuery.LIKE, value, ColumnName, wed.getDisplay()); + appendCode(code, ColumnName, MQuery.LIKE, value.toString(), "", "AND", "", ""); + } else if (isProductCategoryField && value instanceof Integer) { + m_query.addRestriction(getSubCategoryWhereClause(((Integer) value).intValue())); + appendCode(code, ColumnName, MQuery.EQUAL, value.toString(), "", "AND", "", ""); + } else { + String oper = MQuery.EQUAL; + if (wedTo != null) { + ToolBarButton wedFlag = m_sEditorsFlag.get(i); + if (wedFlag.isChecked()) + oper = MQuery.GREATER_EQUAL; + } + m_query.addRestriction(ColumnSQL.toString(), oper, value, ColumnName, wed.getDisplay()); + appendCode(code, ColumnName, oper, value.toString(), "", "AND", "", ""); + } + + /* + if (value.toString().indexOf('%') != -1) + m_query.addRestriction(ColumnName, MQuery.LIKE, value, ColumnName, ved.getDisplay()); + else + m_query.addRestriction(ColumnName, MQuery.EQUAL, value, ColumnName, ved.getDisplay()); + */ + // end globalqss patch + } + } else if (valueTo != null && valueTo.toString().length() > 0) { + // filled upper limit without filling lower limit + StringBuilder msglog = new StringBuilder(ColumnName).append("<=").append(valueTo); + if (log.isLoggable(Level.FINE)) log.fine(msglog.toString()); + + GridField field = getTargetMField(ColumnName); + StringBuilder ColumnSQL = new StringBuilder(field.getColumnSQL(false)); + // + m_query.addRestriction(ColumnSQL.toString(), MQuery.LESS_EQUAL, valueTo, ColumnName, wed.getDisplay()); + appendCode(code, ColumnName, MQuery.LESS_EQUAL, valueTo.toString(), "", "AND", "", ""); + } + } // editors + + if(historyCombo.getSelectedItem()!=null) + { + addHistoryRestriction(historyCombo.getSelectedItem()); + } + + saveQuery(saveQuery, code); + + } // cmd_saveSimple private void refreshUserQueries() { @@ -1867,96 +1964,10 @@ public class FindWindow extends Window implements EventListener, ValueCha **/ private void cmd_ok_Simple() { - // Create Query String - m_query = new MQuery(m_tableName); - m_query.addRestriction(Env.parseContext(Env.getCtx(), m_targetWindowNo, m_whereExtended, false)); - // Special Editors - for (int i = 0; i < m_sEditors.size(); i++) - { - WEditor wed = (WEditor)m_sEditors.get(i); - Object value = wed.getValue(); - String ColumnName = wed.getColumnName(); - WEditor wedTo = (WEditor)m_sEditorsTo.get(i); - Object valueTo = null; - if (wedTo != null && wedTo.getComponent().isVisible()) - valueTo = wedTo.getValue(); - if (value != null && value.toString().length() > 0) - { - if (valueTo != null && valueTo.toString().length() > 0) { - // range - StringBuilder msglog = new StringBuilder(ColumnName).append(">=").append(value).append("<=").append(valueTo); - if (log.isLoggable(Level.FINE)) log.fine(msglog.toString()); - - GridField field = getTargetMField(ColumnName); - StringBuilder ColumnSQL = new StringBuilder(field.getColumnSQL(false)); - m_query.addRangeRestriction(ColumnSQL.toString(), value, valueTo, - ColumnName, wed.getDisplay(), wedTo.getDisplay(), true, 0); - } else { - StringBuilder msglog = new StringBuilder(ColumnName).append("=").append(value); - if (log.isLoggable(Level.FINE)) log.fine(msglog.toString()); - - // globalqss - Carlos Ruiz - 20060711 - // fix a bug with virtualColumn + isSelectionColumn not yielding results - GridField field = getTargetMField(ColumnName); - // add encryption here if the field is encrypted. - if (field.isEncryptedColumn()) { - value = SecureEngine.encrypt(value, Env.getAD_Client_ID(Env.getCtx())); - } - - boolean isProductCategoryField = isProductCategoryField(field.getColumnName()); - StringBuilder ColumnSQL = new StringBuilder(field.getColumnSQL(false)); - // - // Be more permissive for String columns - if (isSearchLike(field)) - { - StringBuilder valueStr = new StringBuilder(value.toString().toUpperCase()); - if (!valueStr.toString().endsWith("%")) - valueStr.append("%"); - // - ColumnSQL = new StringBuilder("UPPER(").append(ColumnSQL).append(")"); - value = valueStr.toString(); - } - // - if (value.toString().indexOf('%') != -1) - m_query.addRestriction(ColumnSQL.toString(), MQuery.LIKE, value, ColumnName, wed.getDisplay()); - else if (isProductCategoryField && value instanceof Integer) - m_query.addRestriction(getSubCategoryWhereClause(((Integer) value).intValue())); - else { - String oper = MQuery.EQUAL; - if (wedTo != null) { - ToolBarButton wedFlag = m_sEditorsFlag.get(i); - if (wedFlag.isChecked()) - oper = MQuery.GREATER_EQUAL; - } - m_query.addRestriction(ColumnSQL.toString(), oper, value, ColumnName, wed.getDisplay()); - } - - /* - if (value.toString().indexOf('%') != -1) - m_query.addRestriction(ColumnName, MQuery.LIKE, value, ColumnName, ved.getDisplay()); - else - m_query.addRestriction(ColumnName, MQuery.EQUAL, value, ColumnName, ved.getDisplay()); - */ - // end globalqss patch - } - } else if (valueTo != null && valueTo.toString().length() > 0) { - // filled upper limit without filling lower limit - StringBuilder msglog = new StringBuilder(ColumnName).append("<=").append(valueTo); - if (log.isLoggable(Level.FINE)) log.fine(msglog.toString()); - - GridField field = getTargetMField(ColumnName); - StringBuilder ColumnSQL = new StringBuilder(field.getColumnSQL(false)); - // - m_query.addRestriction(ColumnSQL.toString(), MQuery.LESS_EQUAL, valueTo, ColumnName, wed.getDisplay()); - } - } // editors - - if(historyCombo.getSelectedItem()!=null) - { - addHistoryRestriction(historyCombo.getSelectedItem()); - } - m_isCancel = false; // teo_sarca [ 1708717 ] + // save pending + cmd_saveSimple(false); + // Test for no records if (getNoOfRecords(m_query, true) != 0) dispose(); @@ -2025,7 +2036,7 @@ public class FindWindow extends Window implements EventListener, ValueCha { m_isCancel = false; // teo_sarca [ 1708717 ] // save pending - cmd_save(false); + cmd_saveAdvanced(false); if(historyCombo.getSelectedItem()!=null) {