Revert update handler to earlier version
[taxeditor.git] / 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 *******************************************************************************/
11 package eu.etaxonomy.taxeditor.update;
12
13 import org.eclipse.equinox.internal.p2.ui.dialogs.UpdateSingleIUWizard;
14 import org.eclipse.equinox.p2.operations.RepositoryTracker;
15 import org.eclipse.equinox.p2.operations.UpdateOperation;
16 import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
17 import org.eclipse.jface.wizard.WizardDialog;
18
19 /**
20 * UpdateHandler invokes the check for updates UI
21 *
22 * @since 3.4
23 */
24 public class UpdateHandler extends PreloadingRepositoryHandler {
25
26 boolean hasNoRepos = false;
27
28 @Override
29 protected void doExecute(LoadMetadataRepositoryJob job) {
30 if (hasNoRepos) {
31 return;
32 }
33 UpdateOperation operation = getProvisioningUI().getUpdateOperation(null, null);
34
35
36 // check for updates
37 operation.resolveModal(null);
38 if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
39 if (UpdateSingleIUWizard.validFor(operation)) {
40 // Special case for only updating a single root
41 UpdateSingleIUWizard wizard = new UpdateSingleIUWizard(getProvisioningUI(), operation);
42 WizardDialog dialog = new WizardDialog(getShell(), wizard);
43 dialog.create();
44 dialog.open();
45 } else {
46 // Open the normal version of the update wizard
47 getProvisioningUI().openUpdateWizard(false, operation, job);
48 }
49 }
50 }
51
52 @Override
53 protected boolean preloadRepositories() {
54 hasNoRepos = false;
55 RepositoryTracker repoMan = getProvisioningUI().getRepositoryTracker();
56 if (repoMan.getKnownRepositories(getProvisioningUI().getSession()).length == 0) {
57 hasNoRepos = true;
58 return false;
59 }
60 return super.preloadRepositories();
61 }
62 }