01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.forms.formmodel;
18:
19: import org.apache.avalon.framework.CascadingRuntimeException;
20: import org.apache.cocoon.forms.binding.BindingException;
21: import org.apache.cocoon.forms.event.ValueChangedEvent;
22: import org.apache.cocoon.forms.event.ValueChangedListener;
23:
24: /**
25: * @version $Id: RepeaterFilterField.java 517733 2007-03-13 15:37:22Z vgritsenko $
26: */
27: public class RepeaterFilterField extends Field {
28:
29: private EnhancedRepeater repeater;
30: private String field;
31:
32: public RepeaterFilterField(
33: RepeaterFilterFieldDefinition fieldDefinition) {
34: super (fieldDefinition);
35: this .field = fieldDefinition.getField();
36: }
37:
38: public void initialize() {
39: super .initialize();
40: String name = ((RepeaterFilterFieldDefinition) getDefinition())
41: .getRepeaterName();
42: Widget w = getParent().lookupWidget(name);
43: if (w == null) {
44: throw new IllegalArgumentException(
45: "Cannot find repeater named " + name);
46: }
47: if (!(w instanceof EnhancedRepeater)) {
48: throw new IllegalArgumentException("The repeater named "
49: + name + " is not an enhanced repeater");
50: }
51: this .repeater = (EnhancedRepeater) w;
52:
53: addValueChangedListener(new ValueChangedListener() {
54: public void valueChanged(ValueChangedEvent event) {
55: if (repeater.validate()) {
56: try {
57: repeater.setFilter(field, event.getNewValue());
58: } catch (BindingException e) {
59: throw new CascadingRuntimeException(
60: "Error setting filter", e);
61: }
62: }
63: }
64: });
65: }
66:
67: }
|