1 19 20 package org.netbeans.examples.debugger.jpda.callstackviewfilterring; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import org.netbeans.api.debugger.jpda.CallStackFrame; 25 import org.netbeans.spi.viewmodel.ComputingException; 26 import org.netbeans.spi.viewmodel.NoInformationException; 27 import org.netbeans.spi.viewmodel.NodeModel; 28 import org.netbeans.spi.viewmodel.TreeModel; 29 import org.netbeans.spi.viewmodel.TreeModelFilter; 30 import org.netbeans.spi.viewmodel.TreeModelListener; 31 import org.netbeans.spi.viewmodel.UnknownTypeException; 32 33 34 35 36 public class CallStackFilter implements TreeModelFilter, NodeModel { 37 38 39 45 public Object getRoot (TreeModel original) { 46 return original.getRoot (); 47 } 48 49 63 public int getChildrenCount ( 64 TreeModel original, 65 Object node 66 ) throws NoInformationException, ComputingException, UnknownTypeException { 67 if (node.equals (original.getRoot ())) { 68 Object [] originalCh = original.getChildren ( 69 node, 70 0, 71 original.getChildrenCount (node) 72 ); 73 int i, k = originalCh.length, j = 0; 74 boolean in = false; 75 for (i = 0; i < k; i++) { 76 if (! (originalCh [i] instanceof CallStackFrame)) { 77 j++; 78 continue; 79 } 80 CallStackFrame f = (CallStackFrame) originalCh [i]; 81 String className = f.getClassName (); 82 if (className.startsWith ("java")) { 83 if (!in) { 84 j++; 85 in = true; 86 } 87 } else { 88 in = false; 89 j++; 90 } 91 } 92 return j; 93 } 94 if (node instanceof JavaFrames) 95 return ((JavaFrames) node).getStack ().size (); 96 return original.getChildrenCount (node); 97 } 98 99 117 public Object [] getChildren ( 118 TreeModel original, 119 Object parent, 120 int from, 121 int to 122 ) throws NoInformationException, ComputingException, UnknownTypeException { 123 if (parent.equals (original.getRoot ())) { 124 Object [] originalCh = original.getChildren ( 125 parent, 126 0, 127 original.getChildrenCount (parent) 128 ); 129 int i, k = originalCh.length; 130 ArrayList newCh = new ArrayList (); 131 JavaFrames javaFrames = null; 132 for (i = 0; i < k; i++) { 133 if (! (originalCh [i] instanceof CallStackFrame)) { 134 newCh.add (originalCh [i]); 135 continue; 136 } 137 CallStackFrame f = (CallStackFrame) originalCh [i]; 138 String className = f.getClassName (); 139 if (className.startsWith ("java")) { 140 if (javaFrames == null) { 141 javaFrames = new JavaFrames (); 142 newCh.add (javaFrames); 143 } 144 javaFrames.addFrame (f); 145 } else { 146 javaFrames = null; 147 newCh.add (f); 148 } 149 } 150 return newCh.subList (from, to).toArray (); 151 } 152 if (parent instanceof JavaFrames) 153 return ((JavaFrames) parent).getStack ().toArray (); 154 return original.getChildren (parent, from, to); 155 } 156 157 166 public boolean isLeaf (TreeModel original, Object node) 167 throws UnknownTypeException { 168 if (node instanceof JavaFrames) return false; 169 return original.isLeaf (node); 170 } 171 172 public void addTreeModelListener (TreeModelListener l) { 173 } 174 public void removeTreeModelListener (TreeModelListener l) { 175 } 176 177 public String getDisplayName (Object node) throws UnknownTypeException { 178 if (node instanceof JavaFrames) 179 return "Java Callstack Frames"; 180 throw new UnknownTypeException (node); 181 } 182 183 public String getIconBase (Object node) throws UnknownTypeException { 184 if (node instanceof JavaFrames) 185 return "org/netbeans/examples/debugger/jpda/callstackviewfilterring/NonCurrentFrame"; 186 throw new UnknownTypeException (node); 187 } 188 189 public String getShortDescription (Object node) throws UnknownTypeException { 190 if (node instanceof JavaFrames) 191 return "Unimportant hidden callstack frames"; 192 throw new UnknownTypeException (node); 193 } 194 195 196 198 private static class JavaFrames { 199 private List frames = new ArrayList (); 200 201 void addFrame (CallStackFrame frame) { 202 frames.add (frame); 203 } 204 205 List getStack () { 206 return frames; 207 } 208 209 public boolean equals (Object o) { 210 if (!(o instanceof JavaFrames)) return false; 211 if (frames.size () != ((JavaFrames) o).frames.size ()) return false; 212 if (frames.size () == 0) return o == this; 213 return frames.get (0).equals ( 214 ((JavaFrames) o).frames.get (0) 215 ); 216 } 217 218 public int hashCode () { 219 if (frames.size () == 0) return super.hashCode (); 220 return frames.get (0).hashCode (); 221 } 222 } 223 } 224 | Popular Tags |