KickJava   Java API By Example, From Geeks To Geeks.

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


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
21 package org.netbeans.modules.autoupdate;
22
23 import java.awt.Font JavaDoc;
24 import java.awt.event.FocusEvent JavaDoc;
25 import java.awt.event.FocusListener JavaDoc;
26 import java.beans.PropertyChangeListener JavaDoc;
27 import java.beans.PropertyChangeEvent JavaDoc;
28 import java.util.Collection JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.ArrayList JavaDoc;
32
33 import java.util.Date JavaDoc;
34 import java.util.HashSet JavaDoc;
35 import javax.swing.DefaultListModel JavaDoc;
36 import javax.swing.JComponent JavaDoc;
37 import javax.swing.SwingUtilities JavaDoc;
38 import javax.swing.UIManager JavaDoc;
39 import javax.swing.event.ListSelectionListener JavaDoc;
40 import javax.swing.text.html.HTMLEditorKit JavaDoc;
41 import javax.swing.text.html.StyleSheet JavaDoc;
42 import org.openide.DialogDisplayer;
43
44 import org.openide.NotifyDescriptor;
45 import org.openide.awt.HtmlBrowser;
46 import org.openide.nodes.Children;
47 import org.openide.nodes.Node;
48 import org.openide.explorer.ExplorerManager;
49 import org.openide.explorer.view.BeanTreeView;
50 import org.openide.modules.SpecificationVersion;
51 import org.openide.util.NbBundle;
52 import org.openide.util.RequestProcessor;
53
54
55 class UpdatePanel extends javax.swing.JPanel JavaDoc {
56
57     private static final String JavaDoc EMPTY_STRING = ""; // NOI18N
58

59     private static final java.awt.Dimension JavaDoc PREFERRED_SIZE = new java.awt.Dimension JavaDoc( 600, 500 );
60
61     private static final String JavaDoc SPACE = " "; //NOI18N
62

63     transient private static final HashSet JavaDoc acceptedLicencies = new HashSet JavaDoc (10);
64
65     /** Explorer tree */
66     private ExplorerView explorerView;
67     /** List model for listBox with selected modules */
68     private DefaultListModel JavaDoc selectedListModel;
69     /** Summation of lengths of all selected modules */
70     private long totalSize;
71
72     private Wizard.Validator validator;
73     
74     private UpdateNode.AllServers allNodes;
75     
76     private int duplicateStatus = 0;
77     
78     private PropertyChangeListener JavaDoc nodeListener;
79
80     static final long serialVersionUID =897622109141801200L;
81     
82     static final String JavaDoc LINE_SEPARATOR = "<br>"; //NOI18N
83

84     /**
85      * Creates new form UpdatePanel
86      * @param validator controls if next button should be enabled or disbled
87      */

88     public UpdatePanel( Wizard.Validator validator ) {
89         putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); // NOI18N
90
putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE); // NOI18N
91
putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE); // NOI18N
92
putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(1)); // NOI18N
93
putClientProperty("WizardPanel_contentData", new String JavaDoc[] { // NOI18N
94
getBundle("WIZ_First"),
95             getBundle("WIZ_Select"),
96             getBundle("WIZ_Download"),
97             getBundle("WIZ_View")
98         });
99         initComponents();
100         
101         HTMLEditorKit JavaDoc htmlkit = new HTMLEditorKit JavaDoc ();
102         // override the Swing default CSS to make the HTMLEditorKit use the
103
// same font as the rest of the UI.
104

105         // XXX the style sheet is shared by all HTMLEditorKits. We must
106
// detect if it has been tweaked by ourselves or someone else
107
// (code completion javadoc popup for example) and avoid doing the
108
// same thing again
109

110         StyleSheet JavaDoc css = htmlkit.getStyleSheet ();
111
112         if (css.getStyleSheets() == null) {
113             StyleSheet JavaDoc css2 = new StyleSheet JavaDoc();
114             Font JavaDoc f = jList1.getFont ();
115             int size = jList1.getFont ().getSize ();
116             css2.addRule(new StringBuffer JavaDoc("body { font-size: ").append(size) // NOI18N
117
.append("; font-family: ").append(f.getName()).append("; }").toString()); // NOI18N
118
css2.addStyleSheet(css);
119             htmlkit.setStyleSheet(css2);
120         }
121
122         this.description.setEditorKit (htmlkit);
123         
124         setName(getBundle("LAB_Select2"));
125         
126         this.validator = validator;
127
128         // Add Explorer view
129
explorerView = new ExplorerView();
130         explorerView.getExplorerManager().addPropertyChangeListener(
131             new PropertyChangeListener JavaDoc() {
132                 public void propertyChange( PropertyChangeEvent JavaDoc evt ) {
133                     if ( evt.getPropertyName() == ExplorerManager.PROP_SELECTED_NODES ) {
134                         selectionChange( true );
135                     }
136                 }
137             } );
138         
139         jList1.addFocusListener(
140             new FocusListener JavaDoc() {
141                 public void focusGained( FocusEvent JavaDoc evt ) {
142                     unselectLeft();
143                     if ( jList1.getSelectedIndex() == -1 && selectedListModel.getSize() > 0 )
144                         jList1.setSelectedIndex( 0 );
145                 }
146             
147                 public void focusLost( FocusEvent JavaDoc evt ) {
148                 }
149             } );
150
151         java.awt.GridBagConstraints JavaDoc gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc ();
152         gridBagConstraints1.gridwidth = 0;
153         gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
154         gridBagConstraints1.weightx = 1.0;
155         gridBagConstraints1.weighty = 1.0;
156         gridBagConstraints1.insets = new java.awt.Insets JavaDoc (0, 3, 0, 3);
157         jPanel1.add (explorerView, gridBagConstraints1);
158
159         // Customize jList1
160

161         jList1.setCellRenderer( new SelectedListCellRenderer() );
162         selectedListModel = new DefaultListModel JavaDoc();
163         jList1.setModel( selectedListModel );
164         jList1.getSelectionModel().setSelectionMode( javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
165         jList1.getSelectionModel().addListSelectionListener(
166             new ListSelectionListener JavaDoc() {
167                 public void valueChanged( javax.swing.event.ListSelectionEvent JavaDoc evt ) {
168                     selectionChange( false );
169                 }
170             }
171         );
172                 
173         panel1Label.setLabelFor(explorerView);
174
175         getAccessibleContext().setAccessibleName(getBundle("ACS_UpdatePanel"));
176         getAccessibleContext().setAccessibleDescription(getBundle("ACSD_UpdatePanel") + getBundle("LAB_227"));
177         moreButton.getAccessibleContext().setAccessibleDescription(getBundle("ACS_More"));
178         jList1.getAccessibleContext().setAccessibleDescription(getBundle("ACS_InstallList"));
179         explorerView.setName (getBundle ("ACSN_ExplorerView"));
180     }
181     
182     /** Returns preferred size of the panel */
183     public java.awt.Dimension JavaDoc getPreferredSize() {
184         return PREFERRED_SIZE;
185     }
186
187     /** This method is called from within the constructor to
188      * initialize the form.
189      * WARNING: Do NOT modify this code. The content of this method is
190      * always regenerated by the Form Editor.
191      */

192     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
193
private void initComponents() {
194         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
195
196         panel1Label = new javax.swing.JLabel JavaDoc();
197         jPanel1 = new javax.swing.JPanel JavaDoc();
198         addButton = new javax.swing.JButton JavaDoc();
199         removeButton = new javax.swing.JButton JavaDoc();
200         addallButton = new javax.swing.JButton JavaDoc();
201         removeallButton = new javax.swing.JButton JavaDoc();
202         scrollpaneLabel = new javax.swing.JLabel JavaDoc();
203         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
204         jList1 = new javax.swing.JList JavaDoc();
205         jPanel3 = new javax.swing.JPanel JavaDoc();
206         totalsizeLabel = new javax.swing.JLabel JavaDoc();
207         totalsizeTextField = new javax.swing.JTextField JavaDoc();
208         jPanel2 = new javax.swing.JPanel JavaDoc();
209         avLabel = new javax.swing.JLabel JavaDoc();
210         avTextField = new javax.swing.JTextField JavaDoc();
211         ivLabel = new javax.swing.JLabel JavaDoc();
212         ivTextField = new javax.swing.JTextField JavaDoc();
213         jScrollPane2 = new javax.swing.JScrollPane JavaDoc();
214         description = new javax.swing.JEditorPane JavaDoc();
215         moreButton = new javax.swing.JButton JavaDoc();
216
217         setLayout(new java.awt.GridBagLayout JavaDoc());
218
219         org.openide.awt.Mnemonics.setLocalizedText(panel1Label, getBundle("LAB_221")); // NOI18N
220
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
221         gridBagConstraints.gridx = 0;
222         gridBagConstraints.gridy = 0;
223         gridBagConstraints.gridwidth = 2;
224         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
225         add(panel1Label, gridBagConstraints);
226
227         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
228
229         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
230         gridBagConstraints.gridx = 0;
231         gridBagConstraints.gridy = 1;
232         gridBagConstraints.gridwidth = 2;
233         gridBagConstraints.gridheight = 5;
234         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
235         gridBagConstraints.weightx = 1.0;
236         gridBagConstraints.weighty = 1.0;
237         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 0, 0, 0);
238         add(jPanel1, gridBagConstraints);
239
240         org.openide.awt.Mnemonics.setLocalizedText(addButton, getBundle("BTN_Add_2")); // NOI18N
241
addButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
242             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
243                 addButtonActionPerformed(evt);
244             }
245         });
246
247         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
248         gridBagConstraints.gridx = 2;
249         gridBagConstraints.gridy = 1;
250         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
251         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 12, 0, 12);
252         add(addButton, gridBagConstraints);
253
254         org.openide.awt.Mnemonics.setLocalizedText(removeButton, getBundle("BTN_Remove_2")); // NOI18N
255
removeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
256             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
257                 removeButtonActionPerformed(evt);
258             }
259         });
260
261         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
262         gridBagConstraints.gridx = 2;
263         gridBagConstraints.gridy = 2;
264         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
265         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 12, 0, 12);
266         add(removeButton, gridBagConstraints);
267
268         org.openide.awt.Mnemonics.setLocalizedText(addallButton, getBundle("BTN_AddAll_2")); // NOI18N
269
addallButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
270             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
271                 addallButtonActionPerformed(evt);
272             }
273         });
274
275         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
276         gridBagConstraints.gridx = 2;
277         gridBagConstraints.gridy = 3;
278         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
279         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 12, 0, 12);
280         add(addallButton, gridBagConstraints);
281
282         org.openide.awt.Mnemonics.setLocalizedText(removeallButton, getBundle("BTN_RemoveAll_2")); // NOI18N
283
removeallButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
284             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
285                 removeallButtonActionPerformed(evt);
286             }
287         });
288
289         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
290         gridBagConstraints.gridx = 2;
291         gridBagConstraints.gridy = 4;
292         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
293         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 12, 0, 12);
294         add(removeallButton, gridBagConstraints);
295
296         scrollpaneLabel.setLabelFor(jList1);
297         org.openide.awt.Mnemonics.setLocalizedText(scrollpaneLabel, getBundle("LAB_222")); // NOI18N
298
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
299         gridBagConstraints.gridx = 3;
300         gridBagConstraints.gridy = 0;
301         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
302         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
303         add(scrollpaneLabel, gridBagConstraints);
304
305         jList1.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
306             public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt) {
307                 jList1MouseClicked(evt);
308             }
309         });
310
311         jScrollPane1.setViewportView(jList1);
312
313         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
314         gridBagConstraints.gridx = 3;
315         gridBagConstraints.gridy = 1;
316         gridBagConstraints.gridwidth = 3;
317         gridBagConstraints.gridheight = 5;
318         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
319         gridBagConstraints.weightx = 1.0;
320         gridBagConstraints.weighty = 1.0;
321         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 0, 0, 0);
322         add(jScrollPane1, gridBagConstraints);
323
324         jPanel3.setLayout(new java.awt.GridLayout JavaDoc(1, 2, 6, 0));
325
326         totalsizeLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
327         totalsizeLabel.setLabelFor(totalsizeTextField);
328         org.openide.awt.Mnemonics.setLocalizedText(totalsizeLabel, getBundle("LAB_223")); // NOI18N
329
jPanel3.add(totalsizeLabel);
330
331         totalsizeTextField.setEditable(false);
332         totalsizeTextField.setDisabledTextColor(java.awt.Color.black);
333         totalsizeTextField.setMinimumSize(new java.awt.Dimension JavaDoc(6, 20));
334         jPanel3.add(totalsizeTextField);
335
336         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
337         gridBagConstraints.gridx = 3;
338         gridBagConstraints.gridy = 6;
339         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
340         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
341         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
342         gridBagConstraints.weightx = 1.0;
343         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
344         add(jPanel3, gridBagConstraints);
345
346         jPanel2.setLayout(new java.awt.GridBagLayout JavaDoc());
347
348         jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
349         avLabel.setLabelFor(avTextField);
350         org.openide.awt.Mnemonics.setLocalizedText(avLabel, getBundle("LAB_224")); // NOI18N
351
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
352         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
353         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 10, 0, 0);
354         jPanel2.add(avLabel, gridBagConstraints);
355
356         avTextField.setEditable(false);
357         avTextField.setDisabledTextColor(java.awt.Color.black);
358         avTextField.setMinimumSize(new java.awt.Dimension JavaDoc(60, 21));
359         avTextField.setPreferredSize(new java.awt.Dimension JavaDoc(60, 21));
360         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
361         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
362         gridBagConstraints.ipadx = 60;
363         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
364         gridBagConstraints.weightx = 1.0;
365         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 6, 0, 0);
366         jPanel2.add(avTextField, gridBagConstraints);
367
368         ivLabel.setLabelFor(ivTextField);
369         org.openide.awt.Mnemonics.setLocalizedText(ivLabel, getBundle("LAB_225")); // NOI18N
370
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
371         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
372         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 12, 0, 0);
373         jPanel2.add(ivLabel, gridBagConstraints);
374
375         ivTextField.setEditable(false);
376         ivTextField.setDisabledTextColor(java.awt.Color.black);
377         ivTextField.setMinimumSize(new java.awt.Dimension JavaDoc(60, 21));
378         ivTextField.setPreferredSize(new java.awt.Dimension JavaDoc(63, 21));
379         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
380         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
381         gridBagConstraints.ipadx = 60;
382         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
383         gridBagConstraints.weightx = 1.0;
384         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 6, 0, 0);
385         jPanel2.add(ivTextField, gridBagConstraints);
386
387         jScrollPane2.setMinimumSize(new java.awt.Dimension JavaDoc(22, 52));
388         description.setEditable(false);
389         jScrollPane2.setViewportView(description);
390
391         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
392         gridBagConstraints.gridx = 0;
393         gridBagConstraints.gridy = 1;
394         gridBagConstraints.gridwidth = 5;
395         gridBagConstraints.gridheight = 2;
396         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
397         gridBagConstraints.weightx = 1.0;
398         gridBagConstraints.weighty = 1.0;
399         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 10, 4, 0);
400         jPanel2.add(jScrollPane2, gridBagConstraints);
401
402         org.openide.awt.Mnemonics.setLocalizedText(moreButton, getBundle("BTN_More")); // NOI18N
403
moreButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
404         moreButton.setIconTextGap(0);
405         moreButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
406             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
407                 moreButtonActionPerformed(evt);
408             }
409         });
410
411         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
412         gridBagConstraints.gridx = 5;
413         gridBagConstraints.gridy = 2;
414         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
415         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 11, 4, 4);
416         jPanel2.add(moreButton, gridBagConstraints);
417
418         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
419         gridBagConstraints.gridx = 0;
420         gridBagConstraints.gridy = 7;
421         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
422         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
423         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
424         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
425         gridBagConstraints.weighty = 1.0;
426         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
427         add(jPanel2, gridBagConstraints);
428
429     }// </editor-fold>//GEN-END:initComponents
430

431     private void moreButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_moreButtonActionPerformed
432
ModuleUpdate mu = getSingleSelection();
433
434         if (mu != null && mu.getHomePage() != null) {
435             HtmlBrowser.URLDisplayer.getDefault().showURL(mu.getHomePage());
436         }
437     }//GEN-LAST:event_moreButtonActionPerformed
438

439     private void removeallButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_removeallButtonActionPerformed
440
for( int i = 0; i < selectedListModel.size(); i++ ) {
441             ((ModuleUpdate)selectedListModel.get(i)).setSelected( false );
442             ((ModuleUpdate)selectedListModel.get(i)).setDownloadOK( false );
443             ((ModuleUpdate)selectedListModel.get(i)).setSecurity( SignVerifier.NOT_CHECKED );
444         }
445         refreshNodes();
446
447         selectedListModel.clear();
448         Downloader.deleteDownload();
449         showSize();
450         validator.setValid( selectedListModel.size() > 0 );
451         
452         buttonsCheck();
453     }//GEN-LAST:event_removeallButtonActionPerformed
454

455     private void addallButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_addallButtonActionPerformed
456
Collection JavaDoc modules = Wizard.getAllModules();
457
458         Iterator JavaDoc it = modules.iterator();
459
460         while ( it.hasNext() ) {
461             ModuleUpdate mu = (ModuleUpdate) it.next();
462             if (mu.isSelected () || !DependencyChecker.checkPlatformDependency (mu.getRemoteModule ())) {
463                 continue;
464             }
465             if ( !addModule (mu) ) {
466                 // Some licence rejected
467
removeallButtonActionPerformed(evt);
468                 return;
469             }
470         }
471         buttonsCheck();
472         
473     }//GEN-LAST:event_addallButtonActionPerformed
474

475     private void removeButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_removeButtonActionPerformed
476
int[] index = jList1.getSelectedIndices();
477
478         if ( index.length == 0 )
479             return;
480         
481         java.util.List JavaDoc toremove = new ArrayList JavaDoc();
482         for (int i = index.length -1; i >= 0 ; i-- )
483             toremove.add( selectedListModel.get( index[i] ));
484         
485         Iterator JavaDoc it = toremove.iterator();
486         while (it.hasNext())
487             removeModule( (ModuleUpdate)it.next() );
488
489         refreshNodes();
490
491         showSize();
492         validator.setValid( selectedListModel.size() > 0 );
493         buttonsCheck();
494     }//GEN-LAST:event_removeButtonActionPerformed
495

496     private void addButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_addButtonActionPerformed
497
Node[] nodes = explorerView.getSelectedNodes();
498         List JavaDoc modulesToAdd = new ArrayList JavaDoc();
499         ModuleUpdate mu = null;
500
501         for ( int i = 0; i < nodes.length; i ++ ) {
502             mu = (ModuleUpdate)nodes[i].getCookie( ModuleUpdate.class );
503             if ( mu != null ) {
504                 modulesToAdd.add( mu );
505             }
506             else {
507                 // Add whole group - subtree
508
modulesToAdd.addAll( getUnselectedChildren( nodes[i] ) );
509             }
510         }
511         
512         Iterator JavaDoc iter = modulesToAdd.iterator();
513         while ( iter.hasNext() ) {
514             mu = (ModuleUpdate)iter.next();
515             if ( !addModule( mu , modulesToAdd ) ) {
516                 return;
517             }
518         }
519
520         buttonsCheck();
521     }//GEN-LAST:event_addButtonActionPerformed
522

523     private void jList1MouseClicked(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jList1MouseClicked
524
if ( evt.getClickCount() == 2 ) {
525             int index = jList1.locationToIndex( evt.getPoint() );
526
527             if ( index >= 0 && index < selectedListModel.size() ) {
528                 removeModule( (ModuleUpdate)selectedListModel.get( index ) );
529                 showSize();
530                 validator.setValid( selectedListModel.size() > 0 );
531                 refreshNodes();
532             }
533             buttonsCheck();
534         }
535     }//GEN-LAST:event_jList1MouseClicked
536

537     // Variables declaration - do not modify//GEN-BEGIN:variables
538
private javax.swing.JButton JavaDoc addButton;
539     private javax.swing.JButton JavaDoc addallButton;
540     private javax.swing.JLabel JavaDoc avLabel;
541     private javax.swing.JTextField JavaDoc avTextField;
542     private javax.swing.JEditorPane JavaDoc description;
543     private javax.swing.JLabel JavaDoc ivLabel;
544     private javax.swing.JTextField JavaDoc ivTextField;
545     private javax.swing.JList JavaDoc jList1;
546     private javax.swing.JPanel JavaDoc jPanel1;
547     private javax.swing.JPanel JavaDoc jPanel2;
548     private javax.swing.JPanel JavaDoc jPanel3;
549     private javax.swing.JScrollPane JavaDoc jScrollPane1;
550     private javax.swing.JScrollPane JavaDoc jScrollPane2;
551     private javax.swing.JButton JavaDoc moreButton;
552     private javax.swing.JLabel JavaDoc panel1Label;
553     private javax.swing.JButton JavaDoc removeButton;
554     private javax.swing.JButton JavaDoc removeallButton;
555     private javax.swing.JLabel JavaDoc scrollpaneLabel;
556     private javax.swing.JLabel JavaDoc totalsizeLabel;
557     private javax.swing.JTextField JavaDoc totalsizeTextField;
558     // End of variables declaration//GEN-END:variables
559

560     void setUpdates( int wizardType ) {
561
562         boolean firstTime = true;
563         
564         allNodes = null;
565         selectedListModel.clear();
566         totalSize = 0;
567         Iterator JavaDoc it = Wizard.getAllModules().iterator();
568
569         while( it.hasNext() ) {
570             ModuleUpdate mu = (ModuleUpdate)it.next();
571             
572             if ( mu.isSelected() && ( !selectedListModel.contains( mu ) ) ) {
573                 selectedListModel.addElement( mu );
574                 totalSize += mu.getDownloadSize();
575             }
576             
577             if ( firstTime ) {
578                 if ( wizardType == 1 || mu.isPurchased() ) {
579                     addModule( mu );
580                 }
581             }
582         }
583         validator.setValid( selectedListModel.size() > 0 );
584
585         totalsizeTextField.setText( ( totalSize / 1024 ) + SPACE + getBundle("CTL_UpdatePanel_KB") );
586
587         buttonsCheck();
588         showSize();
589         
590         javax.swing.SwingUtilities.invokeLater(new Runnable JavaDoc() {
591             public void run() {
592                 refreshNodes();
593             }
594         });
595         
596         nodeListener = new PropertyChangeListener JavaDoc() {
597                             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
598                                 if ( Settings.NODE_DEFAULT_ACTION.equals( evt.getPropertyName() )) {
599                                     // #81687: More modules than desired (NodeDefaultAction is invoked twice. TreeView bug?)
600
final Node[] selectedNodes = explorerView.getSelectedNodes();
601                                     SwingUtilities.invokeLater (new Runnable JavaDoc () {
602                                         public void run () {
603                                             if ( selectedNodes.length == 1 ) {
604                                                 ModuleUpdate mu = (ModuleUpdate)selectedNodes[0].getCookie( ModuleUpdate.class );
605                                                 if ( mu != null )
606                                                     if ( ! addModule( mu ) )
607                                                         buttonsCheck();
608                                             }
609                                         }
610                                     });
611                                 }
612                             }
613                         };
614         Settings.getShared().addPropertyChangeListener( nodeListener );
615     }
616
617     // INNERCLAS ------------------------------------------------------
618
static class ExplorerView extends JComponent JavaDoc implements ExplorerManager.Provider {
619
620         private ExplorerManager em;
621         private BeanTreeView btv;
622
623         static final long serialVersionUID =-5811911993587966912L;
624         ExplorerView( ) {
625             Node waitNode = new UpdateNode.Wait();
626             createContent( waitNode );
627         }
628
629         private void createContent ( Node node ) {
630
631             btv = new BeanTreeView ();
632             btv.setPopupAllowed( false );
633             btv.setDefaultActionAllowed( true );
634             btv.setBorder (UIManager.getBorder ("ScrollPane.border")); // NOI18N
635

636             //sp.add (new org.openide.explorer.view.ListView (), SplittedPanel.ADD_LEFT);
637
setLayout (new java.awt.BorderLayout JavaDoc());
638             add ( java.awt.BorderLayout.CENTER, btv );
639
640             getExplorerManager ().setRootContext ( node );
641
642             btv.setRootVisible( false );
643         }
644
645         public java.awt.Dimension JavaDoc getPreferredSize () {
646             java.awt.Dimension JavaDoc sup = super.getPreferredSize ();
647             return new java.awt.Dimension JavaDoc ( Math.max (sup.width, 450), Math.max (sup.height, 300 ));
648         }
649
650         void expandAll() {
651             expandChildren(getExplorerManager().getRootContext());
652         }
653         
654         public void addNotify () {
655             super.addNotify ();
656             btv.requestFocus ();
657         }
658         
659         private void expandChildren (Node n) {
660             Node[] kids = n.getChildren().getNodes();
661             for (int i=0; i < kids.length; i++) {
662                 if (!kids[i].getDisplayName().startsWith("L10N")) { //NOI18N
663
btv.expandNode(kids[i]);
664                     if (kids[i].getChildren() != Children.LEAF) {
665                         expandChildren(kids[i]);
666                     }
667                 }
668             }
669         }
670
671         Node[] getSelectedNodes() {
672             return getExplorerManager ().getSelectedNodes();
673         }
674
675         public ExplorerManager getExplorerManager () {
676             if (em == null) {
677                 em = new ExplorerManager ();
678                 
679             }
680             return em;
681         }
682
683     }
684
685     private ModuleUpdate getSingleSelection() {
686         if ( jList1.getSelectedIndex() >= 0 )
687             // modules from right panel
688
return ((ModuleUpdate)selectedListModel.get(jList1.getSelectedIndex()));
689         else {
690             // modules from left panel
691
Node[] selectedNodes = explorerView.getSelectedNodes();
692             if ( selectedNodes.length != 1 ) {
693                 return null;
694             }
695             else {
696                 return (ModuleUpdate)selectedNodes[0].getCookie( ModuleUpdate.class );
697             }
698         }
699     }
700
701     private void unselectLeft() {
702         try {
703             explorerView.getExplorerManager().setSelectedNodes( new Node[0]);
704         } catch (java.beans.PropertyVetoException JavaDoc e) {
705         }
706     }
707     
708     private String JavaDoc formatDescription (ModuleUpdate mu) {
709         Date JavaDoc date = mu.getReleaseDate ();
710         String JavaDoc release = date != null ? ModuleUpdate.DATE_FORMAT.format (date) : ""; // NOI18N
711
String JavaDoc author = mu.getModuleAuthor () == null ? "" : mu.getModuleAuthor (); //NOI18N
712

713         // Module size
714
String JavaDoc desc = getBundle ("LAB_226") + SPACE + ( mu.getDownloadSize() / 1024 ) //NOI18N
715
+ SPACE + getBundle("CTL_UpdatePanel_KB") + LINE_SEPARATOR + //NOI18N
716
// Author
717
((author.length () == 0) ? "" : getBundle ("LAB_AuthorName") + SPACE + author + LINE_SEPARATOR) + //NOI18N
718
// Release Date
719
((release.length () == 0) ? "" : getBundle ("LAB_ReleaseDate") + SPACE + release + LINE_SEPARATOR) + //NOI18N
720
// Description
721
mu.getDescription ();
722         return desc;
723     }
724         
725     /** Called when the selection in jList1 or explorerView changes */
726     private void selectionChange( boolean onLeft ) {
727         ModuleUpdate mu;
728         
729         if ( onLeft && explorerView.getSelectedNodes().length > 0) {
730             jList1.clearSelection();
731         }
732         
733         mu = getSingleSelection();
734
735         if ( mu == null ) {
736             ivTextField.setText( EMPTY_STRING );
737             avTextField.setText( EMPTY_STRING );
738             description.setText( EMPTY_STRING );
739         }
740         else {
741             ivTextField.setText( mu.getLocalModule() == null ?
742                                        getBundle( "CTL_UpdatePanel_ModuleNotInstalled" ) :
743                                        (mu.getLocalModule().getSpecificationVersion() == null ?
744                                         "" :
745                                         mu.getLocalModule().getSpecificationVersion().toString()));
746             SpecificationVersion sv = mu.getRemoteModule().getSpecificationVersion();
747             avTextField.setText( sv == null ? "" : sv.toString() );
748             description.setText( formatDescription ( mu ) );
749             description.setCaretPosition (0);
750         }
751         
752         buttonsCheck();
753     }
754
755     private void buttonsCheck() {
756         if ( selectedListModel.getSize() > 0 ) {
757             removeallButton.setEnabled(true);
758             if ( jList1.getSelectedIndex() != -1 )
759                 removeButton.setEnabled(true);
760             else
761                 removeButton.setEnabled(false);
762         } else {
763             removeButton.setEnabled(false);
764             removeallButton.setEnabled(false);
765         }
766         
767         if ( existUnselectedModule() ) {
768             addallButton.setEnabled(true);
769             if ( isLeftSelection() )
770                 addButton.setEnabled(true);
771             else
772                 addButton.setEnabled(false);
773         } else {
774             addButton.setEnabled(false);
775             addallButton.setEnabled(false);
776         }
777         
778         ModuleUpdate mu = getSingleSelection();
779         moreButton.setEnabled(mu != null && mu.getHomePage() != null);
780     }
781     
782     private boolean isLeftSelection() {
783         // modules from left panel
784
Node[] selectedNodes = explorerView.getSelectedNodes();
785         for (int i=0; i<selectedNodes.length; i++)
786             if (selectedNodes[i].getCookie( ModuleUpdate.class ) != null)
787                 return true;
788             else {
789                 // To add whole group - subtree
790
List JavaDoc lst = getUnselectedChildren( selectedNodes[i] );
791                 if ( lst.size() > 0 )
792                     return true;
793             }
794         return false;
795     }
796     
797     /** List of all unselected modules in current group - subtree */
798     private List JavaDoc getUnselectedChildren(Node group) {
799         Node[] nodes = group.getChildren().getNodes();
800         List JavaDoc modlist = new ArrayList JavaDoc();
801         for (int i = 0; i < nodes.length; i++) {
802             if (nodes[i].getCookie( ModuleUpdate.class ) != null) {
803                 ModuleUpdate mu = (ModuleUpdate)nodes[i].getCookie( ModuleUpdate.class );
804                 if ( !mu.isSelected() )
805                     modlist.add( mu );
806             }
807             else {
808                 List JavaDoc lst = getUnselectedChildren( nodes[i] );
809                 if ( lst.size() > 0 )
810                     modlist.addAll( lst );
811             }
812         }
813         return modlist;
814     }
815
816     private boolean addModule( final ModuleUpdate mu ) {
817         return addModule( mu, null );
818     }
819     
820     private boolean addModule( final ModuleUpdate mu, final List JavaDoc group ) {
821         return addModule( mu, group, true );
822     }
823     
824     /** Adds module to selected list. Shows LicenceAgreement if needed.
825      * Increases total size of download. Checks dependencies and adds
826      * all modules needed to satisfy all dependencies.
827      *@return False if the licence was rejected
828      */

829     private boolean addModule( final ModuleUpdate mu, final List JavaDoc group, boolean askForDuplicates ) {
830         if ( selectedListModel.contains( mu ) )
831             return true; // Already in download list
832

833         String JavaDoc prepSpecVersion = PreparedModules.getPrepared().getPreparedVersion( mu.getCodeNameBase() );
834         // is this module prepared
835
if ( prepSpecVersion != null ) {
836             NotifyDescriptor.Confirmation nd =
837                 new NotifyDescriptor.Confirmation(
838                     NbBundle.getMessage( UpdatePanel.class, "MSG_Prepared_Module",
839                                          mu.getName(), prepSpecVersion ),
840                     getBundle( "CTL_Prepared_Title" ),
841                     NotifyDescriptor.YES_NO_OPTION );
842             if ( DialogDisplayer.getDefault().notify( nd ).equals( NotifyDescriptor.YES_OPTION ) ) {
843                 PreparedModules.getPrepared().removeModule( mu.getCodeNameBase() );
844             }
845             else
846                 return true;
847         }
848
849         // already selected from other server
850
boolean remove = false;
851         for( int j = 0; j < selectedListModel.size(); j++ ) {
852             ModuleUpdate mu2 = (ModuleUpdate)selectedListModel.get(j);
853             // bugfix #31764, allow install multiple languages at one time
854
String JavaDoc loc = null;
855             if (mu instanceof L10NUpdate) {
856                 loc = ((L10NUpdate) mu).getLangcode ();
857             }
858             loc = loc == null ? "" : loc; // NOI18N
859
String JavaDoc loc2 = null;
860             if (mu2 instanceof L10NUpdate) {
861                 loc2 = ((L10NUpdate) mu2).getLangcode ();
862             }
863             loc2 = loc2 == null ? "" : loc2; // NOI18N
864
if ( mu2.getCodeNameBase().equals( mu.getCodeNameBase() )
865                     && loc2.equals( loc ) ) { // l10n update isn't duplicate
866
if ( askForDuplicates ) {
867                     if ( duplicateStatus == DuplicateWarningDialog.YES_ALL )
868                         remove = true;
869                     else if ( duplicateStatus == DuplicateWarningDialog.NO_ALL )
870                         return true;
871                     else {
872                         final java.awt.Dialog JavaDoc warnDialog = DuplicateWarningDialog.getDialog(mu.getName());
873                         warnDialog.setVisible (true);
874                         duplicateStatus = DuplicateWarningDialog.getResult();
875                         if ( duplicateStatus == DuplicateWarningDialog.YES ||
876                                 duplicateStatus == DuplicateWarningDialog.YES_ALL )
877                             remove = true;
878                         else
879                             return true;
880                     }
881                 }
882                 else
883                     remove = true;
884             }
885             if ( remove ) {
886                 removeModule( mu2, mu );
887                 break;
888             }
889         }
890
891         // View module notification if exists
892
if ( mu.getNotification() != null && mu.getNotification().length() > 0
893                 && !mu.getNotificationAccepted() ) {
894             if ( Notification.performModuleNotification( mu.getNotification() ) ) {
895                 mu.setNotificationAccepted( true );
896             } else {
897                 return false;
898             }
899         }
900         
901         List JavaDoc ext_list = mu.getExternals();
902         if ( ext_list != null ) {
903             Iterator JavaDoc it = ext_list.iterator();
904             while ( it.hasNext() )
905                 ExternalDialog.showExternal( mu.getName(), (ModuleUpdate.External)it.next() );
906         }
907
908         // Module not selected yet and licence accepted
909

910         DependencyChecker dc = new DependencyChecker();
911         StringBuffer JavaDoc dontAddModuleName = new StringBuffer JavaDoc();
912         Collection JavaDoc modulesToAdd = dc.modulesToAdd( mu, selectedListModel.elements(), group, dontAddModuleName );
913         if ( dontAddModuleName.length() > 0 )
914             return false;
915         
916         selectedListModel.add( findPosition( mu ), mu );
917
918         Iterator JavaDoc it = modulesToAdd.iterator();
919         while( it.hasNext() ) {
920             ModuleUpdate addMu = (ModuleUpdate)it.next();
921             if ( !addModule( addMu, null, false ) ) {
922                 selectedListModel.removeElement( mu );
923                 totalSize += mu.getDownloadSize();
924                 return false;
925             }
926         }
927
928         showSize();
929         validator.setValid( selectedListModel.size() > 0 );
930         jList1.revalidate();
931         
932         mu.setSelected( true );
933         refreshNodes();
934         
935         return true;
936     }
937
938     /** Shows LicenceAgreement if needed.
939      *@return False if the licence was rejected
940      */

941     boolean checkLicencies() {
942         ModuleUpdate mu;
943         for( int i = 0; i < selectedListModel.size(); i++ ) {
944             mu = (ModuleUpdate)selectedListModel.get(i);
945
946             if ( mu.getLicenceText() != null && mu.getLicenceID() != null ) {
947
948                 // Test if the licence was already accepted
949
if (!acceptedLicencies.contains (mu.getLicenceID ())) {
950                     if (LicenceDialog.acceptLicence (mu.getLicenceText ())) {
951                         acceptedLicencies.add (mu.getLicenceID ());
952                     } else {
953                         return false;
954                     }
955                 }
956             }
957         }
958         return true;
959     }
960     
961     /** Finds the right position of the module in the modules list */
962     private int findPosition( ModuleUpdate mu ) {
963         int pos = 0;
964
965         Collection JavaDoc modules = Wizard.getAllModules();
966         Iterator JavaDoc it = modules.iterator();
967         while ( it.hasNext() ) {
968
969             ModuleUpdate imu = ((ModuleUpdate)it.next());
970
971             if ( mu == imu ) {
972                 return pos;
973             }
974             if ( selectedListModel.contains( imu ) ) {
975                 pos++;
976             }
977         }
978
979         return pos;
980     }
981
982     private void removeModule( final ModuleUpdate mu ) {
983         removeModule( mu, null );
984     }
985     
986     /** Removes module at position <CODE>index</CODE>. Decreases total
987      * size of download. Checks all dependencies and removes all dependent
988      * modules.
989      */

990     private void removeModule( final ModuleUpdate mu, ModuleUpdate toReplace ) {
991
992         if ( !selectedListModel.contains( mu ) )
993             return; // is not selected
994

995         final int index = selectedListModel.indexOf ( mu );
996         totalSize -= mu.getDownloadSize();
997
998         selectedListModel.remove( index );
999         if ( mu.isDownloadStarted() )
1000            Downloader.deleteModuleNBM( mu );
1001
1002        DependencyChecker dc = new DependencyChecker();
1003        Collection JavaDoc modulesToRemove = dc.modulesToRemove( mu, toReplace );
1004        Iterator JavaDoc it = modulesToRemove.iterator();
1005        while( it.hasNext() ) {
1006            ModuleUpdate removeMu = (ModuleUpdate)it.next();
1007            removeModule( removeMu );
1008        }
1009
1010        mu.setSelected( false );
1011        mu.setDownloadOK( false );
1012        mu.setSecurity( SignVerifier.NOT_CHECKED );
1013    }
1014
1015    void showSize() {
1016        totalSize = 0;
1017
1018        for( int i = 0; i < selectedListModel.size(); i++ ) {
1019            if ( !((ModuleUpdate)selectedListModel.get(i)).isDownloadOK() ) {
1020                totalSize += ((ModuleUpdate)selectedListModel.get(i)).getDownloadSize();
1021            }
1022        }
1023
1024        totalsizeTextField.setText( ( totalSize / 1024 ) + SPACE + getBundle("CTL_UpdatePanel_KB") );
1025    }
1026
1027    int modulesToDownload() {
1028        int result = 0;
1029
1030        for( int i = 0; i < selectedListModel.size(); i++ ) {
1031            if ( !((ModuleUpdate)selectedListModel.get(i)).isDownloadOK()
1032                  ||((ModuleUpdate)selectedListModel.get(i)).isNotChecked()) {
1033                result++;
1034            }
1035        }
1036
1037        return result;
1038    }
1039
1040    private boolean existUnselectedModule() {
1041        Collection JavaDoc modules = Wizard.getAllModules();
1042        Iterator JavaDoc it = modules.iterator();
1043        while ( it.hasNext() )
1044            if ( ! ((ModuleUpdate)it.next()).isSelected() )
1045                return true;
1046        return false;
1047    }
1048    
1049    void markSelectedModules() {
1050
1051        // We have firts to unmark all modules
1052
Collection JavaDoc modules = Wizard.getAllModules();
1053        Iterator JavaDoc it = modules.iterator();
1054        while ( it.hasNext() ) {
1055            ((ModuleUpdate)it.next()).setSelected( false );
1056        }
1057
1058        // Then mark the selected
1059

1060        for( int i = 0; i < selectedListModel.size(); i++ ) {
1061            ((ModuleUpdate)selectedListModel.get(i)).setSelected( true );
1062        }
1063    }
1064    
1065    private void refreshNodes() {
1066        if ( allNodes == null ) {
1067            allNodes = UpdateNode.getAllServers();
1068            explorerView.getExplorerManager ().setRootContext (allNodes);
1069            explorerView.expandAll();
1070            Runnable JavaDoc makeVisible = new Runnable JavaDoc () {
1071                public void run () {
1072                    if (! allNodes.isLeaf ()) {
1073                        explorerView.getExplorerManager ().setExploredContext (allNodes.getChildren ().getNodes ()[0]);
1074                    }
1075                }
1076            };
1077            RequestProcessor.getDefault ().post (makeVisible, 300);
1078        }
1079        else
1080            allNodes.refreshContent( true );
1081    }
1082    
1083    void removeListeners() {
1084        if ( nodeListener != null )
1085            Settings.getShared().removePropertyChangeListener( nodeListener );
1086    }
1087    
1088    private static String JavaDoc getBundle( String JavaDoc key ) {
1089        return NbBundle.getMessage( UpdatePanel.class, key );
1090    }
1091}
1092
Popular Tags