|
What this is
Other links
The source code/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.autoupdate;
import java.awt.Dialog;
import java.awt.Component;
import java.awt.Dimension;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.util.Collection;
import java.util.HashMap;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import javax.swing.event.EventListenerList;
import javax.swing.JDialog;
import java.io.File;
import javax.swing.JPanel;
import org.openide.WizardDescriptor;
import org.openide.NotifyDescriptor;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.awt.StatusDisplayer;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;
/** Implements the behavior of AutoUpdate wizard
*
* @author Petr Hrebejk
* @version
*/
class Wizard extends Object implements WizardDescriptor.Iterator {
/** Structure of the updates */
private Updates updates;
/** pairs AutoupdateType, Updates */
private static HashMap allUpdates = new HashMap();
private static int errorType = Updates.NO_ERROR;
private static String errorMessage;
private static RequestProcessor processor;
/** Panels of the wizard */
private WizardPanel[][] panels = new WizardPanel[][] {
{ new StartPanel(),
new PropPanel(),
null,
new ConfigPanel(),
new DownloadPanel(),
new LastPanel()
},
{ null,
null,
new SelectPanel(),
null,
null,
null
}
};
/** Current panel */
private int current = 0;
private int modulesOK = 0;
private boolean canceled = false;
/** Which type of wizard should run */
private int wizardType = 0;
/** The wizard descriptor */
private WizardDescriptor wizardDescriptor;
private List auTypesWithCust = new ArrayList();
private HashMap installNow = new HashMap();
/** The dialog */
static Dialog dialog;
Wizard() {
this( null );
}
/** Creates the wizard */
Wizard( HashMap allUpd ) {
this( allUpd, 0 );
}
private PropertyChangeListener updater_listener =
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (event.getPropertyName().equals("FINISHED")) {
Wizard.this.updaterFinished();
}
}
};
private void updaterFinished() {
if ( SafeModule.write( installNow ) ) {
StatusDisplayer.getDefault().setStatusText( getBundle( "MSG_Install_Finished" ) );
}
else
finishDialog( true );
}
private void finishDialog(boolean all) {
if ( FinishDialog.showDialog() ) {
Collection modules = getAllModules();
Iterator it = modules.iterator();
while( it.hasNext() ) {
ModuleUpdate mu = (ModuleUpdate)it.next();
if ( mu.isInstallApproved() && mu.isDownloadOK() && ( all || !mu.isSafeToInstall() ) ) {
if ( !mu.isSafeToInstall() && mu.isToInstallDir() )
if ( !Downloader.tryMove( mu ) )
mu.setToInstallDir( false );
PreparedModules.getPrepared().addModule( mu );
}
}
if ( FinishDialog.isRestart() ) {
PreparedModules.getPrepared().delete();
Autoupdater.restart();
}
else {
PreparedModules.getPrepared().write();
}
}
else {
Downloader.deleteDownload();
}
}
/** Creates the wizard */
Wizard( HashMap allUpd, int wizardType ) {
this.wizardType = wizardType;
// Create the wizard
PropertyChangeListener listener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (event.getPropertyName().equals(DialogDescriptor.PROP_VALUE)) {
Object option = event.getNewValue();
if (option == WizardDescriptor.FINISH_OPTION ||
option == NotifyDescriptor.CANCEL_OPTION ||
option == NotifyDescriptor.CLOSED_OPTION) {
if ( option != WizardDescriptor.FINISH_OPTION ) {
canceled = true;
Downloader.deleteDownload();
}
getCurrent().end( true );
dialog.setVisible(false);
Autoupdater.Support.deleteTempDir();
Autoupdater.setRunning( false );
dialog.dispose();
allUpdates.clear();
dialog = null;
}
}
}
};
Updates.reset();
if ( allUpd != null ) {
int ist = 3;
allUpdates = allUpd;
current = ist;
if ( wizardType == 0 )
panels[0][ist].start( true );
}
wizardDescriptor = new WizardDescriptor( this );//, new Object() );
wizardDescriptor.setModal( false );
wizardDescriptor.setTitle(getBundle( "CTL_Wizard"));
wizardDescriptor.setTitleFormat (new java.text.MessageFormat (" {0}")); // NOI18N
wizardDescriptor.setAdditionalOptions (new Object[] { });
wizardDescriptor.addPropertyChangeListener(listener);
wizardDescriptor.putProperty ("WizardPanel_helpDisplayed", Boolean.FALSE);
wizardDescriptor.setOptions (new Object[] {
WizardDescriptor.PREVIOUS_OPTION,
WizardDescriptor.NEXT_OPTION,
WizardDescriptor.FINISH_OPTION,
NotifyDescriptor.CANCEL_OPTION } );
}
/** Runs the wizard */
static void go( HashMap allUpd ) {
go( allUpd, 0 );
}
/** Runs the wizard */
static Wizard go( HashMap allUpd, int wizardType ) {
if ( !tryToRun() ) {
// UC wizard already running dialog
DialogDisplayer.getDefault().notify(
new NotifyDescriptor.Message(
getBundle( "MSG_WizardRunning"),
NotifyDescriptor.WARNING_MESSAGE
)
);
return null;
}
else {
Wizard wiz = new Wizard ( allUpd, wizardType );
wiz.startDialog();
return wiz;
}
}
void refreshUpdatePanel() {
if ( current == 3 )
panels[0][current].start( true );
}
/** Runs the wizard */
static void go() {
if ( !tryToRun() ) {
if ( dialog != null ) {
dialog.requestFocus();
// because of JDK 1.4
if ( dialog instanceof JDialog )
((JDialog)dialog).getRootPane().requestDefaultFocus();
}
}
else {
Wizard wiz = new Wizard ();
wiz.startDialog();
}
}
private static synchronized boolean tryToRun() {
if ( !Autoupdater.isRunning() ) {
Autoupdater.setRunning( true );
return true;
}
return false;
}
private void startDialog() {
dialog = DialogDisplayer.getDefault().createDialog( wizardDescriptor );
canceled = false;
dialog.show();
dialog.toFront();
}
// Implementation of Iterator --------------------------------------------------------
public String name() {
return getCurrent().getName();
}
public WizardDescriptor.Panel current() {
return getCurrent();
/*
return panels[ wizardType ][ current ] == null ?
panels[ 0 ][ current ] : panels[ wizardType ][ current ];
*/
}
private WizardPanel getCurrent() {
return panels[ wizardType ][ current ] == null ?
panels[ 0 ][ current ] : panels[ wizardType ][ current ];
}
public boolean hasNext() {
if ( current == 1 && getCurrent().nextPanelOffset() == -1 )
return false;
else
return current < panels[wizardType].length - 1;
}
public boolean hasPrevious() {
return current > 0;
}
public void nextPanel() {
getCurrent().end( true );
if ( current < 0 && wizardType == 0 )
current = current + 2;
else if ( current == 0 && wizardType == 1 )
current = 2;
else if ( current == 0 && wizardType == 0 && auTypesWithCust.size() == 0 )
current = 3;
else if ( current == 1 && wizardType == 0 && auTypesWithCust.size() == 0 )
current = current + 2;
else if ( current == 1 && wizardType == 0 && auTypesWithCust.size() > 0 )
current = 1;
else if ( current == 3 && getCurrent().nextPanelOffset() == 2 )
current = 5;
else
current ++;
getCurrent().start( true );
//centerDialog();
}
public void previousPanel() {
getCurrent().end( false );
switch ( current ) {
case 2:
if ( wizardType == 1 )
current = 0;
else
current--;
break;
case 3:
if ( wizardType == 0 )
current = 0;
else
current--;
break;
case 5:
current = 3;
break;
default:
current --;
break;
}
getCurrent().start( false );
//centerDialog();
}
public synchronized void addChangeListener(javax.swing.event.ChangeListener listener) {}
public synchronized void removeChangeListener(javax.swing.event.ChangeListener listener) {}
static HashMap getAllUpdates() {
return allUpdates;
}
static void setAllUpdates(HashMap allUpd) {
allUpdates = allUpd;
}
static Collection getAllModules() {
Set ret = new HashSet();
Iterator it = getAllUpdates().values().iterator();
while (it.hasNext())
ret.addAll(((Updates)it.next()).getModules());
return ret;
}
static RequestProcessor getRequestProcessor() {
if ( processor == null )
processor = new RequestProcessor();
return processor;
}
private static String getBundle( String key ) {
return NbBundle.getMessage( Wizard.class, key );
}
// Inner classes ----------------------------------------------------------------------
static interface Validator {
// Called from component when the next button should be enabled or disbled
public void setValid( boolean valid );
}
abstract class WizardPanel implements WizardDescriptor.Panel, Validator {
protected Dimension WIZARD_SIZE = new Dimension( 550, 400 );
protected boolean valid = true;
/** Utility field used by event firing mechanism. */
private EventListenerList listenerList = new EventListenerList();
void start( boolean forward ) {}
void end( boolean forward ) { }
/** Called to get offset of the new panel */
int nextPanelOffset() {
return 1;
}
abstract String getName();
// Implementation of Validator
public void setValid(boolean valid) {
this.valid = valid;
fireChangeListenerStateChanged( this );
}
// Implementation of WizardDescriptor.Panel
public boolean isValid() {
return valid;
}
public HelpCtx getHelp() {
return null;
}
public abstract Component getComponent();
public void readSettings( Object settings ) {}
public void storeSettings( Object settings ) {}
/** Registers ChangeListener to receive events.
*@param listener The listener to register.
*/
public synchronized void addChangeListener(javax.swing.event.ChangeListener listener) {
listenerList.add (javax.swing.event.ChangeListener.class, listener);
}
/** Removes ChangeListener from the list of listeners.
*@param listener The listener to remove.
*/
public synchronized void removeChangeListener(javax.swing.event.ChangeListener listener) {
listenerList.remove (javax.swing.event.ChangeListener.class, listener);
}
/** Notifies all registered listeners about the event.
*
*@param param1 Parameter #1 of the
|
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.