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.labels;
17:
18: import javax.swing.AbstractCellEditor;
19: import org.itsnat.comp.ItsNatComponent;
20: import org.itsnat.comp.ItsNatComponentManager;
21: import org.itsnat.comp.ItsNatLabel;
22: import org.itsnat.comp.ItsNatLabelEditor;
23: import org.itsnat.core.DocFragmentTemplate;
24: import org.itsnat.core.ItsNatDocument;
25: import org.itsnat.core.ItsNatServlet;
26: import org.itsnat.feashow.features.components.shared.Person;
27: import org.w3c.dom.Document;
28: import org.w3c.dom.DocumentFragment;
29: import org.w3c.dom.Element;
30: import org.w3c.dom.events.Event;
31: import org.w3c.dom.events.EventListener;
32:
33: public class PersonCustomLabelEditor extends AbstractCellEditor
34: implements ItsNatLabelEditor, EventListener {
35: protected PersonEditorComponent editorComp;
36:
37: public PersonCustomLabelEditor() {
38: }
39:
40: public ItsNatComponent getLabelEditorComponent(ItsNatLabel label,
41: Object value, Element labelElem) {
42: ItsNatComponentManager compMgr = label
43: .getItsNatComponentManager();
44: ItsNatDocument itsNatDoc = compMgr.getItsNatDocument();
45: Document doc = itsNatDoc.getDocument();
46:
47: ItsNatServlet servlet = itsNatDoc.getDocumentTemplate()
48: .getItsNatServlet();
49: DocFragmentTemplate docFragTemplate = servlet
50: .getDocFragmentTemplate("feashow.components.shared.personEditor");
51: DocumentFragment editorFrag = docFragTemplate
52: .loadDocumentFragment(itsNatDoc);
53:
54: labelElem.appendChild(editorFrag);
55:
56: Element editorElem = doc.getElementById("personEditorId");
57:
58: this .editorComp = new PersonEditorComponent((Person) value,
59: editorElem, compMgr);
60:
61: editorComp.getOKButton().addEventListener("click", this );
62: editorComp.getCancelButton().addEventListener("click", this );
63:
64: return editorComp;
65: }
66:
67: public Object getCellEditorValue() {
68: return editorComp.getPerson();
69: }
70:
71: public void handleEvent(Event evt) {
72: if (evt.getCurrentTarget() == editorComp.getOKButton()
73: .getHTMLInputElement()) {
74: editorComp.updatePerson();
75:
76: editorComp.dispose(); // Before the DOM sub tree is removed from the tree by the editor manager
77: stopCellEditing();
78: } else {
79: editorComp.dispose(); // "
80: cancelCellEditing();
81: }
82:
83: this.editorComp = null;
84: }
85:
86: }
|