IDEMPIERE-377 Improve current search dialog box / Peer review on the operators and editors for advanced search

This commit is contained in:
Carlos Ruiz 2012-08-23 19:00:04 -05:00
parent 5cd19d949b
commit e26b6e6ea9
3 changed files with 92 additions and 158 deletions

View File

@ -421,71 +421,45 @@ public class MQuery implements Serializable
/** Between - 8 */
public static final int BETWEEN_INDEX = 8;
/** For IDEMPIERE-377 */
public static final String NOT_NULL = "IS NOT NULL";
public static final String NOT_NULL = " IS NOT NULL ";
/** For IDEMPIERE-377 */
public static final String NULL = "IS NULL";
public static final String NULL = " IS NULL ";
/** Operators for Strings */
public static final ValueNamePair[] OPERATORS = new ValueNamePair[] {
new ValueNamePair (EQUAL, " = "), // 0
new ValueNamePair (NOT_EQUAL, " != "),
new ValueNamePair (EQUAL, " = "), // 0 - EQUAL_INDEX
new ValueNamePair (NOT_EQUAL, " != "), // 1 - NOT_EQUAL_INDEX
new ValueNamePair (LIKE, " ~ "),
new ValueNamePair (NOT_LIKE, " !~ "),
new ValueNamePair (GREATER, " > "),
new ValueNamePair (GREATER_EQUAL, " >= "), // 5
new ValueNamePair (GREATER_EQUAL, " >= "),
new ValueNamePair (LESS, " < "),
new ValueNamePair (LESS_EQUAL, " <= "),
new ValueNamePair (BETWEEN, " >-< ") // 8
new ValueNamePair (BETWEEN, " >-< "), // 8 - BETWEEN_INDEX
new ValueNamePair (NULL, " NULL "),
new ValueNamePair (NOT_NULL, " !NULL ")
};
/** Operators for IDs */
public static final ValueNamePair[] OPERATORS_ID = new ValueNamePair[] {
new ValueNamePair (EQUAL, " = "), // 0
new ValueNamePair (NOT_EQUAL, " != ")
};
/** Operators for Boolean */
public static final ValueNamePair[] OPERATORS_YN = new ValueNamePair[] {
new ValueNamePair (EQUAL, " = ")
/** Operators for Lookups and Lists (including Y/N) */
public static final ValueNamePair[] OPERATORS_LOOKUP = new ValueNamePair[] {
new ValueNamePair (EQUAL, " = "),
new ValueNamePair (NOT_EQUAL, " != "),
new ValueNamePair (NULL, " NULL "),
new ValueNamePair (NOT_NULL, " !NULL ")
};
/** Operators for Number, Amount, Date, Costs+Prices, Quantity, Integer, ID */
/** Operators for Numbers, Dates, Integers */
public static final ValueNamePair[] OPERATORS_NUMBERS = new ValueNamePair[] {
new ValueNamePair (EQUAL, " = "), // 0
new ValueNamePair (EQUAL, " = "),
new ValueNamePair (NOT_EQUAL, " != "),
new ValueNamePair (GREATER, " > "),
new ValueNamePair (GREATER_EQUAL, " >= "), // 5
new ValueNamePair (GREATER_EQUAL, " >= "),
new ValueNamePair (LESS, " < "),
new ValueNamePair (LESS_EQUAL, " <= "),
new ValueNamePair (BETWEEN, " >-< "), // 8
new ValueNamePair (BETWEEN, " >-< "),
new ValueNamePair (NULL, " NULL "),
new ValueNamePair (NOT_NULL, " !NULL ")
};
/** Operators for URL */
public static final ValueNamePair[] OPERATORS_EQUAL_LIKE = new ValueNamePair[] {
new ValueNamePair (EQUAL, " = "), // 0
new ValueNamePair (NOT_EQUAL, " != "),
new ValueNamePair (NOT_EQUAL, " ~ "),
new ValueNamePair (LIKE, " !~ "),
new ValueNamePair (NULL, " NULL "),
new ValueNamePair (NOT_NULL, " !NULL ")
};
/** Operators for all */
public static final ValueNamePair[] OPERATORS_ALL = new ValueNamePair[] {
new ValueNamePair (EQUAL, " = "), // 0
new ValueNamePair (NOT_EQUAL, " != "),
new ValueNamePair (LIKE, " ~ "),
new ValueNamePair (NOT_LIKE, " !~ "),
new ValueNamePair (GREATER, " > "),
new ValueNamePair (GREATER_EQUAL, " >= "), // 5
new ValueNamePair (LESS, " < "),
new ValueNamePair (LESS_EQUAL, " <= "),
new ValueNamePair (BETWEEN, " >-< "), // 8
new ValueNamePair (NULL, " NULL "),
new ValueNamePair (NOT_NULL, " !NULL ")
};
/*************************************************************************
* Add Restriction
* @param ColumnName ColumnName
@ -1150,50 +1124,28 @@ class Restriction implements Serializable
else
sb.append(ColumnName);
// NULL Operator
if ((Operator.equals("=") || Operator.equals("!="))
&& (Code == null
|| "NULL".equals (Code.toString().toUpperCase())))
{
if (Operator.equals("="))
sb.append(" IS NULL ");
else
sb.append(" IS NOT NULL ");
}
else if ((Operator.equals(MQuery.NULL) || Operator.equals(MQuery.NOT_NULL))
&& (Code == null
|| "NULL".equals (Code.toString().toUpperCase())))
{
if (Operator.equals(MQuery.NULL))
sb.append(" IS NULL ");
else
sb.append(" IS NOT NULL ");
}
else
{
sb.append(Operator);
if (Code instanceof String)
sb.append(DB.TO_STRING(Code.toString()));
else if (Code instanceof Timestamp)
sb.append(DB.TO_DATE((Timestamp)Code));
else
sb.append(Code);
// Between
// if (Code_to != null && InfoDisplay_to != null)
if (MQuery.BETWEEN.equals(Operator))
if ( ! (Operator.equals(MQuery.NULL) || Operator.equals(MQuery.NOT_NULL)))
{
sb.append(" AND ");
if (Code_to instanceof String)
sb.append(DB.TO_STRING(Code_to.toString()));
else if (Code_to instanceof Timestamp)
sb.append(DB.TO_DATE((Timestamp)Code_to));
if (Code instanceof String)
sb.append(DB.TO_STRING(Code.toString()));
else if (Code instanceof Timestamp)
sb.append(DB.TO_DATE((Timestamp)Code));
else
sb.append(Code_to);
}
sb.append(Code);
// Between
// if (Code_to != null && InfoDisplay_to != null)
if (MQuery.BETWEEN.equals(Operator))
{
sb.append(" AND ");
if (Code_to instanceof String)
sb.append(DB.TO_STRING(Code_to.toString()));
else if (Code_to instanceof Timestamp)
sb.append(DB.TO_DATE((Timestamp)Code_to));
else
sb.append(Code_to);
}
}
return sb.toString();
} // getSQL

View File

@ -81,6 +81,7 @@ import org.compiere.model.MLookupFactory;
import org.compiere.model.MProduct;
import org.compiere.model.MQuery;
import org.compiere.model.MRole;
import org.compiere.model.MTable;
import org.compiere.model.MUserQuery;
import static org.compiere.model.SystemIDs.*;
import org.compiere.model.X_AD_Column;
@ -856,12 +857,26 @@ public final class Find extends CDialog
if (columnName != null)
{
log.config("Column: " + columnName);
if (columnName.endsWith("_ID") || columnName.endsWith("_Acct"))
operators.setModel(new DefaultComboBoxModel(MQuery.OPERATORS_ID));
else if (columnName.startsWith("Is"))
operators.setModel(new DefaultComboBoxModel(MQuery.OPERATORS_YN));
else
int referenceType = -1;
MTable table = MTable.get(Env.getCtx(), m_tableName);
MColumn col = table.getColumn(columnName);
referenceType = col.getAD_Reference_ID();
if (DisplayType.isLookup(referenceType)
|| DisplayType.YesNo == referenceType
|| DisplayType.Button == referenceType)
{
operators.setModel(new DefaultComboBoxModel(MQuery.OPERATORS_LOOKUP));
}
else if (DisplayType.isNumeric(referenceType)
|| DisplayType.isDate(referenceType)
|| DisplayType.isID(referenceType)) // Note that lookups were filtered above
{
operators.setModel(new DefaultComboBoxModel(MQuery.OPERATORS_NUMBERS));
}
else // DisplayType.isText
{
operators.setModel(new DefaultComboBoxModel(MQuery.OPERATORS));
}
}
}
else if (e.getSource() == fQueryName)

View File

@ -70,6 +70,7 @@ import org.compiere.model.MLookupFactory;
import org.compiere.model.MProduct;
import org.compiere.model.MQuery;
import org.compiere.model.MRole;
import org.compiere.model.MTable;
import org.compiere.model.MUserQuery;
import static org.compiere.model.SystemIDs.*;
import org.compiere.model.X_AD_Column;
@ -678,8 +679,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
ValueNamePair[] cols = new ValueNamePair[items.size()];
items.toArray(cols);
Arrays.sort(cols); // sort alpha
ValueNamePair[] op = MQuery.OPERATORS_ALL;
ValueNamePair[] op = MQuery.OPERATORS;
if(fields == null)
{
@ -1279,75 +1279,28 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
**/
private void addOperators(ListItem column, Listbox listOperator)
{
String columnName = column.getValue().toString();
int columnID = MColumn.getColumn_ID(this.m_tableName, columnName);
String SQL = "SELECT ad_reference_id FROM ad_column WHERE ad_column_id = ?";
PreparedStatement pstmt = null;
ResultSet rs = null;
int referenceType = -1;
try
{
pstmt = DB.prepareStatement(SQL, null);
pstmt.setInt(1, columnID);
rs = pstmt.executeQuery();
if( rs.next() )
{
referenceType = rs.getInt(1);
}
}
catch (SQLException e2)
{
log.log(Level.SEVERE, SQL, e2);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
log.config("Column: " + columnName);
log.log(Level.INFO, "referenceType : " + referenceType);
List<Integer> numbersList = new ArrayList<Integer>();
numbersList.add(DisplayType.Number);
numbersList.add(DisplayType.Date);
numbersList.add(DisplayType.Amount);
numbersList.add(DisplayType.CostPrice);
numbersList.add(DisplayType.Quantity);
numbersList.add(DisplayType.ID);
numbersList.add(DisplayType.Integer);
List<Integer> equalNotEqualList = new ArrayList<Integer>();
equalNotEqualList.add(DisplayType.TableDir);
equalNotEqualList.add(DisplayType.Table);
equalNotEqualList.add(DisplayType.Search);
equalNotEqualList.add(DisplayType.List);
List<Integer> equalAndLikeList = new ArrayList<Integer>();
equalAndLikeList.add(DisplayType.URL);
equalAndLikeList.add(DisplayType.Memo);
equalAndLikeList.add(DisplayType.TextLong);
equalAndLikeList.add(DisplayType.Text);
if(numbersList.contains(referenceType))
String columnName = column.getValue().toString();
int referenceType = -1;
if (columnName != null) {
MTable table = MTable.get(Env.getCtx(), m_tableName);
MColumn col = table.getColumn(columnName);
referenceType = col.getAD_Reference_ID();
}
if (DisplayType.isLookup(referenceType)
|| DisplayType.YesNo == referenceType
|| DisplayType.Button == referenceType)
{
addOperators(MQuery.OPERATORS_LOOKUP, listOperator);
}
else if (DisplayType.isNumeric(referenceType)
|| DisplayType.isDate(referenceType)
|| DisplayType.isID(referenceType)) // Note that lookups were filtered above
{
addOperators(MQuery.OPERATORS_NUMBERS, listOperator);
}
else if (equalNotEqualList.contains(referenceType))
else // DisplayType.isText
{
addOperators(MQuery.OPERATORS_ID, listOperator);
}
else if (DisplayType.YesNo == referenceType)
{
addOperators(MQuery.OPERATORS_YN, listOperator);
}
else if (equalAndLikeList.contains(referenceType))
{
addOperators(MQuery.OPERATORS_EQUAL_LIKE, listOperator);
}
else
{
addOperators(MQuery.OPERATORS_ALL, listOperator);
addOperators(MQuery.OPERATORS, listOperator);
}
} // addOperators
@ -1389,10 +1342,24 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
if(field == null) return new Label("");
WEditor editor = null;
if (field.isKey())
if (field.isKey()
|| (!DisplayType.isLookup(field.getDisplayType()) && DisplayType.isID(field.getDisplayType())))
{
editor = new WNumberEditor(field);
}
else if (field.getDisplayType() == DisplayType.Button)
{
if (columnName.endsWith("_ID"))
{
editor = new WNumberEditor(field);
} else {
editor = new WStringEditor(field);
}
}
else
{
editor = WebEditorFactory.getEditor(field, true);
}
if (editor == null)
editor = new WStringEditor(field);