1 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.nodes.AbstractNode; 25 import org.openide.util.actions.SystemAction; 26 import org.openide.util.Utilities; 27 28 import java.util.StringTokenizer ; 29 import java.text.DateFormat ; 30 import java.util.Date ; 31 import java.awt.Image ; 32 import org.netbeans.modules.web.monitor.data.Constants; 33 34 public class TransactionNode extends AbstractNode { 35 36 String id, method, uri, name = null, timestamp = null; 37 boolean current; 38 private int statusCode; 39 static boolean showTimeStamp = true; 40 41 public TransactionNode(String id, String method, String uri, 42 boolean current, int statusCode) { 43 44 super(Children.LEAF); 45 46 this.id = id; 47 this.method = method; 48 this.uri = uri; 49 this.current = current; 50 this.statusCode = statusCode; 51 52 setProperties(); 53 } 54 55 public TransactionNode(String id, String method, String uri, 56 Children ch, boolean current, int statusCode) { 57 58 super(ch); 59 60 this.id = id; 61 this.method = method; 62 this.uri = uri; 63 this.current = current; 64 this.statusCode = statusCode; 65 66 setProperties(); 67 } 68 69 public String getLongName() { 71 72 StringBuffer buf = new StringBuffer (method); 73 buf.append(" "); buf.append(uri); 75 if(timestamp == null) setTimeStamp(); 76 buf.append(" "); buf.append(timestamp); 78 79 return buf.toString(); 80 } 81 82 public Image getIcon(int type) { 83 Image base; 84 if(method.equals(Constants.Http.GET)) { 86 base = Utilities.loadImage("org/netbeans/modules/web/monitor/client/icons/get.gif"); 87 } else if(method.equals(Constants.Http.POST)) { 89 base = Utilities.loadImage("org/netbeans/modules/web/monitor/client/icons/post.gif"); } else { 92 base = Utilities.loadImage("org/netbeans/modules/web/monitor/client/icons/other.gif"); } 94 95 Image badge; 96 if (statusCode >= 400 || statusCode < 0) { 97 badge = Utilities.loadImage("org/netbeans/modules/web/monitor/client/icons/infoBadge.gif"); } else if (statusCode >= 300) { 99 badge = Utilities.loadImage("org/netbeans/modules/web/monitor/client/icons/warningBadge.gif"); } else if (statusCode >= 200) { 101 return base; 102 } else { 103 badge = Utilities.loadImage("org/netbeans/modules/web/monitor/client/icons/errorBadge.gif"); } 105 return Utilities.mergeImages(base, badge, 0, 0); 106 } 107 108 public Image getOpenedIcon(int type) { 109 return getIcon(type); 110 } 111 112 public String getID() { 113 return id; 114 } 115 116 public String getMethod() { 117 return method; 118 } 119 120 public String getURI() { 121 return uri; 122 } 123 124 public boolean isCurrent() { 125 return current; 126 } 127 128 public void setCurrent(boolean b) { 129 current = b; 130 } 131 132 139 140 protected SystemAction[] createActions () { 141 142 if(current) { 143 return new SystemAction[] { 144 SystemAction.get(SaveAction.class), 145 null, 146 SystemAction.get(ReplayAction.class), 147 SystemAction.get(EditReplayAction.class), 148 null, 149 SystemAction.get(DeleteAction.class) 150 }; 151 } 152 153 return new SystemAction[] { 154 SystemAction.get(ReplayAction.class), 155 SystemAction.get(EditReplayAction.class), 156 null, 157 SystemAction.get(DeleteAction.class), 158 }; 159 } 160 161 162 public SystemAction[] getActions () { 163 164 if(current) { 165 return new SystemAction[] { 166 SystemAction.get(SaveAction.class), 167 null, 168 SystemAction.get(ReplayAction.class), 169 SystemAction.get(EditReplayAction.class), 170 null, 171 SystemAction.get(DeleteAction.class) 172 }; 173 } 174 175 return new SystemAction[] { 176 SystemAction.get(ReplayAction.class), 177 SystemAction.get(EditReplayAction.class), 178 null, 179 SystemAction.get(DeleteAction.class), 180 }; 181 } 182 183 186 public boolean canCopy () { 187 return true; 188 } 189 190 193 public boolean canCut () { 194 return false; 195 } 196 197 200 public static void toggleTimeStamp() { 201 if(showTimeStamp) showTimeStamp = false; 202 else showTimeStamp = true; 203 } 204 205 208 public static boolean showTimeStamp() { 209 return showTimeStamp; 210 } 211 212 private void setProperties() { 213 setNameString(); 214 setShortDescription(uri); 215 } 216 217 public void setNameString() { 218 219 String name = null; 220 if(uri.equals("/")) name = uri; else { 222 StringTokenizer st = new StringTokenizer (uri,"/"); while(st.hasMoreTokens()) name = st.nextToken(); 224 } 225 226 StringBuilder buf = new StringBuilder (method); 227 buf.append(' '); buf.append(name); 229 if(showTimeStamp) { 230 if(timestamp == null) setTimeStamp(); 231 buf.append(' '); buf.append(timestamp); 233 } 234 setName(buf.toString()); 235 } 236 237 private void setTimeStamp() { 238 239 try { 240 long ldate = Long.valueOf(id).longValue(); 241 Date date = new Date (ldate); 242 243 StringBuilder buf = new StringBuilder ('['); DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT); 245 buf.append(df.format(date)); 246 buf.append(" "); df = DateFormat.getDateInstance(DateFormat.SHORT); 248 buf.append(df.format(date)); 249 buf.append(']'); timestamp = buf.toString(); 251 } 252 catch(Exception e) {} 253 } 254 255 public String toString() { 256 StringBuilder buf = new StringBuilder ("TransactionNode: "); buf.append(this.getName()); 258 buf.append('\n'); buf.append("id="); buf.append(id); 261 262 buf.append('\n'); buf.append("method="); buf.append(method); 265 266 buf.append('\n'); buf.append("uri="); buf.append(uri); 269 270 buf.append('\n'); buf.append("current="); buf.append(String.valueOf(current)); 273 buf.append('\n'); 275 return buf.toString(); 276 } 277 } 279 280 281 282 283 284 | Popular Tags |