KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.api.debugger.jpda.InvalidExpressionException;
23 import org.netbeans.api.debugger.jpda.ObjectVariable;
24 import org.netbeans.api.debugger.jpda.Variable;
25 import org.netbeans.spi.debugger.jpda.VariablesFilterAdapter;
26 import org.netbeans.spi.debugger.ui.Constants;
27 import org.netbeans.spi.viewmodel.TableModel;
28 import org.netbeans.spi.viewmodel.TreeModel;
29 import org.netbeans.spi.viewmodel.UnknownTypeException;
30
31
32 /**
33  * Filter for instances of enumetaion types. Instead of #20 it displays the name of the constant.
34  *
35  * @author Maros Sandor
36  */

37 public class EnumConstantsFilter extends VariablesFilterAdapter {
38
39     public String JavaDoc[] getSupportedTypes () {
40         return new String JavaDoc[] {
41         };
42     }
43     
44     public String JavaDoc[] getSupportedAncestors () {
45         return new String JavaDoc[] {
46             "java.lang.Enum"
47         };
48     }
49     
50     /**
51      * Returns true.
52      *
53      * @param original the original tree model
54      * @param variable an enumeraion constant
55      * @return true
56      */

57     public boolean isLeaf (TreeModel original, Variable variable) throws UnknownTypeException {
58         return true;
59     }
60     
61     public Object JavaDoc getValueAt (
62         TableModel original,
63         Variable variable,
64         String JavaDoc columnID
65     ) throws UnknownTypeException {
66         
67         ObjectVariable ov = (ObjectVariable) variable;
68         if ( columnID == Constants.LOCALS_VALUE_COLUMN_ID ||
69              columnID == Constants.WATCH_VALUE_COLUMN_ID
70         ) {
71             try {
72                 return ov.getToStringValue ();
73             } catch (InvalidExpressionException ex) {
74                 return ex.getLocalizedMessage ();
75             }
76         } else if (columnID == Constants.LOCALS_TYPE_COLUMN_ID || columnID == Constants.WATCH_TYPE_COLUMN_ID) {
77             String JavaDoc typeName = ov.getType();
78             int idx = typeName.lastIndexOf("$");
79             if (idx != -1) {
80                 return typeName.substring(idx + 1);
81             }
82             idx = typeName.lastIndexOf(".");
83             if (idx != -1) {
84                 return typeName.substring(idx + 1);
85             }
86         }
87         return original.getValueAt (variable, columnID);
88     }
89 }
90
Popular Tags