001: /*
002: * Created on Dec 15, 2005
003: *
004: * TODO To change the template for this generated file go to
005: * Window - Preferences - Java - Code Style - Code Templates
006: */
007: package org.jasig.portal.channels.jsp.tree;
008:
009: import java.util.ArrayList;
010: import java.util.List;
011:
012: /**
013: * @author Mark Boyd
014: *
015: * TODO To change the template for this generated type comment go to
016: * Window - Preferences - Java - Code Style - Code Templates
017: */
018: public class Node {
019: private static final Node[] TREE_NODE_ARRAY = new Node[] {};
020:
021: private String id = null;
022: private boolean isAspect = false;
023: private boolean hasNextSibling = false;
024: private ISurrogate surrogate = null;
025: private Object domainObject = null;
026: private boolean isExpanded = false;
027: private boolean isShowingAspects = false;
028: private Node[] children = null;
029: private Model model = null;
030: private boolean isUnresolveable = false;
031:
032: private Node[] aspects;
033:
034: private Node() {
035: }
036:
037: Node(Model model, String id, Object domainObject) {
038: this (model, id, domainObject, null);
039: this .isUnresolveable = true;
040: }
041:
042: Node(Model model, String id, Object domainObject, ISurrogate s) {
043: this .model = model;
044: this .id = id;
045: this .domainObject = domainObject;
046: this .surrogate = s;
047: }
048:
049: Object getLabelData() {
050: if (surrogate == null)
051: return null;
052: return surrogate.getLabelData(domainObject);
053: }
054:
055: /**
056: * Returns the domain object represented by this node.
057: * @return
058: */
059: Object getDomainObject() {
060: return domainObject;
061: }
062:
063: public boolean isUnresolveable() {
064: return isUnresolveable;
065: }
066:
067: public String getId() {
068: return id;
069: }
070:
071: public boolean getIsAspect() {
072: return isAspect;
073: }
074:
075: void setIsAspect(boolean b) {
076: this .isAspect = b;
077: }
078:
079: /**
080: * Set by the tree renderer JSP during rendering.
081: * @param b
082: */
083: public void setHasNextSibling(boolean b) {
084: this .hasNextSibling = b;
085: }
086:
087: /**
088: * Used by the tree renderer JSP during rendering.
089: * @param b
090: */
091: public boolean getHasNextSibling() {
092: return this .hasNextSibling;
093: }
094:
095: public boolean getCanContainChildren() {
096: if (isAspect)
097: return false;
098: return this .surrogate.canContainChildren(this .domainObject);
099: }
100:
101: public boolean getHasChildren() {
102: if (isAspect)
103: return false;
104: if (children != null && children.length > 0)
105: return true;
106: return this .surrogate.hasChildren(this .domainObject);
107: }
108:
109: public boolean getIsExpanded() {
110: return this .isExpanded;
111: }
112:
113: public void setIsExpanded(boolean b) {
114: this .isExpanded = b;
115: if (isExpanded && children == null)
116: loadChildren();
117: }
118:
119: public boolean getHasAspects() {
120: if (this .isAspect)
121: return false;
122: return this .surrogate.hasAspects(this .domainObject);
123: }
124:
125: public boolean getIsShowingAspects() {
126: return this .isShowingAspects;
127: }
128:
129: public void setIsShowingAspects(boolean b) {
130: this .isShowingAspects = b;
131: if (isShowingAspects && aspects == null)
132: loadAspects();
133: }
134:
135: public Node[] getChildren() {
136: return this .children;
137: }
138:
139: void loadChildren() {
140: Object[] domainObjects = null;
141: domainObjects = this .surrogate.getChildren(this .domainObject);
142: List nodes = new ArrayList();
143:
144: if (domainObjects != null && domainObjects.length > 0) {
145: for (int i = 0; i < domainObjects.length; i++) {
146: Node node = this .model.resolveChild(domainObjects[i]);
147: if (node != null)
148: nodes.add(node);
149: }
150: }
151: this .children = (Node[]) nodes.toArray(TREE_NODE_ARRAY);
152: }
153:
154: void loadAspects() {
155: Object[] domainObjects = null;
156: domainObjects = this .surrogate.getAspects(this .domainObject);
157: List nodes = new ArrayList();
158:
159: if (domainObjects != null && domainObjects.length > 0) {
160: for (int i = 0; i < domainObjects.length; i++) {
161: Node node = this .model.resolveAspect(domainObjects[i]);
162: if (node != null)
163: nodes.add(node);
164: }
165: }
166: this .aspects = (Node[]) nodes.toArray(TREE_NODE_ARRAY);
167: }
168:
169: public Node[] getAspects() {
170: return this.aspects;
171: }
172: }
|