001: /*
002: ItsNat Java Web Application Framework
003: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
004: Author: Jose Maria Arranz Santamaria
005:
006: This program is free software: you can redistribute it and/or modify
007: it under the terms of the GNU Affero General Public License as published by
008: the Free Software Foundation, either version 3 of the License, or
009: (at your option) any later version. See the GNU Affero General Public
010: License for more details. See the copy of the GNU Affero General Public License
011: included in this program. If not, see <http://www.gnu.org/licenses/>.
012: */
013:
014: package org.itsnat.impl.core.domutil;
015:
016: import java.util.ArrayList;
017: import java.util.Iterator;
018: import org.itsnat.core.domutil.ElementTreeNodeRenderer;
019: import org.itsnat.core.domutil.ElementTreeNodeStructure;
020: import org.itsnat.impl.core.ItsNatDocumentImpl;
021: import org.w3c.dom.Element;
022:
023: /**
024: *
025: * @author jmarranz
026: */
027: public abstract class ElementTreeNormalNodeListImpl extends
028: ElementTreeNodeListImpl {
029: protected ElementListImpl childElemList;
030: protected boolean removePattern;
031:
032: /**
033: * Creates a new instance of ElementTreeNormalNodeListImpl
034: */
035: public ElementTreeNormalNodeListImpl(ItsNatDocumentImpl itsNatDoc,
036: ElementTreeNodeNormalImpl parentTreeNode,
037: Element childListParentElem, Element childPatternElement,
038: boolean clonePattern, boolean removePattern,
039: ElementTreeNodeStructure structure,
040: ElementTreeNodeRenderer renderer) {
041: super (itsNatDoc, parentTreeNode, structure, renderer);
042:
043: this .removePattern = removePattern;
044:
045: // Necesariamente debe funcionar en modo master porque se mantiene la lista childTreeNodes
046: // que no se entera si se aņaden nodos directamente via DOM
047: // No necesitamos renderizar con esta lista
048: this .childElemList = itsNatDoc
049: .createElementListNoRenderInternal(childListParentElem,
050: childPatternElement, clonePattern,
051: removePattern);
052:
053: initialSynch();
054: }
055:
056: protected void initialSynch() {
057: // Puede haber elementos en la lista cuando se crea el gestor
058: // necesitamos mantener una lista de objetos Pattern... sincronizada con los nodos
059: // No se deben aņadir o quitar nodos DOM padres de TreeNodes utilizando directamente DOM
060: // pues desincronizaremos
061:
062: if (!childElemList.isEmpty()) {
063: ArrayList childTreeNodes = getInternalTreeNodeList();
064: int i = 0;
065: for (Iterator it = childElemList
066: .getInternalElementListFreeMaster().iterator(); it
067: .hasNext();) {
068: Element elem = (Element) it.next();
069:
070: ElementTreeNodeImpl treeNode = createTreeNode(i, elem);
071: childTreeNodes.add(treeNode);
072:
073: i++;
074: }
075: }
076: }
077:
078: public Element getParentElement() {
079: return childElemList.getParentElement();
080: }
081:
082: public ElementTreeNodeImpl createTreeNode(int index,
083: Element childElem) {
084: return new ElementTreeNodeNormalImpl(
085: (ItsNatDocumentImpl) getItsNatDocument(), this , index,
086: childElem, getChildPatternElement(), false,
087: removePattern, structure, renderer);
088: }
089:
090: public Element getChildPatternElement() {
091: return childElemList.getChildPatternElement();
092: }
093:
094: protected Element addTreeNodeDOMElementAt() {
095: return childElemList.addElement();
096: }
097:
098: protected Element insertTreeNodeDOMElementAt(int index) {
099: return childElemList.insertElementAt(index);
100: }
101:
102: protected Element removeTreeNodeDOMElementAt(int index) {
103: return childElemList.removeElementAt(index);
104: }
105:
106: public Element getTreeContainerElement() {
107: if (parentTreeNode != null)
108: return parentTreeNode.getTreeContainerElement();
109: else
110: return childElemList.getParentElement();
111: }
112: }
|