1 11 package org.eclipse.update.internal.ui.wizards; 12 13 import org.eclipse.core.runtime.Status; 14 import org.eclipse.core.runtime.jobs.IJobChangeEvent; 15 import org.eclipse.core.runtime.jobs.IJobChangeListener; 16 import org.eclipse.core.runtime.jobs.Job; 17 import org.eclipse.core.runtime.jobs.JobChangeAdapter; 18 import org.eclipse.jface.dialogs.MessageDialog; 19 import org.eclipse.jface.wizard.WizardDialog; 20 import org.eclipse.swt.custom.BusyIndicator; 21 import org.eclipse.swt.widgets.Shell; 22 import org.eclipse.update.internal.ui.UpdateUI; 23 import org.eclipse.update.internal.ui.UpdateUIMessages; 24 import org.eclipse.update.ui.UpdateJob; 25 26 public class InstallWizardOperation { 27 private UpdateJob job; 28 private IJobChangeListener jobListener; 29 private Shell shell; 30 private Shell parentShell; 31 32 public InstallWizardOperation() { 33 } 34 35 public void run(Shell parent, UpdateJob task) { 36 shell = parent; 37 if (shell.getParent()!=null && shell.getParent() instanceof Shell) 38 parentShell = (Shell)shell.getParent(); 39 if (jobListener != null) 41 Job.getJobManager().removeJobChangeListener(jobListener); 42 if (job != null) 43 Job.getJobManager().cancel(job); 44 45 job = task; 47 jobListener = new UpdateJobChangeListener(); 48 Job.getJobManager().addJobChangeListener(jobListener); 49 job.schedule(); 50 } 51 52 private Shell getValidShell() { 53 if (shell.isDisposed()) 54 return parentShell; 55 return shell; 56 } 57 58 private class UpdateJobChangeListener extends JobChangeAdapter { 59 public void done(final IJobChangeEvent event) { 60 final Shell validShell = getValidShell(); 61 if (event.getJob() == job) { 63 Job.getJobManager().removeJobChangeListener(this); 64 Job.getJobManager().cancel(job); 65 if (job.getStatus() == Status.CANCEL_STATUS) 66 return; 67 if (job.getStatus() != Status.OK_STATUS) 68 getValidShell().getDisplay().syncExec(new Runnable () { 69 public void run() { 70 UpdateUI.log(job.getStatus(), true); 71 } 72 }); 73 74 validShell.getDisplay().asyncExec(new Runnable () { 75 public void run() { 76 validShell.getDisplay().beep(); 77 BusyIndicator.showWhile(validShell.getDisplay(), new Runnable () { 78 public void run() { 79 openInstallWizard2(); 80 } 81 }); 82 } 83 }); 84 } 85 } 86 87 private void openInstallWizard2() { 88 if (InstallWizard2.isRunning()) { 89 MessageDialog.openInformation(getValidShell(), UpdateUIMessages.InstallWizard_isRunningTitle, UpdateUIMessages.InstallWizard_isRunningInfo); 90 return; 91 } 92 if (job.getUpdates() == null || job.getUpdates().length == 0) { 93 if (job.isUpdate()) 94 MessageDialog.openInformation(getValidShell(), UpdateUIMessages.InstallWizard_ReviewPage_zeroUpdates, UpdateUIMessages.InstallWizard_ReviewPage_zeroUpdates); 95 else 96 MessageDialog.openInformation(getValidShell(), UpdateUIMessages.InstallWizard_ReviewPage_zeroFeatures, UpdateUIMessages.InstallWizard_ReviewPage_zeroFeatures); 97 return; 98 } 99 InstallWizard2 wizard = new InstallWizard2(job.getSearchRequest(), job.getUpdates(), job.isUpdate()); 100 WizardDialog dialog = new ResizableInstallWizardDialog(getValidShell(), wizard, UpdateUIMessages.AutomaticUpdatesJob_Updates); 101 dialog.create(); 102 dialog.open(); 103 } 104 } 105 } 106 | Popular Tags |