KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > monitor > client > NestedNode


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.monitor.client;
21
22 import org.openide.nodes.Children;
23 import org.openide.util.actions.*;
24 import org.openide.util.Utilities;
25 import org.openide.nodes.AbstractNode;
26 import org.openide.util.actions.SystemAction;
27 import java.awt.Image JavaDoc;
28 import java.util.StringTokenizer JavaDoc;
29 import org.netbeans.modules.web.monitor.data.Constants;
30
31 public class NestedNode extends AbstractNode {
32
33     private String JavaDoc resource = null;
34     private String JavaDoc method = null;
35     private int statusCode;
36     private int[] index;
37      
38     public NestedNode(String JavaDoc resource, String JavaDoc method, int[] index, int statusCode) {
39         
40     super(Children.LEAF);
41     this.resource = resource;
42     this.method = method;
43     this.index = index;
44         this.statusCode = statusCode;
45     setProperties();
46     }
47
48
49     public NestedNode(String JavaDoc resource,
50               String JavaDoc method,
51               Children ch,
52               int[] index,
53                       int statusCode) {
54     super(ch);
55     this.resource = resource;
56     this.method = method;
57     this.index = index;
58         this.statusCode = statusCode;
59     setProperties();
60     }
61
62     public String JavaDoc getLongName() {
63     return getName();
64     }
65     
66     public Image JavaDoc getIcon(int type) {
67         Image JavaDoc base;
68     // Get icon
69
if(method.equals(Constants.Http.GET)) {
70             base = Utilities.loadImage("org/netbeans/modules/web/monitor/client/icons/get.gif");
71     // Post icon
72
} else if(method.equals(Constants.Http.POST)) {
73             base = Utilities.loadImage("org/netbeans/modules/web/monitor/client/icons/post.gif"); // NOI18N
74
// Other
75
} else {
76             base = Utilities.loadImage("org/netbeans/modules/web/monitor/client/icons/other.gif"); // NOI18N
77
}
78         
79         Image JavaDoc badge;
80         if (statusCode >= 400 || statusCode < 0) {
81             badge = Utilities.loadImage("org/netbeans/modules/web/monitor/client/icons/infoBadge.gif"); // NOI18N
82
} else if (statusCode >= 300) {
83             badge = Utilities.loadImage("org/netbeans/modules/web/monitor/client/icons/warningBadge.gif"); // NOI18N
84
} else if (statusCode >= 200) {
85             return base;
86         } else {
87             badge = Utilities.loadImage("org/netbeans/modules/web/monitor/client/icons/errorBadge.gif"); // NOI18N
88
}
89         return Utilities.mergeImages(base, badge, 0, 0);
90     }
91     
92     public Image JavaDoc getOpenedIcon(int type) {
93         return getIcon(type);
94     }
95     
96     public String JavaDoc getResource() {
97     return resource;
98     }
99
100     public int[] getIndex() {
101     return index;
102     }
103
104     /* Getter for set of actions that should be present in the
105      * popup menu of this node. This set is used in construction of
106      * menu returned from getContextMenu and specially when a menu for
107      * more nodes is constructed.
108      *
109      * @return array of system actions that should be in popup menu
110      */

111
112     protected SystemAction[] createActions () {
113
114     return new SystemAction[] {
115     };
116     }
117
118     /** Can this node be copied?
119      * @return <code>true</code> in the default implementation
120      */

121     public boolean canCopy () {
122     return false;
123     }
124
125     /** Can this node be cut?
126      * @return <code>false</code> in the default implementation
127      */

128     public boolean canCut () {
129     return false;
130     }
131
132     private void setProperties() {
133     setNameString();
134     }
135     
136     public void setNameString() {
137     
138     String JavaDoc name = null;
139     if(resource.equals("/")) name = resource; //NOI18N
140
else {
141         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(resource,"/"); //NOI18N
142
while(st.hasMoreTokens()) name = st.nextToken();
143     }
144     setName(name);
145     }
146
147     public String JavaDoc toString() {
148     StringBuilder JavaDoc buf = new StringBuilder JavaDoc("NestedNode: "); //NOI18N
149
buf.append(this.getName());
150     buf.append(", resource="); //NOI18N
151
buf.append(resource);
152     buf.append(", index="); //NOI18N
153
for(int i=0; i<index.length; ++i) {
154         buf.append(index[i]);
155         buf.append(','); //NOI18N
156
}
157     return buf.toString();
158     }
159 } // NestedNode
160
Popular Tags