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-2007 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.monitor.client;
043:
044: import org.openide.nodes.Children;
045: import org.openide.util.actions.*;
046: import org.openide.util.Utilities;
047: import org.openide.nodes.AbstractNode;
048: import org.openide.util.actions.SystemAction;
049: import java.awt.Image;
050: import java.util.StringTokenizer;
051: import org.netbeans.modules.web.monitor.data.Constants;
052:
053: public class NestedNode extends AbstractNode {
054:
055: private String resource = null;
056: private String method = null;
057: private int statusCode;
058: private int[] index;
059:
060: public NestedNode(String resource, String method, int[] index,
061: int statusCode) {
062:
063: super (Children.LEAF);
064: this .resource = resource;
065: this .method = method;
066: this .index = index;
067: this .statusCode = statusCode;
068: setProperties();
069: }
070:
071: public NestedNode(String resource, String method, Children ch,
072: int[] index, int statusCode) {
073: super (ch);
074: this .resource = resource;
075: this .method = method;
076: this .index = index;
077: this .statusCode = statusCode;
078: setProperties();
079: }
080:
081: public String getLongName() {
082: return getName();
083: }
084:
085: public Image getIcon(int type) {
086: Image base;
087: // Get icon
088: if (method.equals(Constants.Http.GET)) {
089: base = Utilities
090: .loadImage("org/netbeans/modules/web/monitor/client/icons/get.gif");
091: // Post icon
092: } else if (method.equals(Constants.Http.POST)) {
093: base = Utilities
094: .loadImage("org/netbeans/modules/web/monitor/client/icons/post.gif"); // NOI18N
095: // Other
096: } else {
097: base = Utilities
098: .loadImage("org/netbeans/modules/web/monitor/client/icons/other.gif"); // NOI18N
099: }
100:
101: Image badge;
102: if (statusCode >= 400 || statusCode < 0) {
103: badge = Utilities
104: .loadImage("org/netbeans/modules/web/monitor/client/icons/infoBadge.gif"); // NOI18N
105: } else if (statusCode >= 300) {
106: badge = Utilities
107: .loadImage("org/netbeans/modules/web/monitor/client/icons/warningBadge.gif"); // NOI18N
108: } else if (statusCode >= 200) {
109: return base;
110: } else {
111: badge = Utilities
112: .loadImage("org/netbeans/modules/web/monitor/client/icons/errorBadge.gif"); // NOI18N
113: }
114: return Utilities.mergeImages(base, badge, 0, 0);
115: }
116:
117: public Image getOpenedIcon(int type) {
118: return getIcon(type);
119: }
120:
121: public String getResource() {
122: return resource;
123: }
124:
125: public int[] getIndex() {
126: return index;
127: }
128:
129: /* Getter for set of actions that should be present in the
130: * popup menu of this node. This set is used in construction of
131: * menu returned from getContextMenu and specially when a menu for
132: * more nodes is constructed.
133: *
134: * @return array of system actions that should be in popup menu
135: */
136:
137: protected SystemAction[] createActions() {
138:
139: return new SystemAction[] {};
140: }
141:
142: /** Can this node be copied?
143: * @return <code>true</code> in the default implementation
144: */
145: public boolean canCopy() {
146: return false;
147: }
148:
149: /** Can this node be cut?
150: * @return <code>false</code> in the default implementation
151: */
152: public boolean canCut() {
153: return false;
154: }
155:
156: private void setProperties() {
157: setNameString();
158: }
159:
160: public void setNameString() {
161:
162: String name = null;
163: if (resource.equals("/"))
164: name = resource; //NOI18N
165: else {
166: StringTokenizer st = new StringTokenizer(resource, "/"); //NOI18N
167: while (st.hasMoreTokens())
168: name = st.nextToken();
169: }
170: setName(name);
171: }
172:
173: public String toString() {
174: StringBuilder buf = new StringBuilder("NestedNode: "); //NOI18N
175: buf.append(this .getName());
176: buf.append(", resource="); //NOI18N
177: buf.append(resource);
178: buf.append(", index="); //NOI18N
179: for (int i = 0; i < index.length; ++i) {
180: buf.append(index[i]);
181: buf.append(','); //NOI18N
182: }
183: return buf.toString();
184: }
185: } // NestedNode
|