KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > ui > DelegatingClickListenerCollection


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 ClickListenerCollection} 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 DelegatingClickListenerCollection},
27  * simply use the {@link DelegatingClickListenerCollection} instead of a
28  * {@link ClickListenerCollection}. For example, in {@link SuggestBox}, the
29  * following code is used to listen to click events on the {@link SuggestBox}'s
30  * underlying widget.
31  * </p>
32  *
33  * <pre>
34  * public void addClickListener(ClickListener listener) {
35  * if (clickListeners == null) {
36  * clickListeners = new DelegatingClickListenerCollection(this, box);
37  * }
38  * clickListeners.add(listener);
39  * }
40  *</pre>
41  */

42 public class DelegatingClickListenerCollection extends ClickListenerCollection
43     implements ClickListener {
44
45   private final Widget owner;
46
47   /**
48    * Constructor for {@link DelegatingClickListenerCollection}.
49    *
50    * @param owner owner of listeners
51    * @param delegatedTo source of events
52    */

53   public DelegatingClickListenerCollection(Widget owner,
54       SourcesClickEvents delegatedTo) {
55     this.owner = owner;
56     delegatedTo.addClickListener(this);
57   }
58
59   public void onClick(Widget sender) {
60     super.fireClick(owner);
61   }
62 }
63
Popular Tags