IDEMPIERE-377 Improve current search dialog box / Peer review on the operators and editors for advanced search
This commit is contained in:
parent
5cd19d949b
commit
e26b6e6ea9
|
@ -427,61 +427,35 @@ public class MQuery implements Serializable
|
||||||
|
|
||||||
/** Operators for Strings */
|
/** Operators for Strings */
|
||||||
public static final ValueNamePair[] OPERATORS = new ValueNamePair[] {
|
public static final ValueNamePair[] OPERATORS = new ValueNamePair[] {
|
||||||
new ValueNamePair (EQUAL, " = "), // 0
|
new ValueNamePair (EQUAL, " = "), // 0 - EQUAL_INDEX
|
||||||
new ValueNamePair (NOT_EQUAL, " != "),
|
new ValueNamePair (NOT_EQUAL, " != "), // 1 - NOT_EQUAL_INDEX
|
||||||
new ValueNamePair (LIKE, " ~ "),
|
new ValueNamePair (LIKE, " ~ "),
|
||||||
new ValueNamePair (NOT_LIKE, " !~ "),
|
new ValueNamePair (NOT_LIKE, " !~ "),
|
||||||
new ValueNamePair (GREATER, " > "),
|
new ValueNamePair (GREATER, " > "),
|
||||||
new ValueNamePair (GREATER_EQUAL, " >= "), // 5
|
new ValueNamePair (GREATER_EQUAL, " >= "),
|
||||||
new ValueNamePair (LESS, " < "),
|
new ValueNamePair (LESS, " < "),
|
||||||
new ValueNamePair (LESS_EQUAL, " <= "),
|
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 */
|
/** Operators for Lookups and Lists (including Y/N) */
|
||||||
public static final ValueNamePair[] OPERATORS_ID = new ValueNamePair[] {
|
public static final ValueNamePair[] OPERATORS_LOOKUP = new ValueNamePair[] {
|
||||||
new ValueNamePair (EQUAL, " = "), // 0
|
new ValueNamePair (EQUAL, " = "),
|
||||||
new ValueNamePair (NOT_EQUAL, " != ")
|
new ValueNamePair (NOT_EQUAL, " != "),
|
||||||
};
|
new ValueNamePair (NULL, " NULL "),
|
||||||
/** Operators for Boolean */
|
new ValueNamePair (NOT_NULL, " !NULL ")
|
||||||
public static final ValueNamePair[] OPERATORS_YN = new ValueNamePair[] {
|
|
||||||
new ValueNamePair (EQUAL, " = ")
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Operators for Number, Amount, Date, Costs+Prices, Quantity, Integer, ID */
|
/** Operators for Numbers, Dates, Integers */
|
||||||
public static final ValueNamePair[] OPERATORS_NUMBERS = new ValueNamePair[] {
|
public static final ValueNamePair[] OPERATORS_NUMBERS = new ValueNamePair[] {
|
||||||
new ValueNamePair (EQUAL, " = "), // 0
|
new ValueNamePair (EQUAL, " = "),
|
||||||
new ValueNamePair (NOT_EQUAL, " != "),
|
new ValueNamePair (NOT_EQUAL, " != "),
|
||||||
new ValueNamePair (GREATER, " > "),
|
new ValueNamePair (GREATER, " > "),
|
||||||
new ValueNamePair (GREATER_EQUAL, " >= "), // 5
|
new ValueNamePair (GREATER_EQUAL, " >= "),
|
||||||
new ValueNamePair (LESS, " < "),
|
new ValueNamePair (LESS, " < "),
|
||||||
new ValueNamePair (LESS_EQUAL, " <= "),
|
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 (NULL, " NULL "),
|
||||||
new ValueNamePair (NOT_NULL, " !NULL ")
|
new ValueNamePair (NOT_NULL, " !NULL ")
|
||||||
};
|
};
|
||||||
|
@ -1150,31 +1124,9 @@ class Restriction implements Serializable
|
||||||
else
|
else
|
||||||
sb.append(ColumnName);
|
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);
|
sb.append(Operator);
|
||||||
|
if ( ! (Operator.equals(MQuery.NULL) || Operator.equals(MQuery.NOT_NULL)))
|
||||||
|
{
|
||||||
if (Code instanceof String)
|
if (Code instanceof String)
|
||||||
sb.append(DB.TO_STRING(Code.toString()));
|
sb.append(DB.TO_STRING(Code.toString()));
|
||||||
else if (Code instanceof Timestamp)
|
else if (Code instanceof Timestamp)
|
||||||
|
|
|
@ -81,6 +81,7 @@ import org.compiere.model.MLookupFactory;
|
||||||
import org.compiere.model.MProduct;
|
import org.compiere.model.MProduct;
|
||||||
import org.compiere.model.MQuery;
|
import org.compiere.model.MQuery;
|
||||||
import org.compiere.model.MRole;
|
import org.compiere.model.MRole;
|
||||||
|
import org.compiere.model.MTable;
|
||||||
import org.compiere.model.MUserQuery;
|
import org.compiere.model.MUserQuery;
|
||||||
import static org.compiere.model.SystemIDs.*;
|
import static org.compiere.model.SystemIDs.*;
|
||||||
import org.compiere.model.X_AD_Column;
|
import org.compiere.model.X_AD_Column;
|
||||||
|
@ -856,14 +857,28 @@ public final class Find extends CDialog
|
||||||
if (columnName != null)
|
if (columnName != null)
|
||||||
{
|
{
|
||||||
log.config("Column: " + columnName);
|
log.config("Column: " + columnName);
|
||||||
if (columnName.endsWith("_ID") || columnName.endsWith("_Acct"))
|
int referenceType = -1;
|
||||||
operators.setModel(new DefaultComboBoxModel(MQuery.OPERATORS_ID));
|
MTable table = MTable.get(Env.getCtx(), m_tableName);
|
||||||
else if (columnName.startsWith("Is"))
|
MColumn col = table.getColumn(columnName);
|
||||||
operators.setModel(new DefaultComboBoxModel(MQuery.OPERATORS_YN));
|
referenceType = col.getAD_Reference_ID();
|
||||||
else
|
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));
|
operators.setModel(new DefaultComboBoxModel(MQuery.OPERATORS));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (e.getSource() == fQueryName)
|
else if (e.getSource() == fQueryName)
|
||||||
{
|
{
|
||||||
Object o = fQueryName.getSelectedItem();
|
Object o = fQueryName.getSelectedItem();
|
||||||
|
|
|
@ -70,6 +70,7 @@ import org.compiere.model.MLookupFactory;
|
||||||
import org.compiere.model.MProduct;
|
import org.compiere.model.MProduct;
|
||||||
import org.compiere.model.MQuery;
|
import org.compiere.model.MQuery;
|
||||||
import org.compiere.model.MRole;
|
import org.compiere.model.MRole;
|
||||||
|
import org.compiere.model.MTable;
|
||||||
import org.compiere.model.MUserQuery;
|
import org.compiere.model.MUserQuery;
|
||||||
import static org.compiere.model.SystemIDs.*;
|
import static org.compiere.model.SystemIDs.*;
|
||||||
import org.compiere.model.X_AD_Column;
|
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()];
|
ValueNamePair[] cols = new ValueNamePair[items.size()];
|
||||||
items.toArray(cols);
|
items.toArray(cols);
|
||||||
Arrays.sort(cols); // sort alpha
|
Arrays.sort(cols); // sort alpha
|
||||||
ValueNamePair[] op = MQuery.OPERATORS_ALL;
|
ValueNamePair[] op = MQuery.OPERATORS;
|
||||||
|
|
||||||
|
|
||||||
if(fields == null)
|
if(fields == null)
|
||||||
{
|
{
|
||||||
|
@ -1280,74 +1280,27 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
|
||||||
private void addOperators(ListItem column, Listbox listOperator)
|
private void addOperators(ListItem column, Listbox listOperator)
|
||||||
{
|
{
|
||||||
String columnName = column.getValue().toString();
|
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;
|
int referenceType = -1;
|
||||||
try
|
if (columnName != null) {
|
||||||
{
|
MTable table = MTable.get(Env.getCtx(), m_tableName);
|
||||||
pstmt = DB.prepareStatement(SQL, null);
|
MColumn col = table.getColumn(columnName);
|
||||||
pstmt.setInt(1, columnID);
|
referenceType = col.getAD_Reference_ID();
|
||||||
rs = pstmt.executeQuery();
|
|
||||||
if( rs.next() )
|
|
||||||
{
|
|
||||||
referenceType = rs.getInt(1);
|
|
||||||
}
|
}
|
||||||
}
|
if (DisplayType.isLookup(referenceType)
|
||||||
catch (SQLException e2)
|
|| DisplayType.YesNo == referenceType
|
||||||
|
|| DisplayType.Button == referenceType)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, SQL, e2);
|
addOperators(MQuery.OPERATORS_LOOKUP, listOperator);
|
||||||
}
|
}
|
||||||
finally
|
else if (DisplayType.isNumeric(referenceType)
|
||||||
{
|
|| DisplayType.isDate(referenceType)
|
||||||
DB.close(rs, pstmt);
|
|| DisplayType.isID(referenceType)) // Note that lookups were filtered above
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
addOperators(MQuery.OPERATORS_NUMBERS, listOperator);
|
addOperators(MQuery.OPERATORS_NUMBERS, listOperator);
|
||||||
}
|
}
|
||||||
else if (equalNotEqualList.contains(referenceType))
|
else // DisplayType.isText
|
||||||
{
|
{
|
||||||
addOperators(MQuery.OPERATORS_ID, listOperator);
|
addOperators(MQuery.OPERATORS, 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
|
} // addOperators
|
||||||
|
|
||||||
|
@ -1389,10 +1342,24 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
|
||||||
if(field == null) return new Label("");
|
if(field == null) return new Label("");
|
||||||
|
|
||||||
WEditor editor = null;
|
WEditor editor = null;
|
||||||
if (field.isKey())
|
if (field.isKey()
|
||||||
|
|| (!DisplayType.isLookup(field.getDisplayType()) && DisplayType.isID(field.getDisplayType())))
|
||||||
|
{
|
||||||
editor = new WNumberEditor(field);
|
editor = new WNumberEditor(field);
|
||||||
|
}
|
||||||
|
else if (field.getDisplayType() == DisplayType.Button)
|
||||||
|
{
|
||||||
|
if (columnName.endsWith("_ID"))
|
||||||
|
{
|
||||||
|
editor = new WNumberEditor(field);
|
||||||
|
} else {
|
||||||
|
editor = new WStringEditor(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
editor = WebEditorFactory.getEditor(field, true);
|
editor = WebEditorFactory.getEditor(field, true);
|
||||||
|
}
|
||||||
if (editor == null)
|
if (editor == null)
|
||||||
editor = new WStringEditor(field);
|
editor = new WStringEditor(field);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue