1 23 package com.sun.enterprise.tools.verifier.gui; 24 25 26 import javax.swing.BorderFactory ; 27 import javax.swing.DefaultCellEditor ; 28 import javax.swing.JPanel ; 29 import javax.swing.JScrollBar ; 30 import javax.swing.JScrollPane ; 31 import javax.swing.JTable ; 32 import javax.swing.JTextArea ; 33 import javax.swing.JTextField ; 34 import javax.swing.ListSelectionModel ; 35 import javax.swing.event.ListSelectionEvent ; 36 import javax.swing.event.ListSelectionListener ; 37 import javax.swing.table.DefaultTableModel ; 38 39 import java.awt.BorderLayout ; 40 import java.awt.Color ; 41 import java.awt.event.ActionEvent ; 42 import java.awt.event.ActionListener ; 43 import java.util.Enumeration ; 44 import java.util.EventObject ; 45 import java.util.Vector ; 46 import java.util.logging.LogRecord ; 47 48 import com.sun.enterprise.tools.verifier.CheckMgr; 49 import com.sun.enterprise.tools.verifier.Result; 50 import com.sun.enterprise.tools.verifier.StringManagerHelper; 51 import com.sun.enterprise.tools.verifier.VerifierEventsListener; 52 import com.sun.enterprise.tools.verifier.util.VerifierConstants; 53 54 public class ResultsPanel extends JPanel implements VerifierEventsListener { 55 56 JTable table; 57 DefaultTableModel tableModel; 58 JScrollPane tableScrollPane; 59 JScrollPane textScrollPane; 60 JTextArea detailText; 61 Vector <String > details = new Vector <String >(); 62 private static Vector <Result> passResults = new Vector <Result>(); 63 private static Vector <Result> failResults = new Vector <Result>(); 64 private static Vector <LogRecord > errorResults = new Vector <LogRecord >(); 65 private static Vector <Result> warnResults = new Vector <Result>(); 66 private static Vector <Result> naResults = new Vector <Result>(); 67 private static Vector <Result> notImplementedResults = new Vector <Result>(); 68 private static Vector <Result> notRunResults = new Vector <Result>(); 69 private static Vector <Result> defaultResults = new Vector <Result>(); 70 static com.sun.enterprise.util.LocalStringManagerImpl smh = 71 StringManagerHelper.getLocalStringsManager(); 72 73 final String [] columnNames = { 75 (smh.getLocalString( 76 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".columnName1", "Item")), (smh.getLocalString( 80 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".columnName2", "Test Name")), (smh.getLocalString( 84 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".columnName3", "Result"))}; final String errStr = smh.getLocalString(getClass().getName()+".errStr", "Error during verification"); final String errStr1 = smh.getLocalString(getClass().getName()+".errStr1", "ERROR"); 92 93 public ResultsPanel() { 94 95 setLayout(new BorderLayout ()); 96 setBorder( 97 BorderFactory.createTitledBorder( 98 BorderFactory.createLineBorder(Color.black), 99 (smh.getLocalString( 100 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".ResultsPanelLabel", "Results: (Click on Item to show test Details below)")))); 104 this.getAccessibleContext().setAccessibleName( 106 smh.getLocalString( 107 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".panelName", "Panel")); this.getAccessibleContext().setAccessibleDescription( 111 smh.getLocalString( 112 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".PanelDesc", "This is a panel")); 116 CheckMgr.addVerifierEventsListener(this); 117 118 tableModel = new DefaultTableModel (columnNames, 0); 120 table = new JTable (tableModel); 121 table.getAccessibleContext().setAccessibleName( 123 smh.getLocalString( 124 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".tableName", "Table")); table.getAccessibleContext().setAccessibleDescription( 128 smh.getLocalString( 129 "com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".tableDesc", "This is a table of items")); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 133 tableScrollPane = new JScrollPane (table); 134 tableScrollPane.getAccessibleContext().setAccessibleName( 136 smh.getLocalString( 137 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".scrName1", "Scroll Pane")); tableScrollPane.getAccessibleContext().setAccessibleDescription( 141 smh.getLocalString( 142 "com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".scrDesc1", "This is a scroll pane that helps to scroll the list")); sizeTableColumns(); 146 JTextField field = new JTextField (); 148 field.getAccessibleContext().setAccessibleName( 150 smh.getLocalString( 151 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".fielsName", "Text Field")); field.getAccessibleContext().setAccessibleDescription( 155 smh.getLocalString( 156 "com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".fieldDesc", "This is a text field")); table.setDefaultEditor(Object .class, new DefaultCellEditor (field) { 160 public boolean isCellEditable(EventObject anEvent) { 161 return false; 162 } 163 }); 164 table.getSelectionModel().addListSelectionListener(new ListSelectionListener () { 166 public void valueChanged(ListSelectionEvent e) { 167 if (!e.getValueIsAdjusting()) { 168 if (table.getSelectionModel().isSelectedIndex( 169 e.getLastIndex())) { 170 setDetailText( 171 (String ) details.elementAt(e.getLastIndex())); 172 } else if (table.getSelectionModel().isSelectedIndex( 173 e.getFirstIndex())) { 174 setDetailText( 175 (String ) details.elementAt(e.getFirstIndex())); 176 } 177 } 178 } 179 }); 180 181 detailText = new JTextArea (4, 50); 183 detailText.getAccessibleContext().setAccessibleName( 185 smh.getLocalString( 186 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".areaName", "Text Area")); detailText.getAccessibleContext().setAccessibleDescription( 190 smh.getLocalString( 191 "com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".areaDesc", "This is a text area")); detailText.setEditable(false); 195 textScrollPane = new JScrollPane (detailText); 196 textScrollPane.getAccessibleContext().setAccessibleName( 198 smh.getLocalString( 199 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".scrName2", "Scroll Pane")); textScrollPane.getAccessibleContext().setAccessibleDescription( 203 smh.getLocalString( 204 "com.sun.enterprise.tools.verifier.gui.ControlPanel" + ".scrDesc2", "This is a scroll pane that helps to scroll the list")); textScrollPane.setBorder( 208 BorderFactory.createTitledBorder( 209 BorderFactory.createEmptyBorder(), 210 (smh.getLocalString( 211 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".DetailsPanelLabel", "Details:")))); 215 add("Center", tableScrollPane); add("South", textScrollPane); 219 RadioListener myListener = new RadioListener(); 222 ControlPanel.addRadioButtonListener((ActionListener ) myListener); 223 } 224 225 class RadioListener implements ActionListener { 226 public void actionPerformed(ActionEvent e) { 227 if (e.getSource() == ControlPanel.allButton) { 228 if ((getPassResultsForDisplay().size() > 0) || 229 (getFailResultsForDisplay().size() > 0) || 230 (getErrorResultsForDisplay().size() > 0) || 231 (getWarnResultsForDisplay().size() > 0) || 232 (getNaResultsForDisplay().size() > 0) || 233 (getNotImplementedResultsForDisplay().size() > 0) || 234 (getNotRunResultsForDisplay().size() > 0) || 235 (getDefaultResultsForDisplay().size() > 0)) { 236 upDateDisplay(VerifierConstants.ALL); 237 } else { 238 clearResults(); 239 } 240 } 241 if (e.getSource() == ControlPanel.failButton) { 242 if (getFailResultsForDisplay().size() > 0 || 243 getErrorResultsForDisplay().size() > 0) { 244 upDateDisplay(VerifierConstants.FAIL); 245 } else { 246 clearResults(); 247 } 248 } 249 if (e.getSource() == ControlPanel.warnButton) { 250 if ((getFailResultsForDisplay().size() > 0) || 251 (getErrorResultsForDisplay().size() > 0) || 252 (getWarnResultsForDisplay().size() > 0)) { 253 upDateDisplay(VerifierConstants.WARN); 254 } else { 255 clearResults(); 256 } 257 } 258 } 259 } 260 261 public void setDetailText(String details) { 262 detailText.setText(details); 263 JScrollBar scrollBar = textScrollPane.getVerticalScrollBar(); 264 if (scrollBar != null) { 265 scrollBar.setValue(0); 266 } 267 } 268 269 public void addDetailText(String details) { 270 detailText.append(details); 271 } 272 273 public void clearResults() { 274 tableModel = new DefaultTableModel (columnNames, 0); 276 table.setModel(tableModel); 277 sizeTableColumns(); 278 setDetailText(""); 280 details = new Vector <String >(); 282 } 283 284 void sizeTableColumns() { 285 table.getColumn( 286 (smh.getLocalString( 287 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".columnName1", "Item"))) .setMinWidth(150); 291 table.getColumn( 292 (smh.getLocalString( 293 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".columnName1", "Item"))) .setMaxWidth(200); 297 table.getColumn( 298 (smh.getLocalString( 299 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".columnName1", "Item"))) .setPreferredWidth(180); 303 table.getColumn( 304 (smh.getLocalString( 305 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".columnName2", "Test Name"))) .setMinWidth(150); 309 table.getColumn( 310 (smh.getLocalString( 311 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".columnName2", "Test Name"))) .setPreferredWidth(180); 315 table.getColumn( 316 (smh.getLocalString( 317 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".columnName3", "Result"))) .setMinWidth(120); 321 table.getColumn( 322 (smh.getLocalString( 323 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".columnName3", "Result"))) .setMaxWidth(200); 327 table.getColumn( 328 (smh.getLocalString( 329 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".columnName3", "Result"))) .setPreferredWidth(160); 333 table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); 334 table.sizeColumnsToFit(0); 335 } 336 337 private void upDateDisplayAll() { 338 upDateDisplayFail(); 339 upDateDisplayWarn(); 340 upDateDisplayPass(); 341 upDateDisplayNa(); 342 upDateDisplayNotImplemented(); 343 upDateDisplayNotRun(); 344 upDateDisplayDefault(); 345 upDateDisplayError(); 346 } 347 348 349 private void updateTableRows(Vector results) { 350 String status; 351 for (int i = 0; i < results.size(); i++) { 353 Result r = ((Result) results.elementAt(i)); 354 StringBuffer s = new StringBuffer ( 355 "Assertion:" + r.getAssertion() + "\n"); switch (r.getStatus()) { 357 case Result.PASSED: 358 { 359 status = 360 (smh.getLocalString( 361 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".Status_Passed", "Passed")); Enumeration e = r.getGoodDetails().elements(); 365 while (e.hasMoreElements()) { 366 s.append((String ) e.nextElement()); 367 s.append("\n"); } 369 break; 370 } 371 case Result.FAILED: 372 { 373 status = 374 (smh.getLocalString( 375 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".Status_Failed", "FAILED")); Enumeration e = r.getErrorDetails().elements(); 379 while (e.hasMoreElements()) { 380 s.append((String ) e.nextElement()); 381 s.append("\n"); } 383 break; 384 } 385 case Result.WARNING: 386 { 387 status = 388 (smh.getLocalString( 389 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".Status_Warning", "WARNING")); Enumeration e = r.getWarningDetails().elements(); 393 while (e.hasMoreElements()) { 394 s.append((String ) e.nextElement()); 395 s.append("\n"); } 397 break; 398 } 399 case Result.NOT_APPLICABLE: 400 { 401 status = 402 (smh.getLocalString( 403 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".Status_NotApplicable", "Not Applicable")); Enumeration e = r.getNaDetails().elements(); 407 while (e.hasMoreElements()) { 408 s.append((String ) e.nextElement()); 409 s.append("\n"); } 411 break; 412 } 413 case Result.NOT_IMPLEMENTED: 414 status = 415 (smh.getLocalString( 416 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".Status_NotImplemented", "Not Implemented")); break; 420 case Result.NOT_RUN: 421 status = 422 (smh.getLocalString( 423 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".Status_NotRun", "Not Run")); break; 427 default: 428 status = 429 (smh.getLocalString( 430 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".Status_Unknown", "Unknown")); break; 434 } 435 details.add(s.toString()); 436 Object [] row = {r.getComponentName(), r.getTestName(), status}; 437 tableModel.addRow(row); 438 } table.sizeColumnsToFit(0); 440 } 441 442 private void upDateDisplayPass() { 443 updateTableRows(getPassResultsForDisplay()); 444 } 445 446 private void upDateDisplayFail() { 447 updateTableRows(getFailResultsForDisplay()); 448 } 449 450 private void upDateDisplayError() { 451 Vector errors = getErrorResultsForDisplay(); 452 for (int i = 0; i < errors.size(); i++) { 453 LogRecord r = (LogRecord ) errors.elementAt(i); 454 details.add(r.getMessage() + "\n" + r.getThrown().getMessage()); Object [] row = {r.getLoggerName(), errStr, errStr1}; 456 tableModel.addRow(row); 457 } 458 table.sizeColumnsToFit(0); 459 } 460 461 private void upDateDisplayWarn() { 462 updateTableRows(getWarnResultsForDisplay()); 463 } 464 465 private void upDateDisplayNa() { 466 updateTableRows(getNaResultsForDisplay()); 467 } 468 469 private void upDateDisplayNotImplemented() { 470 updateTableRows(getNotImplementedResultsForDisplay()); 471 } 472 473 private void upDateDisplayNotRun() { 474 updateTableRows(getNotRunResultsForDisplay()); 475 } 476 477 private void upDateDisplayDefault() { 478 updateTableRows(getDefaultResultsForDisplay()); 479 } 480 481 void addError(LogRecord r) { 482 saveErrorResultsForDisplay(r); 483 details.add(r.getMessage() + "\n" + r.getThrown().getMessage()); Object [] row = {r.getLoggerName(), errStr, errStr1}; 486 tableModel.addRow(row); 487 table.sizeColumnsToFit(0); 488 } 489 490 public void upDateDisplay(int status) { 491 clearResults(); 493 if (status == VerifierConstants.ALL) { 494 upDateDisplayAll(); 495 } 496 if (status == VerifierConstants.FAIL) { 497 upDateDisplayError(); 498 upDateDisplayFail(); 499 } 500 if (status == VerifierConstants.WARN) { 501 upDateDisplayError(); 502 upDateDisplayFail(); 503 upDateDisplayWarn(); 504 } 505 } 506 507 private void savePassResultsForDisplay(Result r) { 508 passResults.addElement(r); 509 } 510 511 private void saveWarnResultsForDisplay(Result r) { 512 warnResults.addElement(r); 513 } 514 515 private void saveFailResultsForDisplay(Result r) { 516 failResults.addElement(r); 517 } 518 519 private void saveErrorResultsForDisplay(LogRecord r) { 520 errorResults.addElement(r); 521 } 522 523 private void saveNaResultsForDisplay(Result r) { 524 naResults.addElement(r); 525 } 526 527 private void saveNotRunResultsForDisplay(Result r) { 528 notRunResults.addElement(r); 529 } 530 531 private void saveNotImplementedResultsForDisplay(Result r) { 532 notImplementedResults.addElement(r); 533 } 534 535 private void saveDefaultResultsForDisplay(Result r) { 536 defaultResults.addElement(r); 537 } 538 539 private Vector getPassResultsForDisplay() { 540 return passResults; 541 } 542 543 private Vector getWarnResultsForDisplay() { 544 return warnResults; 545 } 546 547 private Vector getFailResultsForDisplay() { 548 return failResults; 549 } 550 551 private Vector getErrorResultsForDisplay() { 552 return errorResults; 553 } 554 555 private Vector getNaResultsForDisplay() { 556 return naResults; 557 } 558 559 private Vector getNotImplementedResultsForDisplay() { 560 return notImplementedResults; 561 } 562 563 private Vector getNotRunResultsForDisplay() { 564 return notRunResults; 565 } 566 567 private Vector getDefaultResultsForDisplay() { 568 return defaultResults; 569 } 570 571 public void clearOldResults() { 572 passResults = new Vector <Result>(); 573 failResults = new Vector <Result>(); 574 errorResults = new Vector <LogRecord >(); 575 warnResults = new Vector <Result>(); 576 naResults = new Vector <Result>(); 577 notImplementedResults = new Vector <Result>(); 578 notRunResults = new Vector <Result>(); 579 defaultResults = new Vector <Result>(); 580 } 581 582 583 public void testFinished(EventObject evt) { 585 Result r = (Result) evt.getSource(); 586 StringBuffer s = new StringBuffer ("Assertion:" + r.getAssertion() + "\n"); String status; 588 switch (r.getStatus()) { 589 case Result.PASSED: 590 { 591 status = 592 (smh.getLocalString( 593 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".Status_Passed", "Passed")); savePassResultsForDisplay(r); 597 Enumeration e = r.getGoodDetails().elements(); 598 while (e.hasMoreElements()) { 599 s.append((String ) e.nextElement()); 600 s.append("\n"); } 602 break; 603 } 604 case Result.FAILED: 605 { 606 status = 607 (smh.getLocalString( 608 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".Status_Failed", "FAILED")); saveFailResultsForDisplay(r); 612 Enumeration e = r.getErrorDetails().elements(); 613 while (e.hasMoreElements()) { 614 s.append((String ) e.nextElement()); 615 s.append("\n"); } 617 break; 618 } 619 case Result.WARNING: 620 { 621 status = 622 (smh.getLocalString( 623 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".Status_Warning", "WARNING")); saveWarnResultsForDisplay(r); 627 Enumeration e = r.getWarningDetails().elements(); 628 while (e.hasMoreElements()) { 629 s.append((String ) e.nextElement()); 630 s.append("\n"); } 632 break; 633 } 634 case Result.NOT_APPLICABLE: 635 { 636 status = 637 (smh.getLocalString( 638 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".Status_NotApplicable", "Not Applicable")); saveNaResultsForDisplay(r); 642 Enumeration e = r.getNaDetails().elements(); 643 while (e.hasMoreElements()) { 644 s.append((String ) e.nextElement()); 645 s.append("\n"); } 647 break; 648 } 649 case Result.NOT_IMPLEMENTED: 650 { 651 status = 652 (smh.getLocalString( 653 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".Status_NotImplemented", "Not Implemented")); saveNotImplementedResultsForDisplay(r); 657 break; 658 } 659 case Result.NOT_RUN: 660 { 661 status = 662 (smh.getLocalString( 663 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".Status_NotRun", "Not Run")); saveNotRunResultsForDisplay(r); 667 break; 668 } 669 default: 670 { 671 status = 672 (smh.getLocalString( 673 "com.sun.enterprise.tools.verifier.gui.ResultsPanel" + ".Status_Unknown", "Unknown")); saveDefaultResultsForDisplay(r); 677 break; 678 } 679 } 680 Object [] row = {r.getComponentName(), r.getTestName(), status}; 682 if (ControlPanel.getReportLevel() == VerifierConstants.FAIL && 683 r.getStatus() == Result.FAILED) { 684 details.add(s.toString()); 685 tableModel.addRow(row); 686 } 687 688 if (ControlPanel.getReportLevel() == VerifierConstants.WARN && 689 (r.getStatus() == Result.FAILED || 690 r.getStatus() == Result.WARNING)) { 691 details.add(s.toString()); 692 tableModel.addRow(row); 693 } 694 695 if (ControlPanel.getReportLevel() == VerifierConstants.ALL) { 696 details.add(s.toString()); 697 tableModel.addRow(row); 698 } 699 } 700 701 public void allTestsFinished(EventObject e) { 702 } 704 } 705 | Popular Tags |