Author: adietish
Date: 2012-02-22 18:47:35 -0500 (Wed, 22 Feb 2012)
New Revision: 39021
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/DelegatingProgressMonitor.java
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/WizardUtils.java
Log:
[JBIDE-10979] now calling #done on the wizard monitor only (was: on the delegate monitor,
too) since the job monitor is then already gone and would cause "widget disposed
error"
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/DelegatingProgressMonitor.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/DelegatingProgressMonitor.java 2012-02-22
22:59:09 UTC (rev 39020)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/DelegatingProgressMonitor.java 2012-02-22
23:47:35 UTC (rev 39021)
@@ -25,7 +25,7 @@
List<IProgressMonitor> monitors = new ArrayList<IProgressMonitor>();
- public void add(IProgressMonitor monitor) {
+ public synchronized void add(IProgressMonitor monitor) {
if (monitors.size() > 0) {
IProgressMonitor removed = monitors.remove(0);
monitors.add(monitor);
@@ -36,35 +36,35 @@
}
@Override
- public void subTask(final String name) {
+ public synchronized void subTask(final String name) {
for (IProgressMonitor monitor : monitors) {
monitor.subTask(name);
}
}
@Override
- public void beginTask(final String name, final int totalWork) {
+ public synchronized void beginTask(final String name, final int totalWork) {
for (IProgressMonitor monitor : monitors) {
monitor.beginTask(name, totalWork);
}
}
@Override
- public void done() {
+ public synchronized void done() {
for (IProgressMonitor monitor : monitors) {
monitor.done();
}
}
@Override
- public void internalWorked(final double work) {
+ public synchronized void internalWorked(final double work) {
for (IProgressMonitor monitor : monitors) {
monitor.internalWorked(work);
}
}
@Override
- public boolean isCanceled() {
+ public synchronized boolean isCanceled() {
for (IProgressMonitor monitor : monitors) {
if (monitor.isCanceled()) {
return true;
@@ -74,21 +74,21 @@
}
@Override
- public void setCanceled(final boolean value) {
+ public synchronized void setCanceled(final boolean value) {
for (IProgressMonitor monitor : monitors) {
monitor.setCanceled(value);
}
}
@Override
- public void setTaskName(final String name) {
+ public synchronized void setTaskName(final String name) {
for (IProgressMonitor monitor : monitors) {
monitor.setTaskName(name);
}
}
@Override
- public void worked(final int work) {
+ public synchronized void worked(final int work) {
for (IProgressMonitor monitor : monitors) {
monitor.worked(work);
}
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 2012-02-22
22:59:09 UTC (rev 39020)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/WizardUtils.java 2012-02-22
23:47:35 UTC (rev 39021)
@@ -37,11 +37,11 @@
}
/**
- * Runs the given job in the given wizard container. This method will return
immediately, it will not wait for the
- * job completion.
+ * 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>.
+ * 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
@@ -64,13 +64,14 @@
/**
* Runs the given job in the given wizard container.
* <p>
- * In order to have the wizard displaying a progress bar, you need to set
Wizard#setNeedsProgressMonitor to
- * <code>true</code>.
+ * 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.
+ * 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
@@ -81,17 +82,31 @@
final IWizardContainer container) throws InvocationTargetException,
InterruptedException {
return runInWizard(job, delegatingMonitor, container, 120);
}
-
+
/**
* Runs the given job in the given wizard container.
* <p>
- * In order to have the wizard displaying a progress bar, you need to set
Wizard#setNeedsProgressMonitor to
- * <code>true</code>.
+ * In order to have the wizard displaying a progress bar, you need to set
+ * Wizard#setNeedsProgressMonitor to <code>true</code>.
+ * <p>
+ * In order to be able to report updates in the job to the wizard progress,
+ * you'd have to use the {@link DelegatingProgressMonitor}. Add your job
+ * monitor to that aggregating monitor and call #subTask #done etc. on that
+ * one (@link
https://bugs.eclipse.org/bugs/show_bug.cgi?id=293098)
*
+ * <code>
+ * DelegatingProgressMonitor delegate = new DelegatingProgressMonitor();
+ * delegate.add(myJobMonitor)
+ * delegate.add(wizardMonitor)
+ * ...
+ * delegate.subTask("now reporting to the delegate so that progress is shown in
workbench and wizard");
+ * </code>
+ *
* @param job
* the job to run in the wizard
* @param delegatingMonitor
- * the delegating monitor that the wizard monitor shall be added to.
+ * 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
@@ -104,18 +119,21 @@
container.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
- IProgressMonitor monitorToUse = setupDelegatingMonitorIfPresent(delegatingMonitor,
monitor);
- monitorToUse.beginTask(job.getName(), IProgressMonitor.UNKNOWN);
+ if (delegatingMonitor != null) {
+ delegatingMonitor.add(monitor);
+ }
+ monitor.beginTask(job.getName(), IProgressMonitor.UNKNOWN);
job.schedule();
try {
future.get(timeout, TimeUnit.SECONDS);
} catch (ExecutionException e) {
} catch (TimeoutException e) {
+ } finally {
+ monitor.done();
}
- monitorToUse.done();
}
});
- if(future.isDone()) {
+ if (future.isDone()) {
return job.getResult();
}
CommonUIPlugin.getDefault().logError("Operation did not complete in a reasonnable
amount of time");
@@ -124,31 +142,15 @@
}
/**
- * Returns the delegating monitor if present or the simple monitor otherwise. The simple
monitor is added to the
- * delegating one.
- *
- * @param delegatingMonitor
- * @param monitor
- * @return
- */
- private static IProgressMonitor
setupDelegatingMonitorIfPresent(DelegatingProgressMonitor delegatingMonitor,
- IProgressMonitor monitor) {
- if (delegatingMonitor == null) {
- return monitor;
- }
-
- delegatingMonitor.add(monitor);
- return delegatingMonitor;
- }
-
- /**
* Runs the given job in the given wizard container.
* <p>
- * Furhtermore it updates the models and targets of the given data binding context. This
might be necessary if the
- * given job will change widget enablements in the calling wizard page. The reason for
is that the runner saves the
- * widget enablement states when it's up to execute the runnable. It then restores
those states once he finished
- * executing the runnable. It may therefore restore incorrect states since the job
changed the enablements when it
- * was run.
+ * Furhtermore it updates the models and targets of the given data binding
+ * context. This might be necessary if the given job will change widget
+ * enablements in the calling wizard page. The reason for is that the runner
+ * saves the widget enablement states when it's up to execute the runnable.
+ * It then restores those states once he finished executing the runnable. It
+ * may therefore restore incorrect states since the job changed the
+ * enablements when it was run.
*
* @param job
* the job