1 11 package org.eclipse.update.internal.scheduler; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.core.runtime.jobs.Job; 17 import org.eclipse.jface.dialogs.MessageDialog; 18 import org.eclipse.jface.wizard.WizardDialog; 19 import org.eclipse.swt.custom.BusyIndicator; 20 import org.eclipse.swt.widgets.Display; 21 import org.eclipse.update.core.IFeature; 22 import org.eclipse.update.internal.core.*; 23 import org.eclipse.update.internal.operations.UpdateUtils; 24 import org.eclipse.update.internal.ui.wizards.*; 25 import org.eclipse.update.operations.*; 26 import org.eclipse.update.search.*; 27 28 public class AutomaticUpdatesJob extends Job { 29 30 private class AutomaticSearchResultCollector implements IUpdateSearchResultCollector { 31 public void accept(IFeature feature) { 32 IInstallFeatureOperation operation = 33 OperationsManager 34 .getOperationFactory() 35 .createInstallOperation(null, feature, null, null, null); 36 updates.add(operation); 37 } 38 } 39 40 public static final Object family = new Object (); 42 private IUpdateSearchResultCollector resultCollector; 43 44 private static final IStatus OK_STATUS = 45 new Status( 46 IStatus.OK, 47 UpdateScheduler.getPluginId(), 48 IStatus.OK, 49 "", null); 51 private UpdateSearchRequest searchRequest; 52 private ArrayList updates; 53 54 public AutomaticUpdatesJob() { 55 super(UpdateScheduler.getString("AutomaticUpdatesJob.AutomaticUpdateSearch")); updates = new ArrayList (); 57 setPriority(Job.DECORATE); 58 } 59 60 61 66 public static Display getStandardDisplay() { 67 Display display; 68 display = Display.getCurrent(); 69 if (display == null) 70 display = Display.getDefault(); 71 return display; 72 } 73 74 public boolean belongsTo(Object family) { 75 return AutomaticUpdatesJob.family == family; 76 } 77 78 public IStatus run(IProgressMonitor monitor) { 79 if (UpdateCore.DEBUG) { 80 UpdateCore.debug("Automatic update search started."); } 82 searchRequest = UpdateUtils.createNewUpdatesRequest(null); 83 try { 84 if (resultCollector == null) 85 resultCollector = new AutomaticSearchResultCollector(); 86 searchRequest.performSearch(resultCollector, monitor); 87 if (UpdateCore.DEBUG) { 88 UpdateCore.debug("Automatic update search finished - " + updates.size() 90 + " results."); } 92 if (updates.size() > 0) { 93 boolean download = UpdateCore.getPlugin().getPluginPreferences().getBoolean(UpdateScheduler.P_DOWNLOAD); 94 if (download) 96 { 97 if (UpdateCore.DEBUG) { 98 UpdateCore.debug("Automatic download of updates started."); } 100 for (int i=0; i<updates.size(); i++) { 101 IInstallFeatureOperation op = (IInstallFeatureOperation)updates.get(i); 102 IFeature feature = op.getFeature(); 103 UpdateUtils.downloadFeatureContent(feature, monitor); 104 } 105 if (UpdateCore.DEBUG) { 106 UpdateCore.debug("Automatic download of updates finished."); } 108 } 109 if (!InstallWizard.isRunning()) { 111 if (download) { 112 getStandardDisplay().asyncExec(new Runnable () { 113 public void run() { 114 asyncNotifyDownloadUser(); 115 } 116 }); 117 } else { 118 getStandardDisplay().asyncExec(new Runnable () { 119 public void run() { 120 asyncNotifyUser(); 121 } 122 }); 123 } 124 } 125 return Job.ASYNC_FINISH; 126 } 127 } catch (CoreException e) { 128 return e.getStatus(); 129 } 130 return OK_STATUS; 131 } 132 133 private void asyncNotifyUser() { 134 getStandardDisplay().beep(); 136 if (MessageDialog 137 .openQuestion( 138 UpdateScheduler.getActiveWorkbenchShell(), 139 UpdateScheduler.getString("AutomaticUpdatesJob.EclipseUpdates1"), UpdateScheduler.getString("AutomaticUpdatesJob.UpdatesAvailable"))) { BusyIndicator.showWhile(getStandardDisplay(), new Runnable () { 142 public void run() { 143 openInstallWizard(); 144 } 145 }); 146 } 147 done(OK_STATUS); 149 } 150 151 private void asyncNotifyDownloadUser() { 152 getStandardDisplay().beep(); 154 if (MessageDialog 155 .openQuestion( 156 UpdateScheduler.getActiveWorkbenchShell(), 157 UpdateScheduler.getString("AutomaticUpdatesJob.EclipseUpdates2"), UpdateScheduler.getString("AutomaticUpdatesJob.UpdatesDownloaded"))) { BusyIndicator.showWhile(getStandardDisplay(), new Runnable () { 160 public void run() { 161 openInstallWizard(); 162 } 163 }); 164 } else { 165 167 } 170 done(OK_STATUS); 172 } 173 174 private void openInstallWizard() { 175 if (InstallWizard.isRunning()) 176 return; 178 179 InstallWizard wizard = new InstallWizard(searchRequest, updates); 180 WizardDialog dialog = 181 new ResizableInstallWizardDialog( 182 UpdateScheduler.getActiveWorkbenchShell(), 183 wizard, 184 UpdateScheduler.getString("AutomaticUpdatesJob.Updates")); dialog.create(); 186 dialog.open(); 187 } 188 } 189 | Popular Tags |