01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * 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, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16:
17: package com.google.gwt.user.client.ui;
18:
19: /**
20: * {@link ChangeListenerCollection} used to correctly hook up listeners which
21: * need to listen to events from another source.
22: * <p>
23: * For example, {@link Composite} widgets often need to listen to events
24: * generated on their wrapped widget. Upon the firing of a wrapped widget's
25: * event, the composite widget must fire its own listeners with itself as the
26: * source of the event. To use a {@link DelegatingChangeListenerCollection},
27: * simply use the {@link DelegatingChangeListenerCollection} instead of a
28: * {@link ChangeListenerCollection}. For example, in {@link SuggestBox}, the
29: * following code is used to listen to change events on the {@link SuggestBox}'s
30: * underlying widget.
31: * </p>
32: *
33: * <pre>
34: * public void addChangeListener(ChangeListener listener) {
35: * if (changeListeners == null) {
36: * changeListeners = new DelegatingChangeListenerCollection(this, box);
37: * }
38: * changeListeners.add(listener);
39: * }
40: *</pre>
41: */
42: public class DelegatingChangeListenerCollection extends
43: ChangeListenerCollection implements ChangeListener {
44:
45: private final Widget owner;
46:
47: /**
48: * Constructor for {@link DelegatingChangeListenerCollection}.
49: *
50: * @param owner owner of listeners
51: * @param delegatedTo source of events
52: */
53: public DelegatingChangeListenerCollection(Widget owner,
54: SourcesChangeEvents delegatedTo) {
55: this .owner = owner;
56: delegatedTo.addChangeListener(this );
57: }
58:
59: public void onChange(Widget sender) {
60: super.fireChange(owner);
61: }
62: }
|