Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Michel-Lemieux2004-02-25 20:34:58 +0000
committerJean Michel-Lemieux2004-02-25 20:34:58 +0000
commit4a1ca77df6f4238416a8715a8c35819611d5992a (patch)
tree03e4ed09e94442352cb8c3143df59d3b22725627 /bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/JobRunnableContext.java
parenta650f9521c18cb3c840475358086bf5f4052a824 (diff)
downloadeclipse.platform.team-4a1ca77df6f4238416a8715a8c35819611d5992a.tar.gz
eclipse.platform.team-4a1ca77df6f4238416a8715a8c35819611d5992a.tar.xz
eclipse.platform.team-4a1ca77df6f4238416a8715a8c35819611d5992a.zip
SyncView API released to HEAD.
Diffstat (limited to 'bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/JobRunnableContext.java')
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/JobRunnableContext.java118
1 files changed, 118 insertions, 0 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/JobRunnableContext.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/JobRunnableContext.java
new file mode 100644
index 000000000..bca21a756
--- /dev/null
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/JobRunnableContext.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ui.actions;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.jobs.*;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.ui.*;
+import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
+
+/**
+ * This runnable context executes it's operation in the context of a background job.
+ */
+public class JobRunnableContext implements ITeamRunnableContext {
+
+ private IJobChangeListener listener;
+ private IWorkbenchSite site;
+
+ public JobRunnableContext() {
+ this(null, null);
+ }
+
+ public JobRunnableContext(IJobChangeListener listener, IWorkbenchSite site) {
+ this.listener = listener;
+ this.site = site;
+ }
+
+ protected IStatus run(IRunnableWithProgress runnable, IProgressMonitor monitor) {
+ try {
+ runnable.run(monitor);
+ } catch (InvocationTargetException e) {
+ return TeamException.asTeamException(e).getStatus();
+ } catch (InterruptedException e) {
+ return Status.OK_STATUS;
+ }
+ return Status.OK_STATUS;
+ }
+
+ protected Job getBasicJob(String title, final IRunnableWithProgress runnable) {
+ return new Job(title) {
+ public IStatus run(IProgressMonitor monitor) {
+ return JobRunnableContext.this.run(runnable, monitor);
+ }
+ };
+ }
+
+ protected Job getWorkspaceJob(String title, final IRunnableWithProgress runnable) {
+ return new WorkspaceJob(title) {
+ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
+ return JobRunnableContext.this.run(runnable, monitor);
+ }
+ };
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.operations.ITeamRunnableContext#run(java.lang.String, boolean, org.eclipse.jface.operation.IRunnableWithProgress)
+ */
+ public void run(String title, ISchedulingRule schedulingRule, boolean postponeBuild, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
+ Job job;
+ if (schedulingRule == null && !postponeBuild) {
+ job = getBasicJob(title, runnable);
+ } else {
+ job = getWorkspaceJob(title, runnable);
+ if (schedulingRule != null) {
+ job.setRule(schedulingRule);
+ }
+ }
+ if (listener != null) {
+ job.addJobChangeListener(listener);
+ }
+ schedule(job, site);
+ }
+
+ private void schedule(Job job, IWorkbenchSite site) {
+ if (site != null) {
+ IWorkbenchSiteProgressService siteProgress = (IWorkbenchSiteProgressService) site.getAdapter(IWorkbenchSiteProgressService.class);
+ if (siteProgress != null) {
+ siteProgress.schedule(job);
+ return;
+ }
+ }
+ job.schedule();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.operations.ITeamRunnableContext#getShell()
+ */
+ public Shell getShell() {
+ final Shell[] newShell = new Shell[] { null };
+ Display.getDefault().syncExec(
+ new Runnable() {
+ public void run() {
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window == null) {
+ Display display = Display.getDefault();
+ newShell[0] = new Shell(display);
+ } else {
+ newShell[0] = window.getShell();
+ }
+ }
+ });
+ return newShell[0];
+ }
+}

Back to the top