01: /*
02: ItsNat Java Web Application Framework
03: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
04: Author: Jose Maria Arranz Santamaria
05:
06: This program is free software: you can redistribute it and/or modify
07: it under the terms of the GNU Affero General Public License as published by
08: the Free Software Foundation, either version 3 of the License, or
09: (at your option) any later version. See the GNU Affero General Public
10: License for more details. See the copy of the GNU Affero General Public License
11: included in this program. If not, see <http://www.gnu.org/licenses/>.
12: */
13:
14: package org.itsnat.impl.core.listener;
15:
16: import org.itsnat.comp.ItsNatComponent;
17: import org.itsnat.impl.comp.ItsNatComponentManagerImpl;
18: import org.w3c.dom.Node;
19: import org.w3c.dom.events.MutationEvent;
20:
21: /**
22: *
23: * @author jmarranz
24: */
25: public class AutoBuildCompMutationEventBeforeAfterListener implements
26: MutationEventBeforeAfterListener {
27: protected ItsNatComponentManagerImpl compMgr;
28:
29: /** Creates a new instance of AutoBuildCompMutationEventBeforeAfterListener */
30: public AutoBuildCompMutationEventBeforeAfterListener(
31: ItsNatComponentManagerImpl compMgr) {
32: this .compMgr = compMgr;
33: }
34:
35: public ItsNatComponentManagerImpl getItsNatComponentManager() {
36: return compMgr;
37: }
38:
39: public void before(MutationEvent mutEvent) {
40: String type = mutEvent.getType();
41: if (type.equals("DOMNodeRemoved")) {
42: ItsNatComponentManagerImpl compMgr = getItsNatComponentManager();
43:
44: // Element parent = (Element)mutEvent.getRelatedNode();
45: Node removedNode = (Node) mutEvent.getTarget(); // No está eliminado todavía del árbol DOM servidor
46: compMgr.removeItsNatComponents(removedNode, true, null);
47: }
48: }
49:
50: public void after(MutationEvent mutEvent) {
51: String type = mutEvent.getType();
52: if (type.equals("DOMNodeInserted")) {
53: ItsNatComponentManagerImpl compMgr = getItsNatComponentManager();
54:
55: //Element parent = (Element)mutEvent.getRelatedNode();
56: Node newNode = (Node) mutEvent.getTarget(); // Hay que tener en cuenta que el nodo ya está insertado en el DOM servidor
57: compMgr.buildItsNatComponents(newNode);
58: }
59: }
60: }
|