1 /*******************************************************************************
2 * Copyright (c) 2007, 2009 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package eu
.etaxonomy
.taxeditor
.update
;
15 import org
.eclipse
.core
.runtime
.IStatus
;
16 import org
.eclipse
.core
.runtime
.OperationCanceledException
;
17 import org
.eclipse
.core
.runtime
.Status
;
18 import org
.eclipse
.equinox
.internal
.p2
.ui
.ProvUI
;
19 import org
.eclipse
.equinox
.internal
.p2
.ui
.dialogs
.UpdateSingleIUWizard
;
20 import org
.eclipse
.equinox
.p2
.core
.IProvisioningAgent
;
21 import org
.eclipse
.equinox
.p2
.core
.ProvisionException
;
22 import org
.eclipse
.equinox
.p2
.operations
.ProvisioningJob
;
23 import org
.eclipse
.equinox
.p2
.operations
.RepositoryTracker
;
24 import org
.eclipse
.equinox
.p2
.operations
.UpdateOperation
;
25 import org
.eclipse
.equinox
.p2
.repository
.IRepositoryManager
;
26 import org
.eclipse
.equinox
.p2
.repository
.metadata
.IMetadataRepositoryManager
;
27 import org
.eclipse
.equinox
.p2
.ui
.LoadMetadataRepositoryJob
;
28 import org
.eclipse
.equinox
.p2
.ui
.ProvisioningUI
;
29 import org
.eclipse
.jface
.wizard
.WizardDialog
;
30 import org
.osgi
.framework
.BundleContext
;
31 import org
.osgi
.framework
.ServiceReference
;
33 import eu
.etaxonomy
.taxeditor
.TaxonomicEditorPlugin
;
34 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
37 * UpdateHandler invokes the check for updates UI
41 public class UpdateHandler
extends PreloadingRepositoryHandler
{
43 boolean hasNoRepos
= false;
46 protected void doExecute(LoadMetadataRepositoryJob job
) {
50 UpdateOperation operation
= getProvisioningUI().getUpdateOperation(null, null);
53 IStatus status
= checkForUpdates(operation
);
55 if (status
.getCode() == UpdateOperation
.STATUS_NOTHING_TO_UPDATE
) {
56 MessagingUtils
.informationDialog("Checking for updates", status
);
60 if (status
.isOK() && status
.getSeverity() != IStatus
.ERROR
) {
62 boolean doInstall
= MessagingUtils
.confirmDialog("Updates available", "Do you want to install the available updates ?");
64 ProvisioningJob provisioningJob
= operation
.getProvisioningJob(null);
65 if (provisioningJob
== null) {
66 MessagingUtils
.messageDialog("Error in performing update",
68 "ProvisioningJob could not be created." + System
.getProperty("line.separator") +
69 "Either this application does not support p2 software installation or this application has been launched from within the Eclipse IDE",
74 if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation
, getShell())) {
75 if (UpdateSingleIUWizard
.validFor(operation
)) {
76 // Special case for only updating a single root
77 UpdateSingleIUWizard wizard
= new UpdateSingleIUWizard(getProvisioningUI(), operation
);
78 WizardDialog dialog
= new WizardDialog(getShell(), wizard
);
82 // Open the normal version of the update wizard
83 getProvisioningUI().openUpdateWizard(false, operation
, job
);
96 private IStatus
checkForUpdates(UpdateOperation operation
) {
98 // force refresh all the caches before
99 IMetadataRepositoryManager metaManager
= ProvUI
.getMetadataRepositoryManager(ProvisioningUI
.getDefaultUI().getSession());
100 URI
[] repos
= metaManager
.getKnownRepositories(IRepositoryManager
.REPOSITORIES_ALL
);
101 for(URI repo
: repos
) {
103 metaManager
.refreshRepository(repo
, null);
104 } catch (ProvisionException pe
) {
105 IStatus errorStatus
= new Status(IStatus
.ERROR
, TaxonomicEditorPlugin
.PLUGIN_ID
,
106 "Error occured while reloading cache.", pe
);
108 } catch (OperationCanceledException oce
) {
109 IStatus errorStatus
= new Status(IStatus
.ERROR
, TaxonomicEditorPlugin
.PLUGIN_ID
,
110 "Error occured while reloading cache.", oce
);
113 BundleContext bundleContext
= TaxonomicEditorPlugin
.getContext();
114 ServiceReference reference
= bundleContext
.getServiceReference(IProvisioningAgent
.SERVICE_NAME
);
115 if (reference
== null) {
116 IStatus errorStatus
= new Status(IStatus
.ERROR
, TaxonomicEditorPlugin
.PLUGIN_ID
,
117 "No provisioning agent found. This application is not set up for updates.");
122 return operation
.resolveModal(null);
124 bundleContext
.ungetService(reference
);
130 protected boolean preloadRepositories() {
132 RepositoryTracker repoMan
= getProvisioningUI().getRepositoryTracker();
133 if (repoMan
.getKnownRepositories(getProvisioningUI().getSession()).length
== 0) {
137 return super.preloadRepositories();