KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.google.gwt.user.client.ui;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Iterator JavaDoc;
20
21 /**
22  * Helper class for widgets that accept
23  * {@link com.google.gwt.user.client.ui.FormHandler FormHandlers}. This
24  * subclass of ArrayList assumes that all items added to it will be of type
25  * {@link com.google.gwt.user.client.ui.FormHandler}.
26  */

27 public class FormHandlerCollection extends ArrayList JavaDoc {
28
29   /**
30    * Fires a {@link FormHandler#onSubmitComplete(FormSubmitCompleteEvent)} on
31    * all handlers in the collection.
32    *
33    * @param sender the object sending the event
34    * @param results the results of the form submission
35    */

36   public void fireOnComplete(Object JavaDoc sender, String JavaDoc results) {
37     FormSubmitCompleteEvent event = new FormSubmitCompleteEvent(sender, results);
38
39     for (Iterator JavaDoc it = iterator(); it.hasNext();) {
40       FormHandler handler = (FormHandler) it.next();
41       handler.onSubmitComplete(event);
42     }
43   }
44
45   /**
46    * Fires a {@link FormHandler#onSubmit(FormSubmitEvent)} on all handlers in
47    * the collection.
48    *
49    * @param sender the object sending the event
50    * @return <code>true</code> if the event should be cancelled
51    */

52   public boolean fireOnSubmit(Object JavaDoc sender) {
53     FormSubmitEvent event = new FormSubmitEvent(sender);
54
55     for (Iterator JavaDoc it = iterator(); it.hasNext();) {
56       FormHandler handler = (FormHandler) it.next();
57       handler.onSubmit(event);
58     }
59
60     return event.isCancelled();
61   }
62 }
63
Popular Tags