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.field;
016:
017: import java.util.Map;
018: import org.araneaframework.backend.list.memorybased.Expression;
019: import org.araneaframework.uilib.form.Control;
020: import org.araneaframework.uilib.form.FormElement;
021: import org.araneaframework.uilib.list.structure.filter.FilterContext;
022: import org.araneaframework.uilib.list.util.ExpressionUtil;
023: import org.araneaframework.uilib.list.util.FilterFormUtil;
024:
025: public abstract class NullFilter extends BaseFieldFilter {
026:
027: private static final long serialVersionUID = 1L;
028:
029: public static NullFilter getIdNullInstance(FilterContext ctx,
030: String fieldId, String valueId, Object conditionValue) {
031: IsNull filter = new IsNull();
032: filter.setFieldId(fieldId);
033: filter.setValueId(valueId);
034: filter.setConditionValue(conditionValue);
035: return filter;
036: }
037:
038: public static NullFilter getIsNullConstantInstance(
039: FilterContext ctx, String fieldId) {
040: IsNullConstant filter = new IsNullConstant();
041: filter.setFieldId(fieldId);
042: return filter;
043: }
044:
045: public static NullFilter getNotNullInstance(FilterContext ctx,
046: String fieldId, String valueId, Object conditionValue) {
047: NotNull filter = new NotNull();
048: filter.setFieldId(fieldId);
049: filter.setValueId(valueId);
050: filter.setConditionValue(conditionValue);
051: return filter;
052: }
053:
054: public static NullFilter getNotNullConstantInstance(
055: FilterContext ctx, String fieldId) {
056: NotNullConstant filter = new NotNullConstant();
057: filter.setFieldId(fieldId);
058: return filter;
059: }
060:
061: public static void addToForm(FilterContext ctx, String id,
062: FormElement element) {
063: ctx.getForm().addElement(id, element);
064: }
065:
066: public static void addToForm(FilterContext ctx, String id,
067: Control control) {
068: addToForm(ctx, id, FilterFormUtil.createElement(ctx, id,
069: control));
070: }
071:
072: public static void addToForm(FilterContext ctx, String id) {
073: addToForm(ctx, id, FilterFormUtil.createElement(ctx, id));
074: }
075:
076: static abstract class ConditionValue extends NullFilter {
077: private Object conditionValue;
078:
079: public Object getConditionValue() {
080: return conditionValue;
081: }
082:
083: public void setConditionValue(Object conditionValue) {
084: this .conditionValue = conditionValue;
085: }
086: }
087:
088: static class IsNull extends ConditionValue {
089: public Expression buildExpression(Map data) {
090: if (equals(data.get(getValueId()), getConditionValue())) {
091: return ExpressionUtil.isNull(buildVariableExpression());
092: }
093: return null;
094: }
095: }
096:
097: static class IsNullConstant extends NullFilter {
098: public Expression buildExpression(Map data) {
099: return ExpressionUtil.isNull(buildVariableExpression());
100: }
101: }
102:
103: static class NotNull extends ConditionValue {
104: public Expression buildExpression(Map data) {
105: if (equals(data.get(getValueId()), getConditionValue())) {
106: return ExpressionUtil
107: .notNull(buildVariableExpression());
108: }
109: return null;
110: }
111: }
112:
113: static class NotNullConstant extends NullFilter {
114: public Expression buildExpression(Map data) {
115: return ExpressionUtil.notNull(buildVariableExpression());
116: }
117: }
118:
119: static boolean equals(Object o1, Object o2) {
120: return o1 == o2 || o1 == null ? o2 == null : o1.equals(o2);
121: }
122:
123: }
|