KickJava   Java API By Example, From Geeks To Geeks.

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


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.Dialog JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.Dimension JavaDoc;
25 import java.beans.PropertyChangeListener JavaDoc;
26 import java.beans.PropertyChangeEvent JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Enumeration JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.Set JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.HashSet JavaDoc;
35 import javax.swing.event.EventListenerList JavaDoc;
36 import java.io.File JavaDoc;
37 import java.util.logging.Level JavaDoc;
38 import java.util.logging.Logger JavaDoc;
39 import javax.swing.JPanel JavaDoc;
40
41 import org.openide.WizardDescriptor;
42 import org.openide.NotifyDescriptor;
43 import org.openide.DialogDescriptor;
44 import org.openide.DialogDisplayer;
45 import org.openide.awt.StatusDisplayer;
46 import org.openide.util.HelpCtx;
47 import org.openide.util.NbBundle;
48 import org.openide.util.RequestProcessor;
49
50 /** Implements the behavior of AutoUpdate wizard
51  *
52  * @author Petr Hrebejk
53  * @version
54  */

55 public class Wizard extends Object JavaDoc implements WizardDescriptor.Iterator {
56
57     /** Structure of the updates */
58     private Updates updates;
59
60     /** pairs AutoupdateType, Updates */
61     private static HashMap JavaDoc allUpdates = new HashMap JavaDoc();
62     
63     private static int errorType = Updates.NO_ERROR;
64     private static String JavaDoc errorMessage;
65     
66     private static RequestProcessor processor;
67     private static final Logger JavaDoc LOG = Logger.getLogger ("org.netbeans.modules.autoupdate.Wizard"); // NOI18N
68

69     /** Panels of the wizard */
70     private WizardPanel[][] panels = new WizardPanel[][] {
71                                          { new StartPanel(),
72                                            new PropPanel(),
73                                            null,
74                                            new ConfigPanel(),
75                                            new DownloadPanel(),
76                                            new LastPanel()
77                                          },
78
79                                          { null,
80                                            null,
81                                            new SelectPanel(),
82                                            null,
83                                            null,
84                                            null
85                                          }
86                                      };
87
88     /** Current panel */
89     private int current = 0;
90
91     private int modulesOK = 0;
92
93     private boolean canceled = false;
94
95     /** Which type of wizard should run */
96     private int wizardType = 0;
97
98     /** The wizard descriptor */
99     private WizardDescriptor wizardDescriptor;
100     
101     private List JavaDoc auTypesWithCust = new ArrayList JavaDoc();
102     
103     private HashMap JavaDoc installNow = new HashMap JavaDoc();
104
105     Wizard() {
106         this( null );
107     }
108
109     /** Creates the wizard */
110     Wizard( HashMap JavaDoc allUpd ) {
111         this( allUpd, 0 );
112     }
113     
114     private PropertyChangeListener JavaDoc updater_listener =
115             new PropertyChangeListener JavaDoc() {
116                 public void propertyChange(PropertyChangeEvent JavaDoc event) {
117                     if (event.getPropertyName().equals("FINISHED")) {
118                         Wizard.this.updaterFinished();
119                     }
120                 }
121             };
122     
123     private void updaterFinished() {
124         if ( SafeModule.write( installNow ) ) {
125             final String JavaDoc message = getBundle( "MSG_Install_Finished" ); // NOI18N
126
StatusDisplayer.getDefault().setStatusText(message);
127             
128             // 64096: remove a lost Waiting ... message
129
RequestProcessor.getDefault ().post (new Runnable JavaDoc () {
130                 public void run () {
131                     if (message.equals (StatusDisplayer.getDefault ().getStatusText ())) {
132                         StatusDisplayer.getDefault ().setStatusText (""); // NOI18N
133
}
134                 }
135             }, 5000);
136         }
137         else
138             finishDialog( true );
139     }
140     
141     private void finishDialog(boolean all) {
142         if ( FinishDialog.showDialog() ) {
143             Collection JavaDoc modules = getAllModules();
144             Iterator JavaDoc it = modules.iterator();
145             while( it.hasNext() ) {
146                 ModuleUpdate mu = (ModuleUpdate)it.next();
147
148                 if ( mu.isInstallApproved() && mu.isDownloadOK() && ( all || !mu.isSafeToInstall() ) ) {
149                     if (!mu.isSafeToInstall () && mu.isToInstallDir ()) {
150                         if ( !Downloader.tryMove( mu ) ) {
151                             try {
152                                 mu.setToInstallDir( false );
153                             } catch (IllegalArgumentException JavaDoc iae) {
154                                 LOG.log(Level.WARNING, null, iae);
155                             }
156                         }
157                     }
158                     
159                     PreparedModules.getPrepared().addModule( mu );
160                 }
161             }
162             if ( FinishDialog.isRestart() ) {
163                 PreparedModules.getPrepared().delete();
164                 Autoupdater.restart();
165             }
166             else {
167                 PreparedModules.getPrepared().write();
168             }
169         }
170         else {
171             Downloader.deleteDownload();
172         }
173     }
174     
175     /** Creates the wizard */
176     Wizard( HashMap JavaDoc allUpd, int wizardType ) {
177         
178         this.wizardType = wizardType;
179
180         // Create the wizard
181

182         PropertyChangeListener JavaDoc listener = new PropertyChangeListener JavaDoc() {
183                                               public void propertyChange(PropertyChangeEvent JavaDoc event) {
184                                                   if (event.getPropertyName().equals(DialogDescriptor.PROP_VALUE)) {
185                                                       Object JavaDoc option = event.getNewValue();
186
187                                                       if (option == WizardDescriptor.FINISH_OPTION ||
188                                                               option == NotifyDescriptor.CANCEL_OPTION ||
189                                                               option == NotifyDescriptor.CLOSED_OPTION) {
190                                                           if ( option != WizardDescriptor.FINISH_OPTION ) {
191                                                               canceled = true;
192                                                               Downloader.deleteDownload();
193                                                           }
194                                                           getCurrent().end( true );
195                                                           Autoupdater.Support.deleteTempDir();
196                                                           allUpdates.clear();
197                                                       }
198                                                   }
199                                               }
200                                           };
201
202         Updates.reset();
203         if ( allUpd != null ) {
204             int ist = 3;
205             
206             allUpdates = allUpd;
207             current = ist;
208             if ( wizardType == 0 )
209                 panels[0][ist].start( true );
210         }
211
212         wizardDescriptor = new WizardDescriptor( this );//, new Object() );
213
wizardDescriptor.setModal( false );
214         wizardDescriptor.setTitle(getBundle( "CTL_Wizard"));
215         wizardDescriptor.setTitleFormat (new java.text.MessageFormat JavaDoc (" {0}")); // NOI18N
216
wizardDescriptor.setAdditionalOptions (new Object JavaDoc[] { });
217         wizardDescriptor.addPropertyChangeListener(listener);
218         wizardDescriptor.putProperty ("WizardPanel_helpDisplayed", Boolean.FALSE);
219         wizardDescriptor.setOptions (new Object JavaDoc[] {
220                                          WizardDescriptor.PREVIOUS_OPTION,
221                                          WizardDescriptor.NEXT_OPTION,
222                                          WizardDescriptor.FINISH_OPTION,
223                                          NotifyDescriptor.CANCEL_OPTION } );
224     }
225     
226     /** Runs the wizard */
227     static void go( HashMap JavaDoc allUpd ) {
228         go( allUpd, 0 );
229     }
230      
231     /** Runs the wizard */
232     static Wizard go( HashMap JavaDoc allUpd, int wizardType ) {
233         
234         Wizard wizard = new Wizard ( allUpd, wizardType );
235         wizard.startDialog();
236         
237         return wizard;
238     }
239     
240     void refreshUpdatePanel() {
241         if ( current == 3 )
242             panels[0][current].start( true );
243     }
244     
245     /** Runs the wizard */
246     public static void go() {
247         new Wizard ().startDialog ();
248     }
249     
250     private void startDialog() {
251         Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog( wizardDescriptor );
252
253         canceled = false;
254
255         dialog.setVisible (true);
256         dialog.toFront();
257     }
258     
259     // Implementation of Iterator --------------------------------------------------------
260

261     public String JavaDoc name() {
262         return getCurrent().getName();
263     }
264
265     public WizardDescriptor.Panel current() {
266
267         return getCurrent();
268         /*
269         return panels[ wizardType ][ current ] == null ?
270           panels[ 0 ][ current ] : panels[ wizardType ][ current ];
271         */

272     }
273
274     private WizardPanel getCurrent() {
275
276         return panels[ wizardType ][ current ] == null ?
277                panels[ 0 ][ current ] : panels[ wizardType ][ current ];
278     }
279
280     public boolean hasNext() {
281
282         if ( current == 1 && getCurrent().nextPanelOffset() == -1 )
283             return false;
284         else
285             return current < panels[wizardType].length - 1;
286     }
287
288     public boolean hasPrevious() {
289
290         return current > 0;
291     }
292
293     public void nextPanel() {
294
295         getCurrent().end( true );
296
297         if ( current < 0 && wizardType == 0 )
298             current = current + 2;
299         else if ( current == 0 && wizardType == 1 )
300             current = 2;
301         else if ( current == 0 && wizardType == 0 && auTypesWithCust.size() == 0 )
302             current = 3;
303         else if ( current == 1 && wizardType == 0 && auTypesWithCust.size() == 0 )
304             current = current + 2;
305         else if ( current == 1 && wizardType == 0 && auTypesWithCust.size() > 0 )
306             current = 1;
307         else if ( current == 3 && getCurrent().nextPanelOffset() == 2 )
308             current = 5;
309         else
310             current ++;
311
312         getCurrent().start( true );
313
314         //centerDialog();
315
}
316
317     public void previousPanel() {
318
319         getCurrent().end( false );
320
321         switch ( current ) {
322         case 2:
323             if ( wizardType == 1 )
324                 current = 0;
325             else
326                 current--;
327             break;
328         case 3:
329             if ( wizardType == 0 )
330                 current = 0;
331             else
332                 current--;
333             break;
334         case 5:
335             current = 3;
336             break;
337         default:
338             current --;
339             break;
340         }
341
342         getCurrent().start( false );
343         //centerDialog();
344
}
345
346     public synchronized void addChangeListener(javax.swing.event.ChangeListener JavaDoc listener) {}
347     public synchronized void removeChangeListener(javax.swing.event.ChangeListener JavaDoc listener) {}
348
349     static HashMap JavaDoc getAllUpdates() {
350         return allUpdates;
351     }
352     
353     static void setAllUpdates(HashMap JavaDoc allUpd) {
354         allUpdates = allUpd;
355     }
356     
357     static Collection JavaDoc getAllModules() {
358         Set JavaDoc ret = new HashSet JavaDoc();
359         Iterator JavaDoc it = getAllUpdates().values().iterator();
360         while (it.hasNext()) {
361             Object JavaDoc modules = ((Updates)it.next()).getModules();
362             if (modules != null) {
363                 ret.addAll((Collection JavaDoc)modules);
364             }
365         }
366         return ret;
367     }
368     
369     static RequestProcessor getRequestProcessor() {
370         if ( processor == null )
371             processor = new RequestProcessor();
372         return processor;
373     }
374     
375     private static String JavaDoc getBundle( String JavaDoc key ) {
376         return NbBundle.getMessage( Wizard.class, key );
377     }
378     
379     // Inner classes ----------------------------------------------------------------------
380

381     static interface Validator {
382
383         // Called from component when the next button should be enabled or disbled
384
public void setValid( boolean valid );
385
386     }
387
388     abstract class WizardPanel implements WizardDescriptor.Panel, Validator {
389
390         protected Dimension JavaDoc WIZARD_SIZE = new Dimension JavaDoc( 550, 400 );
391
392         protected boolean valid = true;
393
394         /** Utility field used by event firing mechanism. */
395         private EventListenerList JavaDoc listenerList = new EventListenerList JavaDoc();
396
397         void start( boolean forward ) {}
398
399         void end( boolean forward ) { }
400
401         /** Called to get offset of the new panel */
402         int nextPanelOffset() {
403             return 1;
404         }
405
406         abstract String JavaDoc getName();
407
408         // Implementation of Validator
409

410         public void setValid(boolean valid) {
411             this.valid = valid;
412             fireChangeListenerStateChanged( this );
413         }
414
415         // Implementation of WizardDescriptor.Panel
416

417         public boolean isValid() {
418             return valid;
419         }
420
421         public HelpCtx getHelp() {
422             return null;
423         }
424
425         public abstract Component JavaDoc getComponent();
426
427         public void readSettings( Object JavaDoc settings ) {}
428
429         public void storeSettings( Object JavaDoc settings ) {}
430
431         /** Registers ChangeListener to receive events.
432          *@param listener The listener to register.
433          */

434         public synchronized void addChangeListener(javax.swing.event.ChangeListener JavaDoc listener) {
435             listenerList.add (javax.swing.event.ChangeListener JavaDoc.class, listener);
436         }
437
438         /** Removes ChangeListener from the list of listeners.
439          *@param listener The listener to remove.
440          */

441         public synchronized void removeChangeListener(javax.swing.event.ChangeListener JavaDoc listener) {
442             listenerList.remove (javax.swing.event.ChangeListener JavaDoc.class, listener);
443         }
444
445         /** Notifies all registered listeners about the event.
446          *
447          *@param param1 Parameter #1 of the <CODE>ChangeEvent<CODE> constructor.
448          */

449         protected void fireChangeListenerStateChanged(java.lang.Object JavaDoc param1) {
450             javax.swing.event.ChangeEvent JavaDoc e = null;
451             Object JavaDoc[] listeners = listenerList.getListenerList ();
452             for (int i = listeners.length-2; i>=0; i-=2) {
453                 if (listeners[i]==javax.swing.event.ChangeListener JavaDoc.class) {
454                     if (e == null)
455                         e = new javax.swing.event.ChangeEvent JavaDoc (param1);
456                     ((javax.swing.event.ChangeListener JavaDoc)listeners[i+1]).stateChanged (e);
457                 }
458             }
459         }
460     }
461
462     class StartPanel extends WizardPanel {
463
464         FirstPanel firstPanel;
465         
466         String JavaDoc getName() {
467             return getBundle( "CTL_StartPanel");
468         }
469
470         /** In this case set valid is used for setting the right wizard type
471         */

472         public void setValid( boolean valid ) {
473             wizardType = ((FirstPanel)getComponent ()).getWizardType();
474         }
475
476         public Component JavaDoc getComponent() {
477             if (firstPanel == null) {
478                 firstPanel = new FirstPanel( this ) {
479                     public Dimension JavaDoc getPreferredSize() {
480                         return WIZARD_SIZE;
481                     }
482                 };
483             }
484             return firstPanel;
485         }
486         
487         public HelpCtx getHelp() {
488             return null;
489             //return new HelpCtx( org.netbeans.modules.autoupdate.FirstPanel.class );
490
}
491
492         void end( boolean forward ) {
493             allUpdates.clear();
494             auTypesWithCust.clear();
495             resetErrorStore ();
496             
497             Downloader.deleteDownload();
498             if ( wizardType == 0 ) {
499                 if ( !canceled ) {
500                     int sum = 0;
501                     Enumeration JavaDoc en = AutoupdateType.autoupdateTypes();
502                     // check all autoupdates in sequence
503
while (en.hasMoreElements()) {
504                         AutoupdateType at = (AutoupdateType)en.nextElement();
505                         boolean hasCust = false;
506                         if (at.isEnabled()) {
507                             try {
508                                 if (java.beans.Introspector.getBeanInfo(at.getClass())
509                                         .getBeanDescriptor().getCustomizerClass() != null) {
510                                     auTypesWithCust.add(at);
511                                     sum ++;
512                                     hasCust = true;
513                                 }
514                             } catch (Exception JavaDoc e) {
515                             }
516                             if (! hasCust) {
517                                 updates = at.connectForUpdates();
518                                 updates.checkUpdates( this, at );
519                                 int res = checkConnect(updates, at);
520                                 if ( res == ConnectingDialog.OK ) {
521                                     sum ++;
522                                     allUpdates.put(at, updates);
523                                 } else if ( res == ConnectingDialog.CANCEL ) {
524                                     current = -2;
525                                     return;
526                                 }
527                             }
528                         }
529                     }
530                     if (sum == 0){
531                         if (isErrorStored ()) {
532                             ConnectingErrorDialog.showDialog(errorType, errorMessage);
533                         } else {
534                             ConnectingErrorDialog.showDialog(Updates.NO_SERVER_ERROR, null);
535                         }
536                         current = -2;
537                         return;
538                     }
539                 }
540             }
541         }
542     }
543     
544     class PropPanel extends WizardPanel {
545
546         LoginPanel lPanel;
547         AutoupdateType currentAT;
548         JPanel JavaDoc custPanel;
549         
550         HelpCtx userHelp = null;
551         
552         String JavaDoc getName() {
553             return getBundle( "CTL_StartPanel");
554         }
555
556         /** In this case set valid is used for setting the right wizard type
557         */

558         public void setValid( boolean valid ) {
559         }
560
561         public Component JavaDoc getComponent() {
562             if (lPanel == null) {
563                 lPanel = new LoginPanel( this ) {
564                     public Dimension JavaDoc getPreferredSize() {
565                         return WIZARD_SIZE;
566                     }
567                 };
568             }
569             return lPanel;
570         }
571
572         public HelpCtx getHelp() {
573             if ( userHelp != null )
574                 return userHelp;
575             else
576                 return null;
577                 //return new HelpCtx( org.netbeans.modules.autoupdate.LoginPanel.class );
578
}
579         
580         void start( boolean forward ) {
581             if ( custPanel != null )
582                 return;
583             currentAT = (AutoupdateType)auTypesWithCust.get(0);
584             userHelp = null;
585             try {
586                 custPanel = (javax.swing.JPanel JavaDoc)(java.beans.Introspector.getBeanInfo(currentAT.getClass())
587                     .getBeanDescriptor().getCustomizerClass().newInstance());
588                 ((LoginPanel)getComponent ()).setCustomizer(custPanel, currentAT);
589                 userHelp = (HelpCtx) custPanel.getClientProperty( "Autoupdate_HelpID" ); // NOI18N
590
} catch (Exception JavaDoc e) {
591             }
592         }
593         
594         void end( boolean forward ) {
595             //System.out.println("Ending start" ); // NOI18N
596
if ( wizardType == 0 ) {
597                 Downloader.deleteDownload();
598                 if ( !canceled && forward ) {
599                     updates = currentAT.connectForUpdates();
600                     updates.checkUpdates( this, currentAT );
601                     int res = checkConnect(updates, currentAT);
602                     if ( res == ConnectingDialog.OK )
603                         allUpdates.put(currentAT, updates);
604                     else if ( res == ConnectingDialog.CANCEL ) {
605                         if ( updates.isError() ) {
606                             current = -1;
607                             return;
608                         }
609                         else
610                             current = -2;
611                     }
612                 }
613                 auTypesWithCust.remove(0);
614                 custPanel = null;
615             }
616         }
617
618     }
619     
620     static void resetErrorStore () {
621         errorMessage = null;
622         errorType = Updates.NO_ERROR;
623     }
624     
625     static private void storeError (int type, String JavaDoc msg) {
626         if (type == Updates.NO_ERROR) {
627             throw new IllegalArgumentException JavaDoc ("Type Updates.NO_ERROR is not error.");
628         }
629         errorType = type;
630         errorMessage = msg;
631     }
632     
633     static boolean isErrorStored () {
634         return errorType != Updates.NO_ERROR;
635     }
636     
637     static int getStoredErrorType () {
638         return errorType;
639     }
640     
641     static String JavaDoc getStoredErrorMessage () {
642         return errorMessage;
643     }
644     
645     static int checkConnect(Updates updates, AutoupdateType at) {
646         if (ConnectingDialog.isCanceled()) {
647             return ConnectingDialog.CANCEL;
648         }
649         else if (ConnectingDialog.isSkipped()) {
650             return ConnectingDialog.SKIP;
651         }
652         else if ( updates.isError() ) {
653             storeError (updates.getError(), updates.getErrorMessage ());
654             return ConnectingDialog.SKIP;
655         }
656         else if ( updates.getModules() != null && updates.getModules().size() > 0 )
657             Notification.performNotification( updates, at );
658         return ConnectingDialog.OK;
659     }
660
661     class ConfigPanel extends WizardPanel {
662
663         private UpdatePanel updatePanel = null;
664
665         String JavaDoc getName() {
666             return getBundle( "CTL_ConfigPanel");
667         }
668
669         public Component JavaDoc getComponent() {
670             if (updatePanel == null) {
671                 updatePanel = new UpdatePanel( this ) {
672                     public Dimension JavaDoc getPreferredSize() {
673                         return WIZARD_SIZE;
674                     }
675                 };
676             }
677             return updatePanel;
678         }
679
680         public HelpCtx getHelp() {
681             return null;
682             //return new HelpCtx( org.netbeans.modules.autoupdate.UpdatePanel.class );
683
}
684         
685         public boolean isValid() {
686             return valid;
687         }
688
689         void start( boolean forward ) {
690             valid = false;
691             if ( forward ) {
692                 PreparedModules.readPrepared();
693                 if (wizardType == 0) {
694                     Iterator JavaDoc atypes = allUpdates.keySet().iterator();
695                     while ( atypes.hasNext() ) {
696                         AutoupdateType at = (AutoupdateType)atypes.next();
697                         Updates upd = (Updates)allUpdates.get( at );
698                         at.setLastTimeStamp( upd.getTimeStamp() );
699                     }
700                 }
701             }
702             ((UpdatePanel)getComponent ()).setUpdates( wizardType );
703         }
704
705         void end( boolean forward ) {
706             if ( forward ) {
707                 ((UpdatePanel)getComponent ()).markSelectedModules();
708                 if ( !canceled )
709                     if ( !((UpdatePanel)getComponent ()).checkLicencies() )
710                         current--;
711             }
712             ((UpdatePanel)getComponent ()).removeListeners();
713         }
714
715         int nextPanelOffset() {
716             if ( ((UpdatePanel)getComponent ()).modulesToDownload() == 0 )
717                 return 2;
718             else
719                 return 1;
720         }
721         
722         void setUpdates(HashMap JavaDoc allUpd) {
723             allUpdates.clear();
724             allUpdates = allUpd;
725         }
726
727     }
728
729     class DownloadPanel extends WizardPanel {
730
731         private Downloader downloader;
732         private SignVerifier signVerifier;
733
734         private DownloadProgressPanel progressPanel = null;
735
736         private boolean isDownloadFinished;
737
738         String JavaDoc getName() {
739             return getBundle( wizardType == 0 ? "CTL_DownloadPanel" : "CTL_CopyPanel" ); // NOI18N
740
}
741
742         public Component JavaDoc getComponent() {
743             if (progressPanel == null) {
744                 progressPanel = new DownloadProgressPanel(this) {
745                     public Dimension JavaDoc getPreferredSize() {
746                         return WIZARD_SIZE;
747                     }
748                 };
749             }
750             return ( Component JavaDoc )progressPanel;
751         }
752         
753         public HelpCtx getHelp() {
754             return null;
755             //return new HelpCtx( org.netbeans.modules.autoupdate.DownloadProgressPanel.class );
756
}
757
758         void start( boolean forward ) {
759             valid = false;
760             isDownloadFinished = false;
761             // needs to re-initialize DownloadProgressPanel when Back->Next - problem with the progress components
762
progressPanel = null;
763             downloader = new Downloader( ((DownloadProgressPanel)getComponent ()), this, wizardType == 0 );
764             downloader.doDownload();
765             // Sign verifier is called in setValid function
766
}
767
768         void end( boolean forward ) {
769             if ( !valid ) {
770                 if ( !isDownloadFinished ) {
771                     downloader.cancelDownload();
772                 } else {
773                     if (signVerifier != null) {
774                         signVerifier.cancelVerify( canceled );
775                     }
776                 }
777             }
778         }
779
780     }
781
782     class LastPanel extends WizardPanel {
783
784         ResultsPanel resultsPanel;
785
786         String JavaDoc getName() {
787             return getBundle( wizardType == 0 ? "CTL_ResultsPanel" : "CTL_ResultsPanel_1"); // NOI18N
788
}
789
790         public Component JavaDoc getComponent() {
791             if (resultsPanel == null) {
792                 resultsPanel = new ResultsPanel( this ) {
793                     public Dimension JavaDoc getPreferredSize() {
794                         return WIZARD_SIZE;
795                     }
796                 };
797             }
798             return resultsPanel;
799         }
800
801         public HelpCtx getHelp() {
802             return null;
803             //return new HelpCtx( org.netbeans.modules.autoupdate.ResultsPanel.class );
804
}
805         
806         void start( boolean forward ) {
807             modulesOK = ((ResultsPanel)getComponent ()).generateResults();
808         }
809         
810         void end( boolean forward ) {
811             if ( wizardDescriptor.getValue() == WizardDescriptor.FINISH_OPTION
812                 && modulesOK > 0 ) {
813
814                 Collection JavaDoc modules = getAllModules();
815                 Iterator JavaDoc it = modules.iterator();
816                 installNow = new HashMap JavaDoc();
817                 int otherCount = 0;
818                 while( it.hasNext() ) {
819                     ModuleUpdate mu = (ModuleUpdate)it.next();
820
821                     if ( mu.isDownloadOK() && Downloader.getNBM( mu ).exists() ) {
822                         if ( !mu.isInstallApproved() ) {
823                             Downloader.getNBM( mu ).delete();
824                             Downloader.getNBM( mu ).deleteOnExit();
825                         } else {
826                             if ( mu.isSafeToInstall() ) {
827                                 if ( mu.isToInstallDir() )
828                                     if ( !Downloader.tryMove( mu ) ) {
829                                         try {
830                                             mu.setToInstallDir( false );
831                                         } catch (IllegalArgumentException JavaDoc iae) {
832                                             LOG.log(Level.WARNING, null, iae);
833                                         }
834                                     }
835                                 installNow.put( mu, Downloader.getMovedNBM( mu ) );
836                             }
837                             else {
838                                 otherCount++;
839                             }
840                         }
841                     }
842                 }
843                 
844                 Autoupdater.Support.deleteTempDir();
845                 modulesOK = 0;
846                 
847                 if ( installNow.size() > 0 && otherCount == 0 ) {
848                     File JavaDoc[] filesInstallNow = new File JavaDoc[]{};
849                     filesInstallNow = (File JavaDoc[])installNow.values().toArray(filesInstallNow);
850                     org.netbeans.updater.UpdaterFrame.runFromIDE (filesInstallNow, updater_listener, NbBundle.getBranding ());
851                 }
852                 else if ( otherCount > 0 ) {
853                     finishDialog( false );
854                 }
855                 else {
856                     DialogDisplayer.getDefault().notify(
857                         new NotifyDescriptor.Message(
858                             getBundle( "MSG_WizardNoNbms"),
859                             NotifyDescriptor.WARNING_MESSAGE
860                         )
861                     );
862                 }
863             }
864         }
865     }
866
867     // Panels for installing manualy downloaded modules ---------
868

869     class SelectPanel extends WizardPanel {
870
871         private SelectModulesPanel selectModulesPanel = null;
872
873         String JavaDoc getName() {
874             return getBundle( "CTL_SelectModulesPanel");
875         }
876
877         public Component JavaDoc getComponent() {
878             if (selectModulesPanel == null) {
879                 selectModulesPanel = new SelectModulesPanel( this ) {
880                     public Dimension JavaDoc getPreferredSize() {
881                         return WIZARD_SIZE;
882                     }
883                 };
884             }
885             return selectModulesPanel;
886         }
887         
888         public HelpCtx getHelp() {
889             return null;
890             //return new HelpCtx( org.netbeans.modules.autoupdate.SelectModulesPanel.class );
891
}
892
893         void start( boolean forward ) {
894             valid = false;
895             if ( forward )
896                 ((SelectModulesPanel)getComponent ()).reset();
897             else
898                 setValid( true );
899         }
900
901         void end( boolean forward ) {
902
903             if ( forward && !canceled ) {
904                 updates = new XMLUpdates( ((SelectModulesPanel)getComponent ()).getFiles() );
905                 ((XMLUpdates)updates).checkDownloadedModules();
906                 allUpdates.put(this, updates);
907             }
908         }
909
910     }
911
912 }
913
Popular Tags