KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > j2ee > VerifierSupport


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

19 /*
20  * Created on August 8, 2004, 1:47 PM
21  */

22
23 package org.netbeans.modules.j2ee.sun.ide.j2ee;
24
25
26 import javax.swing.SwingUtilities JavaDoc;
27 import java.awt.BorderLayout JavaDoc;
28 import java.awt.Color JavaDoc;
29 import java.awt.Component JavaDoc;
30 import java.awt.Dimension JavaDoc;
31 import java.awt.event.ActionEvent JavaDoc;
32 import java.awt.event.ActionListener JavaDoc;
33 import java.awt.event.KeyEvent JavaDoc;
34 import java.io.File JavaDoc;
35 import java.io.FileInputStream JavaDoc;
36 import java.io.IOException JavaDoc;
37 import java.io.InputStreamReader JavaDoc;
38 import java.io.OutputStream JavaDoc;
39 import java.io.OutputStreamWriter JavaDoc;
40 import java.util.EventObject JavaDoc;
41 import java.util.Vector JavaDoc;
42 import javax.swing.BorderFactory JavaDoc;
43 import javax.swing.BoxLayout JavaDoc;
44 import javax.swing.ButtonGroup JavaDoc;
45 import javax.swing.DefaultCellEditor JavaDoc;
46 import javax.swing.JComponent JavaDoc;
47 import javax.swing.JLabel JavaDoc;
48 import javax.swing.JPanel JavaDoc;
49 import javax.swing.JRadioButton JavaDoc;
50 import javax.swing.JScrollBar JavaDoc;
51 import javax.swing.JScrollPane JavaDoc;
52 import javax.swing.JSplitPane JavaDoc;
53 import javax.swing.JTable JavaDoc;
54 import javax.swing.JTextArea JavaDoc;
55 import javax.swing.JTextField JavaDoc;
56 import javax.swing.ListSelectionModel JavaDoc;
57 import javax.swing.SwingConstants JavaDoc;
58 import javax.swing.event.ListSelectionEvent JavaDoc;
59 import javax.swing.event.ListSelectionListener JavaDoc;
60 import javax.swing.table.DefaultTableModel JavaDoc;
61 import javax.swing.table.TableCellRenderer JavaDoc;
62 import org.netbeans.modules.j2ee.sun.dd.impl.verifier.Appclient;
63 import org.netbeans.modules.j2ee.sun.dd.impl.verifier.Application;
64 import org.netbeans.modules.j2ee.sun.dd.impl.verifier.Connector;
65 import org.netbeans.modules.j2ee.sun.dd.impl.verifier.Ejb;
66 import org.netbeans.modules.j2ee.sun.dd.impl.verifier.Failed;
67 import org.netbeans.modules.j2ee.sun.dd.impl.verifier.NotApplicable;
68 import org.netbeans.modules.j2ee.sun.dd.impl.verifier.Passed;
69 import org.netbeans.modules.j2ee.sun.dd.impl.verifier.StaticVerification;
70 import org.netbeans.modules.j2ee.sun.dd.impl.verifier.Test;
71 import org.netbeans.modules.j2ee.sun.dd.impl.verifier.Warning;
72 import org.netbeans.modules.j2ee.sun.dd.impl.verifier.Web;
73 import org.openide.ErrorManager;
74 import org.openide.windows.TopComponent;
75 import org.openide.windows.WindowManager;
76 import org.openide.windows.Mode;
77 import org.openide.util.NbBundle;
78 import org.netbeans.modules.j2ee.sun.ide.j2ee.db.ExecSupport;
79
80 /**
81  * Main TopComponent to display the output of the Sun J2EE Verifier Tool from an archive file.
82  * @author ludo
83  */

84 public class VerifierSupport extends TopComponent{
85     
86     
87     
88     String JavaDoc _archiveName;
89     
90     
91     final static int FAIL = 0;
92     final static int WARN = 1;
93     final static int ALL = 2;
94     
95     static String JavaDoc allString = NbBundle.getMessage(VerifierSupport.class,"All_Results"); // NOI18N
96
static String JavaDoc failString = NbBundle.getMessage(VerifierSupport.class,"Failures_Only"); //NOI18N
97
static String JavaDoc warnString = NbBundle.getMessage(VerifierSupport.class,"Failures_and_Warnings_only"); //NOI18N
98

99     // Strings used for 508 compliance
100
static String JavaDoc radioButtonName =NbBundle.getMessage(VerifierSupport.class,"Radio_Button"); // NOI18N
101
static String JavaDoc radioButtonDesc = NbBundle.getMessage(VerifierSupport.class,"RadioButtonToSelect"); // NOI18N
102
static String JavaDoc panelName =NbBundle.getMessage(VerifierSupport.class,"Panel"); // NOI18N
103
static String JavaDoc panelDesc =NbBundle.getMessage(VerifierSupport.class,"VerifierPanel"); //NOI18N
104

105     
106     JRadioButton JavaDoc allButton ;
107     JRadioButton JavaDoc failButton ;
108     JRadioButton JavaDoc warnButton ;
109     RadioListener myListener ;
110     //what shoudl be displayed:ALL, FAIL, WARN
111
int statusLeveltoDisplay = ALL;//by default
112
boolean verifierIsStillRunning = true; //needed for the ui to know if a status message has to be printed or not...
113
JPanel JavaDoc controlPanel ;
114     JPanel JavaDoc resultPanel;
115     JTable JavaDoc table ;
116     DefaultTableModel JavaDoc tableModel;
117     ListSelectionListener JavaDoc tableSelectionListener;
118     JScrollPane JavaDoc tableScrollPane;
119     JScrollPane JavaDoc textScrollPane;
120     JTextArea JavaDoc detailText;
121     
122     private static String JavaDoc STATUS_LIT = "Status"; // NOI18N
123

124     final String JavaDoc[] columnNames = {
125         NbBundle.getMessage(VerifierSupport.class,STATUS_LIT),
126         NbBundle.getMessage(VerifierSupport.class,"Test_Description"), // NOI18N
127
NbBundle.getMessage(VerifierSupport.class,"Result")}; // NOI18N
128
private Vector JavaDoc passResults = new Vector JavaDoc();
129     private Vector JavaDoc failResults = new Vector JavaDoc();
130     private Vector JavaDoc errorResults = new Vector JavaDoc();
131     private Vector JavaDoc warnResults = new Vector JavaDoc();
132     private Vector JavaDoc naResults = new Vector JavaDoc();
133     private Vector JavaDoc notImplementedResults = new Vector JavaDoc();
134     private Vector JavaDoc notRunResults = new Vector JavaDoc();
135     private Vector JavaDoc defaultResults = new Vector JavaDoc();
136     
137     
138     public static void launchVerifier(final String JavaDoc fileName, OutputStream JavaDoc outs){
139         final File JavaDoc f = new File JavaDoc(fileName);
140         final File JavaDoc dir = f.getParentFile();
141         final VerifierSupport verifierSupport=new VerifierSupport(fileName);
142         
143         File JavaDoc irf = org.netbeans.modules.j2ee.sun.api.ServerLocationManager.getLatestPlatformLocation();
144         if (null == irf || !irf.exists()) {
145             //ErrorManager.getDefault().log(NbBundle.getMessage (VerifierSupport.class, "ERR_CannotFind"));
146
org.netbeans.modules.j2ee.sun.ide.j2ee.ui.Util.showWarning(NbBundle.getMessage(VerifierSupport.class, "ERR_CannotFind"));// NOI18N
147
return;
148         }
149         String JavaDoc installRoot = irf.getAbsolutePath();
150         SwingUtilities.invokeLater( new Runnable JavaDoc(){
151             public void run() {
152                 verifierSupport.initUI();
153                 verifierSupport.showInMode();
154             }
155         });
156         
157         
158         try{
159             
160             String JavaDoc cmd = installRoot+File.separator+"bin"+File.separator+"verifier";//NOI18N
161
if (File.separatorChar != '/') {
162                 cmd =cmd + ".bat"; // NOI18N
163
}
164             Runtime JavaDoc rt = Runtime.getRuntime();
165             String JavaDoc arr[] = {cmd, "-ra", "-d" , dir.getAbsolutePath(), fileName};//NOI18N
166

167             String JavaDoc cmdName=""; // NOI18N
168
for (int j=0;j<arr.length;j++){
169                 cmdName= cmdName+arr[j]+" "; // NOI18N
170
}
171             System.out.println(NbBundle.getMessage(VerifierSupport.class,"running_", cmdName)); // NOI18N
172
final Process JavaDoc child = rt.exec(arr);
173             
174             
175             //
176
// Attach to the process's stdout, and ignore what comes back.
177
//
178
final Thread JavaDoc[] copyMakers = new Thread JavaDoc[2];
179             OutputStreamWriter JavaDoc oss=null;
180             if (outs!=null) {
181                 oss=new OutputStreamWriter JavaDoc(outs);
182             }
183             (copyMakers[0] = new ExecSupport.OutputCopier(new InputStreamReader JavaDoc(child.getInputStream()), oss, true)).start();
184             (copyMakers[1] = new ExecSupport.OutputCopier(new InputStreamReader JavaDoc(child.getErrorStream()), oss, true)).start();
185             try {
186                 //int ret =
187
child.waitFor();
188                 Thread.sleep(1000); // time for copymakers
189
} catch (InterruptedException JavaDoc e) {
190             } finally {
191                 try {
192                     copyMakers[0].interrupt();
193                     copyMakers[1].interrupt();
194                 } catch (Exception JavaDoc e) {
195                 }
196             }
197             
198             
199             
200         } catch (Exception JavaDoc e) {
201             
202             e.printStackTrace();
203         }
204         
205         
206         
207         String JavaDoc onlyJarFile = f.getName();
208         File JavaDoc ff = new File JavaDoc(dir, onlyJarFile+".xml"); // NOI18N
209
FileInputStream JavaDoc in = null;
210         StaticVerification sv = null;
211         org.netbeans.modules.j2ee.sun.dd.impl.verifier.Error err = null;
212         try {
213             in = new FileInputStream JavaDoc(ff);
214             
215             sv = StaticVerification.createGraph(in); // this can throw a RT exception
216
err = sv.getError();
217             if (err!=null){
218                 verifierSupport.saveErrorResultsForDisplay( err);
219                 
220             }
221             Ejb e = sv.getEjb();
222             if (e!=null){
223                 Failed fail= e.getFailed();
224                 if (fail!=null){
225                     Test t[] =fail.getTest();
226                     for (int i=0;i<t.length ;i++){
227                         verifierSupport.saveFailResultsForDisplay( t[i]);
228                     }
229                 }
230                 Warning w= e.getWarning();
231                 if (w!=null){
232                     Test t[] =w.getTest();
233                     for (int i=0;i<t.length ;i++){
234                         verifierSupport.saveWarnResultsForDisplay( t[i]);
235                     }
236                 }
237                 Passed p= e.getPassed();
238                 if (p!=null){
239                     Test t[] =p.getTest();
240                     for (int i=0;i<t.length ;i++){
241                         verifierSupport.savePassResultsForDisplay(t[i]);
242                     }
243                 }
244                 NotApplicable na= e.getNotApplicable();
245                 if (na!=null){
246                     Test t[] =na.getTest();
247                     for (int i=0;i<t.length ;i++){
248                         verifierSupport.saveNaResultsForDisplay( t[i]);
249                     }
250                 }
251             }
252             Web we = sv.getWeb();
253             if (we!=null){
254                 Failed fail= we.getFailed();
255                 if (fail!=null){
256                     Test t[] =fail.getTest();
257                     for (int i=0;i<t.length ;i++){
258                         verifierSupport.saveFailResultsForDisplay(t[i]);
259                     }
260                 }
261                 Warning w= we.getWarning();
262                 if (w!=null){
263                     Test t[] =w.getTest();
264                     for (int i=0;i<t.length ;i++){
265                         verifierSupport.saveWarnResultsForDisplay(t[i]);
266                     }
267                 }
268                 Passed p= we.getPassed();
269                 if (p!=null){
270                     Test t[] =p.getTest();
271                     for (int i=0;i<t.length ;i++){
272                         verifierSupport.savePassResultsForDisplay(t[i]);
273                     }
274                 }
275                 NotApplicable na= we.getNotApplicable();
276                 if (na!=null){
277                     Test t[] =na.getTest();
278                     for (int i=0;i<t.length ;i++){
279                         verifierSupport.saveNaResultsForDisplay(t[i]);
280                     }
281                 }
282             }
283             Appclient ac = sv.getAppclient();
284             if (ac!=null){
285                 Failed fail= ac.getFailed();
286                 if (fail!=null){
287                     Test t[] =fail.getTest();
288                     for (int i=0;i<t.length ;i++){
289                         verifierSupport.saveFailResultsForDisplay(t[i]);
290                     }
291                 }
292                 Warning w= ac.getWarning();
293                 if (w!=null){
294                     Test t[] =w.getTest();
295                     for (int i=0;i<t.length ;i++){
296                         verifierSupport.saveWarnResultsForDisplay(t[i]);
297                     }
298                 }
299                 Passed p= ac.getPassed();
300                 if (p!=null){
301                     Test t[] =p.getTest();
302                     for (int i=0;i<t.length ;i++){
303                         verifierSupport.savePassResultsForDisplay(t[i]);
304                     }
305                 }
306                 NotApplicable na= ac.getNotApplicable();
307                 if (na!=null){
308                     Test t[] =na.getTest();
309                     for (int i=0;i<t.length ;i++){
310                         verifierSupport.saveNaResultsForDisplay(t[i]);
311                     }
312                 }
313             }
314             Application app = sv.getApplication();
315             if (app!=null){
316                 Failed fail= app.getFailed();
317                 if (fail!=null){
318                     Test t[] =fail.getTest();
319                     for (int i=0;i<t.length ;i++){
320                         verifierSupport.saveFailResultsForDisplay(t[i]);
321                     }
322                 }
323                 Warning w= app.getWarning();
324                 if (w!=null){
325                     Test t[] =w.getTest();
326                     for (int i=0;i<t.length ;i++){
327                         verifierSupport.saveWarnResultsForDisplay(t[i]);
328                     }
329                 }
330                 Passed p= app.getPassed();
331                 if (p!=null){
332                     Test t[] =p.getTest();
333                     for (int i=0;i<t.length ;i++){
334                         verifierSupport.savePassResultsForDisplay(t[i]);
335                     }
336                 }
337                 NotApplicable na= app.getNotApplicable();
338                 if (na!=null){
339                     Test t[] =na.getTest();
340                     for (int i=0;i<t.length ;i++){
341                         verifierSupport.saveNaResultsForDisplay(t[i]);
342                     }
343                 }
344             }
345             Connector rar = sv.getConnector();
346             if (rar!=null){
347                 Failed fail= rar.getFailed();
348                 if (fail!=null){
349                     Test t[] =fail.getTest();
350                     for (int i=0;i<t.length ;i++){
351                         verifierSupport.saveFailResultsForDisplay(t[i]);
352                     }
353                 }
354                 Warning w= rar.getWarning();
355                 if (w!=null){
356                     Test t[] =w.getTest();
357                     for (int i=0;i<t.length ;i++){
358                         verifierSupport.saveWarnResultsForDisplay(t[i]);
359                     }
360                 }
361                 Passed p= rar.getPassed();
362                 if (p!=null){
363                     Test t[] =p.getTest();
364                     for (int i=0;i<t.length ;i++){
365                         verifierSupport.savePassResultsForDisplay(t[i]);
366                     }
367                 }
368                 NotApplicable na= rar.getNotApplicable();
369                 if (na!=null){
370                     Test t[] =na.getTest();
371                     for (int i=0;i<t.length ;i++){
372                         verifierSupport.saveNaResultsForDisplay(t[i]);
373                     }
374                 }
375             }
376 // } catch (org.netbeans.modules.schema2beans.Schema2BeansRuntimeException s2brte) {
377
// // use a different parser to get the bogus data out
378
// s2brte.printStackTrace();
379
} catch (RuntimeException JavaDoc rte) {
380             err = StaticVerification.createGraph().newError();
381             err.setErrorName(NbBundle.getMessage(VerifierSupport.class,"ERR_PARSING_OUTPUT")); // NOI18N
382
err.setErrorDescription(rte.getMessage());
383             if (rte.getMessage().indexOf("error-name") > -1) {
384                 // TODO do the reparse, correct error-name and error-description
385
// currently, tell user to look in the output window
386
err.setErrorDescription(NbBundle.getMessage(VerifierSupport.class,"READ_OUTPUT_WINDOW")); // NOI18N
387
}
388             verifierSupport.saveErrorResultsForDisplay( err);
389         } catch (IOException JavaDoc ioe){
390             ioe.printStackTrace();
391             err = StaticVerification.createGraph().newError();
392             err.setErrorName(NbBundle.getMessage(VerifierSupport.class,"ERR_PARSING_OUTPUT")); // NOI18N
393
err.setErrorDescription(ioe.getMessage());
394             verifierSupport.saveErrorResultsForDisplay( err);
395         } finally {
396             if (null != in) {
397                 try {
398                     in.close();
399                 } catch (IOException JavaDoc ioe) {
400                     // I cannot do anything here...
401
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
402                             ioe);
403                 }
404             }
405         }
406         verifierSupport.verifierIsStillRunning = false;// we are done
407
verifierSupport.updateDisplay();
408     }
409     
410     
411     
412     
413     /** Creates a new instance of VerifierOuput */
414     public VerifierSupport(String JavaDoc archiveName) {
415         _archiveName = archiveName;
416     }
417     
418     
419     public void initUI(){
420         setLayout(new BorderLayout JavaDoc());
421         setName(NbBundle.getMessage(VerifierSupport.class,"LBL_Verifier", //NOI18N
422
new File JavaDoc(_archiveName).getName()));
423         CreateResultsPanel();
424         add(resultPanel);
425         
426     }
427     public void componentActivated() {
428         super.componentActivated();
429     }
430     
431     
432     /**
433      * Called when the object is opened. Add the GUI.
434      * @todo Trigger source listening on window getting VISIBLE instead
435      * of getting opened.
436      */

437     protected void componentOpened() {
438     }
439     
440     
441     /** Called when the window is closed. Cleans up. */
442     protected void componentClosed() {
443         clearResults();
444         table.getSelectionModel().removeListSelectionListener(tableSelectionListener);
445         
446         allButton.removeActionListener(myListener);
447         failButton.removeActionListener(myListener);
448         warnButton.removeActionListener(myListener);
449         remove(resultPanel);
450         resultPanel =null;
451         table=null;
452         allButton = null;
453         failButton = null;
454         warnButton=null;
455         myListener =null;
456         tableSelectionListener = null;
457     }
458     
459     protected void componentDeactivated() {
460         super.componentDeactivated();
461         
462     }
463     public int getPersistenceType() {
464         return TopComponent.PERSISTENCE_NEVER;
465     }
466     /**
467      * Shows the TC in the output mode and activates it.
468      */

469     public void showInMode() {
470         if (!isOpened()) {
471             Mode mode = WindowManager.getDefault().findMode("output"); // NOI18N
472
if (mode != null) {
473                 mode.dockInto(this);
474             }
475         }
476         open();
477         requestVisible();
478         requestActive();
479         
480         
481     }
482     protected String JavaDoc preferredID() {
483         return NbBundle.getMessage(VerifierSupport.class,"verifierID");//NOI18N
484
}
485     
486     
487     
488     
489     public void CreateResultsPanel() {
490         resultPanel = new JPanel JavaDoc();
491         resultPanel.setLayout(new BorderLayout JavaDoc());
492         resultPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black),
493                 _archiveName));
494         
495         // 508 compliance
496
resultPanel.getAccessibleContext().setAccessibleName( NbBundle.getMessage(VerifierSupport.class,"Panel")); // NOI18N
497
resultPanel.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage(VerifierSupport.class,"This_is_a_panel")); // NOI18N
498

499         
500         // set up result table
501
tableModel = new DefaultTableModel JavaDoc(columnNames, 0);
502         table = new JTable JavaDoc(tableModel) {
503             public Component JavaDoc prepareRenderer(TableCellRenderer JavaDoc renderer,
504                     int rowIndex, int vColIndex) {
505                 Component JavaDoc c = super.prepareRenderer(renderer, rowIndex, vColIndex);
506                 if (c instanceof JComponent JavaDoc) {
507                     JComponent JavaDoc jc = (JComponent JavaDoc)c;
508                     jc.setToolTipText((String JavaDoc)getValueAt(rowIndex, vColIndex));
509                 }
510                 return c;
511             }
512         };
513
514
515         // 508 for JTable
516
table.getAccessibleContext().setAccessibleName( NbBundle.getMessage(VerifierSupport.class,"Table")); // NOI18N
517
table.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage(VerifierSupport.class,"This_is_a_table_of_items"));//NOI18N
518
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
519         tableScrollPane = new JScrollPane JavaDoc(table);
520         Object JavaDoc [] row = {NbBundle.getMessage(VerifierSupport.class,"Wait"),NbBundle.getMessage(VerifierSupport.class,"Running_Verifier_Tool..."),NbBundle.getMessage(VerifierSupport.class,"Running...") }; // NOI18N
521
tableModel.addRow(row);
522         table.sizeColumnsToFit(0);
523         // 508 for JScrollPane
524
tableScrollPane.getAccessibleContext().setAccessibleName( NbBundle.getMessage(VerifierSupport.class,"Scroll_Pane")); // NOI18N
525
tableScrollPane.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(VerifierSupport.class,"ScrollArea")); // NOI18N
526
sizeTableColumns();
527         // make the cells uneditable
528
JTextField JavaDoc field = new JTextField JavaDoc();
529         // 508 for JTextField
530
field.getAccessibleContext().setAccessibleName(
531                 NbBundle.getMessage(VerifierSupport.class,"Text_Field")); // NOI18N
532
field.getAccessibleContext().setAccessibleDescription(
533                 NbBundle.getMessage(VerifierSupport.class,"This_is_a_text_field")); // NOI18N
534
table.setDefaultEditor(Object JavaDoc.class, new DefaultCellEditor JavaDoc(field) {
535             public boolean isCellEditable(EventObject JavaDoc anEvent) {
536                 return false;
537             }
538         });
539         // add action listener to table to show details
540
tableSelectionListener = new ListSelectionListener JavaDoc() {
541             public void valueChanged(ListSelectionEvent JavaDoc e){
542                 if (!e.getValueIsAdjusting()){
543                     // System.out.println(e);
544
if(table.getSelectionModel().isSelectedIndex(e.getLastIndex())){
545                         setDetailText( table.getModel().getValueAt(e.getLastIndex(),1)+
546                                 "\n"+table.getModel().getValueAt(e.getLastIndex(),2));//NOI18N
547
}else if(table.getSelectionModel().isSelectedIndex(e.getFirstIndex())){
548                         setDetailText(table.getModel().getValueAt(e.getFirstIndex(),1)+
549                                 "\n"+table.getModel().getValueAt(e.getFirstIndex(),2));//NOI18N
550
}
551                 }
552             }
553         };
554         table.getSelectionModel().addListSelectionListener(tableSelectionListener);
555         
556         // create detail text area
557
detailText = new JTextArea JavaDoc(4,50);
558         // 508 for JTextArea
559
detailText.getAccessibleContext().setAccessibleName( NbBundle.getMessage(VerifierSupport.class,"Text_Area")); // NOI18N
560
detailText.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage(VerifierSupport.class,"This_is_a_text_area"));//NOI18N
561
detailText.setEditable(false);
562         textScrollPane = new JScrollPane JavaDoc(detailText);
563         // 508 for JScrollPane
564
textScrollPane.getAccessibleContext().setAccessibleName( NbBundle.getMessage(VerifierSupport.class,"Scroll_Pane")); // NOI18N
565
textScrollPane.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage(VerifierSupport.class,"ScrollListPane"));//NOI18N
566
textScrollPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), NbBundle.getMessage(VerifierSupport.class,"Detail:")));// NOI18N
567

568         //add the components to the panel
569
CreateControlPanel();
570         
571         //Create a split pane with the two scroll panes in it.
572
JSplitPane JavaDoc splitPane = new JSplitPane JavaDoc(JSplitPane.VERTICAL_SPLIT,
573                 tableScrollPane, textScrollPane);
574         splitPane.setOneTouchExpandable(true);
575         splitPane.setDividerLocation(150);
576         
577         //Provide minimum sizes for the two components in the split pane
578
Dimension JavaDoc minimumSize = new Dimension JavaDoc(100, 50);
579         tableScrollPane.setMinimumSize(minimumSize);
580         textScrollPane.setMinimumSize(minimumSize);
581         
582         
583         
584         
585         resultPanel.add("North", controlPanel); //NOI18N
586
resultPanel.add("Center", splitPane); // NOI18N
587

588     }
589     
590     class RadioListener implements ActionListener JavaDoc {
591         public void actionPerformed(ActionEvent JavaDoc e) {
592             if (verifierIsStillRunning==true){
593                 if(e.getSource() == allButton){
594                     statusLeveltoDisplay = ALL;
595                 }
596                 if(e.getSource() == failButton){
597                     statusLeveltoDisplay = FAIL;
598                     
599                 }
600                 
601                 if(e.getSource() == warnButton){
602                     statusLeveltoDisplay = WARN;
603                 }
604                 
605                 return; // we need to wait!
606
}
607             if(e.getSource() == allButton){
608                 statusLeveltoDisplay = ALL;
609                 if ((getPassResultsForDisplay().size() > 0) ||
610                         (getFailResultsForDisplay().size() > 0) ||
611                         (getErrorResultsForDisplay().size() > 0) ||
612                         (getWarnResultsForDisplay().size() > 0) ||
613                         (getNaResultsForDisplay().size() > 0) ||
614                         (getNotImplementedResultsForDisplay().size() > 0) ||
615                         (getNotRunResultsForDisplay().size() > 0) ||
616                         (getDefaultResultsForDisplay().size() > 0)) {
617                     updateDisplay();
618                 } else {
619                     clearResults();
620                 }
621             }
622             if(e.getSource() == failButton){
623                 statusLeveltoDisplay = FAIL;
624                 if (getFailResultsForDisplay().size() > 0 || getErrorResultsForDisplay().size() > 0) {
625                     updateDisplay();
626                 } else {
627                     clearResults();
628                 }
629             }
630             if(e.getSource() == warnButton){
631                 statusLeveltoDisplay = WARN;
632                 if ((getFailResultsForDisplay().size() > 0) ||
633                         (getErrorResultsForDisplay().size() > 0) ||
634                         (getWarnResultsForDisplay().size() > 0)) {
635                     updateDisplay();
636                 } else {
637                     clearResults();
638                 }
639             }
640         }
641     }
642     
643     public void setDetailText(String JavaDoc details) {
644         detailText.setText(details);
645         JScrollBar JavaDoc scrollBar = textScrollPane.getVerticalScrollBar();
646         if (scrollBar != null){
647             scrollBar.setValue(0);
648         }
649     }
650     
651     
652     public void clearResults() {
653         //clear the table
654
tableModel = new DefaultTableModel JavaDoc(columnNames, 0);
655         table.setModel(tableModel);
656         sizeTableColumns();
657         //clear the detail text
658
setDetailText("");
659         //clear the details Vector
660
//// details = new Vector();
661
}
662     
663     
664     void sizeTableColumns() {
665         table.getColumn( NbBundle.getMessage(VerifierSupport.class,STATUS_LIT)).setMinWidth(30);
666         table.getColumn(NbBundle.getMessage(VerifierSupport.class,STATUS_LIT)).setMaxWidth(100);
667         table.getColumn( NbBundle.getMessage(VerifierSupport.class,STATUS_LIT)).setPreferredWidth(180);
668         table.getColumn(NbBundle.getMessage(VerifierSupport.class,"Test_Description")).setMinWidth(150); // NOI18N
669
table.getColumn( NbBundle.getMessage(VerifierSupport.class,"Test_Description")).setPreferredWidth(180);// NOI18N
670
table.getColumn( NbBundle.getMessage(VerifierSupport.class,"Result")).setMinWidth(120); //NOI18N
671
// table.getColumn("Result").setMaxWidth(200);
672
table.getColumn( NbBundle.getMessage(VerifierSupport.class,"Result")).setPreferredWidth(160);//NOI18N
673
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
674         table.sizeColumnsToFit(0);
675     }
676     
677     
678     
679  /* public void addTest( Test t) {
680         // details.add(r.getMessage() + "\n" + r.getThrown().getMessage());
681         // create a table row for this result
682         Object [] row = {t.getTestName(), t.getTestAssertion(), t.getTestDescription() };
683         tableModel.addRow(row);
684         table.sizeColumnsToFit(0);
685     }
686   
687   */

688     
689     
690     
691     /**
692      * This is the control panel of the Verifier GUI
693      */

694     public void CreateControlPanel() {
695         allButton = new JRadioButton JavaDoc(); //allString);
696
org.openide.awt.Mnemonics.setLocalizedText(allButton, allString); // NOI18N
697
failButton = new JRadioButton JavaDoc();//failString);
698
org.openide.awt.Mnemonics.setLocalizedText(failButton, failString); // NOI18N
699
warnButton = new JRadioButton JavaDoc();//warnString);
700
org.openide.awt.Mnemonics.setLocalizedText(warnButton, warnString); // NOI18N
701
controlPanel = new JPanel JavaDoc();
702         
703         // 508 for this panel
704
controlPanel.getAccessibleContext().setAccessibleName(panelName);
705         controlPanel.getAccessibleContext().setAccessibleDescription(panelDesc);
706         allButton.getAccessibleContext().setAccessibleName(radioButtonName);
707         allButton.getAccessibleContext().setAccessibleDescription(radioButtonDesc);
708         failButton.getAccessibleContext().setAccessibleName(radioButtonName);
709         failButton.getAccessibleContext().setAccessibleDescription(radioButtonDesc);
710         warnButton.getAccessibleContext().setAccessibleName(radioButtonName);
711         warnButton.getAccessibleContext().setAccessibleDescription(radioButtonDesc);
712         
713         // set up title border
714
// setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black),
715
// "Items to be Verified"));
716
controlPanel.setLayout(new BoxLayout JavaDoc(controlPanel, BoxLayout.Y_AXIS));
717         
718         
719         
720         // set-up the radio buttons.
721
allButton.setActionCommand(allString);
722         allButton.setSelected(true);//rifier.getReportLevel()==VerifierSupport.ALL);
723

724         failButton.setActionCommand(failString);
725         //failButton.setSelected(Verifier.getReportLevel()==VerifierSupport.FAIL);
726

727         warnButton.setActionCommand(warnString);
728         // warnButton.setSelected(Verifier.getReportLevel()==VerifierSupport.WARN);
729

730         // Group the radio buttons.
731
ButtonGroup JavaDoc group = new ButtonGroup JavaDoc();
732         group.add(allButton);
733         group.add(failButton);
734         group.add(warnButton);
735         
736         
737         // Put the radio buttons in a column in a panel
738
JPanel JavaDoc radioPanel = new JPanel JavaDoc();
739         // 508 for this panel
740
radioPanel.getAccessibleContext().setAccessibleName(panelName);
741         radioPanel.getAccessibleContext().setAccessibleDescription(panelDesc);
742         radioPanel.setLayout(new BoxLayout JavaDoc(radioPanel, BoxLayout.X_AXIS));
743         JLabel JavaDoc d = new JLabel JavaDoc(
744                 NbBundle.getMessage(VerifierSupport.class,"DisplayLabel")); // NOI18N
745
d.setVerticalAlignment(SwingConstants.BOTTOM);
746         // 508 compliance for the JLabel
747
d.getAccessibleContext().setAccessibleName(
748                 NbBundle.getMessage(VerifierSupport.class,"Label")); // NOI18N
749
d.getAccessibleContext().setAccessibleDescription(
750                 NbBundle.getMessage(VerifierSupport.class,"This_is_a_label")); // NOI18N
751
radioPanel.add(d);
752         radioPanel.add(allButton);
753         radioPanel.add(failButton);
754         radioPanel.add(warnButton);
755         
756         
757         
758         
759         // Add the controls to the Panel
760

761         controlPanel.add(radioPanel);
762         
763         
764         // Register a listener for the report level radio buttons.
765
myListener = new RadioListener();
766         allButton.addActionListener(myListener);
767         failButton.addActionListener(myListener);
768         warnButton.addActionListener(myListener);
769     }
770     
771     
772     
773     private void updateTableRows(String JavaDoc type, Vector JavaDoc results) {
774 // String status;
775
// update display approriately
776
for (int i = 0; i < results.size(); i++) {
777             Test t = ((Test)results.elementAt(i));
778             Object JavaDoc [] row = {type,/*t.getTestName(),*/ t.getTestAssertion(), t.getTestDescription() };
779             tableModel.addRow(row);
780             
781         }//for
782
table.sizeColumnsToFit(0);
783     }
784     private void updateDisplayAll(){
785         updateDisplayFail();
786         updateDisplayWarn();
787         updateDisplayPass();
788         updateDisplayNa();
789         updateDisplayNotImplemented();
790         updateDisplayNotRun();
791         updateDisplayDefault();
792         updateDisplayError();
793     }
794     private void updateDisplayPass(){
795         updateTableRows(NbBundle.getMessage(VerifierSupport.class,"Pass"),getPassResultsForDisplay()); // NOI18N
796
}
797     
798     private void updateDisplayFail(){
799         updateTableRows(NbBundle.getMessage(VerifierSupport.class,"Fail"),getFailResultsForDisplay()); // NOI18N
800
}
801     
802     private void updateDisplayError(){
803         Vector JavaDoc errors = getErrorResultsForDisplay();
804         for (int i = 0; i < errors.size(); i++) {
805             org.netbeans.modules.j2ee.sun.dd.impl.verifier.Error t = ((org.netbeans.modules.j2ee.sun.dd.impl.verifier.Error)errors.elementAt(i));
806             Object JavaDoc [] row = {NbBundle.getMessage(VerifierSupport.class,"Error"), // NOI18N
807
t.getErrorName(),t.getErrorDescription() };
808             tableModel.addRow(row);
809             
810         }
811         table.sizeColumnsToFit(0);
812     }
813     
814     private void updateDisplayWarn(){
815         updateTableRows(NbBundle.getMessage(VerifierSupport.class,"Warning"),getWarnResultsForDisplay()); // NOI18N
816
}
817     
818     private void updateDisplayNa(){
819         updateTableRows(NbBundle.getMessage(VerifierSupport.class,"Not_Applicable"),getNaResultsForDisplay()); // NOI18N
820
}
821     
822     private void updateDisplayNotImplemented(){
823         updateTableRows(NbBundle.getMessage(VerifierSupport.class,"Not_Implemented"),getNotImplementedResultsForDisplay()); // NOI18N
824
}
825     
826     private void updateDisplayNotRun(){
827         updateTableRows(NbBundle.getMessage(VerifierSupport.class,"Not_Run"),getNotRunResultsForDisplay()); // NOI18N
828
}
829     
830     private void updateDisplayDefault(){
831         updateTableRows("???",getDefaultResultsForDisplay()); // NOI18N
832
}
833     
834     /***************88 void addError(LogRecord r) {
835      * saveErrorResultsForDisplay(r);
836      * details.add(r.getMessage() + "\n" + r.getThrown().getMessage());
837      * // create a table row for this result
838      * Object [] row = {r.getLoggerName(), "Error during verification", "ERROR" };
839      * tableModel.addRow(row);
840      * table.sizeColumnsToFit(0);
841      * }*******************/

842     
843     public void updateDisplay(){
844         // update display approriately
845
clearResults();
846         if (statusLeveltoDisplay == ALL){
847             updateDisplayAll();
848         }
849         if (statusLeveltoDisplay == FAIL){
850             updateDisplayError();
851             updateDisplayFail();
852         }
853         if (statusLeveltoDisplay == WARN){
854             updateDisplayError();
855             updateDisplayFail();
856             updateDisplayWarn();
857         }
858     }
859     
860     private void savePassResultsForDisplay(Test r){
861         passResults.addElement(r);
862     }
863     
864     private void saveWarnResultsForDisplay(Test r){
865         warnResults.addElement(r);
866     }
867     
868     private void saveFailResultsForDisplay(Test r){
869         failResults.addElement(r);
870     }
871     
872     public void saveErrorResultsForDisplay(org.netbeans.modules.j2ee.sun.dd.impl.verifier.Error r){
873         errorResults.addElement(r);
874     }
875     
876     private void saveNaResultsForDisplay(Test r){
877         naResults.addElement(r);
878     }
879         
880     private Vector JavaDoc getPassResultsForDisplay(){
881         return passResults;
882     }
883     
884     private Vector JavaDoc getWarnResultsForDisplay(){
885         return warnResults;
886     }
887     
888     private Vector JavaDoc getFailResultsForDisplay(){
889         return failResults;
890     }
891     
892     private Vector JavaDoc getErrorResultsForDisplay(){
893         return errorResults;
894     }
895     
896     private Vector JavaDoc getNaResultsForDisplay(){
897         return naResults;
898     }
899     
900     private Vector JavaDoc getNotImplementedResultsForDisplay(){
901         return notImplementedResults;
902     }
903     
904     private Vector JavaDoc getNotRunResultsForDisplay(){
905         return notRunResults;
906     }
907     
908     private Vector JavaDoc getDefaultResultsForDisplay(){
909         return defaultResults;
910     }
911     
912  /* public void clearOldResults(){
913         passResults = new Vector();
914         failResults = new Vector();
915         errorResults = new Vector();
916         warnResults = new Vector();
917         naResults = new Vector();
918         notImplementedResults = new Vector();
919         notRunResults = new Vector();
920         defaultResults = new Vector();
921     }
922   
923   */

924     
925     
926 }
927
928
929
Popular Tags