KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > wizards > InstallWizard


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.ui.wizards;
12 import java.util.ArrayList JavaDoc;
13
14 import org.eclipse.core.runtime.jobs.Job;
15 import org.eclipse.jface.dialogs.MessageDialog;
16 import org.eclipse.jface.wizard.IWizardPage;
17 import org.eclipse.jface.wizard.Wizard;
18 import org.eclipse.update.internal.core.UpdateCore;
19 import org.eclipse.update.internal.search.SiteSearchCategory;
20 import org.eclipse.update.internal.ui.UpdateUI;
21 import org.eclipse.update.internal.ui.UpdateUIImages;
22 import org.eclipse.update.internal.ui.UpdateUIMessages;
23 import org.eclipse.update.search.BackLevelFilter;
24 import org.eclipse.update.search.UpdateSearchRequest;
25 import org.eclipse.update.search.UpdateSearchScope;
26 import org.eclipse.update.ui.UpdateJob;
27
28 public class InstallWizard
29     extends Wizard
30     implements ISearchProvider {
31     private ModeSelectionPage modePage;
32     private SitePage sitePage;
33     private int installCount = 0;
34     private UpdateSearchRequest searchRequest;
35     private boolean needsRestart;
36     private static boolean isRunning;
37     private UpdateJob job;
38     private InstallWizardOperation operation;
39
40
41     public InstallWizard(UpdateSearchRequest searchRequest) {
42         isRunning = true;
43         if (searchRequest == null) {
44             searchRequest =
45                 new UpdateSearchRequest(
46                     new SiteSearchCategory(true),
47                     new UpdateSearchScope());
48             searchRequest.addFilter(new BackLevelFilter());
49         }
50         this.searchRequest = searchRequest;
51         setDialogSettings(UpdateUI.getDefault().getDialogSettings());
52         setDefaultPageImageDescriptor(UpdateUIImages.DESC_UPDATE_WIZ);
53         setForcePreviousAndNextButtons(true);
54         setNeedsProgressMonitor(true);
55         setWindowTitle(UpdateUIMessages.InstallWizard_wtitle);
56     }
57
58     public InstallWizard(UpdateSearchRequest searchRequest, ArrayList JavaDoc jobs) {
59         this(searchRequest);
60     }
61
62     public boolean isRestartNeeded() {
63         return installCount > 0 && needsRestart; // or == selectedJobs.length
64
}
65
66     public boolean performCancel() {
67         isRunning = false;
68         return super.performCancel();
69     }
70
71     public void addPages() {
72         modePage = new ModeSelectionPage(searchRequest);
73         addPage(modePage);
74         sitePage = new SitePage(searchRequest);
75         addPage(sitePage);
76     }
77
78     private void saveSettings() {
79         if (modePage != null)
80             modePage.saveSettings();
81     }
82
83     public IWizardPage getNextPage(IWizardPage page) {
84
85         if (modePage != null && page.equals(modePage)) {
86             boolean update = modePage.isUpdateMode();
87             if (!update)
88                 return sitePage;
89         }
90         return null;
91     }
92
93     /* (non-Javadoc)
94      * @see org.eclipse.update.internal.ui.wizards.ISearchProvider2#getSearchRequest()
95      */

96     public UpdateSearchRequest getSearchRequest() {
97         return searchRequest;
98     }
99
100     public static synchronized boolean isRunning() {
101         return isRunning || Job.getJobManager().find(UpdateJob.FAMILY).length > 0;
102     }
103
104     /**
105      * @see Wizard#performFinish()
106      */

107     public boolean performFinish() {
108
109         saveSettings();
110         
111         if (Job.getJobManager().find(UpdateJob.FAMILY).length > 0) {
112             // another update/install job is running, need to wait to finish or cancel old job
113
boolean proceed = MessageDialog.openQuestion(
114                     UpdateUI.getActiveWorkbenchShell(),
115                     UpdateUIMessages.InstallWizard_anotherJobTitle,
116                     UpdateUIMessages.InstallWizard_anotherJob);
117             if (!proceed)
118                 return false; // cancel this job, and let the old one go on
119
}
120         UpdateCore.getPlugin().getUpdateSession().reset();
121         launchInBackground();
122         isRunning = false;
123         return true;
124     }
125     
126     private void launchInBackground() {
127         // Downloads the feature content in the background.
128
// The job listener will then install the feature when download is finished.
129

130         if (isUpdate())
131             job = new UpdateJob(UpdateUIMessages.InstallWizard_jobName, false, false);
132         else
133             job = new UpdateJob(UpdateUIMessages.InstallWizard_jobName, searchRequest);
134         job.setUser(true);
135         job.setPriority(Job.INTERACTIVE);
136 // if (wait) {
137
// progressService.showInDialog(workbench.getActiveWorkbenchWindow().getShell(), job);
138
// }
139
getOperation().run(UpdateUI.getActiveWorkbenchShell(), job);
140     }
141     
142     private InstallWizardOperation getOperation() {
143         if (operation == null)
144             operation = new InstallWizardOperation();
145         return operation;
146     }
147
148     public boolean canFinish() {
149               
150         if ( modePage.isCurrentPage()) {
151             return isUpdate();
152         } else {
153             return sitePage.isPageComplete();
154         }
155     }
156     
157     private boolean isUpdate() {
158         return (modePage != null && modePage.isUpdateMode());
159     }
160 }
161
Popular Tags