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.components;
17:
18: import org.itsnat.comp.ItsNatComponentManager;
19: import org.itsnat.comp.html.ItsNatHTMLAnchor;
20: import org.itsnat.comp.html.ItsNatHTMLForm;
21: import org.itsnat.core.ItsNatDocument;
22: import org.itsnat.core.SyncMode;
23: import org.itsnat.feashow.FeatureTreeNode;
24: import org.w3c.dom.events.Event;
25: import org.w3c.dom.events.EventListener;
26: import org.w3c.dom.events.EventTarget;
27:
28: public class FormTreeNode extends FeatureTreeNode implements
29: EventListener {
30: protected ItsNatHTMLForm formComp;
31: protected ItsNatHTMLAnchor linkComp;
32:
33: public FormTreeNode() {
34: }
35:
36: public void startExamplePanel() {
37: ItsNatDocument itsNatDoc = getItsNatDocument();
38: ItsNatComponentManager componentMgr = itsNatDoc
39: .getItsNatComponentManager();
40:
41: this .formComp = (ItsNatHTMLForm) componentMgr
42: .createItsNatComponentById("formId");
43:
44: formComp.setEventListenerParams("submit", false, SyncMode.SYNC,
45: null, null, -1);
46: formComp.setEventListenerParams("reset", false, SyncMode.SYNC,
47: null, null, -1);
48:
49: formComp.addEventListener("submit", this );
50: formComp.addEventListener("reset", this );
51:
52: this .linkComp = (ItsNatHTMLAnchor) componentMgr
53: .createItsNatComponentById("linkId");
54: linkComp.addEventListener("click", this );
55: }
56:
57: public void endExamplePanel() {
58: this .formComp.dispose();
59: this .formComp = null;
60:
61: this .linkComp.dispose();
62: this .linkComp = null;
63: }
64:
65: public void handleEvent(Event evt) {
66: log(evt.getCurrentTarget() + " " + evt.getType());
67:
68: EventTarget currentTarget = evt.getCurrentTarget();
69: if (currentTarget == formComp.getHTMLFormElement()) {
70: if (evt.getType().equals("submit")) {
71: log("Submit canceled");
72: evt.preventDefault(); // Cancels the submission, only works in SYNC mode
73: }
74: // reset is not cancellable
75: } else {
76: formComp.reset(); // submit() method is defined too
77: }
78: }
79: }
|