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 org.itsnat.core.domutil.ElementTreeNodeRenderer;
017: import org.itsnat.core.domutil.ElementTreeNodeStructure;
018: import org.itsnat.impl.core.ItsNatDocumentImpl;
019: import org.itsnat.impl.core.util.*;
020: import org.w3c.dom.Element;
021:
022: /**
023: *
024: * @author jmarranz
025: */
026: public abstract class ElementTreeTableNodeListImpl extends
027: ElementTreeNodeListImpl {
028: /** Creates a new instance of ElementTreeTableNodeListImpl */
029: public ElementTreeTableNodeListImpl(ItsNatDocumentImpl itsNatDoc,
030: ElementTreeTableNodeImpl parentTreeNode,
031: ElementTreeNodeStructure structure,
032: ElementTreeNodeRenderer renderer) {
033: super (itsNatDoc, parentTreeNode, structure, renderer);
034: }
035:
036: public abstract ElementListImpl getGlobalChildList();
037:
038: public Element getParentElement() {
039: return getGlobalChildList().getParentElement();
040: }
041:
042: public ElementTreeNodeImpl createTreeNode(int index,
043: Element childElem) {
044: return new ElementTreeTableNodeImpl(
045: (ItsNatDocumentImpl) getItsNatDocument(), this , index,
046: childElem, structure, renderer);
047: }
048:
049: public Element getChildPatternElement() {
050: return getGlobalChildList().getChildPatternElement();
051: }
052:
053: public int getRow(int index) {
054: if (index == 0) {
055: if (parentTreeNode == null) // Caso de lista contenedora del root
056: return 0; // Se pide la row del root: 0
057: else
058: return parentTreeNode.getRow() + 1;
059: } else {
060: ElementTreeNodeImpl treeNode = (ElementTreeNodeImpl) getTreeNodeAt(index);
061: if (treeNode == null) {
062: // Caso por ejemplo de obtener la row para añadir al final de la lista
063: // No debería ser nulo el resultado ahora
064: treeNode = (ElementTreeNodeImpl) getTreeNodeAt(index - 1);
065: treeNode = treeNode.getDeepMostLastTreeNode();
066: return treeNode.getRow() + 1;
067: } else {
068: return treeNode.getRow();
069: }
070: }
071: }
072:
073: protected Element addTreeNodeDOMElementAt() {
074: int index = getLength(); // posición relativa
075: return insertTreeNodeDOMElementAt(index);
076: }
077:
078: protected Element insertTreeNodeDOMElementAt(int index) {
079: // index es la posición relativa
080: int row = getRow(index); // fila global
081: return getGlobalChildList().insertElementAt(row);
082: }
083:
084: protected Element removeTreeNodeDOMElementAt(int index) {
085: ElementTreeNodeImpl treeNodeStart = (ElementTreeNodeImpl) getTreeNodeAt(index);
086: if (treeNodeStart == null)
087: return null; // Fuera de rango
088: ElementTreeNodeImpl treeNodeEnd = (ElementTreeNodeImpl) treeNodeStart
089: .getDeepMostLastTreeNode();
090: // treeNodeEnd puede ser el mismo que treeNodeStart
091:
092: int rowFrom = treeNodeStart.getRow();
093: int rowTo = treeNodeEnd.getRow();
094: getGlobalChildList().removeElementRange(rowFrom, rowTo);
095:
096: return treeNodeStart.getParentElement();
097: }
098:
099: public Element getTreeContainerElement() {
100: return getGlobalChildList().getParentElement();
101: }
102: }
|