1 19 20 package org.netbeans.modules.debugger.jpda.ui.models; 21 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import java.util.HashSet ; 25 import java.util.List ; 26 import java.util.Set ; 27 import javax.swing.Action ; 28 29 import org.netbeans.spi.debugger.ContextProvider; 30 import org.netbeans.api.debugger.jpda.Field; 31 import org.netbeans.api.debugger.jpda.ObjectVariable; 32 import org.netbeans.spi.viewmodel.NodeActionsProvider; 33 import org.netbeans.spi.viewmodel.NodeModel; 34 import org.netbeans.spi.viewmodel.TableModel; 35 import org.netbeans.spi.viewmodel.TreeModel; 36 import org.netbeans.spi.viewmodel.TreeModelFilter; 37 import org.netbeans.spi.viewmodel.ModelListener; 38 import org.netbeans.spi.viewmodel.UnknownTypeException; 39 import org.openide.util.NbBundle; 41 42 43 48 public class VariablesTreeModelFilterSI implements TreeModelFilter, 49 NodeModel, TableModel, NodeActionsProvider { 50 51 public static final String INHERITED = 52 "org/netbeans/modules/debugger/resources/watchesView/SuperVariable"; 53 public static final String STATIC = 54 "org/netbeans/modules/debugger/resources/watchesView/SuperVariable"; 55 private static final Set ignore = new HashSet (Arrays.asList (new String [] { 56 "java.lang.String", 57 "java.lang.StringBuffer", 58 "java.lang.Character", 59 "java.lang.Integer", 60 "java.lang.Float", 61 "java.lang.Byte", 62 "java.lang.Boolean", 63 "java.lang.Double", 64 "java.lang.Long", 65 "java.lang.Short", 66 67 "java.lang.ref.WeakReference", 68 69 "java.util.ArrayList", 70 "java.util.HashSet", 71 "java.util.LinkedHashSet", 72 "java.util.LinkedList", 73 "java.util.Stack", 74 "java.util.TreeSet", 75 "java.util.Vector", 76 "java.util.Hashtable", 77 "java.util.Hashtable$Entry", 78 "java.util.HashMap", 79 "java.util.HashMap$Entry", 80 "java.util.IdentityHashMap", 81 "java.util.AbstractMap$SimpleEntry", 82 "java.util.TreeMap", 83 "java.util.TreeMap$Entry", 84 "java.util.WeakHashMap", 85 "java.util.LinkedHashMap", 86 "java.util.LinkedHashMap$Entry", 87 "java.beans.PropertyChangeSupport" 88 })); 89 private ContextProvider lookupProvider; 90 91 92 public VariablesTreeModelFilterSI (ContextProvider lookupProvider) { 93 this.lookupProvider = lookupProvider; 94 } 95 96 102 public Object getRoot (TreeModel original) { 103 return original.getRoot (); 104 } 105 106 120 public Object [] getChildren ( 121 TreeModel original, 122 Object parent, 123 int from, 124 int to 125 ) throws UnknownTypeException { 126 if (parent instanceof ObjectVariable) { 128 ObjectVariable variable = (ObjectVariable) parent; 129 if (ignore.contains (variable.getType ())) 130 return original.getChildren (parent, from, to); 131 int tto = Math.min (to, original.getChildrenCount (parent)); 132 List l = new ArrayList (Arrays.asList ( 133 original.getChildren (parent, from, tto) 134 )); 135 if (l.size() < to && variable.getAllStaticFields(0, 0).length > 0) 136 l.add (new StaticNode(variable)); 137 if (l.size() < to && variable.getInheritedFields(0, 0).length > 0) 138 l.add (new InheritedNode(variable)); 139 return l.toArray (); 140 } else if (parent instanceof SpecialNode) { 141 return ((SpecialNode) parent).getChildren(0, 0); 142 } 143 return original.getChildren (parent, from, to); 144 } 145 146 161 public int getChildrenCount ( 162 TreeModel original, 163 Object parent 164 ) throws UnknownTypeException { 165 if (parent instanceof ObjectVariable) { 167 ObjectVariable variable = (ObjectVariable) parent; 168 if (ignore.contains (variable.getType ())) 169 return original.getChildrenCount (parent); 170 int i = original.getChildrenCount (parent); 171 if (i == Integer.MAX_VALUE) { 172 return i; 173 } 174 if (variable.getAllStaticFields (0, 0).length > 0) i++; 175 if (variable.getInheritedFields (0, 0).length > 0) i++; 176 return i; 177 } else if (parent instanceof SpecialNode) { 178 return ((SpecialNode) parent).getChildren(0, 0).length; 179 } 180 return original.getChildrenCount (parent); 181 } 182 183 193 201 public boolean isLeaf ( 202 TreeModel original, 203 Object node 204 ) throws UnknownTypeException { 205 return (node instanceof SpecialNode) ? false : original.isLeaf(node); 206 } 207 208 public void addModelListener (ModelListener l) { 209 } 210 211 public void removeModelListener (ModelListener l) { 212 } 213 214 215 217 public String getDisplayName (Object node) 218 throws UnknownTypeException { 219 if (node instanceof SpecialNode) return ((SpecialNode) node).getDisplayName(); 220 throw new UnknownTypeException (node); 221 } 222 223 public String getIconBase (Object node) 224 throws UnknownTypeException { 225 if (node instanceof SpecialNode) return ((SpecialNode) node).getIconBase(); 226 throw new UnknownTypeException (node); 227 } 228 229 public String getShortDescription (Object node) 230 throws UnknownTypeException { 231 if (node instanceof SpecialNode) return null; 232 throw new UnknownTypeException (node); 233 } 234 235 236 238 public Action [] getActions ( 239 Object node 240 ) throws UnknownTypeException { 241 if (node instanceof SpecialNode) return new Action [0]; 242 throw new UnknownTypeException (node); 243 } 244 245 public void performDefaultAction ( 246 Object node 247 ) throws UnknownTypeException { 248 if (node instanceof SpecialNode) return; 249 throw new UnknownTypeException (node); 250 } 251 252 253 255 public Object getValueAt ( 256 Object row, 257 String columnID 258 ) throws UnknownTypeException { 259 if (row instanceof SpecialNode) return ""; 260 throw new UnknownTypeException (row); 261 } 262 263 public boolean isReadOnly ( 264 Object row, 265 String columnID 266 ) throws UnknownTypeException { 267 if (row instanceof SpecialNode) return true; 268 throw new UnknownTypeException (row); 269 } 270 271 public void setValueAt ( 272 Object row, 273 String columnID, 274 Object value 275 ) throws UnknownTypeException { 276 if (row instanceof SpecialNode) return; 277 throw new UnknownTypeException (row); 278 } 279 280 private static class StaticNode extends SpecialNode { 281 282 StaticNode(ObjectVariable parent) { 283 super(parent); 284 } 285 286 Field [] getChildren(int from, int to) { 287 return object.getAllStaticFields(0, 0); 288 } 289 290 public boolean equals(Object o) { 291 if (this == o) return true; 292 if (!(o instanceof StaticNode)) return false; 293 return object.equals(((StaticNode) o).object); 294 } 295 296 String getDisplayName() { 297 return NbBundle.getBundle(VariablesTreeModelFilterSI.class).getString("MSG_VariablesFilter_StaticNode"); } 299 300 String getIconBase() { 301 return STATIC; 302 } 303 } 304 305 private static class InheritedNode extends SpecialNode { 306 307 InheritedNode(ObjectVariable object) { 308 super(object); 309 } 310 311 Field [] getChildren(int from, int to) { 312 return object.getInheritedFields(0, 0); 313 } 314 315 public boolean equals(Object o) { 316 if (this == o) return true; 317 if (!(o instanceof InheritedNode)) return false; 318 return object.equals(((InheritedNode) o).object); 319 } 320 321 String getDisplayName() { 322 return NbBundle.getBundle(VariablesTreeModelFilterSI.class).getString("MSG_VariablesFilter_InheritedNode"); } 324 325 String getIconBase() { 326 return INHERITED; 327 } 328 } 329 330 private static abstract class SpecialNode { 331 protected ObjectVariable object; 332 333 protected SpecialNode(ObjectVariable parent) { 334 this.object = parent; 335 } 336 337 public int hashCode() { 338 return object.hashCode(); 339 } 340 341 abstract Field [] getChildren(int from, int to); 342 abstract String getDisplayName(); 343 abstract String getIconBase(); 344 } 345 346 } 348 | Popular Tags |