001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.uilib.list.structure.filter;
016:
017: import java.util.ArrayList;
018: import java.util.List;
019: import org.araneaframework.backend.list.memorybased.ExpressionBuilder;
020: import org.araneaframework.uilib.form.Control;
021: import org.araneaframework.uilib.form.FormElement;
022: import org.araneaframework.uilib.form.FormWidget;
023: import org.araneaframework.uilib.form.control.TextControl;
024: import org.araneaframework.uilib.list.ListWidget;
025: import org.araneaframework.uilib.list.TypeHelper;
026: import org.araneaframework.uilib.list.structure.ListFilter;
027: import org.araneaframework.uilib.list.structure.filter.advanced.RangeInRangeFilter;
028: import org.araneaframework.uilib.list.structure.filter.advanced.SqlFunctionFilter;
029: import org.araneaframework.uilib.list.structure.filter.atomic.Constant;
030: import org.araneaframework.uilib.list.structure.filter.atomic.Field;
031: import org.araneaframework.uilib.list.structure.filter.atomic.Value;
032: import org.araneaframework.uilib.list.structure.filter.field.EqualFilter;
033: import org.araneaframework.uilib.list.structure.filter.field.GreaterThanFilter;
034: import org.araneaframework.uilib.list.structure.filter.field.LikeFilter;
035: import org.araneaframework.uilib.list.structure.filter.field.LowerThanFilter;
036: import org.araneaframework.uilib.list.structure.filter.field.NullFilter;
037: import org.araneaframework.uilib.list.structure.filter.field.RangeFilter;
038: import org.araneaframework.uilib.list.util.FormUtil;
039:
040: /**
041: * Standard list filter helper. This class is used to add <b>filters</b> and
042: * their <b>form elements</b> to the {@link ListWidget}.
043: * <p>
044: * THe following filters can be added to the list:
045: * {@link EqualFilter},
046: * {@link GreaterThanFilter},
047: * {@link LowerThanFilter},
048: * {@link LikeFilter},
049: * {@link NullFilter},
050: * {@link RangeFilter},
051: * {@link RangeInRangeFilter},
052: * {@link SqlFunctionFilter}.
053: * </p>
054: * <p>
055: * There are many methods for adding each filter and their form elements.
056: * Note that some methods start with the <b>_</b> sign. These add filters
057: * without adding form elements to them. Use this only if its inevitable.
058: * The default behaivor is to add the filter and its form elements at once to
059: * enable filter specific form elements (e.g {@link LikeFilter} uses
060: * {@link TextControl} ignoring the field type defined by the list) and avoid
061: * many mistakes.
062: * </p>
063: * <p>
064: * Also many filters can be added as constant filters. This means
065: * they are just part of the query but do not depend on the user. For example
066: * one would like to add constant filter to get only clients from one region
067: * without showing this filter to the user or letting it to be modified.
068: * </p>
069: * <p>
070: * In other cases, <b>filters are added with form elements</b> no matter if one
071: * pass it within the method arguments or no. For each form element (e.g 2 in
072: * case of range filter and 1 in case of like filter) one can pass a form
073: * element, just a control or none of these. Passing a control means that the
074: * form element is automatically created using the other information available
075: * for this filter's field - <b>label</b> and <b>type</b>.
076: * Not passing the control either just means that the <b>control</b> is
077: * automatically created according the the field type
078: * (using {@link FormUtil#createControl(Class)})). However if you like to define
079: * label or type for a form element, you can predefine them using
080: * {@link #addCustomLabel(String, String)} and
081: * {@link #addFieldType(String, Class)} methods.
082: * As you could expect, the <b>mandatory</b> is set to <code>false</code> and
083: * the <b>initial value</b> is set to null by default.
084: * </p>
085: * <p>
086: * Their is one more aspect for all filter adding methods. For each method, one
087: * can define <b>valueId</b>. The term <b>value</b> is used here to mark the
088: * blank in the filter (basically the form element). By default the
089: * <b>fieldId</b> is also used as the valueId. So it's unneccesary to pass a
090: * valueId unless one would like to add more than one filter for one field.
091: * In the case of range filter, there are already two values used for one
092: * filter and therefore original fieldId is suffixed to distinguish the two
093: * values - low and high. However for more than two range filter for one field,
094: * custom value ids must be used as well.
095: *
096: * @author <a href="mailto:rein@araneaframework.org">Rein Raudjärv</a>
097: *
098: * @see ListWidget
099: * @see FormWidget
100: * @see ListFilter
101: */
102: public class FilterHelper extends BaseFilterHelper {
103:
104: /**
105: * Constructs a {@link FilterHelper}.
106: *
107: * @param list list widget.
108: */
109: public FilterHelper(ListWidget list) {
110: super (list);
111: }
112:
113: /**
114: * Sets the current case sensitivity behaivor.
115: *
116: * @param ignoreCase whether to ignore case.
117: */
118: public FilterHelper setIgnoreCase(boolean ignoreCase) {
119: super ._setIgnoreCase(ignoreCase);
120: return this ;
121: }
122:
123: // /**
124: // * Sets the current locale.
125: // *
126: // * @param locale new locale.
127: // */
128: // public FilterHelper setLocale(Locale locale) {
129: // super._setLocale(locale);
130: // return this;
131: // }
132:
133: /**
134: * Sets the current strickness behaivor.
135: *
136: * @param strict whether new filters should be strict.
137: */
138: public FilterHelper setStrict(boolean strict) {
139: super ._setStrict(strict);
140: return this ;
141: }
142:
143: /**
144: * Adds custom label for specified field. This can override already defined
145: * label of list field. Those labels are used by new filter form elements
146: * that are automatically created for list filters.
147: *
148: * @param fieldId field id.
149: * @param labelId label id (not yet resolved).
150: */
151: public FilterHelper addCustomLabel(String fieldId, String labelId) {
152: super ._addCustomLabel(fieldId, labelId);
153: return this ;
154: }
155:
156: /**
157: * Defines type for specified field.
158: *
159: * @param fieldId field id.
160: * @param type field type.
161: *
162: * @see TypeHelper#addFieldType(String, Class)
163: */
164: public FilterHelper addFieldType(String fieldId, Class type) {
165: super ._addFieldType(fieldId, type);
166: return this ;
167: }
168:
169: // ========== EQUALS ==========
170:
171: // filter with form element
172:
173: public FilterHelper eq(String fieldId) {
174: return eq(fieldId, fieldId);
175: }
176:
177: public FilterHelper eq(String fieldId, String valueId) {
178: _eq(fieldId, valueId);
179: EqualFilter.addToForm(this , valueId);
180: return this ;
181: }
182:
183: public FilterHelper eq(String fieldId, Control control) {
184: return eq(fieldId, fieldId, control);
185: }
186:
187: public FilterHelper eq(String fieldId, String valueId,
188: Control control) {
189: _eq(fieldId, valueId);
190: EqualFilter.addToForm(this , valueId, control);
191: return this ;
192: }
193:
194: public FilterHelper eq(String fieldId, FormElement element) {
195: return eq(fieldId, fieldId, element);
196: }
197:
198: public FilterHelper eq(String fieldId, String valueId,
199: FormElement element) {
200: _eq(fieldId, valueId);
201: EqualFilter.addToForm(this , valueId, element);
202: return this ;
203: }
204:
205: // filter
206:
207: public FilterHelper _eq(String fieldId) {
208: return _eq(fieldId, fieldId);
209: }
210:
211: public FilterHelper _eq(String fieldId, String valueId) {
212: list.addFilter(EqualFilter.getInstance(this , fieldId, valueId));
213: return this ;
214: }
215:
216: // constant filter
217:
218: public FilterHelper eqConst(String fieldId, Object value) {
219: return eqConst(fieldId, fieldId, value);
220: }
221:
222: public FilterHelper eqConst(String fieldId, String valueId,
223: Object value) {
224: list.addFilter(EqualFilter.getConstantInstance(this , fieldId,
225: valueId, value));
226: return this ;
227: }
228:
229: // ========== GREATER THAN ==========
230:
231: // filter with form element
232:
233: public FilterHelper gt(String fieldId) {
234: return gt(fieldId, fieldId);
235: }
236:
237: public FilterHelper gt(String fieldId, String valueId) {
238: _gt(fieldId, valueId);
239: GreaterThanFilter.addToForm(this , valueId);
240: return this ;
241: }
242:
243: public FilterHelper gt(String fieldId, Control control) {
244: return gt(fieldId, fieldId, control);
245: }
246:
247: public FilterHelper gt(String fieldId, String valueId,
248: Control control) {
249: _gt(fieldId, valueId);
250: GreaterThanFilter.addToForm(this , valueId, control);
251: return this ;
252: }
253:
254: public FilterHelper gt(String fieldId, FormElement element) {
255: return gt(fieldId, fieldId, element);
256: }
257:
258: public FilterHelper gt(String fieldId, String valueId,
259: FormElement element) {
260: _gt(fieldId, valueId);
261: GreaterThanFilter.addToForm(this , valueId, element);
262: return this ;
263: }
264:
265: // filter
266:
267: public FilterHelper _gt(String fieldId) {
268: return _gt(fieldId, fieldId);
269: }
270:
271: public FilterHelper _gt(String fieldId, String valueId) {
272: list.addFilter(GreaterThanFilter.getInstance(this , fieldId,
273: valueId));
274: return this ;
275: }
276:
277: // constant filter
278:
279: public FilterHelper gtConst(String fieldId, Object value) {
280: return gtConst(fieldId, fieldId, value);
281: }
282:
283: public FilterHelper gtConst(String fieldId, String valueId,
284: Object value) {
285: list.addFilter(GreaterThanFilter.getConstantInstance(this ,
286: fieldId, valueId, value));
287: return this ;
288: }
289:
290: // ========== LOWER THAN ==========
291:
292: // filter with form element
293:
294: public FilterHelper lt(String fieldId) {
295: return lt(fieldId, fieldId);
296: }
297:
298: public FilterHelper lt(String fieldId, String valueId) {
299: _lt(fieldId, valueId);
300: LowerThanFilter.addToForm(this , valueId);
301: return this ;
302: }
303:
304: public FilterHelper lt(String fieldId, Control control) {
305: return lt(fieldId, fieldId, control);
306: }
307:
308: public FilterHelper lt(String fieldId, String valueId,
309: Control control) {
310: _lt(fieldId, valueId);
311: LowerThanFilter.addToForm(this , valueId, control);
312: return this ;
313: }
314:
315: public FilterHelper lt(String fieldId, FormElement element) {
316: return lt(fieldId, fieldId, element);
317: }
318:
319: public FilterHelper lt(String fieldId, String valueId,
320: FormElement element) {
321: _lt(fieldId, valueId);
322: LowerThanFilter.addToForm(this , valueId, element);
323: return this ;
324: }
325:
326: // filter
327:
328: public FilterHelper _lt(String fieldId) {
329: return _lt(fieldId, fieldId);
330: }
331:
332: public FilterHelper _lt(String fieldId, String valueId) {
333: list.addFilter(LowerThanFilter.getInstance(this , fieldId,
334: valueId));
335: return this ;
336: }
337:
338: // constant filter
339:
340: public FilterHelper ltConst(String fieldId, Object value) {
341: return ltConst(fieldId, fieldId, value);
342: }
343:
344: public FilterHelper ltConst(String fieldId, String valueId,
345: Object value) {
346: list.addFilter(LowerThanFilter.getConstantInstance(this ,
347: fieldId, valueId, value));
348: return this ;
349: }
350:
351: // ========== LIKE ==========
352:
353: // filter with form element
354:
355: public FilterHelper like(String fieldId) {
356: return like(fieldId, fieldId);
357: }
358:
359: public FilterHelper like(String fieldId, String valueId) {
360: _like(fieldId, valueId);
361: LikeFilter.addToForm(this , valueId);
362: return this ;
363: }
364:
365: public FilterHelper like(String fieldId, Control control) {
366: return like(fieldId, fieldId, control);
367: }
368:
369: public FilterHelper like(String fieldId, String valueId,
370: Control control) {
371: _like(fieldId, valueId);
372: LikeFilter.addToForm(this , valueId, control);
373: return this ;
374: }
375:
376: public FilterHelper like(String fieldId, FormElement element) {
377: return like(fieldId, fieldId, element);
378: }
379:
380: public FilterHelper like(String fieldId, String valueId,
381: FormElement element) {
382: _like(fieldId, valueId);
383: LikeFilter.addToForm(this , valueId, element);
384: return this ;
385: }
386:
387: // filter
388:
389: public FilterHelper _like(String fieldId) {
390: return _like(fieldId, fieldId);
391: }
392:
393: public FilterHelper _like(String fieldId, String valueId) {
394: list.addFilter(LikeFilter.getInstance(this , fieldId, valueId));
395: return this ;
396: }
397:
398: // constant filter
399:
400: public FilterHelper likeConst(String fieldId, Object value) {
401: return likeConst(fieldId, fieldId, value);
402: }
403:
404: public FilterHelper likeConst(String fieldId, String valueId,
405: Object value) {
406: list.addFilter(LikeFilter.getConstantInstance(this , fieldId,
407: valueId, value));
408: return this ;
409: }
410:
411: // ========== IS NULL ==========
412:
413: // filter with form element
414:
415: public FilterHelper isNull(String fieldId, Object conditionValue) {
416: return isNull(fieldId, fieldId, conditionValue);
417: }
418:
419: public FilterHelper isNull(String fieldId, String valueId,
420: Object conditionValueId) {
421: _isNull(fieldId, valueId);
422: NullFilter.addToForm(this , valueId);
423: return this ;
424: }
425:
426: public FilterHelper isNull(String fieldId, Object conditionValue,
427: Control control) {
428: return isNull(fieldId, fieldId, conditionValue, control);
429: }
430:
431: public FilterHelper isNull(String fieldId, String valueId,
432: Object conditionValue, Control control) {
433: _isNull(fieldId, valueId);
434: NullFilter.addToForm(this , valueId, control);
435: return this ;
436: }
437:
438: public FilterHelper isNull(String fieldId, Object conditionValue,
439: FormElement element) {
440: return isNull(fieldId, fieldId, conditionValue, element);
441: }
442:
443: public FilterHelper isNull(String fieldId, String valueId,
444: Object conditionValue, FormElement element) {
445: _isNull(fieldId, valueId);
446: NullFilter.addToForm(this , valueId, element);
447: return this ;
448: }
449:
450: // filter
451:
452: public FilterHelper _isNull(String fieldId, Object conditionValue) {
453: return _isNull(fieldId, fieldId, conditionValue);
454: }
455:
456: public FilterHelper _isNull(String fieldId, String valueId,
457: Object conditionValue) {
458: list.addFilter(NullFilter.getIdNullInstance(this , fieldId,
459: valueId, conditionValue));
460: return this ;
461: }
462:
463: // constant filter
464:
465: public FilterHelper isNullConst(String fieldId) {
466: list.addFilter(NullFilter.getIsNullConstantInstance(this ,
467: fieldId));
468: return this ;
469: }
470:
471: // ========== NOT NULL ==========
472:
473: // filter with form element
474:
475: public FilterHelper notNull(String fieldId, Object conditionValue) {
476: return notNull(fieldId, fieldId, conditionValue);
477: }
478:
479: public FilterHelper notNull(String fieldId, String valueId,
480: Object conditionValueId) {
481: _notNull(fieldId, valueId);
482: NullFilter.addToForm(this , valueId);
483: return this ;
484: }
485:
486: public FilterHelper notNull(String fieldId, Object conditionValue,
487: Control control) {
488: return notNull(fieldId, fieldId, conditionValue, control);
489: }
490:
491: public FilterHelper notNull(String fieldId, String valueId,
492: Object conditionValue, Control control) {
493: _notNull(fieldId, valueId);
494: NullFilter.addToForm(this , valueId, control);
495: return this ;
496: }
497:
498: public FilterHelper notNull(String fieldId, Object conditionValue,
499: FormElement element) {
500: return notNull(fieldId, fieldId, conditionValue, element);
501: }
502:
503: public FilterHelper notNull(String fieldId, String valueId,
504: Object conditionValue, FormElement element) {
505: _notNull(fieldId, valueId);
506: NullFilter.addToForm(this , valueId, element);
507: return this ;
508: }
509:
510: // filter
511:
512: public FilterHelper _notNull(String fieldId, Object conditionValue) {
513: return _notNull(fieldId, fieldId, conditionValue);
514: }
515:
516: public FilterHelper _notNull(String fieldId, String valueId,
517: Object conditionValue) {
518: list.addFilter(NullFilter.getNotNullInstance(this , fieldId,
519: valueId, conditionValue));
520: return this ;
521: }
522:
523: // constant filter
524:
525: public FilterHelper notNullConst(String fieldId) {
526: list.addFilter(NullFilter.getNotNullConstantInstance(this ,
527: fieldId));
528: return this ;
529: }
530:
531: // ========== RANGE ==========
532:
533: // filter with form element
534:
535: public FilterHelper range(String fieldId) {
536: return range(fieldId, getLowValueId(fieldId),
537: getHighValueId(fieldId));
538: }
539:
540: public FilterHelper range(String fieldId, String lowValueId,
541: String highValueId) {
542: _range(fieldId, lowValueId, highValueId);
543: RangeFilter.addToForm(this , lowValueId, highValueId);
544: return this ;
545: }
546:
547: public FilterHelper range(String fieldId, Control lowControl,
548: Control highControl) {
549: return range(fieldId, getLowValueId(fieldId),
550: getHighValueId(fieldId), lowControl, highControl);
551: }
552:
553: public FilterHelper range(String fieldId, String lowValueId,
554: String highValueId, Control lowControl, Control highControl) {
555: _range(fieldId, lowValueId, highValueId);
556: RangeFilter.addToForm(this , lowValueId, highValueId,
557: lowControl, highControl);
558: return this ;
559: }
560:
561: public FilterHelper range(String fieldId, FormElement lowElement,
562: FormElement highElement) {
563: return range(fieldId, getLowValueId(fieldId),
564: getHighValueId(fieldId), lowElement, highElement);
565: }
566:
567: public FilterHelper range(String fieldId, String lowValueId,
568: String highValueId, FormElement lowElement,
569: FormElement highElement) {
570: _range(fieldId, lowValueId, highValueId);
571: RangeFilter.addToForm(this , lowValueId, highValueId,
572: lowElement, highElement);
573: return this ;
574: }
575:
576: // filter
577:
578: public FilterHelper _range(String fieldId) {
579: return _range(fieldId, getLowValueId(fieldId),
580: getHighValueId(fieldId));
581: }
582:
583: public FilterHelper _range(String fieldId, String lowValueId,
584: String highValueId) {
585: list.addFilter(RangeFilter.getInstance(this , fieldId,
586: lowValueId, highValueId));
587: return this ;
588: }
589:
590: // ========== FIELD RANGE IN VALUE RANGE ==========
591:
592: // filter with form element
593:
594: public FilterHelper fieldRangeInValueRange(String lowFieldId,
595: String highFieldId) {
596: return fieldRangeInValueRange(lowFieldId, highFieldId,
597: lowFieldId, highFieldId);
598: }
599:
600: public FilterHelper fieldRangeInValueRange(String lowFieldId,
601: String highFieldId, String lowValueId, String highValueId) {
602: _fieldRangeInValueRange(lowFieldId, highFieldId, lowValueId,
603: highFieldId);
604: RangeInRangeFilter.addToForm(this , lowValueId, highFieldId);
605: return this ;
606: }
607:
608: public FilterHelper fieldRangeInValueRange(String lowFieldId,
609: String highFieldId, Control lowControl, Control highControl) {
610: return fieldRangeInValueRange(lowFieldId, highFieldId,
611: lowFieldId, highFieldId, lowControl, highControl);
612: }
613:
614: public FilterHelper fieldRangeInValueRange(String lowFieldId,
615: String highFieldId, String lowValueId, String highValueId,
616: Control lowControl, Control highControl) {
617: _fieldRangeInValueRange(lowFieldId, highFieldId, lowValueId,
618: highFieldId);
619: RangeInRangeFilter.addToForm(this , lowValueId, highFieldId,
620: lowControl, highControl);
621: return this ;
622: }
623:
624: public FilterHelper fieldRangeInValueRange(String lowFieldId,
625: String highFieldId, FormElement lowElement,
626: FormElement highElement) {
627: return fieldRangeInValueRange(lowFieldId, highFieldId,
628: lowFieldId, highFieldId, lowElement, highElement);
629: }
630:
631: public FilterHelper fieldRangeInValueRange(String lowFieldId,
632: String highFieldId, String lowValueId, String highValueId,
633: FormElement lowElement, FormElement highElement) {
634: _fieldRangeInValueRange(lowFieldId, highFieldId, lowValueId,
635: highFieldId);
636: RangeInRangeFilter.addToForm(this , lowValueId, highFieldId,
637: lowElement, highElement);
638: return this ;
639: }
640:
641: // filter
642:
643: public FilterHelper _fieldRangeInValueRange(String lowFieldId,
644: String highFieldId) {
645: return _fieldRangeInValueRange(lowFieldId, highFieldId,
646: lowFieldId, highFieldId);
647: }
648:
649: public FilterHelper _fieldRangeInValueRange(String lowFieldId,
650: String highFieldId, String lowValueId, String highValueId) {
651: list.addFilter(RangeInRangeFilter
652: .getFieldRangeInValueRangeInstance(this , lowFieldId,
653: highFieldId, lowValueId, highValueId));
654: return this ;
655: }
656:
657: // ========== VALUE RANGE IN FIELD RANGE ==========
658:
659: // filter with form element
660:
661: public FilterHelper valueRangeInFieldRange(String lowFieldId,
662: String highFieldId) {
663: return valueRangeInFieldRange(lowFieldId, highFieldId,
664: lowFieldId, highFieldId);
665: }
666:
667: public FilterHelper valueRangeInFieldRange(String lowFieldId,
668: String highFieldId, String lowValueId, String highValueId) {
669: _valueRangeInFieldRange(lowFieldId, highFieldId, lowValueId,
670: highFieldId);
671: RangeInRangeFilter.addToForm(this , lowValueId, highFieldId);
672: return this ;
673: }
674:
675: public FilterHelper valueRangeInFieldRange(String lowFieldId,
676: String highFieldId, Control lowControl, Control highControl) {
677: return valueRangeInFieldRange(lowFieldId, highFieldId,
678: lowFieldId, highFieldId, lowControl, highControl);
679: }
680:
681: public FilterHelper valueRangeInFieldRange(String lowFieldId,
682: String highFieldId, String lowValueId, String highValueId,
683: Control lowControl, Control highControl) {
684: _valueRangeInFieldRange(lowFieldId, highFieldId, lowValueId,
685: highFieldId);
686: RangeInRangeFilter.addToForm(this , lowValueId, highFieldId,
687: lowControl, highControl);
688: return this ;
689: }
690:
691: public FilterHelper valueRangeInFieldRange(String lowFieldId,
692: String highFieldId, FormElement lowElement,
693: FormElement highElement) {
694: return valueRangeInFieldRange(lowFieldId, highFieldId,
695: lowFieldId, highFieldId, lowElement, highElement);
696: }
697:
698: public FilterHelper valueRangeInFieldRange(String lowFieldId,
699: String highFieldId, String lowValueId, String highValueId,
700: FormElement lowElement, FormElement highElement) {
701: _valueRangeInFieldRange(lowFieldId, highFieldId, lowValueId,
702: highFieldId);
703: RangeInRangeFilter.addToForm(this , lowValueId, highFieldId,
704: lowElement, highElement);
705: return this ;
706: }
707:
708: // filter
709:
710: public FilterHelper _valueRangeInFieldRange(String lowFieldId,
711: String highFieldId) {
712: return _fieldRangeInValueRange(lowFieldId, highFieldId,
713: lowFieldId, highFieldId);
714: }
715:
716: public FilterHelper _valueRangeInFieldRange(String lowFieldId,
717: String highFieldId, String lowValueId, String highValueId) {
718: list.addFilter(RangeInRangeFilter
719: .getValueRangeInFieldRangeInstance(this , lowFieldId,
720: highFieldId, lowValueId, highValueId));
721: return this ;
722: }
723:
724: // ========== OVERLAP RANGE ==========
725:
726: // filter with form element
727:
728: public FilterHelper overlapRange(String lowFieldId,
729: String highFieldId) {
730: return overlapRange(lowFieldId, highFieldId, lowFieldId,
731: highFieldId);
732: }
733:
734: public FilterHelper overlapRange(String lowFieldId,
735: String highFieldId, String lowValueId, String highValueId) {
736: _overlapRange(lowFieldId, highFieldId, lowValueId, highFieldId);
737: RangeInRangeFilter.addToForm(this , lowValueId, highFieldId);
738: return this ;
739: }
740:
741: public FilterHelper overlapRange(String lowFieldId,
742: String highFieldId, Control lowControl, Control highControl) {
743: return overlapRange(lowFieldId, highFieldId, lowFieldId,
744: highFieldId, lowControl, highControl);
745: }
746:
747: public FilterHelper overlapRange(String lowFieldId,
748: String highFieldId, String lowValueId, String highValueId,
749: Control lowControl, Control highControl) {
750: _overlapRange(lowFieldId, highFieldId, lowValueId, highFieldId);
751: RangeInRangeFilter.addToForm(this , lowValueId, highFieldId,
752: lowControl, highControl);
753: return this ;
754: }
755:
756: public FilterHelper overlapRange(String lowFieldId,
757: String highFieldId, FormElement lowElement,
758: FormElement highElement) {
759: return overlapRange(lowFieldId, highFieldId, lowFieldId,
760: highFieldId, lowElement, highElement);
761: }
762:
763: public FilterHelper overlapRange(String lowFieldId,
764: String highFieldId, String lowValueId, String highValueId,
765: FormElement lowElement, FormElement highElement) {
766: _overlapRange(lowFieldId, highFieldId, lowValueId, highFieldId);
767: RangeInRangeFilter.addToForm(this , lowValueId, highFieldId,
768: lowElement, highElement);
769: return this ;
770: }
771:
772: // filter
773:
774: public FilterHelper _overlapRange(String lowFieldId,
775: String highFieldId) {
776: return _fieldRangeInValueRange(lowFieldId, highFieldId,
777: lowFieldId, highFieldId);
778: }
779:
780: public FilterHelper _overlapRange(String lowFieldId,
781: String highFieldId, String lowValueId, String highValueId) {
782: list.addFilter(RangeInRangeFilter.getOverlapInstance(this ,
783: lowFieldId, highFieldId, lowValueId, highValueId));
784: return this ;
785: }
786:
787: // ========== SQL FUNCTION ==========
788:
789: public SqlFunction sqlFunction(String name) {
790: return new SqlFunction(name);
791: }
792:
793: /**
794: * SQL Function filter helper.
795: *
796: * @author <a href="mailto:rein@araneaframework.org">Rein Raudjärv</a>
797: */
798: public class SqlFunction {
799: private String name;
800: private List params = new ArrayList();
801:
802: SqlFunction(String name) {
803: this .name = name;
804: }
805:
806: private ExpressionBuilder[] getParams() {
807: return (ExpressionBuilder[]) params
808: .toArray(new ExpressionBuilder[params.size()]);
809: }
810:
811: // add params
812:
813: public SqlFunction addFieldParam(String fieldId) {
814: params.add(new Field(fieldId));
815: return this ;
816: }
817:
818: public SqlFunction addValueParam(String valueId) {
819: SqlFunctionFilter.addToForm(FilterHelper.this , valueId);
820: return _addValueParam(valueId);
821: }
822:
823: public SqlFunction addValueParam(String valueId, Control control) {
824: SqlFunctionFilter.addToForm(FilterHelper.this , valueId,
825: control);
826: return _addValueParam(valueId);
827: }
828:
829: public SqlFunction addValueParam(String valueId,
830: FormElement element) {
831: SqlFunctionFilter.addToForm(FilterHelper.this , valueId,
832: element);
833: return _addValueParam(valueId);
834: }
835:
836: public SqlFunction _addValueParam(String valueId) {
837: params.add(new Value(valueId));
838: return this ;
839: }
840:
841: public SqlFunction addConstParam(Object value) {
842: return addConstParam(null, value);
843: }
844:
845: public SqlFunction addConstParam(String valueId, Object value) {
846: params.add(new Constant(valueId, value));
847: return this ;
848: }
849:
850: // add EQUALS filter
851:
852: public FilterHelper eqField(String fieldId) {
853: list.addFilter(SqlFunctionFilter.getFieldEqualInstance(
854: FilterHelper.this , fieldId, name, getParams()));
855: return FilterHelper.this ;
856: }
857:
858: public FilterHelper eqValue(String valueId) {
859: _eqValue(valueId);
860: SqlFunctionFilter.addToForm(FilterHelper.this , valueId);
861: return FilterHelper.this ;
862: }
863:
864: public FilterHelper eqValue(String valueId, Control control) {
865: _eqValue(valueId);
866: SqlFunctionFilter.addToForm(FilterHelper.this , valueId,
867: control);
868: return FilterHelper.this ;
869: }
870:
871: public FilterHelper eqValue(String valueId, FormElement element) {
872: _eqValue(valueId);
873: SqlFunctionFilter.addToForm(FilterHelper.this , valueId,
874: element);
875: return FilterHelper.this ;
876: }
877:
878: public FilterHelper _eqValue(String valueId) {
879: list.addFilter(SqlFunctionFilter.getValueEqualInstance(
880: FilterHelper.this , valueId, name, getParams()));
881: return FilterHelper.this ;
882: }
883:
884: public FilterHelper eqConst(String valueId) {
885: return eqConst(null, valueId);
886: }
887:
888: public FilterHelper eqConst(String valueId, Object value) {
889: list.addFilter(SqlFunctionFilter.getConstantEqualInstance(
890: FilterHelper.this , valueId, value, name,
891: getParams()));
892: return FilterHelper.this ;
893: }
894:
895: // add GREATER THAN filter
896:
897: public FilterHelper gtField(String fieldId) {
898: list.addFilter(SqlFunctionFilter
899: .getFieldGreaterThanInstance(FilterHelper.this ,
900: fieldId, name, getParams()));
901: return FilterHelper.this ;
902: }
903:
904: public FilterHelper gtValue(String valueId) {
905: _gtValue(valueId);
906: SqlFunctionFilter.addToForm(FilterHelper.this , valueId);
907: return FilterHelper.this ;
908: }
909:
910: public FilterHelper gtValue(String valueId, Control control) {
911: _gtValue(valueId);
912: SqlFunctionFilter.addToForm(FilterHelper.this , valueId,
913: control);
914: return FilterHelper.this ;
915: }
916:
917: public FilterHelper gtValue(String valueId, FormElement element) {
918: _gtValue(valueId);
919: SqlFunctionFilter.addToForm(FilterHelper.this , valueId,
920: element);
921: return FilterHelper.this ;
922: }
923:
924: public FilterHelper _gtValue(String valueId) {
925: list.addFilter(SqlFunctionFilter
926: .getValueGreaterThanInstance(FilterHelper.this ,
927: valueId, name, getParams()));
928: return FilterHelper.this ;
929: }
930:
931: public FilterHelper gtConst(String valueId) {
932: return gtConst(null, valueId);
933: }
934:
935: public FilterHelper gtConst(String valueId, Object value) {
936: list.addFilter(SqlFunctionFilter
937: .getConstantGreaterThanInstance(FilterHelper.this ,
938: valueId, value, name, getParams()));
939: return FilterHelper.this ;
940: }
941:
942: // add LOWER THAN filter
943:
944: public FilterHelper ltField(String fieldId) {
945: list.addFilter(SqlFunctionFilter.getFieldLowerThanInstance(
946: FilterHelper.this , fieldId, name, getParams()));
947: return FilterHelper.this ;
948: }
949:
950: public FilterHelper ltValue(String valueId) {
951: _ltValue(valueId);
952: SqlFunctionFilter.addToForm(FilterHelper.this , valueId);
953: return FilterHelper.this ;
954: }
955:
956: public FilterHelper ltValue(String valueId, Control control) {
957: _ltValue(valueId);
958: SqlFunctionFilter.addToForm(FilterHelper.this , valueId,
959: control);
960: return FilterHelper.this ;
961: }
962:
963: public FilterHelper ltValue(String valueId, FormElement element) {
964: _ltValue(valueId);
965: SqlFunctionFilter.addToForm(FilterHelper.this , valueId,
966: element);
967: return FilterHelper.this ;
968: }
969:
970: public FilterHelper _ltValue(String valueId) {
971: list.addFilter(SqlFunctionFilter.getValueLowerThanInstance(
972: FilterHelper.this , valueId, name, getParams()));
973: return FilterHelper.this ;
974: }
975:
976: public FilterHelper ltConst(String valueId) {
977: return ltConst(null, valueId);
978: }
979:
980: public FilterHelper ltConst(String valueId, Object value) {
981: list.addFilter(SqlFunctionFilter
982: .getConstantLowerThanInstance(FilterHelper.this,
983: valueId, value, name, getParams()));
984: return FilterHelper.this;
985: }
986:
987: }
988:
989: }
|