Project

General

Profile

« Previous | Next » 

Revision c7a2c22e

Added by Cherian Mathew over 8 years ago

Add repo URIs to update operation

View differences:

eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/update/UpdateHandler.java
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
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
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
*/
11 9
package eu.etaxonomy.taxeditor.update;
12 10

  
13 11
import java.net.URI;
14 12

  
15 13
import org.eclipse.core.runtime.IStatus;
16 14
import org.eclipse.core.runtime.OperationCanceledException;
17
import org.eclipse.core.runtime.Status;
18 15
import org.eclipse.equinox.internal.p2.ui.ProvUI;
19 16
import org.eclipse.equinox.internal.p2.ui.dialogs.UpdateSingleIUWizard;
20 17
import org.eclipse.equinox.p2.core.IProvisioningAgent;
21 18
import org.eclipse.equinox.p2.core.ProvisionException;
19
import org.eclipse.equinox.p2.operations.ProvisioningSession;
22 20
import org.eclipse.equinox.p2.operations.UpdateOperation;
23 21
import org.eclipse.equinox.p2.repository.IRepositoryManager;
24 22
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
25 23
import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
26 24
import org.eclipse.equinox.p2.ui.ProvisioningUI;
25
import org.eclipse.jface.dialogs.MessageDialog;
27 26
import org.eclipse.jface.wizard.WizardDialog;
27
import org.eclipse.ui.IWorkbench;
28
import org.eclipse.ui.PlatformUI;
28 29
import org.osgi.framework.BundleContext;
29 30
import org.osgi.framework.ServiceReference;
30 31

  
31 32
import eu.etaxonomy.taxeditor.TaxonomicEditorPlugin;
33
import eu.etaxonomy.taxeditor.model.MessagingUtils;
32 34

  
33 35
/**
34 36
 * UpdateHandler invokes the check for updates UI
35 37
 *
36
 * @since 3.4
37 38
 */
38 39
public class UpdateHandler extends PreloadingRepositoryHandler {
39 40

  
......
41 42
    @Override
42 43
    protected void doExecute(LoadMetadataRepositoryJob job) {
43 44

  
44
        UpdateOperation operation = new UpdateOperation(ProvisioningUI.getDefaultUI().getSession());
45
        //UpdateOperation operation = new UpdateOperation(ProvisioningUI.getDefaultUI().getSession());
45 46

  
46
        // check for updates
47
        checkForUpdates(operation);
48
        if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
49
            if (UpdateSingleIUWizard.validFor(operation)) {
50
                // Special case for only updating a single root
51
                UpdateSingleIUWizard wizard = new UpdateSingleIUWizard(getProvisioningUI(), operation);
52
                WizardDialog dialog = new WizardDialog(getShell(), wizard);
53
                dialog.create();
54
                dialog.open();
55
            } else {
56
                // Open the normal version of the update wizard
57
                getProvisioningUI().openUpdateWizard(false, operation, job);
58
            }
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;
59 55
        }
60
    }
61 56

  
57
        final IProvisioningAgent agent = (IProvisioningAgent) bundleContext.getService(reference);
58
        IWorkbench workbench = PlatformUI.getWorkbench();
62 59

  
63
    /**
64
     * @param monitor
65
     * @return
66
     */
67
    private IStatus checkForUpdates(UpdateOperation operation) {
60
        ProvisioningSession session = new ProvisioningSession(agent);
61
        // update all user-visible installable units
62
        UpdateOperation operation = new UpdateOperation(session);
68 63

  
69
        // force refresh all the caches before
64
        // force refresh all the repository caches before update
70 65
        IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ProvisioningUI.getDefaultUI().getSession());
71 66
        URI[] repos = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
67

  
72 68
        for(URI repo : repos) {
73 69
            try {
74 70
                metaManager.refreshRepository(repo, null);
75 71
            } catch (ProvisionException pe) {
76
                IStatus errorStatus = new Status(IStatus.ERROR, TaxonomicEditorPlugin.PLUGIN_ID,
77
                        "Error occured while reloading cache.", pe);
72
                MessagingUtils.errorDialog("Error reloading repository cache",
73
                        this,
74
                        pe.getMessage(),
75
                        TaxonomicEditorPlugin.PLUGIN_ID,
76
                        pe,
77
                        true);
78
                return;
78 79

  
79 80
            } catch (OperationCanceledException oce) {
80
                IStatus errorStatus = new Status(IStatus.ERROR, TaxonomicEditorPlugin.PLUGIN_ID,
81
                        "Error occured while reloading cache.", oce);
81
                MessagingUtils.errorDialog("Error reloading repository cache",
82
                        this,
83
                        oce.getMessage(),
84
                        TaxonomicEditorPlugin.PLUGIN_ID,
85
                        oce,
86
                        true);
87
                return;
82 88
            }
83 89
        }
84
        BundleContext bundleContext = TaxonomicEditorPlugin.getContext();
85
        ServiceReference reference = bundleContext.getServiceReference(IProvisioningAgent.SERVICE_NAME);
86
        if (reference == null) {
87
            IStatus errorStatus = new Status(IStatus.ERROR, TaxonomicEditorPlugin.PLUGIN_ID,
88
                    "No provisioning agent found.  This application is not set up for updates.");
89
            return errorStatus;
90
        }
91 90

  
92
        try {
93
            return operation.resolveModal(null);
94
        } finally {
95
            bundleContext.ungetService(reference);
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
            }
96 108
        }
97 109
    }
98

  
99 110
}

Also available in: Unified diff