diff --git a/base/src/org/compiere/model/Callout_AD_Column.java b/base/src/org/compiere/model/Callout_AD_Column.java new file mode 100644 index 0000000000..0c7932aeff --- /dev/null +++ b/base/src/org/compiere/model/Callout_AD_Column.java @@ -0,0 +1,25 @@ +/** + * + */ +package org.compiere.model; + +import java.util.Properties; + +import org.adempiere.model.GridTabWrapper; + +/** + * @author teo_sarca + * + */ +public class Callout_AD_Column extends CalloutEngine +{ + public String columnName (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) + { + I_AD_Column column = GridTabWrapper.create(mTab, I_AD_Column.class); + if (MColumn.isSuggestSelectionColumn(column.getColumnName(), true)) + column.setIsSelectionColumn(true); + // + return ""; + } + +} diff --git a/base/src/org/compiere/model/MColumn.java b/base/src/org/compiere/model/MColumn.java index bcd7b96252..8b60b5b0f6 100644 --- a/base/src/org/compiere/model/MColumn.java +++ b/base/src/org/compiere/model/MColumn.java @@ -28,6 +28,7 @@ import org.compiere.util.DB; import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.Msg; +import org.compiere.util.Util; /** * Persistent Column Model @@ -566,5 +567,24 @@ public class MColumn extends X_AD_Column return DB.getSQLValue(trxName, sqlStmt, AD_Column_ID); } - + + public static boolean isSuggestSelectionColumn(String columnName, boolean caseSensitive) + { + if (Util.isEmpty(columnName, true)) + return false; + // + if (columnName.equals("Value") || (!caseSensitive && columnName.equalsIgnoreCase("Value"))) + return true; + else if (columnName.equals("Name") || (!caseSensitive && columnName.equalsIgnoreCase("Name"))) + return true; + else if (columnName.equals("DocumentNo") || (!caseSensitive && columnName.equalsIgnoreCase("DocumentNo"))) + return true; + else if (columnName.equals("Description") || (!caseSensitive && columnName.equalsIgnoreCase("Description"))) + return true; + else if (columnName.indexOf("Name") != -1 + || (!caseSensitive && columnName.toUpperCase().indexOf("Name".toUpperCase()) != -1) ) + return true; + else + return false; + } } // MColumn diff --git a/client/src/org/compiere/apps/search/Find.java b/client/src/org/compiere/apps/search/Find.java index 6b7e4ac8d4..b2f7260fb1 100644 --- a/client/src/org/compiere/apps/search/Find.java +++ b/client/src/org/compiere/apps/search/Find.java @@ -77,6 +77,7 @@ import org.compiere.model.DataStatusListener; import org.compiere.model.GridField; import org.compiere.model.GridFieldVO; import org.compiere.model.GridTab; +import org.compiere.model.MColumn; import org.compiere.model.MLookupFactory; import org.compiere.model.MProduct; import org.compiere.model.MQuery; @@ -512,6 +513,7 @@ public final class Find extends CDialog } } + /** metas: teo_sarca: Specify exactly which are the search fields - http://sourceforge.net/projects/adempiere/forums/forum/610548/topic/3736214 if (columnName.equals("Value")) hasValue = true; else if (columnName.equals("Name")) @@ -520,10 +522,14 @@ public final class Find extends CDialog hasDocNo = true; else if (columnName.equals("Description")) hasDescription = true; - else if (mField.isSelectionColumn()) + else + /**/ + if (mField.isSelectionColumn()) addSelectionColumn (mField); + /** metas: teo_sarca: Specify exactly which are the search fields - http://sourceforge.net/projects/adempiere/forums/forum/610548/topic/3736214 else if (columnName.indexOf("Name") != -1) addSelectionColumn (mField); + /**/ // TargetFields m_targetFields.put (new Integer(mField.getAD_Column_ID()), mField); @@ -1041,6 +1047,18 @@ public final class Find extends CDialog GridField field = getTargetMField(ColumnName); boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID()); String ColumnSQL = field.getColumnSQL(false); + // + // Be more permissive for String columns + if (isSearchLike(field)) + { + String valueStr = value.toString().toUpperCase(); + if (!valueStr.endsWith("%")) + valueStr += "%"; + // + ColumnSQL = "UPPER("+ColumnSQL+")"; + value = valueStr; + } + // if (value.toString().indexOf('%') != -1) m_query.addRestriction(ColumnSQL, MQuery.LIKE, value, ColumnName, ved.getDisplay()); else if (isProductCategoryField && value instanceof Integer) @@ -1682,6 +1700,12 @@ public final class Find extends CDialog return null; } // getTargetMField + private boolean isSearchLike(GridField field) + { + return DisplayType.isText(field.getDisplayType()) + && MColumn.isSuggestSelectionColumn(field.getColumnName(), true); + } + private class ProxyRenderer implements TableCellRenderer { /** diff --git a/migration/360lts-release/oracle/738_FR3016592_SpecifySelectionColumns.sql b/migration/360lts-release/oracle/738_FR3016592_SpecifySelectionColumns.sql new file mode 100644 index 0000000000..7afe97ff0e --- /dev/null +++ b/migration/360lts-release/oracle/738_FR3016592_SpecifySelectionColumns.sql @@ -0,0 +1,9 @@ +-- Jun 15, 2010 7:27:00 PM EEST +-- Disable automatic field selection in Find windows +UPDATE AD_Column SET Callout='org.compiere.model.Callout_AD_Column.columnName',Updated=TO_DATE('2010-06-15 19:27:00','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Column_ID=116 +; + +UPDATE AD_Column SET IsSelectionColumn='Y' +WHERE IsSelectionColumn='N' AND (ColumnName IN ('Value', 'Name', 'Description') OR ColumnName LIKE '%Name%') +; + diff --git a/migration/360lts-release/postgresql/738_FR3016592_SpecifySelectionColumns.sql b/migration/360lts-release/postgresql/738_FR3016592_SpecifySelectionColumns.sql new file mode 100644 index 0000000000..4cba249c2c --- /dev/null +++ b/migration/360lts-release/postgresql/738_FR3016592_SpecifySelectionColumns.sql @@ -0,0 +1,9 @@ +-- Jun 15, 2010 7:27:00 PM EEST +-- Disable automatic field selection in Find windows +UPDATE AD_Column SET Callout='org.compiere.model.Callout_AD_Column.columnName',Updated=TO_TIMESTAMP('2010-06-15 19:27:00','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Column_ID=116 +; + +UPDATE AD_Column SET IsSelectionColumn='Y' +WHERE IsSelectionColumn='N' AND (ColumnName IN ('Value', 'Name', 'Description') OR ColumnName LIKE '%Name%') +; + diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/window/FindWindow.java b/zkwebui/WEB-INF/src/org/adempiere/webui/window/FindWindow.java index b6e3b6be2c..c47c98ea59 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/window/FindWindow.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/window/FindWindow.java @@ -61,6 +61,7 @@ import org.adempiere.webui.part.MultiTabPart; import org.compiere.model.GridField; import org.compiere.model.GridFieldVO; import org.compiere.model.GridTab; +import org.compiere.model.MColumn; import org.compiere.model.MLookupFactory; import org.compiere.model.MProduct; import org.compiere.model.MQuery; @@ -537,6 +538,7 @@ public class FindWindow extends Window implements EventListener,ValueChangeListe } } + /** metas: teo_sarca: Specify exactly which are the search fields - http://sourceforge.net/projects/adempiere/forums/forum/610548/topic/3736214 if (columnName.equals("Value")) hasValue = true; else if (columnName.equals("Name")) @@ -545,10 +547,14 @@ public class FindWindow extends Window implements EventListener,ValueChangeListe hasDocNo = true; else if (columnName.equals("Description")) hasDescription = true; - else if (mField.isSelectionColumn()) + else + /**/ + if (mField.isSelectionColumn()) addSelectionColumn (mField); + /** metas: teo_sarca: Specify exactly which are the search fields - http://sourceforge.net/projects/adempiere/forums/forum/610548/topic/3736214 else if (columnName.indexOf("Name") != -1) addSelectionColumn (mField); + /**/ // TargetFields m_targetFields.put (new Integer(mField.getAD_Column_ID()), mField); @@ -745,6 +751,7 @@ public class FindWindow extends Window implements EventListener,ValueChangeListe contentSimpleRows.appendChild(panel); m_sEditors.add(editor); + fieldLabel.addEventListener(Events.ON_OK,this); } // addSelectionColumn public void onEvent(Event event) throws Exception @@ -845,6 +852,15 @@ public class FindWindow extends Window implements EventListener,ValueChangeListe cmd_ok_Advanced(); dispose(); } + // Check simple panel fields + for (WEditor editor : m_sEditors) + { + if (editor.getComponent() == event.getTarget()) + { + cmd_ok_Simple(); + dispose(); + } + } } } // onEvent @@ -1339,9 +1355,21 @@ public class FindWindow extends Window implements EventListener,ValueChangeListe if (field.isEncryptedColumn()) { value = SecureEngine.encrypt(value); } - + boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID()); String ColumnSQL = field.getColumnSQL(false); + // + // Be more permissive for String columns + if (isSearchLike(field)) + { + String valueStr = value.toString().toUpperCase(); + if (!valueStr.endsWith("%")) + valueStr += "%"; + // + ColumnSQL = "UPPER("+ColumnSQL+")"; + value = valueStr; + } + // if (value.toString().indexOf('%') != -1) m_query.addRestriction(ColumnSQL, MQuery.LIKE, value, ColumnName, wed.getDisplay()); else if (isProductCategoryField && value instanceof Integer) @@ -1782,5 +1810,11 @@ public class FindWindow extends Window implements EventListener,ValueChangeListe } return ret; } + + private boolean isSearchLike(GridField field) + { + return DisplayType.isText(field.getDisplayType()) + && MColumn.isSuggestSelectionColumn(field.getColumnName(), true); + } } // FindPanel \ No newline at end of file