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: package com.google.gwt.user.client.ui;
17:
18: import java.util.ArrayList;
19:
20: /**
21: * Helper class for widgets that accept
22: * {@link com.google.gwt.user.client.ui.FormHandler FormHandlers}. This
23: * subclass of ArrayList assumes that all items added to it will be of type
24: * {@link com.google.gwt.user.client.ui.FormHandler}.
25: */
26: public class FormHandlerCollection extends ArrayList<FormHandler> {
27:
28: /**
29: * Fires a {@link FormHandler#onSubmitComplete(FormSubmitCompleteEvent)} on
30: * all handlers in the collection.
31: *
32: * @param sender the object sending the event
33: * @param results the results of the form submission
34: */
35: public void fireOnComplete(Object sender, String results) {
36: FormSubmitCompleteEvent event = new FormSubmitCompleteEvent(
37: sender, results);
38: for (FormHandler handler : this ) {
39: handler.onSubmitComplete(event);
40: }
41: }
42:
43: /**
44: * Fires a {@link FormHandler#onSubmit(FormSubmitEvent)} on all handlers in
45: * the collection.
46: *
47: * @param sender the object sending the event
48: * @return <code>true</code> if the event should be cancelled
49: */
50: public boolean fireOnSubmit(Object sender) {
51: FormSubmitEvent event = new FormSubmitEvent(sender);
52: for (FormHandler handler : this) {
53: handler.onSubmit(event);
54: }
55: return event.isCancelled();
56: }
57: }
|