1 /*******************************************************************************
2 * Copyright (c) 2008, 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
.workbench
.update
;
13 import org
.eclipse
.core
.runtime
.jobs
.IJobChangeEvent
;
14 import org
.eclipse
.core
.runtime
.jobs
.Job
;
15 import org
.eclipse
.core
.runtime
.jobs
.JobChangeAdapter
;
16 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
17 import org
.eclipse
.equinox
.p2
.ui
.LoadMetadataRepositoryJob
;
18 import org
.eclipse
.equinox
.p2
.ui
.ProvisioningUI
;
19 import org
.eclipse
.swt
.widgets
.Shell
;
20 import org
.eclipse
.ui
.PlatformUI
;
23 * PreloadingRepositoryHandler provides background loading of
24 * repositories before executing the provisioning handler.
28 abstract class PreloadingRepositoryHandler
{
33 public PreloadingRepositoryHandler() {
38 * Execute the command.
41 public Object
execute() {
46 private void doExecuteAndLoad() {
47 if (preloadRepositories()) {
48 //cancel any load that is already running
49 Job
.getJobManager().cancel(LoadMetadataRepositoryJob
.LOAD_FAMILY
);
50 final LoadMetadataRepositoryJob loadJob
= new LoadMetadataRepositoryJob(getProvisioningUI());
51 setLoadJobProperties(loadJob
);
52 if (waitForPreload()) {
53 loadJob
.addJobChangeListener(new JobChangeAdapter() {
55 public void done(IJobChangeEvent event
) {
56 if (PlatformUI
.isWorkbenchRunning()) {
57 if (event
.getResult().isOK()) {
58 PlatformUI
.getWorkbench().getDisplay().asyncExec(new Runnable() {
68 loadJob
.setUser(true);
72 loadJob
.setSystem(true);
73 loadJob
.setUser(false);
82 protected abstract void doExecute(LoadMetadataRepositoryJob job
);
84 protected boolean preloadRepositories() {
88 protected boolean waitForPreload() {
92 protected void setLoadJobProperties(Job loadJob
) {
93 loadJob
.setProperty(LoadMetadataRepositoryJob
.ACCUMULATE_LOAD_ERRORS
, Boolean
.toString(true));
96 protected ProvisioningUI
getProvisioningUI() {
97 return ProvisioningUI
.getDefaultUI();
101 * Return a shell appropriate for parenting dialogs of this handler.
104 protected Shell
getShell() {
105 return PlatformUI
.getWorkbench().getModalDialogShellProvider().getShell();