KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > autoupdate > ResultsPanel


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 package org.netbeans.modules.autoupdate;
21
22 import java.awt.KeyboardFocusManager JavaDoc;
23 import java.awt.Window JavaDoc;
24 import java.util.*;
25 import java.security.cert.Certificate JavaDoc;
26 import java.security.cert.X509Certificate JavaDoc;
27 import java.awt.Component JavaDoc;
28 import java.awt.Font JavaDoc;
29 import java.io.File JavaDoc;
30 import java.io.FileNotFoundException JavaDoc;
31 import java.util.logging.Level JavaDoc;
32 import java.util.logging.Logger JavaDoc;
33 import javax.swing.*;
34 import javax.swing.table.AbstractTableModel JavaDoc;
35 import javax.swing.table.TableCellRenderer JavaDoc;
36
37 import org.openide.DialogDisplayer;
38 import org.openide.util.NbBundle;
39 import org.openide.NotifyDescriptor;
40 import org.openide.util.Exceptions;
41 import org.openide.util.Utilities;
42 import org.openide.windows.WindowManager;
43
44 class ResultsPanel extends javax.swing.JPanel JavaDoc {
45
46     private static final String JavaDoc SPACE = " "; //NOI18N
47

48     private static final String JavaDoc BAD_DOWNLOAD = SPACE + getBundle("CTL_BAD_DOWNLOAD") + SPACE;
49     private static final String JavaDoc CORRUPTED = SPACE + getBundle("CTL_CORRUPTED") + SPACE;
50     private static final String JavaDoc NOT_SIGNED = SPACE + getBundle("CTL_NOT_SIGNED") + SPACE;
51     private static final String JavaDoc SIGNED = SPACE + getBundle("CTL_SIGNED") + SPACE;
52     private static final String JavaDoc TRUSTED = SPACE + getBundle("CTL_TRUSTED") + SPACE;
53
54     private static final Logger JavaDoc LOG = Logger.getLogger ("org.netbeans.modules.autoupdate.ResultsPanel"); // NOI18N
55

56     private Wizard.Validator validator;
57
58     private int modulesOK;
59
60     private JTable table;
61     private ResultsTableModel model;
62     
63     //private static String yesToAll = getBundle( "CTL_Yes_All" );
64
private static JButton yesToAll;
65     private boolean includeAll = false;
66     private boolean globalAll = false;
67
68     static final long serialVersionUID =-6053101371836354161L;
69     
70     /** Stores the last selected directory */
71     private static File JavaDoc defaultDir = null;
72
73     /** Creates new form ResultsPanel */
74     public ResultsPanel( Wizard.Validator validator ) {
75         putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(3)); // NOI18N
76
setName(getBundle("LBL_View"));
77         initComponents();
78         
79         this.validator = validator;
80         
81         model = new ResultsTableModel();
82         //issue 33790, font size problems in Chinese locale - use a JTable that can
83
//self-size
84
table = new ServerPanel.AutoResizeTable(model, 2);
85         table.getTableHeader().setReorderingAllowed( false );
86         table.getColumnModel().getColumn(0).setCellRenderer( new BooleanRenderer() );
87         table.getColumnModel().getColumn(1).setCellRenderer( new ResultsCellRenderer() );
88         table.getColumnModel().getColumn(2).setCellRenderer( new BooleanRenderer() );
89 // table.setRowHeight( 2 * table.getRowHeight() );
90
table.setSelectionMode( javax.swing.ListSelectionModel.SINGLE_SELECTION );
91         table.getColumnModel().getColumn(0).setPreferredWidth(48);
92         table.getColumnModel().getColumn(1).setPreferredWidth(480);
93         table.getColumnModel().getColumn(2).setPreferredWidth(48);
94         table.setIntercellSpacing( new java.awt.Dimension JavaDoc( 0, 0 ) );
95         
96         jScrollPane1.setViewportView(table);
97
98         table.getSelectionModel().addListSelectionListener(
99             new javax.swing.event.ListSelectionListener JavaDoc() {
100                 public void valueChanged( javax.swing.event.ListSelectionEvent JavaDoc evt ) {
101                     selectionChange();
102                 }
103             }
104         );
105         
106         selectionChange();
107
108         getAccessibleContext().setAccessibleName(getBundle("LBL_View"));
109         getAccessibleContext().setAccessibleDescription(getBundle("LBL_41"));
110         certificateButton.getAccessibleContext().setAccessibleDescription(getBundle("ACS_View"));
111         table.getAccessibleContext().setAccessibleDescription(getBundle("ACS_Module_List"));
112         
113         jLabel1.setLabelFor( table );
114     }
115     
116     /** This method is called from within the constructor to
117      * initialize the form.
118      * WARNING: Do NOT modify this code. The content of this method is
119      * always regenerated by the Form Editor.
120      */

121     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
122
private void initComponents() {
123         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
124
125         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
126         jTextArea1 = new javax.swing.JTextArea JavaDoc();
127         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
128         jLabel1 = new javax.swing.JLabel JavaDoc();
129         jPanel1 = new javax.swing.JPanel JavaDoc();
130         certificateButton = new javax.swing.JButton JavaDoc();
131         saveButton = new javax.swing.JButton JavaDoc();
132
133         setLayout(new java.awt.GridBagLayout JavaDoc());
134
135         jTextArea1.setBackground(getBackground());
136         jTextArea1.setFont(new Font JavaDoc("Dialog", Font.PLAIN, jTextArea1.getFont().getSize()));
137         jTextArea1.setLineWrap(true);
138         jTextArea1.setText(getBundle("LBL_41"));
139         jTextArea1.setWrapStyleWord(true);
140         jTextArea1.setDisabledTextColor(java.awt.Color.black);
141         jTextArea1.setEnabled(false);
142         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
143         gridBagConstraints.gridx = 0;
144         gridBagConstraints.gridy = 0;
145         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
146         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
147         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
148         gridBagConstraints.weightx = 1.0;
149         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 0);
150         add(jTextArea1, gridBagConstraints);
151
152         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
153         gridBagConstraints.gridx = 0;
154         gridBagConstraints.gridy = 2;
155         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
156         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
157         gridBagConstraints.weightx = 1.0;
158         gridBagConstraints.weighty = 1.0;
159         add(jScrollPane1, gridBagConstraints);
160
161         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, getBundle("LAB_ModulesList"));
162         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
163         gridBagConstraints.gridy = 1;
164         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
165         add(jLabel1, gridBagConstraints);
166
167         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
168
169         org.openide.awt.Mnemonics.setLocalizedText(certificateButton, getBundle("BTN_View"));
170         buttonGroup1.add(certificateButton);
171         certificateButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
172             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
173                 certificateButtonActionPerformed(evt);
174             }
175         });
176
177         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
178         gridBagConstraints.gridx = 0;
179         gridBagConstraints.gridy = 0;
180         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
181         gridBagConstraints.weightx = 1.0;
182         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
183         jPanel1.add(certificateButton, gridBagConstraints);
184
185         org.openide.awt.Mnemonics.setLocalizedText(saveButton, getBundle("BTN_SaveCopy"));
186         buttonGroup1.add(saveButton);
187         saveButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
188             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
189                 saveButtonActionPerformed(evt);
190             }
191         });
192
193         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
194         gridBagConstraints.gridx = 1;
195         gridBagConstraints.gridy = 0;
196         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
197         gridBagConstraints.weightx = 1.0;
198         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 11, 0, 0);
199         jPanel1.add(saveButton, gridBagConstraints);
200
201         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
202         gridBagConstraints.gridx = 2;
203         gridBagConstraints.gridy = 3;
204         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
205         gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
206         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
207         add(jPanel1, gridBagConstraints);
208
209     }
210     // </editor-fold>//GEN-END:initComponents
211

212     private void saveButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_saveButtonActionPerformed
213
try {
214             File JavaDoc saveDir = getSaveCopyDir();
215             if (saveDir == null) return ;
216             ModuleUpdate mu = getListSelection();
217             File JavaDoc target = new File JavaDoc ( saveDir, mu.getDistributionFilename());
218             if ( target.exists() ) {
219                 NotifyDescriptor.Confirmation nd =
220                         new NotifyDescriptor.Confirmation(
221                             getBundle( "MSG_OverwriteConfirmation" ),
222                             NotifyDescriptor.YES_NO_OPTION
223                         );
224                 if ( ! DialogDisplayer.getDefault().notify( nd ).equals( NotifyDescriptor.YES_OPTION ) )
225                     return;
226             }
227             Downloader.saveCopy( getListSelection(), target );
228         } catch (FileNotFoundException JavaDoc fnfe) {
229             Exceptions.attachLocalizedMessage(
230                 fnfe, NbBundle.getMessage(ResultsPanel.class,"CTL_Directory_not_exits")
231             );
232             NotifyDescriptor nd = new NotifyDescriptor.Exception(fnfe);
233             DialogDisplayer.getDefault().notifyLater(nd);
234         }
235     }//GEN-LAST:event_saveButtonActionPerformed
236

237     private void certificateButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_certificateButtonActionPerformed
238
int accValue = CertificateDialog.showDialog( getListSelection().getCerts(),
239                                       getListSelection().getSecurity() );
240         doCertAction(accValue, getListSelection());
241         table.invalidate();
242         table.repaint();
243         selectionChange();
244     }//GEN-LAST:event_certificateButtonActionPerformed
245

246     private void doInclude(ModuleUpdate mu) {
247         if ( mu.isForcedGlobal () && Downloader.bannedWriteToInstall (mu)) {
248             NotifyDescriptor.Message nd =
249                 new NotifyDescriptor.Message(
250                     NbBundle.getMessage( ResultsPanel.class, "MSG_CannotInstall_2", mu.getName())
251                 );
252             DialogDisplayer.getDefault().notify( nd );
253             return;
254         }
255         if ( mu.getSecurity() == SignVerifier.NOT_SIGNED ) {
256             if ( mu.isInstallApproved() ) {
257                 mu.setInstallApproved( false );
258                 checkValidity();
259             }
260             else {
261                 Object JavaDoc ret = null;
262                 if ( !includeAll ) {
263                     NotifyDescriptor.Confirmation nd =
264                         new NotifyDescriptor.Confirmation(
265                             getBundle( "MSG_NotSignedConfirmation" ),
266                             getBundle( "CTL_NotSignedConfirmation" ),
267                             NotifyDescriptor.YES_NO_OPTION
268                         );
269                     nd.setOptions( new Object JavaDoc[] {
270                             NotifyDescriptor.YES_OPTION,
271                             NotifyDescriptor.NO_OPTION,
272                             getYesToAll () } );
273                     ret = DialogDisplayer.getDefault().notify( nd );
274                     if (ret.equals (getYesToAll ())) {
275                         includeAll = true;
276                     }
277                 }
278                 if ( includeAll || ret.equals( NotifyDescriptor.YES_OPTION ) ) {
279                     mu.setInstallApproved( true );
280                     checkValidity();
281                 }
282             }
283         }
284         else if ( mu.getSecurity() == SignVerifier.SIGNED ||
285                   mu.getSecurity() == SignVerifier.TRUSTED ) {
286             doCertAction(CertificateDialog.showDialog(
287                                   mu.getCerts(),
288                                   mu.getSecurity()
289                             ),
290                          mu
291             );
292         }
293         else if ( mu.getSecurity() == SignVerifier.CORRUPTED ) {
294             NotifyDescriptor.Message nd =
295                   new NotifyDescriptor.Message(getBundle( "MSG_CorruptedJAR" ) );
296             DialogDisplayer.getDefault().notify( nd );
297         }
298         else {
299             NotifyDescriptor.Message nd =
300                   new NotifyDescriptor.Message(getBundle( "MSG_BadDownload" ) );
301             DialogDisplayer.getDefault().notify( nd );
302         }
303         table.invalidate();
304         table.repaint();
305         selectionChange();
306     }
307     
308     private void doGlobal(ModuleUpdate mu) throws IllegalArgumentException JavaDoc {
309         if ( mu.isForcedGlobal () ) {
310             NotifyDescriptor.Message nd =
311                 new NotifyDescriptor.Message(
312                     NbBundle.getMessage( ResultsPanel.class, "MSG_InstallDepending",
313                         mu.getName()
314                     )
315                 );
316             DialogDisplayer.getDefault().notify( nd );
317             return;
318         }
319         
320         if (Downloader.bannedWriteToInstall (mu)) {
321             NotifyDescriptor.Message nd =
322                     new NotifyDescriptor.Message( getBundle( "MSG_InstallNoWrite" ) );
323             DialogDisplayer.getDefault().notify( nd );
324             return;
325         }
326         
327         if (mu.isGlobal () != null) {
328             if (mu.isGlobal ().booleanValue ()) {
329                 NotifyDescriptor.Message nd =
330                         new NotifyDescriptor.Message (
331                             NbBundle.getMessage( ResultsPanel.class, "MSG_InstallGloballyForced",
332                                 mu.getName()
333                             ),
334                             NotifyDescriptor.INFORMATION_MESSAGE
335                         );
336                 DialogDisplayer.getDefault ().notify (nd);
337                 return ;
338             } else {
339                 NotifyDescriptor.Message nd =
340                         new NotifyDescriptor.Message (
341                             NbBundle.getMessage( ResultsPanel.class, "MSG_InstallLocallyForced",
342                                 mu.getName()
343                             ),
344                             NotifyDescriptor.INFORMATION_MESSAGE
345                         );
346                 DialogDisplayer.getDefault ().notify (nd);
347                 return ;
348             }
349         }
350
351         if ( mu.isToInstallDir() ) {
352             Object JavaDoc ret = null;
353             if ("".equals (getBundle ("MSG_InstallLocallyConfirmation"))) {
354                 mu.setToInstallDir (false);
355             } else {
356                 NotifyDescriptor.Confirmation nd =
357                         new NotifyDescriptor.Confirmation(
358                             NbBundle.getMessage( ResultsPanel.class, "MSG_InstallLocallyConfirmation",
359                                 mu.getName()
360                             ),
361                             NotifyDescriptor.YES_NO_OPTION
362                         );
363                 nd.setOptions( new Object JavaDoc[] {
364                             NotifyDescriptor.YES_OPTION,
365                             NotifyDescriptor.NO_OPTION } );
366                 ret = DialogDisplayer.getDefault().notify( nd );
367                 if ( ret.equals( NotifyDescriptor.YES_OPTION ) ) {
368                     mu.setToInstallDir( false );
369                 }
370             }
371         } else {
372             Object JavaDoc ret = null;
373             if ( !globalAll ) {
374                 if ("".equals (getBundle( "MSG_InstallGloballyConfirmation" ))) {
375                     mu.setToInstallDir (false);
376                 } else {
377                     NotifyDescriptor.Confirmation nd =
378                             new NotifyDescriptor.Confirmation(
379                                 NbBundle.getMessage( ResultsPanel.class, "MSG_InstallGloballyConfirmation",
380                                     mu.getName()
381                                 ),
382                                 NotifyDescriptor.YES_NO_OPTION
383                             );
384                     nd.setOptions( new Object JavaDoc[] {
385                                 NotifyDescriptor.YES_OPTION,
386                                 NotifyDescriptor.NO_OPTION,
387                                 getYesToAll () } );
388                     ret = DialogDisplayer.getDefault().notify( nd );
389                     if (ret.equals ( getYesToAll ())) {
390                         globalAll = true;
391                     }
392                 }
393             }
394             if ( globalAll || ret.equals( NotifyDescriptor.YES_OPTION ) ) {
395                 mu.setToInstallDir( true );
396             }
397         }
398         table.invalidate();
399         table.repaint();
400         selectionChange();
401     }
402     
403     void doCertAction(int accValue, ModuleUpdate mu) {
404         switch ( accValue ) {
405             /*
406         case CertificateDialog.FOR_MODULE:
407             getListSelection().setInstallApproved( true );
408             checkValidity();
409             break;
410              */

411         case CertificateDialog.ACCEPT:
412             setApproved4All( mu.getCerts(), true, -1 );
413             checkValidity();
414             break;
415         case CertificateDialog.REJECT:
416             setApproved4All( mu.getCerts(), false, -1 );
417             checkValidity();
418             break;
419         case CertificateDialog.NOT_ALWAYS_ACCEPT:
420             setApproved4All( mu.getCerts(), false, SignVerifier.SIGNED );
421             checkValidity();
422             try {
423                 SignVerifier.removeCertificates( mu.getCerts() );
424             }
425             catch ( java.security.cert.CertificateException JavaDoc e ) {
426                 LOG.log(Level.WARNING, null, e);
427             }
428             catch ( java.security.KeyStoreException JavaDoc e ) {
429                 LOG.log(Level.WARNING, null, e);
430             }
431             catch ( java.io.IOException JavaDoc e ) {
432                 LOG.log(Level.WARNING, null, e);
433             }
434             catch ( java.security.NoSuchAlgorithmException JavaDoc e ) {
435                 LOG.log(Level.WARNING, null, e);
436             }
437             break;
438         case CertificateDialog.ALWAYS_ACCEPT:
439             setApproved4All( mu.getCerts(), true, SignVerifier.TRUSTED );
440             checkValidity();
441             try {
442                 SignVerifier.addCertificates( mu.getCerts() );
443             }
444             catch ( java.security.cert.CertificateException JavaDoc e ) {
445                 LOG.log(Level.WARNING, null, e);
446             }
447             catch ( java.security.KeyStoreException JavaDoc e ) {
448                 LOG.log(Level.WARNING, null, e);
449             }
450             catch ( java.io.IOException JavaDoc e ) {
451                 LOG.log(Level.WARNING, null, e);
452             }
453             catch ( java.security.NoSuchAlgorithmException JavaDoc e ) {
454                 LOG.log(Level.WARNING, null, e);
455             }
456             break;
457         default:
458             return;
459         }
460     }
461     
462     /** Utility function approves installing of all modules signed
463     * by given Collection of certs
464     */

465     private void setApproved4All( Collection certs, boolean approved, int security ) {
466
467         if ( certs == null ) {
468             return;
469         }
470         
471         for ( int i=0; i < model.getRowCount(); i++ ) {
472             ModuleUpdate mu = (ModuleUpdate)model.getValueAt(i, 1);
473
474             boolean bannedWriteToInstall = Downloader.bannedWriteToInstall(mu);
475             if ( approved && mu.isForcedGlobal () && bannedWriteToInstall ) {
476                 continue;
477             }
478             
479             if ( mu.getCerts() != null && certs.containsAll( mu.getCerts() ) ) {
480                 mu.setInstallApproved( approved );
481
482                 if ( security == SignVerifier.TRUSTED || security == SignVerifier.SIGNED ) {
483                     mu.setSecurity( security );
484                 }
485             }
486
487         }
488     }
489     
490     // Variables declaration - do not modify//GEN-BEGIN:variables
491
private javax.swing.ButtonGroup JavaDoc buttonGroup1;
492     private javax.swing.JButton JavaDoc certificateButton;
493     private javax.swing.JLabel JavaDoc jLabel1;
494     private javax.swing.JPanel JavaDoc jPanel1;
495     private javax.swing.JScrollPane JavaDoc jScrollPane1;
496     private javax.swing.JTextArea JavaDoc jTextArea1;
497     private javax.swing.JButton JavaDoc saveButton;
498     // End of variables declaration//GEN-END:variables
499

500     int generateResults() {
501
502         modulesOK = 0;
503
504         List modulelist = new ArrayList();
505
506         Collection modules = Wizard.getAllModules();
507         Iterator it = modules.iterator();
508         boolean writeConflict = false;
509         int selectRow = -1;
510         while( it.hasNext() ) {
511             ModuleUpdate mu = (ModuleUpdate)it.next();
512
513             if ( mu.isSelected() ) {
514                 modulelist.add( mu );
515                 if ( mu.isDownloadOK() ) {
516                     modulesOK ++;
517                     if ( selectRow == -1 )
518                         if (!mu.isInstallApproved())
519                             selectRow = modulelist.size()-1;
520                 }
521                 if ( mu.isForcedGlobal () ) {
522                     boolean bannedWriteToInstall = Downloader.bannedWriteToInstall (mu);
523                     if ( bannedWriteToInstall ) {
524                         mu.setInstallApproved( false );
525                         writeConflict = true;
526                     }
527                     mu.setToInstallDir( true );
528                 }
529             }
530         }
531         if ( writeConflict ) {
532             NotifyDescriptor.Message nd =
533                     new NotifyDescriptor.Message( getBundle( "MSG_CannotInstall_1" ) );
534             DialogDisplayer.getDefault().notify( nd );
535         }
536         
537         model.refreshContent( modulelist );
538         
539         if ( selectRow == -1 )
540             selectRow = 0;
541         if ( table.getRowCount() > 0 )
542             table.getSelectionModel().setSelectionInterval( selectRow, selectRow );
543
544         checkValidity();
545         selectionChange();
546         includeAll = false;
547         globalAll = false;
548         return modulesOK;
549     }
550
551     /** Called when the selection in selectedList or explorerView changes */
552     private void selectionChange() {
553         ModuleUpdate mu = getListSelection();
554         
555         // Enable/Disable view button
556
if ( mu != null &&
557                 ( mu.getSecurity() == SignVerifier.SIGNED ||
558                   mu.getSecurity() == SignVerifier.TRUSTED ) ) {
559             certificateButton.setEnabled( true );
560         }
561         else {
562             certificateButton.setEnabled( false );
563         }
564         
565         // Enable/Disable save button
566
if ( mu != null &&
567                 mu.getSecurity() != SignVerifier.BAD_DOWNLOAD ) {
568             saveButton.setEnabled( true );
569         }
570         else {
571             saveButton.setEnabled( false );
572         }
573     }
574
575     /** Gets the ModuleUpdate selected in the list */
576     private ModuleUpdate getListSelection() {
577
578         int index = table.getSelectionModel().getMinSelectionIndex();
579
580         if ( index < 0 )
581             return null;
582
583         return (ModuleUpdate) model.getValueAt( index, 1 );
584     }
585     
586     /** Checks wther there exists at least one update with approved install
587     * if so enables finish button
588     */

589     private void checkValidity() {
590
591         boolean valid = false;
592
593         Collection modules = Wizard.getAllModules();
594         Iterator it = modules.iterator();
595         while( it.hasNext() ) {
596             ModuleUpdate mu = (ModuleUpdate)it.next();
597
598             if ( mu.isSelected() && mu.isInstallApproved() ) {
599                 valid = true;
600             }
601
602         }
603
604         validator.setValid( valid );
605
606     }
607     
608     class ResultsTableModel extends AbstractTableModel JavaDoc {
609         final String JavaDoc[] columnNames = {getBundle("LBL_42"),
610                                       getBundle("LBL_43"),
611                                       getBundle("LBL_Global")};
612         private List modulelist = new ArrayList();
613
614         public int getColumnCount() {
615             return columnNames.length;
616         }
617         
618         public int getRowCount() {
619             return modulelist.size();
620         }
621
622         public String JavaDoc getColumnName(int col) {
623             return columnNames[col];
624         }
625
626         public Object JavaDoc getValueAt(int row, int col) {
627             if (col == 0)
628                 return ((ModuleUpdate)modulelist.get(row)).isInstallApproved() ? Boolean.TRUE : Boolean.FALSE;
629             else if (col == 1)
630                 return modulelist.get(row);
631             else {
632                 ModuleUpdate mu = (ModuleUpdate)modulelist.get (row);
633                 return Boolean.valueOf (mu.isToInstallDir());
634             }
635         }
636
637         public Class JavaDoc getColumnClass(int c) {
638             return getValueAt(0, c).getClass();
639         }
640
641         public boolean isCellEditable(int row, int col) {
642             if (col == 1) {
643                 return false;
644             } else {
645                 return true;
646             }
647         }
648
649         public void setValueAt(Object JavaDoc value, int row, int col) {
650             if (value instanceof Boolean JavaDoc) {
651                 if ( col == 0 )
652                     doInclude( (ModuleUpdate)modulelist.get(row) );
653                 else {
654                     try {
655                         doGlobal( (ModuleUpdate)modulelist.get(row) );
656                     } catch (IllegalArgumentException JavaDoc iae) {
657                         LOG.log(Level.WARNING, null, iae);
658                     }
659                 }
660             }
661         }
662         
663         void refreshContent( List modulelist ) {
664             this.modulelist = modulelist;
665         }
666     }
667     
668     private class ResultsCellRenderer extends JPanel implements TableCellRenderer JavaDoc {
669
670         private JLabel nameLabel;
671         private JLabel securityLabel;
672         
673         public ResultsCellRenderer() {
674         super();
675             initComponents();
676     }
677         
678         /** Overrides superclass method. */
679         public Component JavaDoc getTableCellRendererComponent(JTable table, Object JavaDoc value,
680                 boolean isSelected, boolean hasFocus, int row, int column) {
681
682             String JavaDoc sec = ""; // NOI18N
683
if ( value == null )
684                 value = model.getValueAt( row, column );
685             switch ( ((ModuleUpdate)value).getSecurity() ) {
686             case SignVerifier.BAD_DOWNLOAD:
687                 sec = BAD_DOWNLOAD;
688                 break;
689             case SignVerifier.CORRUPTED:
690                 sec = CORRUPTED;
691                 break;
692             case SignVerifier.NOT_SIGNED:
693                 sec = NOT_SIGNED;
694                 break;
695             case SignVerifier.SIGNED:
696                 StringBuffer JavaDoc sb = new StringBuffer JavaDoc( SIGNED );
697                 sb.append( SPACE + getBundle("CTL_By"));
698                 Collection certs = ((ModuleUpdate)value).getCerts();
699                 Iterator it = certs.iterator();
700                 while ( it.hasNext() ) {
701                     Certificate JavaDoc cert = (Certificate JavaDoc)it.next();
702                     if ( cert instanceof X509Certificate JavaDoc ) {
703                         sb.append( " " ).append( ((X509Certificate JavaDoc)cert).getSubjectDN().getName() ); //NOI18N
704
}
705                 }
706
707                 sec = sb.toString();
708                 break;
709             case SignVerifier.TRUSTED:
710                 sec = TRUSTED;
711                 break;
712             }
713
714             if ( isSelected ) {
715                 setBackground ((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("Table.selectionBackground")); // NOI18N
716
nameLabel.setForeground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("Table.selectionForeground")); // NOI18N
717
securityLabel.setForeground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("Table.selectionForeground")); // NOI18N
718
}
719             else {
720                 setBackground ((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("Table.background")); // NOI18N
721
nameLabel.setForeground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("Table.Foreground")); // NOI18N
722
securityLabel.setForeground((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults ().get ("Table.Foreground")); // NOI18N
723
}
724             nameLabel.setText( ((ModuleUpdate)value).getName() +
725                                         " " + getBundle( "CTL_Version" ) +
726                                         ((ModuleUpdate)value).getRemoteModule().getSpecificationVersion());
727             securityLabel.setText( sec );
728             
729             return this;
730         }
731         
732         private void initComponents() {
733             java.awt.GridBagConstraints JavaDoc gridBagConstraints;
734
735             nameLabel = new JLabel();
736             securityLabel = new JLabel();
737             
738             setLayout(new java.awt.GridBagLayout JavaDoc());
739             nameLabel.setFont(doDeriveFont(nameLabel.getFont(), Font.BOLD));
740             
741             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
742             gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
743             gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
744             gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
745             gridBagConstraints.weightx = 1.0;
746             gridBagConstraints.weighty = 1.0;
747             gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
748             add(nameLabel, gridBagConstraints);
749
750             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
751             gridBagConstraints.gridx = 0;
752             gridBagConstraints.gridy = 1;
753             gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
754             gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
755             gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
756             gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
757             gridBagConstraints.weightx = 1.0;
758             gridBagConstraints.weighty = 1.0;
759             add(securityLabel, gridBagConstraints);
760
761         }
762     }
763     
764     static class BooleanRenderer extends JCheckBox implements TableCellRenderer JavaDoc {
765     public BooleanRenderer() {
766         super();
767         setHorizontalAlignment(JLabel.CENTER);
768             setBorder(new javax.swing.border.LineBorder JavaDoc((java.awt.Color JavaDoc) javax.swing.UIManager.getDefaults().get("Button.focus")));
769     }
770
771         public Component JavaDoc getTableCellRendererComponent(JTable table, Object JavaDoc value,
772                                boolean isSelected, boolean hasFocus, int row, int column) {
773         if (isSelected) {
774             setForeground(table.getSelectionForeground());
775             super.setBackground(table.getSelectionBackground());
776         }
777         else {
778             setForeground(table.getForeground());
779             setBackground(table.getBackground());
780         }
781             
782             setBorderPainted( isSelected && table.getSelectedColumn() == column );
783             
784             setSelected((value != null && ((Boolean JavaDoc)value).booleanValue()));
785             return this;
786         }
787     }
788     
789     private File JavaDoc getSaveCopyDir() throws FileNotFoundException JavaDoc {
790         JFileChooser chooser = new JFileChooser();
791         chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
792         chooser.setDialogTitle(
793             NbBundle.getMessage( ResultsPanel.class, "CTL_FileChooserSC_Title",
794                         getListSelection().getDistributionFilename()
795             )
796         );
797         chooser.setFileFilter( new javax.swing.filechooser.FileFilter JavaDoc() {
798             public boolean accept( File JavaDoc f ) {
799                 return f.canWrite();
800             }
801
802             public String JavaDoc getDescription() {
803                 return getBundle( "CTL_FileFilterSCDescription" );
804             }
805         });
806
807         if (defaultDir == null)
808             defaultDir = SelectModulesPanel.getDefaultDir();
809
810         if ( defaultDir != null) {
811             File JavaDoc parent = defaultDir.getParentFile();
812             if ( parent != null ) {
813                 chooser.setCurrentDirectory( parent );
814                 chooser.setSelectedFile( defaultDir );
815             }
816             else
817                 chooser.setCurrentDirectory( defaultDir );
818         }
819         
820         Window JavaDoc focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getActiveWindow ();
821         
822         File JavaDoc res = null;
823
824         if (chooser.showDialog( WindowManager.getDefault().getMainWindow (),
825                                getBundle("CTL_Save"))
826                 == JFileChooser.APPROVE_OPTION) {
827
828             defaultDir = chooser.getSelectedFile();
829             if (defaultDir.exists ()) {
830                 res = defaultDir;
831             } else {
832                 // bugfix #39006, check if the chosen directory exists otherwise throw a exception
833
// notify user the selected directory doesn't exists
834
throw new FileNotFoundException JavaDoc (defaultDir.getAbsolutePath ()); // NOI18N
835
}
836         } else {
837             res = null;
838         }
839         
840         // #46353, recover focus after close the JFileChooser
841
if (focusOwner != null) {
842             focusOwner.toFront ();
843         }
844         
845         return res;
846     }
847     
848     private JButton getYesToAll () {
849         if (yesToAll == null) {
850             yesToAll = new JButton ();
851         org.openide.awt.Mnemonics.setLocalizedText(yesToAll, getBundle("CTL_Yes_All"));
852             yesToAll.getAccessibleContext ().setAccessibleName (getBundle("ACSN_Yes_All"));
853             yesToAll.getAccessibleContext ().setAccessibleDescription (getBundle("ACSD_Yes_All"));
854         }
855         return yesToAll;
856     }
857     
858     private static String JavaDoc getBundle( String JavaDoc key ) {
859         return NbBundle.getMessage( ResultsPanel.class, key );
860     }
861     
862     static Font JavaDoc doDeriveFont(Font JavaDoc original, int style) {
863                 // don't use deriveFont() - see #49973 for details
864
if (Utilities.isMac()) {
865            return new Font JavaDoc(original.getName(), style, original.getSize());
866        }
867        return original.deriveFont(style);
868     }
869 }
870
Popular Tags