KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.jdi.ClassLoaderReference;
23 import com.sun.jdi.ClassType;
24 import com.sun.jdi.InterfaceType;
25 import com.sun.jdi.ReferenceType;
26 import org.netbeans.api.debugger.Properties;
27 import org.netbeans.spi.viewmodel.NodeModel;
28 import org.netbeans.spi.viewmodel.TreeModel;
29 import org.netbeans.spi.viewmodel.ModelListener;
30 import org.netbeans.spi.viewmodel.UnknownTypeException;
31 import org.openide.util.NbBundle;
32
33 /**
34  * @author Jan Jancura
35  */

36 public class ClassesNodeModel implements NodeModel {
37
38     private static final String JavaDoc CLASS =
39         "org/netbeans/modules/debugger/jpda/resources/class";
40     private static final String JavaDoc INTERFACE =
41         "org/netbeans/modules/debugger/jpda/resources/interface";
42     private static final String JavaDoc PACKAGE =
43         "org/netbeans/modules/debugger/jpda/resources/package";
44     private static final String JavaDoc FIELD =
45         "org/netbeans/modules/debugger/jpda/resources/field";
46     private static final String JavaDoc CLASS_LOADER =
47         "org/netbeans/modules/debugger/jpda/resources/classLoader";
48     
49     private Properties classesProperties = Properties.getDefault().
50             getProperties("debugger").getProperties("classesView"); // NOI18N
51

52     
53     public String JavaDoc getDisplayName (Object JavaDoc o) throws UnknownTypeException {
54         if (o == TreeModel.ROOT)
55             return NbBundle.getBundle (ClassesNodeModel.class).getString
56                 ("CTL_ClassesModel_Column_Name_Name");
57         if (o instanceof Object JavaDoc[]) {
58             String JavaDoc name = (String JavaDoc) ((Object JavaDoc[]) o) [0];
59             boolean flat = classesProperties.getBoolean("flat", true);
60             if (!flat) {
61                 int i = name.lastIndexOf ('.');
62                 if (i >= 0)
63                     name = name.substring (i + 1);
64             }
65             return name;
66         }
67         if (o instanceof ReferenceType) {
68             String JavaDoc name = ((ReferenceType) o).name ();
69             int i = name.lastIndexOf ('.');
70             if (i >= 0)
71                 name = name.substring (i + 1);
72             i = name.lastIndexOf ('$');
73             if (i >= 0)
74                 name = name.substring (i + 1);
75             return name;
76         }
77         if (o instanceof ClassLoaderReference) {
78             String JavaDoc name = ((ClassLoaderReference) o).referenceType ().name ();
79             if (name.endsWith ("AppClassLoader"))
80                 return NbBundle.getBundle (ClassesNodeModel.class).getString
81                     ("CTL_ClassesModel_Column_Name_AppClassLoader");
82             return java.text.MessageFormat.format (NbBundle.getBundle
83                 (ClassesNodeModel.class).getString (
84                     "CTL_ClassesModel_Column_Name_ClassLoader"),
85                     new Object JavaDoc [] {name}
86                 );
87         }
88         if (o instanceof Integer JavaDoc) {
89             return NbBundle.getBundle (ClassesNodeModel.class).getString
90                 ("CTL_ClassesModel_Column_Name_SystemClassLoader");
91         }
92         throw new UnknownTypeException (o);
93     }
94     
95     public String JavaDoc getShortDescription (Object JavaDoc o) throws UnknownTypeException {
96         if (o == TreeModel.ROOT)
97             return NbBundle.getBundle (ClassesNodeModel.class).getString
98                 ("CTL_ClassesModel_Column_Name_Desc");
99         if (o instanceof Object JavaDoc[])
100             return java.text.MessageFormat.format (NbBundle.getBundle
101                 (ClassesNodeModel.class).getString (
102                     "CTL_ClassesModel_Column_Name_Package"),
103                 (Object JavaDoc []) o
104             );
105         if (o instanceof ReferenceType) {
106             String JavaDoc format = (o instanceof ClassType) ?
107                     NbBundle.getBundle (ClassesNodeModel.class).getString
108                         ("CTL_ClassesModel_Column_Name_Class") :
109                     NbBundle.getBundle (ClassesNodeModel.class).getString
110                         ("CTL_ClassesModel_Column_Name_Interface");
111             String JavaDoc name = java.text.MessageFormat.format (
112                 format,
113                 new Object JavaDoc [] {((ReferenceType) o).name ()}
114             );
115             ClassLoaderReference cl = ((ReferenceType) o).classLoader ();
116             if (cl != null) {
117                 name += " " + java.text.MessageFormat.format (
118                     NbBundle.getBundle (ClassesNodeModel.class).getString (
119                     "CTL_ClassesModel_Column_Name_LoadedBy"),
120                     new Object JavaDoc [] {cl.referenceType ().name ()}
121                 );
122             }
123             return name;
124         }
125         if (o instanceof ClassLoaderReference)
126             return null;
127         if (o instanceof Integer JavaDoc)
128             return null;
129         throw new UnknownTypeException (o);
130     }
131     
132     public String JavaDoc getIconBase (Object JavaDoc o) throws UnknownTypeException {
133         if (o == TreeModel.ROOT)
134             return CLASS;
135         if (o instanceof Object JavaDoc[])
136             return PACKAGE;
137         if (o instanceof ClassType)
138             return CLASS;
139         if (o instanceof InterfaceType)
140             return INTERFACE;
141         if (o instanceof ClassLoaderReference)
142             return CLASS_LOADER;
143         if (o instanceof Integer JavaDoc)
144             return CLASS_LOADER;
145         throw new UnknownTypeException (o);
146     }
147
148     /**
149      *
150      * @param l the listener to add
151      */

152     public void addModelListener (ModelListener l) {
153     }
154
155     /**
156      *
157      * @param l the listener to remove
158      */

159     public void removeModelListener (ModelListener l) {
160     }
161     
162     
163     // ColumnModels ............................................................
164

165     /**
166      * Defines model for one table view column. Can be used together with
167      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table view
168      * representation.
169      */

170     public static class DefaultClassesColumn extends
171     SourcesModel.AbstractColumn {
172
173         /**
174          * Returns unique ID of this column.
175          *
176          * @return unique ID of this column
177          */

178         public String JavaDoc getID () {
179             return "DefaultClassesColumn";
180         }
181
182         /**
183          * Returns display name of this column.
184          *
185          * @return display name of this column
186          */

187         public String JavaDoc getDisplayName () {
188             return NbBundle.getBundle (DefaultClassesColumn.class).
189                 getString ("CTL_ClassesModel_Column_Name_Name");
190         }
191
192         public Character JavaDoc getDisplayedMnemonic() {
193             return new Character JavaDoc(NbBundle.getBundle (DefaultClassesColumn.class).
194                 getString ("CTL_ClassesModel_Column_Name_Mnc").charAt(0));
195         }
196
197         /**
198          * Returns tooltip for given column.
199          *
200          * @return tooltip for given node
201          */

202         public String JavaDoc getShortDescription () {
203             return NbBundle.getBundle (DefaultClassesColumn.class).getString
204                 ("CTL_ClassesModel_Column_Name_Desc");
205         }
206
207         /**
208          * Returns type of column items.
209          *
210          * @return type of column items
211          */

212         public Class JavaDoc getType () {
213             return null;
214         }
215     }
216 }
217
Popular Tags