Author: adietish
Date: 2011-12-22 08:49:43 -0500 (Thu, 22 Dec 2011)
New Revision: 37524
Added:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/JobUtils.java
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/JobResultFuture.java
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/WizardUtils.java
Log:
[JBIDE-10549] changed WizardUtils to return JobResultFuture, added JobUtils
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/JobResultFuture.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/JobResultFuture.java 2011-12-22
13:13:15 UTC (rev 37523)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/JobResultFuture.java 2011-12-22
13:49:43 UTC (rev 37524)
@@ -33,7 +33,7 @@
private ArrayBlockingQueue<IStatus> queue = new
ArrayBlockingQueue<IStatus>(1);
public JobResultFuture(Job job) {
- onJobFinished(job);
+ addJobFinishedListener(job);
}
@Override
@@ -63,13 +63,13 @@
return queue.poll(timeout, unit);
}
- private JobChangeAdapter onJobFinished(final Job job) {
- return new JobChangeAdapter() {
+ private void addJobFinishedListener(final Job job) {
+ job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
queue.offer(job.getResult());
}
- };
+ });
}
}
Added:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/JobUtils.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/JobUtils.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/JobUtils.java 2011-12-22
13:49:43 UTC (rev 37524)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.ui;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.jobs.Job;
+
+/**
+ * @author André Dietisheim
+ *
+ */
+public class JobUtils {
+
+ private JobUtils() {
+ // inhibit instantiation
+ }
+
+ public static IStatus waitForJobResult(Job job, long timeout, TimeUnit unit) throws
InterruptedException, ExecutionException, TimeoutException {
+ return new JobResultFuture(job).get(timeout, unit);
+ }
+
+ public static boolean isOk(IStatus status) {
+ return status != null
+ && status.isOK();
+ }
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/JobUtils.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/WizardUtils.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/WizardUtils.java 2011-12-22
13:13:15 UTC (rev 37523)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/WizardUtils.java 2011-12-22
13:49:43 UTC (rev 37524)
@@ -11,9 +11,11 @@
package org.jboss.tools.common.ui;
import java.lang.reflect.InvocationTargetException;
+import java.util.concurrent.Future;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.IWizard;
@@ -32,33 +34,52 @@
}
/**
- * Runs the given job in the given wizard container. In order to have the
- * wizard displaying a progress bar, you need to set
+ * Runs the given job in the given wizard container. This method will return
+ * immediately, it will not wait for the job completion.
+ * <p>
+ * In order to have the wizard displaying a progress bar, you need to set
* Wizard#setNeedsProgressMonitor to <code>true</code>.
*
- *
* @param job
* the job to run
* @param container
* the wizard container to run the job in
+ * @return a future that allows you to wait for the job result.
* @throws InvocationTargetException
* the invocation target exception
* @throws InterruptedException
* the interrupted exception
- *
* @author André Dietisheim
- *
* @see IWizardContainer#run(boolean, boolean, IRunnableWithProgress)
* @see Job
*/
- public static void runInWizard(final Job job, IWizardContainer container)
+ public static Future<IStatus> runInWizard(final Job job, IWizardContainer
container)
throws InvocationTargetException,
InterruptedException {
- runInWizard(job, null, container);
+ return runInWizard(job, null, container);
}
- public static void runInWizard(final Job job, final DelegatingProgressMonitor
delegatingMonitor,
+ /**
+ * Runs the given job in the given wizard container. This method will return
+ * immediately, it will not wait for the job completion.
+ * <p>
+ * In order to have the wizard displaying a progress bar, you need to set
+ * Wizard#setNeedsProgressMonitor to <code>true</code>.
+ *
+ * @param job
+ * the job to run in the wizard
+ * @param delegatingMonitor
+ * the delegating monitor that the wizard monitor shall be added
+ * to.
+ * @param container
+ * the wizard container to run the job in
+ * @return a future that allows you to wait for the job result
+ * @throws InvocationTargetException
+ * @throws InterruptedException
+ */
+ public static Future<IStatus> runInWizard(final Job job, final
DelegatingProgressMonitor delegatingMonitor,
IWizardContainer container) throws InvocationTargetException, InterruptedException {
+ JobResultFuture future = new JobResultFuture(job);
container.run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
@@ -79,6 +100,7 @@
}
}
});
+ return future;
}
/**
@@ -103,18 +125,17 @@
* @throws InterruptedException
* the interrupted exception
*/
- public static void runInWizard(final Job job, IWizardContainer container,
DataBindingContext dbc)
+ public static Future<IStatus> runInWizard(final Job job, IWizardContainer
container, DataBindingContext dbc)
throws InvocationTargetException, InterruptedException {
- runInWizard(job, container);
- dbc.updateTargets();
- dbc.updateModels();
+ return runInWizard(job, null, container);
}
- public static void runInWizard(Job job, DelegatingProgressMonitor monitor,
IWizardContainer container,
+ public static Future<IStatus> runInWizard(Job job, DelegatingProgressMonitor
monitor, IWizardContainer container,
DataBindingContext dbc) throws InvocationTargetException, InterruptedException {
- runInWizard(job, monitor, container);
+ Future<IStatus> jobResult = runInWizard(job, monitor, container);
dbc.updateTargets();
dbc.updateModels();
+ return jobResult;
}
/**