KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > scheduler > UpdateJobChangeAdapter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.internal.scheduler;
12
13 import org.eclipse.core.runtime.jobs.IJobChangeEvent;
14 import org.eclipse.core.runtime.jobs.JobChangeAdapter;
15 import org.eclipse.jface.dialogs.MessageDialog;
16 import org.eclipse.jface.wizard.WizardDialog;
17 import org.eclipse.swt.custom.BusyIndicator;
18 import org.eclipse.update.internal.ui.UpdateUI;
19 import org.eclipse.update.internal.ui.UpdateUIMessages;
20 import org.eclipse.update.internal.ui.wizards.InstallWizard;
21 import org.eclipse.update.internal.ui.wizards.InstallWizard2;
22 import org.eclipse.update.internal.ui.wizards.ResizableInstallWizardDialog;
23
24 class UpdateJobChangeAdapter extends JobChangeAdapter {
25     private SchedulerStartup startup;
26
27     public UpdateJobChangeAdapter(SchedulerStartup startup) {
28         this.startup = startup;
29     }
30
31     public void done(IJobChangeEvent event) {
32         if (event.getJob() == startup.getJob()) {
33
34             // prompt the user
35
if (((AutomaticUpdateJob) startup.getJob()).getUpdates().length > 0
36                     && !InstallWizard.isRunning()) {
37                 if (UpdateSchedulerPlugin.getDefault().getPluginPreferences()
38                         .getBoolean(UpdateSchedulerPlugin.P_DOWNLOAD)) {
39                     UpdateUI.getStandardDisplay().asyncExec(new Runnable JavaDoc() {
40                         public void run() {
41                             asyncNotifyDownloadUser();
42                             startup.scheduleUpdateJob();
43                         }
44                     });
45                 } else {
46                     UpdateUI.getStandardDisplay().asyncExec(new Runnable JavaDoc() {
47                         public void run() {
48                             asyncNotifyUser();
49                             startup.scheduleUpdateJob();
50                         }
51                     });
52                 }
53             }
54         }
55     }
56
57     private void asyncNotifyUser() {
58         // ask the user to install updates
59
UpdateUI.getStandardDisplay().beep();
60         if (MessageDialog.openQuestion(UpdateUI.getActiveWorkbenchShell(),
61                 UpdateUIMessages.AutomaticUpdatesJob_EclipseUpdates1,
62                 UpdateUIMessages.AutomaticUpdatesJob_UpdatesAvailable)) {
63             BusyIndicator.showWhile(UpdateUI.getStandardDisplay(),
64                     new Runnable JavaDoc() {
65                         public void run() {
66                             openInstallWizard2();
67                         }
68                     });
69         }
70         // notify the manager that the job is done
71
// job.done(Status.OK_STATUS);
72
}
73
74     private void asyncNotifyDownloadUser() {
75         // ask the user to install updates
76
UpdateUI.getStandardDisplay().beep();
77         if (MessageDialog.openQuestion(UpdateUI.getActiveWorkbenchShell(),
78                 UpdateUIMessages.AutomaticUpdatesJob_EclipseUpdates2,
79                 UpdateUIMessages.AutomaticUpdatesJob_UpdatesDownloaded)) {
80             BusyIndicator.showWhile(UpdateUI.getStandardDisplay(),
81                     new Runnable JavaDoc() {
82                         public void run() {
83                             openInstallWizard2();
84                         }
85                     });
86         } else {
87             // Don't discard downloaded data, as next time we compare
88
// timestamps.
89

90             // discard all the downloaded data from cache (may include old
91
// data as well)
92
// Utilities.flushLocalFile();
93
}
94         // notify the manager that the job is done
95
// job.done(Status.OK_STATUS);
96
}
97
98     private void openInstallWizard2() {
99         if (InstallWizard.isRunning())
100             // job ends and a new one is rescheduled
101
return;
102         AutomaticUpdateJob ujob = (AutomaticUpdateJob) startup.getJob();
103         InstallWizard2 wizard = new InstallWizard2(ujob.getSearchRequest(),
104                 ujob.getUpdates(), true);
105         WizardDialog dialog = new ResizableInstallWizardDialog(UpdateUI
106                 .getActiveWorkbenchShell(), wizard,
107                 UpdateUIMessages.AutomaticUpdatesJob_Updates);
108         dialog.create();
109         dialog.open();
110     }
111
112 }
113
Popular Tags