001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.unifiedGui;
032:
033: import java.util.*;
034:
035: import de.ug2t.kernel.*;
036: import de.ug2t.unifiedGui.exceptions.*;
037: import de.ug2t.unifiedGui.interfaces.*;
038:
039: /**
040: * @author Dirk
041: *
042: * date: 02.01.2004 project: WiSer-Framework
043: *
044: * <p>
045: * This class is responsible for dispatching all events along the
046: * gui-object-tree. Normally this class is not for external use. It is used only
047: * by the frameworks internal procedures. (Synchronisation mechanisms are
048: * implemented in the commercial release only)
049: * </p>
050: */
051: public final class UnEventDispatcher {
052: /**
053: * For internal use only
054: */
055:
056: // @@
057: private IUnDispatchExceptionHandler pem_handler = null;
058:
059: /**
060: * For internal use only
061: */
062: public static synchronized boolean pcmf_isSingleProcessing() {
063: boolean l_ret = false;
064: // @@
065: return (l_ret);
066: }
067:
068: /**
069: * For internal use only
070: */
071: public static synchronized void pcmf_incReqCnt() throws Exception {
072: // @@
073: }
074:
075: // @@
076:
077: /**
078: * For internal use only
079: */
080: public static synchronized void pcmf_decReqCnt() {
081: // @@
082: }
083:
084: /**
085: * For internal use only
086: */
087: public static synchronized void pcmf_startSingleProcessing()
088: throws Exception {
089: // @@
090: }
091:
092: /**
093: * For internal use only
094: */
095: public static synchronized void pcmf_endSingleProcessing() {
096: // @@
097: }
098:
099: /**
100: * Constructs a dispatcher-object with an errorhandler
101: */
102: public UnEventDispatcher(IUnDispatchExceptionHandler xHandler) {
103: this .pem_handler = xHandler;
104: }
105:
106: /**
107: * <p>
108: * Dispatch an event to all chidren of the node referenced by the parameter
109: * xrelativeRoot
110: * </p>
111: * <p>
112: *
113: * </p>
114: * <p>
115: *
116: * @param xrelativeRoot
117: * the root node of the dispatching-process
118: * </p>
119: */
120: public void pcmf_execDispatch(KeTreeNode xrelativeRoot) {
121: Iterator it = new ArrayList(xrelativeRoot.pcmf_getAllSubs())
122: .iterator();
123: KeTreeNode l_go = null;
124:
125: try {
126: try {
127: while (it.hasNext()) {
128: l_go = (KeTreeNode) (it.next());
129: if (l_go.pcmf_isDisabled() == false)
130: this .pcmf_execDispatch(l_go);
131: }
132: ;
133:
134: if (xrelativeRoot instanceof UnComponent) {
135: if (((UnComponent) xrelativeRoot)
136: .pcmf_isRefreshed()) {
137: try {
138: ((UnComponent) xrelativeRoot)
139: .pcmf_dispatchEvent();
140: } catch (UnDispatchErrorWrapper de) {
141: if (this .pem_handler != null) {
142: boolean l_prop = this .pem_handler
143: .pcmf_handle(de);
144: if (l_prop)
145: throw (de.pcmf_getRootCause());
146: } else
147: throw (de.pcmf_getRootCause());
148: }
149:
150: KeTreeNode l_t = xrelativeRoot
151: .pcmf_getParentNode();
152: if (l_t instanceof UnComponent)
153: ((UnComponent) l_t)
154: .pcmf_setIndirectRefresh();
155: }
156: ;
157:
158: if (((UnComponent) xrelativeRoot)
159: .pcmf_isIndirectRefreshed()) {
160: try {
161: ((UnComponent) xrelativeRoot)
162: .pcmf_dispatchIndirectEvent();
163: } catch (UnDispatchErrorWrapper de) {
164: if (this .pem_handler != null) {
165: boolean l_prop = this .pem_handler
166: .pcmf_handle(de);
167: if (l_prop)
168: throw (de.pcmf_getRootCause());
169: } else
170: throw (de.pcmf_getRootCause());
171: }
172:
173: KeTreeNode l_t = xrelativeRoot
174: .pcmf_getParentNode();
175: if (l_t instanceof UnComponent)
176: ((UnComponent) l_t)
177: .pcmf_setIndirectRefresh();
178: }
179: ;
180: }
181: } catch (UnApplicationCloseException ae) {
182: KeLog
183: .pcmf_log(
184: "ug2t",
185: "application session terminated, dispatch aborted",
186: this , KeLog.MESSAGE);
187: }
188: } catch (Exception e) {
189: KeLog
190: .pcmf_log(
191: "ug2t",
192: "error while dispatching events, details as follows",
193: this , KeLog.ERROR);
194: KeLog.pcmf_logException("ug2t", this , e);
195: } catch (Throwable t) {
196: KeLog
197: .pcmf_log(
198: "ug2t",
199: "error while dispatching events, details as follows",
200: this , KeLog.ERROR);
201: KeLog.pcmf_logThrowable("ug2t", this , t);
202: }
203:
204: return;
205: };
206:
207: /**
208: * <p>
209: * Dispatch an event to all chidren of the nodes in the Array
210: * </p>
211: * <p>
212: *
213: * </p>
214: * <p>
215: *
216: * @param xNodes
217: * node list to dispatch events to
218: * </p>
219: */
220: public void pcmf_execDispatch(List xNodes) {
221: try {
222: Iterator l_it = xNodes.iterator();
223: while (l_it.hasNext()) {
224: KeTreeNode l_comp = (KeTreeNode) l_it.next();
225: this .pcmf_execDispatch(l_comp);
226: }
227: } catch (Exception e) {
228: KeLog
229: .pcmf_log(
230: "ug2t",
231: "error while dispatching events, details as follows",
232: this , KeLog.ERROR);
233: KeLog.pcmf_logException("ug2t", this , e);
234: }
235: }
236:
237: public void pcmf_execDispatch(ArrayList xDispList,
238: IUnApplication xAppl) {
239: if (xAppl.pcmf_isEventBubbling()) {
240: this .pcmf_execDispatch(xDispList);
241:
242: if (xAppl.pcmf_isMDI())
243: this .pcmf_execDispatch(xAppl.pcmf_getUnComponent());
244: else {
245: Iterator l_it = xAppl.pcmf_getUnComponent()
246: .pcmf_getSubIterator();
247: while (l_it.hasNext()) {
248: Object l_obj = l_it.next();
249: if (l_obj instanceof KeTreeNode
250: && l_obj instanceof IUnPage == false)
251: this .pcmf_execDispatch((KeTreeNode) l_obj);
252: }
253: this .pcmf_execDispatch(xAppl.pcmf_getActive());
254: }
255: } else {
256: // sort by prio
257: Object[] l_toSort = xDispList.toArray();
258: Arrays.sort(l_toSort, 0, l_toSort.length, new Comparator() {
259:
260: public int compare(Object arg0, Object arg1) {
261: UnComponent l_o1 = (UnComponent) arg0;
262: UnComponent l_o2 = (UnComponent) arg1;
263: if (l_o1.pcmf_getEventPrio() > l_o2
264: .pcmf_getEventPrio())
265: return (1);
266: else if (l_o1.pcmf_getEventPrio() < l_o2
267: .pcmf_getEventPrio())
268: return (-1);
269: else
270: return (0);
271:
272: }
273: });
274:
275: this.pcmf_execDispatch(Arrays.asList(l_toSort));
276: }
277: }
278: }
|