01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.uilib.list.structure.filter.field;
16:
17: import java.io.Serializable;
18: import java.util.Comparator;
19: import java.util.Map;
20: import org.araneaframework.backend.list.memorybased.Expression;
21: import org.araneaframework.core.Assert;
22: import org.araneaframework.uilib.form.Control;
23: import org.araneaframework.uilib.form.FormElement;
24: import org.araneaframework.uilib.list.structure.filter.FilterContext;
25: import org.araneaframework.uilib.list.util.ExpressionUtil;
26: import org.araneaframework.uilib.list.util.FilterFormUtil;
27: import org.araneaframework.uilib.util.Event;
28:
29: public class EqualFilter extends BaseFieldFilter {
30: private static final long serialVersionUID = 1L;
31: private Comparator comparator;
32:
33: public static EqualFilter getInstance(final FilterContext ctx,
34: final String fieldId, String valueId) {
35: final EqualFilter filter = new EqualFilter();
36: filter.setFieldId(fieldId);
37: filter.setValueId(valueId);
38:
39: ctx.addInitEvent(new Event() {
40: public void run() {
41: filter.setComparator(ctx.getFieldComparator(fieldId));
42: }
43: });
44:
45: return filter;
46: }
47:
48: public static EqualFilter getConstantInstance(FilterContext ctx,
49: String fieldId, String valueId, Object value) {
50: EqualFilter filter = getInstance(ctx, fieldId, valueId);
51: filter.setValue(value);
52: return filter;
53: }
54:
55: public static void addToForm(FilterContext ctx, String id,
56: FormElement element) {
57: ctx.getForm().addElement(id, element);
58: }
59:
60: public static void addToForm(FilterContext ctx, String id,
61: Control control) {
62: addToForm(ctx, id, FilterFormUtil.createElement(ctx, id,
63: control));
64: }
65:
66: public static void addToForm(FilterContext ctx, String id) {
67: addToForm(ctx, id, FilterFormUtil.createElement(ctx, id));
68: }
69:
70: private EqualFilter() {
71: // private
72: }
73:
74: public Comparator getComparator() {
75: return comparator;
76: }
77:
78: public void setComparator(Comparator comparator) {
79: Assert.isInstanceOfParam(this , Serializable.class, comparator,
80: "comparator");
81: this .comparator = comparator;
82: }
83:
84: public Expression buildExpression(Map filterInfo) {
85: if (!isActive(filterInfo)) {
86: return null;
87: }
88: return ExpressionUtil.eq(buildVariableExpression(),
89: buildValueExpression(filterInfo), getComparator());
90: }
91: }
|