1 22 package org.jboss.console.navtree; 23 24 import org.jboss.console.manager.interfaces.ResourceTreeNode; 25 import org.jboss.console.manager.interfaces.TreeAction; 26 import org.jboss.console.manager.interfaces.TreeInfo; 27 import org.jboss.console.manager.interfaces.TreeNode; 28 import org.jboss.console.manager.interfaces.TreeNodeMenuEntry; 29 30 45 46 public class StdNodeWrapper 47 implements NodeWrapper 48 { 49 51 53 TreeNode node = null; 54 NodeWrapper[] sons = null; 55 TreeNode[] realSons = null; 56 TreeInfo master = null; 57 String path = null; 58 59 61 63 public StdNodeWrapper (TreeNode node, TreeInfo master, String parentPath) 64 { 65 this.node = node; 66 this.master = master; 67 this.path = parentPath + "/" + this.node.getName (); 68 69 TreeNode[] plugged = null; 70 if (node instanceof ResourceTreeNode) 71 { 72 plugged = master.getTreesForResource( ((ResourceTreeNode)node).getResource() ); 73 74 int visibility = ((ResourceTreeNode)node).getVisibility(); 77 if (visibility == ResourceTreeNode.INVISIBLE_IF_SUBNODE_EXISTS && 78 plugged != null && plugged.length > 0) 79 { 80 this.node = getMasterFromPluggins (plugged); 81 plugged = removeMasterFromList (plugged, this.node); 82 } 83 } 84 85 TreeNode[] res = this.node.getNodeManagableResources (); 86 TreeNode[] sub = this.node.getSubNodes (); 87 88 if (res == null) res = new TreeNode[0]; 89 if (sub == null) sub = new TreeNode[0]; 90 if (plugged == null) plugged = new TreeNode[0]; 91 92 realSons = new TreeNode[res.length + sub.length + plugged.length]; 93 sons = new NodeWrapper[res.length + sub.length + plugged.length]; 94 95 for (int i=0; i<res.length; i++) 96 realSons[i] = res[i]; 97 for (int i=0; i<sub.length; i++) 98 realSons[res.length+i] = sub[i]; 99 for (int i=0; i<plugged.length; i++) 100 realSons[res.length+sub.length+i] = plugged[i]; 101 } 102 103 105 107 public Object getChild (int index) 108 { 109 if (index >= sons.length) 110 return null; 111 112 if (sons[index] == null) 113 sons[index] = new StdNodeWrapper(realSons[index], this.master, this.path); 114 115 return sons[index]; 116 } 117 118 public int getChildCount () 119 { 120 return this.realSons.length; 121 } 122 123 public int getIndexOfChild (Object child) 124 { 125 for (int i=0; i<this.sons.length; i++) 126 { 127 if (this.sons[i] == child) 128 return i; 129 } 130 return -1; 131 } 132 133 public boolean isLeaf () 134 { 135 return this.sons.length == 0; 136 } 137 138 public String toString () 139 { 140 return this.node.getName (); 141 } 142 143 public String getIconUrl () 144 { 145 return this.node.getIcon (); 146 } 147 148 public TreeAction getAssociatedAction () 149 { 150 return this.node.getAction (); 151 } 152 153 public String getDescription () 154 { 155 return this.node.getDescription (); 156 } 157 158 public TreeNodeMenuEntry[] getMenuEntries () 159 { 160 return this.node.getMenuEntries (); 161 } 162 163 public String getPath () 164 { 165 return this.path; 166 } 167 168 170 172 174 protected TreeNode getMasterFromPluggins (TreeNode[] plugged) 175 { 176 for (int i=0; i<plugged.length; i++) 177 { 178 if (plugged[i].isMasterNode()) 179 return plugged[i]; 180 } 181 182 return plugged[0]; 183 184 } 185 186 protected TreeNode[] removeMasterFromList (TreeNode[] all, TreeNode main) 187 { 188 TreeNode[] result = new TreeNode[all.length-1]; 189 190 int cursor = 0; 191 for (int i=0; i<all.length; i++) 192 { 193 if (all[i] != main) 194 { 195 result[cursor] = all[i]; 196 cursor++; 197 } 198 } 199 200 return result; 201 } 202 203 205 207 } 208 209 210 | Popular Tags |