Revert update handler to earlier version
authorCherian Mathew <c.mathew@bgbm.org>
Tue, 24 Nov 2015 16:28:44 +0000 (17:28 +0100)
committerCherian Mathew <c.mathew@bgbm.org>
Tue, 24 Nov 2015 16:29:33 +0000 (17:29 +0100)
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/update/UpdateHandler.java
eu.etaxonomy.taxeditor/eu.etaxonomy.taxeditor.product

index 3894b0432f13dec8553829f174b8158c2b32d77c..a835cdc5c2b0eb65e778fcc88b6bfabd9cbe2aaa 100644 (file)
-/**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
+/*******************************************************************************
+ * Copyright (c) 2007, 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
 package eu.etaxonomy.taxeditor.update;
 
-import java.lang.reflect.InvocationTargetException;
-import java.net.URI;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.jobs.IJobChangeEvent;
-import org.eclipse.core.runtime.jobs.JobChangeAdapter;
-import org.eclipse.equinox.internal.p2.ui.ProvUI;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
-import org.eclipse.equinox.p2.core.ProvisionException;
-import org.eclipse.equinox.p2.operations.ProvisioningJob;
-import org.eclipse.equinox.p2.operations.ProvisioningSession;
+import org.eclipse.equinox.internal.p2.ui.dialogs.UpdateSingleIUWizard;
+import org.eclipse.equinox.p2.operations.RepositoryTracker;
 import org.eclipse.equinox.p2.operations.UpdateOperation;
-import org.eclipse.equinox.p2.repository.IRepositoryManager;
-import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
-import org.eclipse.equinox.p2.ui.ProvisioningUI;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.PlatformUI;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-
-import eu.etaxonomy.taxeditor.TaxonomicEditorPlugin;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
+import org.eclipse.jface.wizard.WizardDialog;
 
 /**
  * UpdateHandler invokes the check for updates UI
  *
+ * @since 3.4
  */
-public class UpdateHandler extends AbstractHandler {
-
-    private static final String ERROR_PERFORMING_UPDATES = "Error performing updates";
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public Object execute(ExecutionEvent event) throws ExecutionException {
-        // update using a progress monitor
-        IRunnableWithProgress runnable = new IRunnableWithProgress() {
-            @Override
-            public void run(IProgressMonitor monitor) throws InvocationTargetException,
-                    InterruptedException {
-                doExecute(monitor);
-            }
-        };
-
-        try {
-            new ProgressMonitorDialog(null).run(true, true, runnable);
-        } catch (InvocationTargetException | InterruptedException e) {
-            showError(e);
-        }
-        return null;
-    }
-
-    private void doExecute(IProgressMonitor monitor) {
-
-        //UpdateOperation operation = new UpdateOperation(ProvisioningUI.getDefaultUI().getSession());
-
-        BundleContext bundleContext = TaxonomicEditorPlugin.getContext();
-        ServiceReference reference = bundleContext.getServiceReference(IProvisioningAgent.SERVICE_NAME);
-        if (reference == null) {
-            showMessage(MessageDialog.ERROR, ERROR_PERFORMING_UPDATES, "No provisioning agent found.  This application is not set up for updates.");
-            return;
-        }
-
-        final IProvisioningAgent agent = (IProvisioningAgent) bundleContext.getService(reference);
-        final IWorkbench workbench = PlatformUI.getWorkbench();
-
-        ProvisioningSession session = new ProvisioningSession(agent);
-        // update all user-visible installable units
-        UpdateOperation operation = new UpdateOperation(session);
+public class UpdateHandler extends PreloadingRepositoryHandler {
 
-        // force refresh all the repository caches before update
-        IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ProvisioningUI.getDefaultUI().getSession());
-        URI[] repos = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
+    boolean hasNoRepos = false;
 
-        for(URI repo : repos) {
-            try {
-                metaManager.refreshRepository(repo, null);
-            } catch (ProvisionException | OperationCanceledException e) {
-                showError(e);
-            }
-        }
-
-        // set location of artifact and metadata repo
-        operation.getProvisioningContext().setArtifactRepositories(repos);
-        operation.getProvisioningContext().setMetadataRepositories(repos);
-
-        IStatus status = operation.resolveModal(monitor);
-
-//        if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
-//            if (UpdateSingleIUWizard.validFor(operation)) {
-//                // Special case for only updating a single root
-//                UpdateSingleIUWizard wizard = new UpdateSingleIUWizard(getProvisioningUI(), operation);
-//                WizardDialog dialog = new WizardDialog(getShell(), wizard);
-//                dialog.create();
-//                dialog.open();
-//            } else {
-//                // Open the normal version of the update wizard
-//                getProvisioningUI().openUpdateWizard(false, operation, job);
-//            }
-//        }
-
-        if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
-            showMessage(MessageDialog.INFORMATION, "Checking for updates", "No updates were found");
+    @Override
+    protected void doExecute(LoadMetadataRepositoryJob job) {
+        if (hasNoRepos) {
             return;
         }
-
-        final ProvisioningJob provisioningJob = operation.getProvisioningJob(monitor);
-        if (provisioningJob != null) {
-            Display.getDefault().syncExec(new Runnable() {
-                @Override
-                public void run() {
-                    boolean performUpdate = MessageDialog.openQuestion(
-                            null,
-                            "Updates available",
-                            "There are updates available. Do you want to install them now?");
-                    if (performUpdate) {
-                        provisioningJob.addJobChangeListener(new JobChangeAdapter() {
-                            @Override
-                            public void done(IJobChangeEvent event) {
-                                if (event.getResult().isOK()) {
-                                    Display.getDefault().syncExec(new Runnable() {
-                                        @Override
-                                        public void run() {
-                                            boolean restart = MessageDialog.openQuestion(null,
-                                                    "Updates installed, restart?",
-                                                    "Updates have been installed successfully, do you want to restart?");
-                                            if (restart) {
-                                                workbench.restart();
-                                            }
-                                        }
-                                    });
-                                } else {
-                                    MessageDialog.openInformation(
-                                            null,
-                                            ERROR_PERFORMING_UPDATES,
-                                            event.getResult().getMessage());
-                                }
-                            }
-                        });
-                        provisioningJob.schedule();
-                    }
-                }
-            });
-        } else {
-            if (operation.hasResolved()) {
-                showMessage(MessageDialog.ERROR, ERROR_PERFORMING_UPDATES, "Couldn't get provisioning job: " + operation.getResolutionResult());
+        UpdateOperation operation = getProvisioningUI().getUpdateOperation(null, null);
+
+
+        // check for updates
+        operation.resolveModal(null);
+        if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
+            if (UpdateSingleIUWizard.validFor(operation)) {
+                // Special case for only updating a single root
+                UpdateSingleIUWizard wizard = new UpdateSingleIUWizard(getProvisioningUI(), operation);
+                WizardDialog dialog = new WizardDialog(getShell(), wizard);
+                dialog.create();
+                dialog.open();
             } else {
-                showMessage(MessageDialog.ERROR, ERROR_PERFORMING_UPDATES, "Couldn't resolve provisioning job");
+                // Open the normal version of the update wizard
+                getProvisioningUI().openUpdateWizard(false, operation, job);
             }
         }
     }
 
-    private void showMessage(final int kind, final String title, final String info) {
-        Display.getDefault().syncExec(new Runnable() {
-            @Override
-            public void run() {
-                MessageDialog.open(kind, null, title, info, SWT.NONE);
-            }
-        });
-    }
-
-    private void showError(final Throwable t) {
-        Display.getDefault().syncExec(new Runnable() {
-            @Override
-            public void run() {
-                MessagingUtils.errorDialog(ERROR_PERFORMING_UPDATES,
-                        this,
-                        t.getMessage(),
-                        TaxonomicEditorPlugin.PLUGIN_ID,
-                        t,
-                        true);
-            }
-        });
+    @Override
+    protected boolean preloadRepositories() {
+        hasNoRepos = false;
+        RepositoryTracker repoMan = getProvisioningUI().getRepositoryTracker();
+        if (repoMan.getKnownRepositories(getProvisioningUI().getSession()).length == 0) {
+            hasNoRepos = true;
+            return false;
+        }
+        return super.preloadRepositories();
     }
-
-
 }
index 70b3b40b6fed0bc8f5b149bcd63fe15750ec995d..a0aa796490dcda32e68692e150c642b4e8398cea 100644 (file)
@@ -1,36 +1,58 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<?pde version="3.5"?><product application="eu.etaxonomy.taxeditor.application.application" id="eu.etaxonomy.taxeditor.application.eu_etaxonomy_taxeditor_product" includeLaunchers="true" name="EDIT Taxonomic Editor" uid="eu.etaxonomy.taxeditor.product" useFeatures="true" version="3.12.0.SNAPSHOT">
-  <aboutInfo>
-    <image path="/eu.etaxonomy.taxeditor.application/icons/256color_48x48.gif"/>
-    <text>
+<?pde version="3.5"?>
+
+<product name="EDIT Taxonomic Editor" uid="eu.etaxonomy.taxeditor.product" id="eu.etaxonomy.taxeditor.application.eu_etaxonomy_taxeditor_product" application="eu.etaxonomy.taxeditor.application.application" version="3.12.0.qualifier" useFeatures="true" includeLaunchers="true">
+
+   <aboutInfo>
+      <image path="/eu.etaxonomy.taxeditor.application/icons/256color_48x48.gif"/>
+      <text>
          %productBlurb
       </text>
-  </aboutInfo>
-  <configIni use="default"></configIni>
-  <launcherArgs>
-    <programArgs>-data @user.home/.cdmLibrary -Dserver_port=58080</programArgs>
-    <vmArgs>-Xmx512M -XX:MaxPermSize=256M -Dorg.eclipse.update.reconcile=false -Declipse.p2.unsignedPolicy=allow</vmArgs>
-    <vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts</vmArgsMac>
-  </launcherArgs>
-  <windowImages i16="/eu.etaxonomy.taxeditor.application/icons/256color_16x16.gif" i32="/eu.etaxonomy.taxeditor.application/icons/256color_32x32.gif" i48="/eu.etaxonomy.taxeditor.application/icons/256color_48x48.gif"/>
-  <splash location="eu.etaxonomy.taxeditor.application" startupForegroundColor="000000" startupMessageRect="7,432,360,20" startupProgressRect="5,447,366,15"/>
-  <launcher name="TaxonomicEditor">
-    <solaris/>
-    <win useIco="false">
-      <bmp/>
-    </win>
-  </launcher>
-  <vm></vm>
-  <plugins></plugins>
-  <features>
-    <feature id="eu.etaxonomy.taxeditor.feature"/>
-  </features>
-  <configurations>
-    <plugin autoStart="true" id="eu.etaxonomy.taxeditor.application" startLevel="5"/>
-    <plugin autoStart="true" id="org.eclipse.core.runtime" startLevel="4"/>
-    <plugin autoStart="true" id="org.eclipse.equinox.common" startLevel="2"/>
-    <plugin autoStart="true" id="org.eclipse.equinox.ds" startLevel="2"/>
-    <plugin autoStart="true" id="org.eclipse.equinox.p2.transport.ecf" startLevel="4"/>
-    <plugin autoStart="true" id="org.eclipse.equinox.simpleconfigurator" startLevel="1"/>
-  </configurations>
+   </aboutInfo>
+
+   <configIni use="default">
+   </configIni>
+
+   <launcherArgs>
+      <programArgs>-data @user.home/.cdmLibrary -Dserver_port=58080
+      </programArgs>
+      <vmArgs>-Xmx512M -XX:MaxPermSize=256M -Dorg.eclipse.update.reconcile=false -Declipse.p2.unsignedPolicy=allow
+      </vmArgs>
+      <vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts
+      </vmArgsMac>
+   </launcherArgs>
+
+   <windowImages i16="/eu.etaxonomy.taxeditor.application/icons/256color_16x16.gif" i32="/eu.etaxonomy.taxeditor.application/icons/256color_32x32.gif" i48="/eu.etaxonomy.taxeditor.application/icons/256color_48x48.gif"/>
+
+   <splash
+      location="eu.etaxonomy.taxeditor.application"
+      startupProgressRect="5,447,366,15"
+      startupMessageRect="7,432,360,20"
+      startupForegroundColor="000000" />
+   <launcher name="TaxonomicEditor">
+      <solaris/>
+      <win useIco="false">
+         <bmp/>
+      </win>
+   </launcher>
+
+   <vm>
+   </vm>
+
+   <plugins>
+   </plugins>
+
+   <features>
+      <feature id="eu.etaxonomy.taxeditor.feature"/>
+   </features>
+
+   <configurations>
+      <plugin id="eu.etaxonomy.taxeditor.application" autoStart="true" startLevel="5" />
+      <plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="4" />
+      <plugin id="org.eclipse.equinox.common" autoStart="true" startLevel="2" />
+      <plugin id="org.eclipse.equinox.ds" autoStart="true" startLevel="2" />
+      <plugin id="org.eclipse.equinox.p2.transport.ecf" autoStart="true" startLevel="4" />
+      <plugin id="org.eclipse.equinox.simpleconfigurator" autoStart="true" startLevel="1" />
+   </configurations>
+
 </product>