001: package com.teamkonzept.webman.mainint;
002:
003: import com.teamkonzept.lib.*;
004: import java.util.*;
005:
006: /**
007: * Dieser Iterator wird benutzt um einen Content Tree zu rendern. Er
008: * berücksichtigt dabei, ob ein Knoten geöffnet oder geschlossen ist und
009: * stellt die nötigen Templateinformationen zur Verfügung um die Liste der
010: * Contents baumartig darstellen zu können.
011: *
012: * @author alex (?)
013: * @version $Revision: 1.8 $
014: **/
015: public class TKOpenContentTreeIterator implements TKListIterator {
016:
017: TKListIterator oldIterator;
018: String listName;
019: TKDBResult dbResult;
020: int lastLeft = -1;
021: int lastRight = -1;
022: int destId = -1;
023: Stack parents;
024: int level;
025: int levels = 0;
026: int maxlevels;
027:
028: public TKOpenContentTreeIterator(TKDBResult dbResult,
029: TKListIterator oldIterator, String listName, int maxlevels) {
030: this .oldIterator = oldIterator;
031: this .listName = listName;
032: this .dbResult = dbResult;
033: this .parents = new Stack();
034: this .level = 0;
035: this .maxlevels = maxlevels;
036: }
037:
038: public TKOpenContentTreeIterator(TKDBResult dbResult,
039: TKListIterator oldIterator, String listName, int destId,
040: int maxlevels) {
041: this .oldIterator = oldIterator;
042: this .listName = listName;
043: this .dbResult = dbResult;
044: this .destId = destId;
045: this .parents = new Stack();
046: this .level = 0;
047: this .maxlevels = maxlevels;
048: }
049:
050: public boolean apply(TKTemplate template, int i, String currListName) {
051: if (currListName.equalsIgnoreCase(listName)) {
052: if (i >= dbResult.size()) {
053: if (!parents.empty())
054: parents.clear();
055: level = 0;
056: lastLeft = -1;
057: lastRight = -1;
058: return false;
059: }
060: TKDBResultRow resultRow = (TKDBResultRow) (dbResult.get(i));
061: if (!TKDBTemplate.prepareTemplate(resultRow, template))
062: return false;
063: try {
064: int myId = Integer.parseInt((String) resultRow
065: .getColumn("CONTENT_NODE_ID"));
066: if (destId != -1 && myId == destId) {
067: template.set("IS_DESTINATION", Boolean.TRUE);
068: }
069: int this Left = Integer.parseInt((String) resultRow
070: .getColumn("LEFT_NR"));
071: int this Right = Integer.parseInt((String) resultRow
072: .getColumn("RIGHT_NR"));
073: String tmp = (String) resultRow
074: .getColumn("CONTENT_NODE_PARENT");
075: int this Parent = (tmp == null || tmp.equals("")) ? myId
076: : Integer.parseInt(tmp);
077:
078: String nodeId = (String) resultRow.getColumn("NODE_ID");
079: int this Par = (nodeId.equals("")) ? myId + 1 : Integer
080: .parseInt(nodeId);
081:
082: String nodeType = (String) resultRow
083: .getColumn("CONTENT_NODE_TYPE");
084: if (nodeType != null
085: && nodeType.equals(DatabaseDefaults.GROUP)) {
086: template.set("IS_GROUP", Boolean.TRUE);
087: }
088:
089: if (nodeId.equals("")) {
090: template.set("IS_LEAF", Boolean.TRUE);
091: } else if (this Par == myId) {
092: template.set("IS_CLOSED", Boolean.TRUE);
093: } else {
094: template.set("IS_OPEN", Boolean.TRUE);
095: }
096:
097: if (i == 0)
098: template.set("IS_ROOT", Boolean.TRUE);
099: if (this Left > lastLeft && this Right < lastRight) {
100: parents.push(new Integer(this Parent));
101: level++;
102: } else if (!parents.empty()) {
103: // wenn der oberste parent im stack gleich dem aktuellen parent, dann gleiche ebene
104: // und nix tun
105: // wenn der aktuelle parent tiefer im stack liegt, dann entspr. viele ebenen zurueck und
106: // level neu setzen
107: if (!(parents.peek()
108: .equals(new Integer(this Parent)))) {
109: while (!parents.empty()) {
110: if (parents.pop().equals(
111: new Integer(this Parent))) {
112: parents.push(new Integer(this Parent));
113: break;
114: }
115: level--;
116: }
117: }
118: }
119: levels = level;
120: template.set("LEVEL", new Integer(level));
121: template.set("CURR_COLSPAN", new Integer(maxlevels
122: - level + 1));
123: lastLeft = this Left;
124: lastRight = this Right;
125: } catch (Throwable th) {
126: throw new Error(th.getMessage());
127: }
128: return true;
129: } else if (currListName.equalsIgnoreCase("LEVELS")) {
130: return (--levels >= 0);
131: } else if (oldIterator != null) {
132: return oldIterator.apply(template, i, currListName);
133: } else {
134: return false;
135: }
136: }
137: }
|