KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > debug > variablesfilterring > JSPVariablesNodeModelFilter


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.web.debug.variablesfilterring;
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.modules.web.debug.variablesfilterring.JSPVariablesFilter.AttributeMap;
26 import org.netbeans.modules.web.debug.variablesfilterring.JSPVariablesFilter.ImplicitLocals;
27 import org.netbeans.spi.viewmodel.NodeModel;
28 import org.netbeans.spi.viewmodel.NodeModelFilter;
29 import org.netbeans.spi.viewmodel.UnknownTypeException;
30 import org.openide.util.NbBundle;
31
32 /**
33  *
34  * @author Libor Kotouc
35  */

36 public class JSPVariablesNodeModelFilter implements NodeModelFilter {
37     
38     /** Creates a new instance of JSPVariablesNodeModelFilter */
39     public JSPVariablesNodeModelFilter() {
40     }
41
42     /**
43      * Returns filterred display name for given node. You should not
44      * throw UnknownTypeException directly from this method!
45      *
46      * @throws ComputingException if the display name resolving process
47      * is time consuming, and the value will be updated later
48      * @throws UnknownTypeException this exception can be thrown from
49      * <code>original.getDisplayName (...)</code> method call only!
50      * @return display name for given node
51      */

52     public String JavaDoc getDisplayName (NodeModel original, Object JavaDoc node)
53     throws UnknownTypeException
54     {
55         
56         String JavaDoc dn = "";
57         if (node instanceof ImplicitLocals)
58             dn = NbBundle.getMessage(JSPVariablesFilter.class, "LBL_IMPLICIT_LOCALS");
59         else if (node instanceof AttributeMap) {
60             String JavaDoc resIcon = "";
61             String JavaDoc ownerName = ((AttributeMap)node).getOwnerName();
62             if (ownerName.equals("request"))
63                 resIcon = "LBL_REQUEST_ATTRIBUTES";
64             else if (ownerName.equals("session"))
65                 resIcon = "LBL_SESSION_ATTRIBUTES";
66             else if (ownerName.equals("application"))
67                 resIcon = "LBL_APPLICATION_ATTRIBUTES";
68             
69             dn = NbBundle.getMessage(JSPVariablesFilter.class, resIcon);
70         }
71         else if (node instanceof AttributeMap.Attribute)
72             dn = ((AttributeMap.Attribute)node).getName();
73         else
74             dn = original.getDisplayName(node);
75         
76         return dn;
77     }
78     
79     /**
80      * Returns filterred icon for given node. You should not throw
81      * UnknownTypeException directly from this method!
82      *
83      * @throws ComputingException if the icon resolving process
84      * is time consuming, and the value will be updated later
85      * @throws UnknownTypeException this exception can be thrown from
86      * <code>original.getIconBase (...)</code> method call only!
87      * @return icon for given node
88      */

89     public String JavaDoc getIconBase (NodeModel original, Object JavaDoc node)
90     throws UnknownTypeException
91     {
92         String JavaDoc ib = "";
93         if (node instanceof ImplicitLocals)
94             ib = NbBundle.getMessage(JSPVariablesFilter.class, "RES_IMPLICIT_LOCALS_GROUP");
95         else if (node instanceof AttributeMap)
96             ib = NbBundle.getMessage(JSPVariablesFilter.class, "RES_ATTRIBUTES_GROUP");
97         else if (node instanceof AttributeMap.Attribute)
98             ib = NbBundle.getMessage(JSPVariablesFilter.class, "RES_ATTRIBUTE_VALUE");
99         else
100             ib = original.getIconBase(node);
101                 
102         return ib;
103     }
104     
105     /**
106      * Returns filterred tooltip for given node. You should not throw
107      * UnknownTypeException directly from this method!
108      *
109      * @throws ComputingException if the tooltip resolving process
110      * is time consuming, and the value will be updated later
111      * @throws UnknownTypeException this exception can be thrown from
112      * <code>original.getShortDescription (...)</code> method call only!
113      * @return tooltip for given node
114      */

115     public String JavaDoc getShortDescription (NodeModel original, Object JavaDoc node)
116     throws UnknownTypeException
117     {
118         String JavaDoc sd = "";
119         if (node instanceof ImplicitLocals)
120             sd = NbBundle.getMessage(JSPVariablesFilter.class, "TLT_IMPLICIT_LOCALS");
121         else if (node instanceof AttributeMap) {
122             String JavaDoc tltAttributes = "";
123             String JavaDoc ownerName = ((AttributeMap)node).getOwnerName();
124             if (ownerName.equals("request"))
125                 tltAttributes = "TLT_REQUEST_ATTRIBUTES";
126             else if (ownerName.equals("session"))
127                 tltAttributes = "TLT_SESSION_ATTRIBUTES";
128             else if (ownerName.equals("application"))
129                 tltAttributes = "TLT_APPLICATION_ATTRIBUTES";
130             
131             sd = NbBundle.getMessage(JSPVariablesFilter.class, "TLT_REQUEST_ATTRIBUTES");
132         }
133         else if (node instanceof AttributeMap.Attribute) {
134             Variable attributeValue = ((AttributeMap.Attribute)node).getValue();
135             String JavaDoc type = attributeValue.getType ();
136             try {
137                 String JavaDoc stringValue = attributeValue.getValue();
138                 if (attributeValue instanceof ObjectVariable)
139                     stringValue = ((ObjectVariable)attributeValue).getToStringValue();
140                 sd = "(" + type + ") " + stringValue;
141             } catch (InvalidExpressionException iee) {
142                 sd = iee.getLocalizedMessage();
143             }
144         }
145         else
146             sd = original.getShortDescription(node);
147                 
148         return sd;
149     }
150
151     /**
152      *
153      * Unregisters given listener.
154      *
155      * @param l the listener to remove
156      */

157     public void removeModelListener(org.netbeans.spi.viewmodel.ModelListener l) {
158     }
159
160     /**
161      *
162      * Registers given listener.
163      *
164      * @param l the listener to add
165      */

166     public void addModelListener(org.netbeans.spi.viewmodel.ModelListener l) {
167     }
168
169     
170 }
171
Popular Tags