1 19 20 23 24 package org.netbeans.modules.web.monitor.client; 25 26 import java.awt.BorderLayout ; 27 import java.awt.Container ; 28 import java.awt.Dimension ; 29 import java.awt.FontMetrics ; 30 import java.awt.Graphics ; 31 import java.awt.event.ActionListener ; 32 import java.awt.event.ActionEvent ; 33 import java.beans.PropertyChangeListener ; 34 import java.beans.PropertyChangeEvent ; 35 import java.io.ObjectStreamException ; 36 import java.io.Serializable ; 37 import java.util.logging.Level ; 38 import java.util.logging.Logger ; 39 import javax.swing.ImageIcon ; 40 import javax.swing.JButton ; 41 import javax.swing.JFrame ; 42 import javax.swing.JPanel ; 43 import javax.swing.JScrollPane ; 44 import javax.swing.JSplitPane ; 45 import javax.swing.JTabbedPane ; 46 import javax.swing.JToggleButton ; 47 import javax.swing.JToolBar ; 48 import javax.swing.border.CompoundBorder ; 49 import javax.swing.border.EmptyBorder ; 50 import javax.swing.border.EtchedBorder ; 51 import javax.swing.event.ChangeListener ; 52 import javax.swing.event.ChangeEvent ; 53 import org.openide.explorer.ExplorerManager; 54 import org.openide.explorer.ExplorerUtils; 55 import org.openide.explorer.view.BeanTreeView; 56 import org.openide.nodes.Node; 57 import org.openide.nodes.Children; 58 import org.openide.nodes.AbstractNode; 59 import org.openide.windows.TopComponent; 60 import org.openide.util.HelpCtx; 61 import org.openide.util.NbBundle; 62 import org.openide.util.RequestProcessor; 63 import org.netbeans.modules.web.monitor.data.DataRecord; 64 65 69 class TransactionView extends TopComponent implements ExplorerManager.Provider, 70 PropertyChangeListener , ChangeListener { 71 72 private transient static TransactionView instance = null; 74 private transient static Controller controller = null; 75 76 private transient JToggleButton timeAButton, timeDButton, 78 alphaButton; 79 80 private transient JToggleButton timestampButton; 81 82 private transient Dimension logD = new Dimension (250, 400); 84 private transient Dimension dataD = new Dimension (500, 400); 85 private transient Dimension tabD = new Dimension (500,472); 86 87 private transient static ExplorerManager mgr = null; 89 private transient JPanel logPanel = null; 90 private transient JPanel dataPanel = null; 91 private transient JSplitPane splitPanel = null; 92 private transient double dividerRatio = .35; 93 private transient BeanTreeView tree = null; 94 private transient AbstractNode selected = null; 95 96 private transient RequestDisplay requestDisplay = null; 97 private transient CookieDisplay cookieDisplay = null; 98 private transient SessionDisplay sessionDisplay = null; 99 private transient ContextDisplay contextDisplay = null; 100 private transient ClientDisplay clientDisplay = null; 101 private transient HeaderDisplay headerDisplay = null; 102 103 boolean fontChanged = true; 105 106 private int displayType = 0; 108 109 public boolean requestFocusInWindow() { 112 if (tree != null) { 113 return tree.requestFocusInWindow(); 114 } else { 115 return false; 116 } 117 } 118 119 public HelpCtx getHelpCtx() { 120 String helpID = NbBundle.getBundle(TransactionView.class).getString("MON_Transaction_View_F1_Help_ID"); return new HelpCtx( helpID ); 122 } 123 124 129 private TransactionView() { 130 setIcon(new ImageIcon (TransactionView.class.getResource 131 ("/org/netbeans/modules/web/monitor/client/icons/menuitem.gif")).getImage()); 132 setToolTipText(NbBundle.getMessage(TransactionView.class, "MON_Window_Tooltip")); 133 controller = Controller.getInstance(); 134 initialize(); 135 this.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(TransactionView.class).getString("ACS_MON_monitorDesc")); 136 this.getAccessibleContext().setAccessibleName(NbBundle.getBundle(TransactionView.class).getString("ACS_MON_monitorName")); 137 138 } 139 140 static synchronized TransactionView getInstance() { 141 if(instance == null) 142 instance = new TransactionView(); 143 return instance; 144 } 145 146 private void initialize() { 147 148 mgr = new ExplorerManager(); 149 mgr.addPropertyChangeListener(this); 150 mgr.setRootContext(controller.getRoot()); 151 152 associateLookup (ExplorerUtils.createLookup (mgr, getActionMap ())); 154 155 setLayout(new java.awt.BorderLayout ()); 156 tree = new BeanTreeView(); 157 tree.setDefaultActionAllowed(true); 158 tree.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(TransactionView.class).getString("ACS_MON_treeName")); 159 tree.getAccessibleContext().setAccessibleName(NbBundle.getBundle(TransactionView.class).getString("ACS_MON_treeDesc")); 160 161 createLogPanel(); 162 createDataPanel(); 163 splitPanel = 164 new JSplitPane (JSplitPane.HORIZONTAL_SPLIT, logPanel, dataPanel); 165 splitPanel.setDividerLocation((int)(logD.getWidth())); 166 splitPanel.setResizeWeight(dividerRatio); 167 splitPanel.setDividerSize(1); 168 splitPanel.setOneTouchExpandable(true); 169 this.add(splitPanel); 170 setName(NbBundle.getBundle(TransactionView.class).getString("MON_Title")); 171 } 172 173 176 void openTransactionNodes() { 177 178 181 OpenTransactionNodesRequest req = new 182 OpenTransactionNodesRequest(); 183 184 RequestProcessor.Task t = 185 RequestProcessor.postRequest(req, 500); } 187 188 public int getPersistenceType() { 189 return TopComponent.PERSISTENCE_ONLY_OPENED; 190 } 191 192 class OpenTransactionNodesRequest implements Runnable { 193 194 public void run() { 195 openTransactionNodes(); 196 } 197 198 void openTransactionNodes() { 199 NavigateNode root = controller.getRoot(); 200 Children ch = root.getChildren(); 201 Node [] nodes = ch.getNodes(); 202 CurrNode cn = (CurrNode)nodes[0]; 203 SavedNode sn = (SavedNode)nodes[1]; 204 205 206 209 Children currCh = cn.getChildren(); 210 Node [] currChNodes = currCh.getNodes(); 211 int numCN = currChNodes.length; 212 if (numCN > 0) { 213 int selectThisOne = 0; 214 if (timeAButton.isSelected()) { 215 selectThisOne = numCN - 1; 216 } 217 selectNode(currChNodes[selectThisOne]); 218 } else { 219 Children savedCh = sn.getChildren(); 220 Node [] savedChNodes = savedCh.getNodes(); 221 int numSN = savedChNodes.length; 222 if (numSN > 0) { 223 selectNode(savedChNodes[0]); 224 } 225 } 226 } 227 } 228 229 void selectNode(Node n) { 230 231 try { 232 mgr.setSelectedNodes(new Node[] {n}); 233 234 } catch (Exception exc) { 235 Logger.getLogger(TransactionView.class.getName()).log(Level.INFO, "selectNode", exc); 236 } } 238 239 241 private boolean openedOnceAlready = false; 242 public void open() { 243 super.open(); 244 if (!openedOnceAlready) { 246 openedOnceAlready = true; 247 controller.getTransactions(); 248 openTransactionNodes(); 249 } 252 controller.checkServer(false); 254 } 255 256 260 public boolean isInitialized() { 261 return openedOnceAlready; 262 } 263 264 protected void updateTitle() { 265 setName(NbBundle.getBundle(TransactionView.class).getString("MON_Title")); 266 } 267 268 271 public Object writeReplace() throws ObjectStreamException { 272 return new ResolvableHelper(); 273 } 274 275 276 279 private void createLogPanel() { 280 281 JToolBar buttonPanel = new JToolBar (); 282 buttonPanel.setBorder 283 (new CompoundBorder (new EtchedBorder (EtchedBorder.LOWERED), 284 new EmptyBorder (4, 4, 4, 4) 285 )); 286 buttonPanel.setFloatable (false); 287 288 JButton updateButton = new JButton (new ImageIcon (TransactionView.class.getResource 289 ("/org/netbeans/modules/web/monitor/client/icons/update.gif")));; updateButton.setToolTipText(NbBundle.getBundle(TransactionView.class).getString("MON_Reload_all_17")); 291 updateButton.addActionListener(new ActionListener () { 292 public void actionPerformed(ActionEvent e) { 293 controller.getTransactions(); 294 }}); 295 296 timeAButton = new JToggleButton (new ImageIcon ( 297 TransactionView.class.getResource("/org/netbeans/modules/web/monitor/client/icons/timesortA.gif")), false); 298 timeAButton.setToolTipText(NbBundle.getBundle(TransactionView.class).getString("MON_Order_transactions_15")); 299 300 timeAButton.addActionListener(new ActionListener () { 301 public void actionPerformed(ActionEvent e) { 302 303 if(!((JToggleButton )e.getSource()).isSelected()) 304 return; 305 else { 306 timeDButton.setSelected(false); 307 alphaButton.setSelected(false); 308 controller.setComparator 309 (controller.new CompTime(false)); 310 } 311 }}); 312 313 timeDButton = new JToggleButton (new ImageIcon ( 314 TransactionView.class.getResource("/org/netbeans/modules/web/monitor/client/icons/timesortB.gif")), true); 315 timeDButton.setToolTipText(NbBundle.getBundle(TransactionView.class).getString("MON_Order_transactions_16")); 316 timeDButton.addActionListener(new ActionListener () { 317 public void actionPerformed(ActionEvent e) { 318 319 if(!((JToggleButton )e.getSource()).isSelected()) 320 return; 321 else { 322 timeAButton.setSelected(false); 323 alphaButton.setSelected(false); 324 controller.setComparator 325 (controller.new CompTime(true)); 326 } 327 328 }}); 329 330 alphaButton = new JToggleButton (new ImageIcon ( 331 TransactionView.class.getResource("/org/netbeans/modules/web/monitor/client/icons/a2z.gif")), false); 332 alphaButton.setToolTipText(NbBundle.getBundle(TransactionView.class).getString("MON_Order_transactions_14")); 333 alphaButton.addActionListener(new ActionListener () { 334 public void actionPerformed(ActionEvent e) { 335 336 if(!((JToggleButton )e.getSource()).isSelected()) 337 return; 338 else { 339 timeAButton.setSelected(false); 340 timeDButton.setSelected(false); 341 controller.setComparator 342 (controller.new CompAlpha()); 343 } 344 345 }}); 346 347 348 timestampButton = new 349 JToggleButton (new ImageIcon ( 350 TransactionView.class.getResource("/org/netbeans/modules/web/monitor/client/icons/timestamp.gif")), 351 TransactionNode.showTimeStamp()); 352 timestampButton.setToolTipText(NbBundle.getBundle(TransactionView.class).getString("MON_Show_time_25")); 353 timestampButton.addActionListener(new ActionListener () { 354 public void actionPerformed(ActionEvent e) { 355 TransactionNode.toggleTimeStamp(); 356 controller.updateNodeNames(); 359 }}); 360 361 buttonPanel.add(updateButton); 362 buttonPanel.add(timeDButton); 363 buttonPanel.add(timeAButton); 364 buttonPanel.add(alphaButton); 365 JPanel sep = new JPanel () { public float getAlignmentX() { 367 return 0; 368 } 369 public float getAlignmentY() { 370 return 0; 371 } 372 }; 373 sep.setMaximumSize(new Dimension (10, 10)); 374 buttonPanel.add(sep); 375 buttonPanel.add(timestampButton); 376 377 logPanel = new JPanel (); 378 logPanel.setLayout(new BorderLayout ()); 379 380 JPanel p = new JPanel (new BorderLayout ()); 381 p.add(BorderLayout.NORTH, buttonPanel); 383 p.add(BorderLayout.CENTER, tree); 384 logPanel.add(BorderLayout.CENTER, p); 385 logPanel.setPreferredSize(logD); 386 } 387 388 389 392 private void createDataPanel() { 393 394 JTabbedPane jtp = new JTabbedPane (); 395 jtp.getAccessibleContext().setAccessibleName(NbBundle.getBundle(TransactionView.class).getString("ACS_MON_Transaction_dataName")); 396 jtp.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(TransactionView.class).getString("ACS_MON_Transaction_dataDesc")); 397 398 jtp.setPreferredSize(tabD); 399 jtp.setMaximumSize(tabD); 400 401 FontMetrics metrics = getFontMetrics(jtp.getFont()); 403 int scrollingUnitIncrement = metrics.getHeight(); 404 405 requestDisplay = new RequestDisplay(); 406 JScrollPane p = new JScrollPane (requestDisplay); 407 p.getVerticalScrollBar().setUnitIncrement(scrollingUnitIncrement); 408 jtp.addTab(NbBundle.getBundle(TransactionView.class).getString("MON_Request_19"), p); 409 410 cookieDisplay = new CookieDisplay(); 411 p = new JScrollPane (cookieDisplay); 412 p.getVerticalScrollBar().setUnitIncrement(scrollingUnitIncrement); 413 jtp.addTab(NbBundle.getBundle(TransactionView.class).getString("MON_Cookies_4"), p); 414 415 sessionDisplay = new SessionDisplay(); 416 p = new JScrollPane (sessionDisplay); 417 p.getVerticalScrollBar().setUnitIncrement(scrollingUnitIncrement); 418 jtp.addTab(NbBundle.getBundle(TransactionView.class).getString("MON_Session_24"), p); 419 420 contextDisplay = new ContextDisplay(); 421 p = new JScrollPane (contextDisplay); 422 p.getVerticalScrollBar().setUnitIncrement(scrollingUnitIncrement); 423 jtp.addTab(NbBundle.getBundle(TransactionView.class).getString("MON_Context_23"), p); 424 425 clientDisplay = new ClientDisplay(); 426 p = new JScrollPane (clientDisplay); 427 p.getVerticalScrollBar().setUnitIncrement(scrollingUnitIncrement); 428 jtp.addTab(NbBundle.getBundle(TransactionView.class).getString("MON_Client_Server"), p); 429 430 headerDisplay = new HeaderDisplay(); 431 p = new JScrollPane (headerDisplay); 432 p.getVerticalScrollBar().setUnitIncrement(scrollingUnitIncrement); 433 jtp.addTab(NbBundle.getBundle(TransactionView.class).getString("MON_Header_19"), p); 434 435 jtp.addChangeListener(this); 436 437 dataPanel = new JPanel (); 438 dataPanel.setLayout(new BorderLayout ()); 439 dataPanel.add(BorderLayout.CENTER, jtp); 440 dataPanel.setPreferredSize(dataD); 441 } 442 443 444 449 void displayTransaction(Node node) { 450 if (node == null) 451 return; 452 453 if(node instanceof TransactionNode || 454 node instanceof NestedNode) { 455 try { 456 selected = (AbstractNode)node; 457 } 458 catch (ClassCastException ex) { 459 selected = null; 460 selectNode(null); 461 } 462 } 463 else { 464 selected = null; 465 selectNode(null); 466 } 467 468 showData(); 469 } 470 471 void saveTransaction(Node[] nodes) { 472 if((nodes == null) || (nodes.length == 0)) return; 473 controller.saveTransaction(nodes); 474 selected = null; 475 selectNode(null); 476 showData(); 477 } 478 479 483 public void stateChanged(ChangeEvent e) { 484 485 setName(NbBundle.getBundle(TransactionView.class).getString("MON_Title")); 486 487 JTabbedPane p = (JTabbedPane )e.getSource(); 488 displayType = p.getSelectedIndex(); 489 showData(); 490 } 491 492 493 void showData() { 494 495 DataRecord dr = null; 496 try { 497 if (selected != null) { 498 dr = controller.getDataRecord(selected); 499 } 500 } 501 catch(Exception ex) { 502 ex.printStackTrace(); 503 } 504 505 if (displayType == 0) 506 requestDisplay.setData(dr); 507 else if (displayType == 1) 508 cookieDisplay.setData(dr); 509 else if (displayType == 2) 510 sessionDisplay.setData(dr); 511 else if (displayType == 3) 512 contextDisplay.setData(dr); 513 else if (displayType == 4) 514 clientDisplay.setData(dr); 515 else if (displayType == 5) 516 headerDisplay.setData(dr); 517 518 this.repaint(); 519 520 } 521 522 527 public void propertyChange(PropertyChangeEvent evt) { 528 529 setName(NbBundle.getBundle(TransactionView.class).getString("MON_Title")); 530 532 if(evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) { 533 534 if(evt.getNewValue() instanceof Node[]) { 535 try { 536 Node[] ns = (Node[])evt.getNewValue(); 537 if(ns.length == 1) { 538 displayTransaction(ns[0]); 539 } 540 } 541 catch(Exception e) { 543 Logger.getLogger(TransactionView.class.getName()).log(Level.INFO, "", e); 544 selected = null; 545 showData(); 546 return; 547 } 548 } 549 } 550 } 551 552 555 void blank() { 556 selected = null; 557 selectNode(null); 558 showData(); 559 } 560 561 564 public void paint(Graphics g) { 565 if(fontChanged) { 566 super.paint(g); 567 return; 568 } 569 570 FontMetrics fm = g.getFontMetrics(getFont()); 571 fontChanged = false; 572 573 double logWidth = fm.stringWidth(NbBundle.getBundle(TransactionView.class).getString("MON_Transactions_27")) * 1.1; 574 575 if(logWidth > logD.getWidth()) { 576 double factor = logWidth/logD.getWidth(); 577 logD.setSize(logWidth, factor * logD.getHeight()); 578 579 580 dataD.setSize(factor * dataD.getWidth(), 581 factor * dataD.getHeight()); 582 } 583 584 logPanel.setPreferredSize(logD); 585 dataPanel.setPreferredSize(dataD); 586 splitPanel.resetToPreferredSizes(); 587 splitPanel.setDividerLocation((int)(logD.getWidth())); 588 589 try { 590 Container o = (Container )this.getParent(); 591 while(true) { 592 if(o instanceof JFrame ) { 593 JFrame parent = (JFrame )o; 594 parent.pack(); 595 break; 596 } 597 o = o.getParent(); 598 } 599 } 600 catch(Throwable t) { 601 } 604 return; 606 } 607 608 public static final class ResolvableHelper implements Serializable { 609 static final long serialVersionUID = 1234546018839457544L; 610 Object readResolve() { 611 Controller.getInstance().getTransactions(); 612 return TransactionView.getInstance(); 613 } 614 } 615 616 protected String preferredID() { 617 return "TransactionView"; } 619 620 void setTimestampButtonSelected(boolean state) { 622 timestampButton.setSelected(state); 623 } 624 625 boolean isTimestampButtonSelected() { 626 return timestampButton.isSelected(); 627 } 628 629 void addTimestampButtonActionListener(ActionListener l) { 630 timestampButton.addActionListener(l); 631 } 632 633 boolean isAscButtonSelected() { 634 return timeAButton.isSelected(); 635 } 636 637 boolean isDescButtonSelected() { 638 return timeDButton.isSelected(); 639 } 640 641 boolean isAlphButtonSelected() { 642 return alphaButton.isSelected(); 643 } 644 645 void toggleTaskbarButtons(boolean asc, boolean desc, boolean alph) { 646 timeAButton.setSelected(asc); 647 timeDButton.setSelected(desc); 648 alphaButton.setSelected(alph); 649 } 650 651 653 public ExplorerManager getExplorerManager() { 654 return mgr; 655 } 656 657 protected void componentActivated() { 658 ExplorerUtils.activateActions(mgr, true); 659 } 660 661 protected void componentDeactivated() { 662 ExplorerUtils.activateActions(mgr, false); 663 } 664 } 665 | Popular Tags |