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.event.UserEvent;
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 UserEventListenerTreeNode extends FeatureTreeNode
28: implements EventListener {
29: protected Element linkToStart;
30:
31: public UserEventListenerTreeNode() {
32: }
33:
34: public void startExamplePanel() {
35: ItsNatDocument itsNatDoc = getItsNatDocument();
36: Document doc = itsNatDoc.getDocument();
37:
38: this .linkToStart = doc.getElementById("linkToStartId");
39:
40: itsNatDoc.addUserEventListener((EventTarget) linkToStart,
41: "myUserAction", this );
42:
43: String code = "";
44: code += "var itsNatDoc = document.getItsNatDoc();";
45: code += "var evt = itsNatDoc.createUserEvent('myUserAction');";
46: code += "evt.setExtraParam('title',document.title);";
47: code += "evt.setExtraParam('url',document.location);";
48: code += "itsNatDoc.dispatchUserEvent(this,evt);";
49: linkToStart.setAttribute("onclick", code);
50: }
51:
52: public void endExamplePanel() {
53: ItsNatDocument itsNatDoc = getItsNatDocument();
54:
55: itsNatDoc.removeUserEventListener((EventTarget) linkToStart,
56: "myUserAction", this );
57:
58: this .linkToStart = null;
59: }
60:
61: public void handleEvent(Event evt) {
62: UserEvent userEvt = (UserEvent) evt;
63: String title = (String) userEvt.getExtraParam("title");
64: log("Page title: " + title);
65: String url = (String) userEvt.getExtraParam("url");
66: log("URL: " + url);
67: }
68: }
|