2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.update
;
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
;
32 import eu
.etaxonomy
.taxeditor
.TaxonomicEditorPlugin
;
33 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
36 * UpdateHandler invokes the check for updates UI
39 public class UpdateHandler
extends PreloadingRepositoryHandler
{
43 protected void doExecute(LoadMetadataRepositoryJob job
) {
45 //UpdateOperation operation = new UpdateOperation(ProvisioningUI.getDefaultUI().getSession());
47 BundleContext bundleContext
= TaxonomicEditorPlugin
.getContext();
48 ServiceReference reference
= bundleContext
.getServiceReference(IProvisioningAgent
.SERVICE_NAME
);
49 if (reference
== null) {
50 MessageDialog
.openInformation(
53 "No provisioning agent found. This application is not set up for updates.");
57 final IProvisioningAgent agent
= (IProvisioningAgent
) bundleContext
.getService(reference
);
58 IWorkbench workbench
= PlatformUI
.getWorkbench();
60 ProvisioningSession session
= new ProvisioningSession(agent
);
61 // update all user-visible installable units
62 UpdateOperation operation
= new UpdateOperation(session
);
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
);
68 for(URI repo
: repos
) {
70 metaManager
.refreshRepository(repo
, null);
71 } catch (ProvisionException pe
) {
72 MessagingUtils
.errorDialog("Error reloading repository cache",
75 TaxonomicEditorPlugin
.PLUGIN_ID
,
80 } catch (OperationCanceledException oce
) {
81 MessagingUtils
.errorDialog("Error reloading repository cache",
84 TaxonomicEditorPlugin
.PLUGIN_ID
,
91 // set location of artifact and metadata repo
92 operation
.getProvisioningContext().setArtifactRepositories(repos
);
93 operation
.getProvisioningContext().setMetadataRepositories(repos
);
95 IStatus status
= operation
.resolveModal(null);
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
);
105 // Open the normal version of the update wizard
106 getProvisioningUI().openUpdateWizard(false, operation
, job
);