KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > provisioner > update > UpdateSiteProvisionerWizard


1 /*******************************************************************************
2  * Copyright (c) 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.pde.internal.ui.wizards.provisioner.update;
12
13 import java.io.File JavaDoc;
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15 import java.net.MalformedURLException JavaDoc;
16 import java.net.URL JavaDoc;
17 import java.util.ArrayList JavaDoc;
18 import java.util.List JavaDoc;
19
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IProgressMonitor;
22 import org.eclipse.jface.operation.IRunnableWithProgress;
23 import org.eclipse.jface.wizard.Wizard;
24 import org.eclipse.pde.internal.ui.PDEPlugin;
25 import org.eclipse.pde.internal.ui.PDEPluginImages;
26 import org.eclipse.pde.internal.ui.PDEUIMessages;
27 import org.eclipse.pde.ui.IProvisionerWizard;
28 import org.eclipse.update.configuration.IConfiguredSite;
29 import org.eclipse.update.configuration.IInstallConfiguration;
30 import org.eclipse.update.configuration.ILocalSite;
31 import org.eclipse.update.core.IFeature;
32 import org.eclipse.update.core.IFeatureReference;
33 import org.eclipse.update.core.ISite;
34 import org.eclipse.update.core.SiteManager;
35 import org.eclipse.update.operations.IInstallFeatureOperation;
36 import org.eclipse.update.operations.IOperation;
37 import org.eclipse.update.operations.IOperationListener;
38 import org.eclipse.update.operations.OperationsManager;
39
40 public class UpdateSiteProvisionerWizard extends Wizard implements
41 IProvisionerWizard {
42
43     class UpdateSiteDownloader implements IRunnableWithProgress, IOperationListener {
44
45         private IUpdateSiteProvisionerEntry[] entries;
46
47         public UpdateSiteDownloader(IUpdateSiteProvisionerEntry[] entries) {
48             this.entries = entries;
49         }
50
51         public void run(IProgressMonitor monitor)
52         throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
53
54             try {
55                 monitor.beginTask(PDEUIMessages.UpdateSiteDownloader_message, entries.length);
56                 for(int i = 0; i < entries.length; i++) {
57                     IUpdateSiteProvisionerEntry entry = entries[i];
58                     File JavaDoc sitePath = new File JavaDoc(entry.getInstallLocation());
59                     URL JavaDoc remoteSiteURL = new URL JavaDoc(entry.getSiteLocation());
60                     ISite site = SiteManager.getSite(sitePath.toURL(), null);
61                     IConfiguredSite csite = site.getCurrentConfiguredSite();
62
63                     if(csite == null) {
64                         ILocalSite localSite = SiteManager.getLocalSite();
65                         IInstallConfiguration config = localSite.getCurrentConfiguration();
66                         csite = config.createConfiguredSite(sitePath);
67                         csite.verifyUpdatableStatus();
68 // if (!status.isOK())
69
// System.out.println("status is not good");
70

71                     }
72
73                     ISite remoteSite = SiteManager.getSite(remoteSiteURL, null);
74
75                     IFeatureReference[] references =
76                         remoteSite.getFeatureReferences();
77                     for(int j = 0; j < references.length; j++) {
78                         IFeatureReference reference = references[j];
79                         IFeature feature = reference.getFeature(null);
80                         IInstallFeatureOperation operation =
81                             OperationsManager.getOperationFactory().createInstallOperation(csite, feature, null, null, null);
82                         operation.execute(monitor, this);
83                     }
84                     monitor.worked(1);
85                 }
86             } catch (MalformedURLException JavaDoc e) {
87                 PDEPlugin.log(e);
88             } catch (CoreException e) {
89                 PDEPlugin.log(e);
90             } finally {
91                 monitor.done();
92             }
93         }
94
95         public boolean afterExecute(IOperation operation, Object JavaDoc data) {
96             return true;
97         }
98
99         public boolean beforeExecute(IOperation operation, Object JavaDoc data) {
100             return true;
101         }
102
103     }
104
105     private File JavaDoc[] fDirs = null;
106     private UpdateSiteProvisionerPage fPage;
107
108     public UpdateSiteProvisionerWizard() {
109         setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
110         setWindowTitle(PDEUIMessages.UpdateSiteProvisionerWizard_title);
111         setNeedsProgressMonitor(true);
112         setDefaultPageImageDescriptor(PDEPluginImages.DESC_NEWSITEPRJ_WIZ);
113     }
114
115     public void addPages() {
116         fPage = new UpdateSiteProvisionerPage("update site"); //$NON-NLS-1$
117
addPage(fPage);
118     }
119
120     public boolean performFinish() {
121         List JavaDoc dirs = new ArrayList JavaDoc();
122         try {
123             IUpdateSiteProvisionerEntry[] entries = fPage.getEntries();
124             getContainer().run(false, false, new UpdateSiteDownloader(entries));
125
126             for(int i = 0; i < entries.length; i++) {
127                 IUpdateSiteProvisionerEntry entry = entries[i];
128                 File JavaDoc file = new File JavaDoc(entry.getInstallLocation(), "eclipse"); //$NON-NLS-1$
129
if(file.exists())
130                     dirs.add(file);
131             }
132             fDirs = (File JavaDoc[]) dirs.toArray(new File JavaDoc[dirs.size()]);
133         } catch (InvocationTargetException JavaDoc e) {
134             PDEPlugin.log(e);
135         } catch (InterruptedException JavaDoc e) {
136             return false;
137         }
138         return true;
139     }
140
141     public File JavaDoc[] getLocations() {
142         return fDirs;
143     }
144
145 }
146
Popular Tags