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;
17:
18: import org.itsnat.core.ItsNatDocument;
19: import org.itsnat.core.ItsNatServlet;
20: import org.itsnat.core.domutil.ItsNatDOMUtil;
21: import org.itsnat.core.html.HTMLDocFragmentTemplate;
22: import org.itsnat.feashow.FeatureTreeNode;
23: import org.w3c.dom.Document;
24: import org.w3c.dom.DocumentFragment;
25: import org.w3c.dom.Element;
26: import org.w3c.dom.events.Event;
27: import org.w3c.dom.events.EventListener;
28: import org.w3c.dom.events.EventTarget;
29: import org.w3c.dom.html.HTMLInputElement;
30:
31: public class MarkupFragmentsTreeNode extends FeatureTreeNode implements
32: EventListener {
33: protected Element includeParent;
34: protected HTMLInputElement button;
35: protected boolean included;
36: protected HTMLDocFragmentTemplate docFragTemplate;
37:
38: public MarkupFragmentsTreeNode() {
39: }
40:
41: public void startExamplePanel() {
42: ItsNatDocument itsNatDoc = getItsNatDocument();
43: Document doc = itsNatDoc.getDocument();
44:
45: this .includeParent = doc.getElementById("includeId");
46:
47: this .button = (HTMLInputElement) doc.getElementById("buttonId");
48: itsNatDoc.addEventListener((EventTarget) button, "click", this ,
49: false);
50:
51: ItsNatServlet servlet = itsNatDoc.getDocumentTemplate()
52: .getItsNatServlet();
53: this .docFragTemplate = (HTMLDocFragmentTemplate) servlet
54: .getDocFragmentTemplate("feashow.fragmentExample");
55:
56: include();
57: }
58:
59: public void endExamplePanel() {
60: ItsNatDocument itsNatDoc = getItsNatDocument();
61: itsNatDoc.removeEventListener((EventTarget) button, "click",
62: this , false);
63:
64: this .includeParent = null;
65: this .button = null;
66: this .docFragTemplate = null;
67: }
68:
69: public void handleEvent(Event evt) {
70: if (included)
71: uninclude();
72: else
73: include();
74: }
75:
76: public void include() {
77: ItsNatDocument itsNatDoc = getItsNatDocument();
78: DocumentFragment docFrag = docFragTemplate
79: .loadDocumentFragmentBody(itsNatDoc);
80:
81: includeParent.appendChild(docFrag); // docFrag is empty now
82:
83: button.setValue("Remove Included");
84:
85: this .included = true;
86: }
87:
88: public void uninclude() {
89: ItsNatDOMUtil.removeAllChildren(includeParent);
90:
91: button.setValue("Include");
92:
93: this .included = false;
94: }
95: }
|