27db567c568da78dd99be42f5d55750bbfa48fe1
[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 java.net.URISyntaxException;
14
15 import org.eclipse.equinox.internal.p2.ui.dialogs.UpdateSingleIUWizard;
16 import org.eclipse.equinox.p2.operations.RepositoryTracker;
17 import org.eclipse.equinox.p2.operations.UpdateOperation;
18 import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
19 import org.eclipse.jface.wizard.WizardDialog;
20
21 import eu.etaxonomy.taxeditor.TaxonomicEditorPlugin;
22 import eu.etaxonomy.taxeditor.model.MessagingUtils;
23
24 /**
25 * UpdateHandler invokes the check for updates UI
26 *
27 * @since 3.4
28 */
29 public class UpdateHandler extends PreloadingRepositoryHandler {
30
31 boolean hasNoRepos = false;
32
33 @Override
34 protected void doExecute(LoadMetadataRepositoryJob job) {
35 // if (hasNoRepos) {
36 // return;
37 // }
38 UpdateOperation operation = getProvisioningUI().getUpdateOperation(null, null);
39 try {
40 P2Util.setUpdateRepositories(operation);
41 } catch (URISyntaxException e) {
42 MessagingUtils.errorDialog("Invalid update site URI",
43 operation,
44 "The update site URI has an invalid syntax",
45 TaxonomicEditorPlugin.PLUGIN_ID,
46 e,
47 false);
48 return;
49 }
50
51 // check for updates
52 operation.resolveModal(null);
53 if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
54 if (UpdateSingleIUWizard.validFor(operation)) {
55 // Special case for only updating a single root
56 UpdateSingleIUWizard wizard = new UpdateSingleIUWizard(getProvisioningUI(), operation);
57 WizardDialog dialog = new WizardDialog(getShell(), wizard);
58 dialog.create();
59 dialog.open();
60 } else {
61 // Open the normal version of the update wizard
62 getProvisioningUI().openUpdateWizard(false, operation, job);
63 }
64 }
65 }
66
67 @Override
68 protected boolean preloadRepositories() {
69 hasNoRepos = false;
70 RepositoryTracker repoMan = getProvisioningUI().getRepositoryTracker();
71 if (repoMan.getKnownRepositories(getProvisioningUI().getSession()).length == 0) {
72 hasNoRepos = true;
73 return false;
74 }
75 return super.preloadRepositories();
76 }
77 }