18 package org.turro.zkoss.filter;
20 import java.io.Serializable;
21 import java.util.Date;
22 import java.util.EnumSet;
23 import org.turro.string.Strings;
24 import org.turro.elephant.db.SQLHelper;
25 import org.turro.elephant.db.WhereClause;
26 import org.turro.elephant.impl.util.StringParser;
27 import org.turro.plugin.filter.IFilterValue;
28 import org.turro.zkoss.dialog.InputEnum;
29 import org.turro.zkoss.input.*;
30 import org.zkoss.zk.ui.HtmlBasedComponent;
31 import org.zkoss.zk.ui.ext.AfterCompose;
32 import org.zkoss.zul.*;
43 protected HtmlBasedComponent
editor, operatorEditor;
80 this.
operator =
operator;
81 operators = EnumSet.of(
96 this.
operator =
operator;
111 this.
operator =
operator;
112 operators = EnumSet.of(
125 this.
operator =
operator;
126 operators = EnumSet.of(
135 this.
operator =
operator;
136 operators = EnumSet.of(
146 this.
operator =
operator;
147 operators = EnumSet.of(
185 this.format = format;
206 if(operatorEditor !=
null) {
213 this.
operator =
operator;
231 if(v instanceof String) {
232 if(Strings.isBlank((String) v)) {
257 if(operatorEditor ==
null) {
259 operatorEditor.setHflex(
"1");
261 return operatorEditor;
273 if(
value instanceof Boolean) {
274 Checkbox cb =
new Checkbox();
275 cb.setChecked((Boolean)
value);
277 }
else if(
value instanceof Number) {
281 }
else if(
value instanceof Date) {
283 db.setFormat(format);
285 }
else if(
value instanceof Enum) {
286 InputEnum ie =
new InputEnum(
choices);
287 ie.setObjectValue((Enum)
value);
290 Textbox tb =
new Textbox((String)
value);
297 col.setObjectValue(
operator);
298 col.setMold(
"select");
304 EnumListbox<ChainOperator> col =
new EnumListbox<ChainOperator>(
ChainOperator.values());
305 col.setObjectValue(
chain);
306 col.setMold(
"select");
312 if(
editor instanceof Checkbox) {
313 return ((Checkbox)
editor).isChecked();
314 }
else if(
editor instanceof Decimalbox) {
318 }
else if(
editor instanceof Datebox) {
319 return ((Datebox)
editor).getValue();
324 }
else if(
editor instanceof Listbox) {
325 return ((Listbox)
editor).getSelectedItem().getValue();
326 }
else if(
editor instanceof InputEnum) {
327 return ((InputEnum)
editor).getObjectValue();
329 return ((Textbox)
editor).getText();
344 if(obj instanceof String) {
370 wc.
addClause(
"select sqx from " + collection +
" as sqx");
372 wc.
addNamedValue(param, ((String) obj).replaceAll(
"\\*",
"%"));
380 wc.
addClause(
"select sqx from " + collection +
" as sqx");
395 addLikeSubqueries(wc, collection, fields, 0);
399 addSubqueries(wc, collection, fields, 0);
403 private void addSubqueries(
WhereClause wc, String collection[], String[] fields,
int count) {
404 if(count >= collection.length)
return;
412 wc.
addClause(
"select sqx from " + collection[count] +
" as sqx");
413 if(count == collection.length - 1) {
418 addSubqueries(wc, collection, fields, count + 1);
423 private void addLikeSubqueries(WhereClause wc, String collection[], String[] fields,
int count) {
424 if(count >= collection.length)
return;
427 wc.addClause(
getChain().getOpSQL() +
" exists");
429 wc.addClause(
"where exists");
432 wc.addClause(
"select sqx from " + collection[count] +
" as sqx");
433 if(count == collection.length - 1) {
435 wc.addClause(
"where sqx." + fields[0] +
" " +
getOperator().getOpSQL() +
" :" + param);
436 wc.addNamedValue(param, ((String) obj).replaceAll(
"\\*",
"%"));
438 addLikeSubqueries(wc, collection, fields, count + 1);
446 ((AfterCompose)
editor).afterCompose();
448 if(operatorEditor !=
null && operatorEditor instanceof AfterCompose) {
449 ((AfterCompose) operatorEditor).afterCompose();
459 return super.clone();
460 }
catch (CloneNotSupportedException e) {
static WhereClause getWhereClause(String[] fields, String value)
void setPrefix(String prefix)
void addClause(String clause)
void addNamedValue(String name, Object value)
static Object convertToClass(Class javaClass, Object value)
abstract void addConstraint(WhereClause wc)
void doAddSubqueryConstraint(WhereClause wc, String collection[], String field)
HtmlBasedComponent createOperatorEditor()
EnumListbox< ChainOperator > chainEditor
void doAddSubqueryConstraint(WhereClause wc, String collection, String field)
void doAddConstraint(WhereClause wc, String field)
HtmlBasedComponent getEditor()
FilterField(String label)
void doAddConstraint(WhereClause wc, String[] fields)
static final String FIELD_SUBSTITUTION_REGEXP
FilterField(String label, Number value)
void setFormat(String format)
void setChain(ChainOperator chain)
EnumSet< FilterFieldOperator > getOperators()
FilterField(String label, Date value, FilterFieldOperator operator)
FilterFieldOperator getOperator()
void setLabel(String label)
EnumListbox< ChainOperator > getChainEditor()
void setChoices(Enum[] choices)
HtmlBasedComponent editor
FilterField(String label, Enum value, FilterFieldOperator operator)
HtmlBasedComponent createEditor()
EnumListbox< ChainOperator > createChainEditor()
void doAddSubqueryConstraint(WhereClause wc, String collection[], String[] fields)
void doAddSubqueryConstraint(WhereClause wc, String collection, String[] fields)
FilterField(String label, Boolean value, FilterFieldOperator operator)
FilterField(String label, String value)
FilterField(String label, Date value)
void setFixed(boolean fixed)
FilterField(String label, Enum value)
FilterField(String label, Number value, FilterFieldOperator operator)
EnumSet< FilterFieldOperator > operators
FilterField(String label, String value, FilterFieldOperator operator)
void setOperators(EnumSet< FilterFieldOperator > operators)
FilterField(String label, Boolean value)
void setOperator(FilterFieldOperator operator)
FilterField(String label, FilterFieldOperator operator)
HtmlBasedComponent getOperatorEditor()