01: /*
02: * This file is not part of the ItsNat framework.
03: *
04: * Original source code use and closed source derivatives are authorized
05: * to third parties with no restriction or fee.
06: * The original source code is owned by the author.
07: *
08: * This program is distributed AS IS in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11: *
12: * Author: Jose Maria Arranz Santamaria
13: * (C) Innowhere Software Services S.L., Spanish company, year 2007
14: */
15:
16: package org.itsnat.feashow.features.core.listeners;
17:
18: import org.itsnat.core.ItsNatDocument;
19: import org.itsnat.core.SyncMode;
20: import org.itsnat.feashow.FeatureTreeNode;
21: import org.w3c.dom.Document;
22: import org.w3c.dom.Element;
23: import org.w3c.dom.events.Event;
24: import org.w3c.dom.events.EventListener;
25: import org.w3c.dom.events.EventTarget;
26:
27: public class AJAXTimeoutTreeNode extends FeatureTreeNode implements
28: EventListener {
29: protected static final long ajaxTimeout = 1000;
30: protected Element linkToStart;
31:
32: public AJAXTimeoutTreeNode() {
33: }
34:
35: public void startExamplePanel() {
36: ItsNatDocument itsNatDoc = getItsNatDocument();
37: Document doc = itsNatDoc.getDocument();
38:
39: this .linkToStart = doc.getElementById("linkToStartId");
40:
41: itsNatDoc.addEventListener((EventTarget) linkToStart, "click",
42: this , false, SyncMode.ASYNC, null, null, ajaxTimeout);
43: }
44:
45: public void endExamplePanel() {
46: ItsNatDocument itsNatDoc = getItsNatDocument();
47: itsNatDoc.removeEventListener((EventTarget) linkToStart,
48: "click", this , false);
49:
50: this .linkToStart = null;
51: }
52:
53: public void handleEvent(Event evt) {
54: try {
55: Thread.sleep(ajaxTimeout + 1000); // greater than AJAX timeout
56: } catch (InterruptedException ex) {
57: }
58:
59: ItsNatDocument itsNatDoc = getItsNatDocument();
60: itsNatDoc.addCodeToSend("alert('Message never shown');");
61: }
62: }
|