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.feashow.FeatureTreeNode;
20: import org.w3c.dom.Document;
21: import org.w3c.dom.Element;
22: import org.w3c.dom.events.Event;
23: import org.w3c.dom.events.EventListener;
24: import org.w3c.dom.events.EventTarget;
25:
26: public class AsynchronousTaskTreeNode extends FeatureTreeNode implements
27: EventListener {
28: protected Element linkToStart;
29:
30: public AsynchronousTaskTreeNode() {
31: }
32:
33: public void startExamplePanel() {
34: ItsNatDocument itsNatDoc = getItsNatDocument();
35: Document doc = itsNatDoc.getDocument();
36:
37: this .linkToStart = doc.getElementById("linkToStartId");
38:
39: itsNatDoc.addEventListener((EventTarget) linkToStart, "click",
40: this , false);
41: }
42:
43: public void endExamplePanel() {
44: ItsNatDocument itsNatDoc = getItsNatDocument();
45: itsNatDoc.removeEventListener((EventTarget) linkToStart,
46: "click", this , false);
47:
48: this .linkToStart = null;
49: }
50:
51: public void handleEvent(Event evt) {
52: // EventTarget currTarget = evt.getCurrentTarget();
53:
54: final ItsNatDocument itsNatDoc = getItsNatDocument();
55: Runnable task = new Runnable() {
56: public void run() {
57: try {
58: Thread.sleep(2000);
59: } catch (InterruptedException ex) {
60: }
61:
62: synchronized (itsNatDoc) {
63: log("Asynchronous task finished, id: " + hashCode());
64: }
65: }
66: };
67:
68: itsNatDoc.addAsynchronousTask(task, false);
69:
70: log("An asynchronous task has started, id: " + task.hashCode());
71: }
72:
73: }
|