1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.update;
|
10
|
|
11
|
import java.net.URI;
|
12
|
|
13
|
import org.eclipse.core.runtime.IStatus;
|
14
|
import org.eclipse.core.runtime.OperationCanceledException;
|
15
|
import org.eclipse.equinox.internal.p2.ui.ProvUI;
|
16
|
import org.eclipse.equinox.internal.p2.ui.dialogs.UpdateSingleIUWizard;
|
17
|
import org.eclipse.equinox.p2.core.IProvisioningAgent;
|
18
|
import org.eclipse.equinox.p2.core.ProvisionException;
|
19
|
import org.eclipse.equinox.p2.operations.ProvisioningSession;
|
20
|
import org.eclipse.equinox.p2.operations.UpdateOperation;
|
21
|
import org.eclipse.equinox.p2.repository.IRepositoryManager;
|
22
|
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
|
23
|
import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
|
24
|
import org.eclipse.equinox.p2.ui.ProvisioningUI;
|
25
|
import org.eclipse.jface.dialogs.MessageDialog;
|
26
|
import org.eclipse.jface.wizard.WizardDialog;
|
27
|
import org.eclipse.ui.IWorkbench;
|
28
|
import org.eclipse.ui.PlatformUI;
|
29
|
import org.osgi.framework.BundleContext;
|
30
|
import org.osgi.framework.ServiceReference;
|
31
|
|
32
|
import eu.etaxonomy.taxeditor.TaxonomicEditorPlugin;
|
33
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
34
|
|
35
|
/**
|
36
|
* UpdateHandler invokes the check for updates UI
|
37
|
*
|
38
|
*/
|
39
|
public class UpdateHandler extends PreloadingRepositoryHandler {
|
40
|
|
41
|
|
42
|
@Override
|
43
|
protected void doExecute(LoadMetadataRepositoryJob job) {
|
44
|
|
45
|
//UpdateOperation operation = new UpdateOperation(ProvisioningUI.getDefaultUI().getSession());
|
46
|
|
47
|
BundleContext bundleContext = TaxonomicEditorPlugin.getContext();
|
48
|
ServiceReference reference = bundleContext.getServiceReference(IProvisioningAgent.SERVICE_NAME);
|
49
|
if (reference == null) {
|
50
|
MessageDialog.openInformation(
|
51
|
null,
|
52
|
"Information",
|
53
|
"No provisioning agent found. This application is not set up for updates.");
|
54
|
return;
|
55
|
}
|
56
|
|
57
|
final IProvisioningAgent agent = (IProvisioningAgent) bundleContext.getService(reference);
|
58
|
IWorkbench workbench = PlatformUI.getWorkbench();
|
59
|
|
60
|
ProvisioningSession session = new ProvisioningSession(agent);
|
61
|
// update all user-visible installable units
|
62
|
UpdateOperation operation = new UpdateOperation(session);
|
63
|
|
64
|
// force refresh all the repository caches before update
|
65
|
IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ProvisioningUI.getDefaultUI().getSession());
|
66
|
URI[] repos = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
|
67
|
|
68
|
for(URI repo : repos) {
|
69
|
try {
|
70
|
metaManager.refreshRepository(repo, null);
|
71
|
} catch (ProvisionException pe) {
|
72
|
MessagingUtils.errorDialog("Error reloading repository cache",
|
73
|
this,
|
74
|
pe.getMessage(),
|
75
|
TaxonomicEditorPlugin.PLUGIN_ID,
|
76
|
pe,
|
77
|
true);
|
78
|
return;
|
79
|
|
80
|
} catch (OperationCanceledException oce) {
|
81
|
MessagingUtils.errorDialog("Error reloading repository cache",
|
82
|
this,
|
83
|
oce.getMessage(),
|
84
|
TaxonomicEditorPlugin.PLUGIN_ID,
|
85
|
oce,
|
86
|
true);
|
87
|
return;
|
88
|
}
|
89
|
}
|
90
|
|
91
|
// set location of artifact and metadata repo
|
92
|
operation.getProvisioningContext().setArtifactRepositories(repos);
|
93
|
operation.getProvisioningContext().setMetadataRepositories(repos);
|
94
|
|
95
|
IStatus status = operation.resolveModal(null);
|
96
|
|
97
|
if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
|
98
|
if (UpdateSingleIUWizard.validFor(operation)) {
|
99
|
// Special case for only updating a single root
|
100
|
UpdateSingleIUWizard wizard = new UpdateSingleIUWizard(getProvisioningUI(), operation);
|
101
|
WizardDialog dialog = new WizardDialog(getShell(), wizard);
|
102
|
dialog.create();
|
103
|
dialog.open();
|
104
|
} else {
|
105
|
// Open the normal version of the update wizard
|
106
|
getProvisioningUI().openUpdateWizard(false, operation, job);
|
107
|
}
|
108
|
}
|
109
|
}
|
110
|
}
|