01: /*
02: * Copyright 2005 jWic group (http://www.jwic.de)
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of 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,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: *
16: * de.jwic.base.BatchUpdateContext
17: * Created on 28.08.2005
18: * $Id: ValueChangedQueue.java,v 1.1 2006/01/16 08:30:40 lordsam Exp $
19: */
20: package de.jwic.base;
21:
22: import java.util.ArrayList;
23: import java.util.Iterator;
24: import java.util.List;
25:
26: import de.jwic.events.ValueChangedEvent;
27: import de.jwic.events.ValueChangedListener;
28:
29: /**
30: * The ValueChangedQueue is used by the dispatcher to collect the
31: * ValueChangedEvents that occured during the field update. The
32: * dispatcher will fire the events when all fields are updated.
33: *
34: * @author Florian Lippisch
35: * @version $Revision: 1.1 $
36: */
37: public class ValueChangedQueue {
38:
39: private List eventQueue = null;
40:
41: /**
42: * Container for the events.
43: */
44: private class ListenerEvents {
45: ValueChangedListener[] listeners;
46: ValueChangedEvent event;
47:
48: public ListenerEvents(ValueChangedListener[] l,
49: ValueChangedEvent e) {
50: this .listeners = l;
51: this .event = e;
52: }
53: }
54:
55: /**
56: * Adds the listeners for the specified event to the event queue. The queue is processed
57: * after all fields have been updated.
58: * @param listeners
59: * @param event
60: */
61: public void valueChanged(ValueChangedListener[] listeners,
62: ValueChangedEvent event) {
63:
64: if (eventQueue == null) {
65: eventQueue = new ArrayList();
66: }
67:
68: eventQueue.add(new ListenerEvents(listeners, event));
69:
70: }
71:
72: /**
73: * Process the event queue.
74: *
75: */
76: public void processQueue() {
77:
78: if (eventQueue != null) {
79: for (Iterator it = eventQueue.iterator(); it.hasNext();) {
80: ListenerEvents task = (ListenerEvents) it.next();
81: if (task.listeners != null) {
82: for (int i = 0; i < task.listeners.length; i++) {
83: task.listeners[i].valueChanged(task.event);
84: }
85: }
86: }
87: }
88:
89: }
90:
91: }
|