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.Environment;
019: import org.araneaframework.backend.list.memorybased.Expression;
020: import org.araneaframework.uilib.ConfigurationContext;
021: import org.araneaframework.uilib.form.Control;
022: import org.araneaframework.uilib.form.FormElement;
023: import org.araneaframework.uilib.form.control.TextControl;
024: import org.araneaframework.uilib.form.data.StringData;
025: import org.araneaframework.uilib.list.structure.filter.FilterContext;
026: import org.araneaframework.uilib.list.util.ExpressionUtil;
027: import org.araneaframework.uilib.list.util.FilterFormUtil;
028: import org.araneaframework.uilib.list.util.like.LikeConfiguration;
029:
030: public class LikeFilter extends BaseFieldFilter {
031:
032: private static final long serialVersionUID = 1L;
033:
034: private boolean ignoreCase;
035: private LikeConfiguration configuration;
036:
037: public static LikeFilter getInstance(FilterContext ctx,
038: String fieldId, String valueId) {
039: LikeFilter filter = new LikeFilter();
040: filter.setFieldId(fieldId);
041: filter.setValueId(valueId);
042: filter.setIgnoreCase(ctx.isIgnoreCase());
043: return filter;
044: }
045:
046: public static LikeFilter getConstantInstance(FilterContext ctx,
047: String fieldId, String valueId, Object value) {
048: LikeFilter filter = getInstance(ctx, fieldId, valueId);
049: filter.setValue(value);
050: return filter;
051: }
052:
053: public static void addToForm(FilterContext ctx, String id,
054: FormElement element) {
055: ctx.getForm().addElement(id, element);
056: }
057:
058: public static void addToForm(FilterContext ctx, String id,
059: Control control) {
060: addToForm(ctx, id, FilterFormUtil.createElement(ctx, id,
061: control, new StringData()));
062: }
063:
064: public static void addToForm(FilterContext ctx, String id) {
065: addToForm(ctx, id, FilterFormUtil.createElement(ctx, id,
066: new TextControl(), new StringData()));
067: }
068:
069: private LikeFilter() {
070: // private
071: }
072:
073: public void init(Environment env) {
074: ConfigurationContext cfg = (ConfigurationContext) env
075: .getEntry(ConfigurationContext.class);
076: if (cfg != null) {
077: configuration = (LikeConfiguration) cfg
078: .getEntry(ConfigurationContext.LIKE_CONFIGURATION);
079: }
080: }
081:
082: public LikeConfiguration getConfiguration() {
083: return configuration;
084: }
085:
086: public void setConfiguration(LikeConfiguration configuration) {
087: this .configuration = configuration;
088: }
089:
090: public boolean isIgnoreCase() {
091: return ignoreCase;
092: }
093:
094: public void setIgnoreCase(boolean ignoreCase) {
095: this .ignoreCase = ignoreCase;
096: }
097:
098: public Expression buildExpression(Map filterInfo) {
099: if (!isActive(filterInfo)) {
100: return null;
101: }
102: return ExpressionUtil.like(buildVariableExpression(),
103: buildValueExpression(filterInfo), isIgnoreCase(),
104: getConfiguration());
105: }
106: }
|