KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > ui > models > BreakpointsTreeModelFilter


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.debugger.jpda.ui.models;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.WeakHashMap JavaDoc;
27 import org.netbeans.api.debugger.Breakpoint;
28 import org.netbeans.api.debugger.DebuggerManager;
29 import org.netbeans.api.debugger.jpda.JPDABreakpoint;
30 import org.netbeans.api.debugger.jpda.LineBreakpoint;
31 import org.netbeans.modules.debugger.jpda.ui.EditorContextBridge;
32 import org.netbeans.spi.viewmodel.TreeModel;
33 import org.netbeans.spi.viewmodel.TreeModelFilter;
34 import org.netbeans.spi.viewmodel.ModelListener;
35 import org.netbeans.spi.viewmodel.UnknownTypeException;
36
37
38 /**
39  * Filters content of some original tree of nodes (represented by
40  * {@link TreeModel}).
41  *
42  * @author Jan Jancura
43  */

44 public class BreakpointsTreeModelFilter implements TreeModelFilter {
45     
46     static Map JavaDoc MAX_LINES = new WeakHashMap JavaDoc();
47     
48     private static boolean verbose =
49         System.getProperty ("netbeans.debugger.show_hidden_breakpoints") != null;
50
51     /**
52      * Returns filtered root of hierarchy.
53      *
54      * @param original the original tree model
55      * @return filtered root of hierarchy
56      */

57     public Object JavaDoc getRoot (TreeModel original) {
58         return original.getRoot ();
59     }
60     
61     /**
62      * Returns filtered children for given parent on given indexes.
63      *
64      * @param original the original tree model
65      * @param parent a parent of returned nodes
66      * @throws NoInformationException if the set of children can not be
67      * resolved
68      * @throws ComputingException if the children resolving process
69      * is time consuming, and will be performed off-line
70      * @throws UnknownTypeException if this TreeModelFilter implementation is not
71      * able to resolve dchildren for given node type
72      *
73      * @return children for given parent on given indexes
74      */

75     public Object JavaDoc[] getChildren (
76         TreeModel original,
77         Object JavaDoc parent,
78         int from,
79         int to
80     ) throws UnknownTypeException {
81         if (to - from <= 0) return new Object JavaDoc[0];
82         Object JavaDoc[] ch = original.getChildren (parent, 0, 0);
83         List JavaDoc l = new ArrayList JavaDoc ();
84         int i, k = ch.length, n = to - from;
85         Map JavaDoc maxLines = new HashMap JavaDoc();
86         for (i = 0; i < k; i++) {
87             if ( (!verbose) &&
88                  (ch [i] instanceof JPDABreakpoint) &&
89                  ((JPDABreakpoint) ch [i]).isHidden ()
90             ) continue;
91             if (--from >= 0) continue;
92             l.add (ch [i]);
93             if (ch[i] instanceof LineBreakpoint) {
94                 LineBreakpoint lb = (LineBreakpoint) ch[i];
95                 String JavaDoc fn = EditorContextBridge.getFileName(lb);
96                 int line = lb.getLineNumber();
97                 Integer JavaDoc mI = (Integer JavaDoc) maxLines.get(fn);
98                 if (mI != null) {
99                     line = Math.max(line, mI.intValue());
100                 }
101                 mI = new Integer JavaDoc(line);
102                 maxLines.put(fn, mI);
103             }
104             if (--n == 0) break;
105         }
106         for (i = l.size() - 1; i >= 0; i--) {
107             Object JavaDoc o = l.get(i);
108             if (o instanceof LineBreakpoint) {
109                 LineBreakpoint lb = (LineBreakpoint) o;
110                 MAX_LINES.put(lb, maxLines.get(EditorContextBridge.getFileName(lb)));
111             }
112         }
113         return l.toArray();
114     }
115     
116     /**
117      * Returns number of filterred children for given node.
118      *
119      * @param original the original tree model
120      * @param node the parent node
121      * @throws NoInformationException if the set of children can not be
122      * resolved
123      * @throws ComputingException if the children resolving process
124      * is time consuming, and will be performed off-line
125      * @throws UnknownTypeException if this TreeModel implementation is not
126      * able to resolve children for given node type
127      *
128      * @return true if node is leaf
129      */

130     public int getChildrenCount (
131         TreeModel original,
132         Object JavaDoc node
133     ) throws UnknownTypeException {
134         return getChildren(original, node, 0, Integer.MAX_VALUE).length;
135     }
136     
137     /**
138      * Returns true if node is leaf.
139      *
140      * @param original the original tree model
141      * @throws UnknownTypeException if this TreeModel implementation is not
142      * able to resolve dchildren for given node type
143      * @return true if node is leaf
144      */

145     public boolean isLeaf (
146         TreeModel original,
147         Object JavaDoc node
148     ) throws UnknownTypeException {
149         return original. isLeaf (node);
150     }
151
152     /**
153      * Registers given listener.
154      *
155      * @param l the listener to add
156      */

157     public void addModelListener (ModelListener l) {
158     }
159
160     /**
161      * Unregisters given listener.
162      *
163      * @param l the listener to remove
164      */

165     public void removeModelListener (ModelListener l) {
166     }
167 }
168
Popular Tags