001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.web.debug.variablesfilterring;
043:
044: import java.awt.datatransfer.Transferable;
045: import java.io.IOException;
046: import org.netbeans.api.debugger.jpda.InvalidExpressionException;
047: import org.netbeans.api.debugger.jpda.ObjectVariable;
048: import org.netbeans.api.debugger.jpda.Variable;
049: import org.netbeans.modules.web.debug.variablesfilterring.JSPVariablesFilter.AttributeMap;
050: import org.netbeans.modules.web.debug.variablesfilterring.JSPVariablesFilter.ImplicitLocals;
051: import org.netbeans.spi.viewmodel.ExtendedNodeModel;
052: import org.netbeans.spi.viewmodel.ExtendedNodeModelFilter;
053: import org.netbeans.spi.viewmodel.NodeModel;
054: import org.netbeans.spi.viewmodel.UnknownTypeException;
055: import org.openide.util.NbBundle;
056: import org.openide.util.datatransfer.PasteType;
057:
058: /**
059: *
060: * @author Libor Kotouc
061: */
062: public class JSPVariablesNodeModelFilter implements
063: ExtendedNodeModelFilter {
064:
065: /** Creates a new instance of JSPVariablesNodeModelFilter */
066: public JSPVariablesNodeModelFilter() {
067: }
068:
069: /**
070: * Returns filterred display name for given node. You should not
071: * throw UnknownTypeException directly from this method!
072: *
073: * @throws ComputingException if the display name resolving process
074: * is time consuming, and the value will be updated later
075: * @throws UnknownTypeException this exception can be thrown from
076: * <code>original.getDisplayName (...)</code> method call only!
077: * @return display name for given node
078: */
079: public String getDisplayName(NodeModel original, Object node)
080: throws UnknownTypeException {
081:
082: String dn = "";
083: if (node instanceof ImplicitLocals)
084: dn = NbBundle.getMessage(JSPVariablesFilter.class,
085: "LBL_IMPLICIT_LOCALS");
086: else if (node instanceof AttributeMap) {
087: String resIcon = "";
088: String ownerName = ((AttributeMap) node).getOwnerName();
089: if (ownerName.equals("request"))
090: resIcon = "LBL_REQUEST_ATTRIBUTES";
091: else if (ownerName.equals("session"))
092: resIcon = "LBL_SESSION_ATTRIBUTES";
093: else if (ownerName.equals("application"))
094: resIcon = "LBL_APPLICATION_ATTRIBUTES";
095:
096: dn = NbBundle.getMessage(JSPVariablesFilter.class, resIcon);
097: } else if (node instanceof AttributeMap.Attribute)
098: dn = ((AttributeMap.Attribute) node).getName();
099: else
100: dn = original.getDisplayName(node);
101:
102: return dn;
103: }
104:
105: /**
106: * Returns filterred icon for given node. You should not throw
107: * UnknownTypeException directly from this method!
108: *
109: * @throws ComputingException if the icon 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.getIconBase (...)</code> method call only!
113: * @return icon for given node
114: */
115: public String getIconBase(NodeModel original, Object node)
116: throws UnknownTypeException {
117: throw new IllegalStateException(
118: "getIconBaseWithExtension should be always called instead");
119: }
120:
121: public String getIconBaseWithExtension(ExtendedNodeModel original,
122: Object node) throws UnknownTypeException {
123: String ib = "";
124: if (node instanceof ImplicitLocals)
125: ib = NbBundle.getMessage(JSPVariablesFilter.class,
126: "RES_IMPLICIT_LOCALS_GROUP");
127: else if (node instanceof AttributeMap)
128: ib = NbBundle.getMessage(JSPVariablesFilter.class,
129: "RES_ATTRIBUTES_GROUP");
130: else if (node instanceof AttributeMap.Attribute)
131: ib = NbBundle.getMessage(JSPVariablesFilter.class,
132: "RES_ATTRIBUTE_VALUE");
133: else
134: ib = original.getIconBaseWithExtension(node);
135:
136: return ib;
137: }
138:
139: /**
140: * Returns filterred tooltip for given node. You should not throw
141: * UnknownTypeException directly from this method!
142: *
143: * @throws ComputingException if the tooltip resolving process
144: * is time consuming, and the value will be updated later
145: * @throws UnknownTypeException this exception can be thrown from
146: * <code>original.getShortDescription (...)</code> method call only!
147: * @return tooltip for given node
148: */
149: public String getShortDescription(NodeModel original, Object node)
150: throws UnknownTypeException {
151: String sd = "";
152: if (node instanceof ImplicitLocals)
153: sd = NbBundle.getMessage(JSPVariablesFilter.class,
154: "TLT_IMPLICIT_LOCALS");
155: else if (node instanceof AttributeMap) {
156: String tltAttributes = "";
157: String ownerName = ((AttributeMap) node).getOwnerName();
158: if (ownerName.equals("request"))
159: tltAttributes = "TLT_REQUEST_ATTRIBUTES";
160: else if (ownerName.equals("session"))
161: tltAttributes = "TLT_SESSION_ATTRIBUTES";
162: else if (ownerName.equals("application"))
163: tltAttributes = "TLT_APPLICATION_ATTRIBUTES";
164:
165: sd = NbBundle.getMessage(JSPVariablesFilter.class,
166: "TLT_REQUEST_ATTRIBUTES");
167: } else if (node instanceof AttributeMap.Attribute) {
168: Variable attributeValue = ((AttributeMap.Attribute) node)
169: .getValue();
170: String type = attributeValue.getType();
171: try {
172: String stringValue = attributeValue.getValue();
173: if (attributeValue instanceof ObjectVariable)
174: stringValue = ((ObjectVariable) attributeValue)
175: .getToStringValue();
176: sd = "(" + type + ") " + stringValue;
177: } catch (InvalidExpressionException iee) {
178: sd = iee.getLocalizedMessage();
179: }
180: } else
181: sd = original.getShortDescription(node);
182:
183: return sd;
184: }
185:
186: /**
187: *
188: * Unregisters given listener.
189: *
190: * @param l the listener to remove
191: */
192: public void removeModelListener(
193: org.netbeans.spi.viewmodel.ModelListener l) {
194: }
195:
196: /**
197: *
198: * Registers given listener.
199: *
200: * @param l the listener to add
201: */
202: public void addModelListener(
203: org.netbeans.spi.viewmodel.ModelListener l) {
204: }
205:
206: public boolean canRename(ExtendedNodeModel original, Object node)
207: throws UnknownTypeException {
208: return false;
209: }
210:
211: public boolean canCopy(ExtendedNodeModel original, Object node)
212: throws UnknownTypeException {
213: return false;
214: }
215:
216: public boolean canCut(ExtendedNodeModel original, Object node)
217: throws UnknownTypeException {
218: return false;
219: }
220:
221: public Transferable clipboardCopy(ExtendedNodeModel original,
222: Object node) throws IOException, UnknownTypeException {
223: throw new UnsupportedOperationException("not supported");
224: }
225:
226: public Transferable clipboardCut(ExtendedNodeModel original,
227: Object node) throws IOException, UnknownTypeException {
228: throw new UnsupportedOperationException("not supported");
229: }
230:
231: public PasteType[] getPasteTypes(ExtendedNodeModel original,
232: Object node, Transferable t) throws UnknownTypeException {
233: return new PasteType[0];
234: }
235:
236: public void setName(ExtendedNodeModel original, Object node,
237: String name) throws UnknownTypeException {
238: }
239:
240: }
|