Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Using IRunnableWithProgress (hint needed)
Using IRunnableWithProgress (hint needed) [message #167343] Mon, 08 December 2003 11:22 Go to next message
Eclipse UserFriend
Hi All,

I'm interested (keen) to use the E3.0 generic progress view for keeping
my users informed during long running processes, but so far I can't seem
to make it happen cleanly, so I wonder if I'm missing a trick?

Originally I had a normal thread which would run in the background - the
data it generated was shown in a view...

// so, where
class X implements Runnable {}

// i had used
Runnable r = new X();
Thread t = new Thread(r);
t.run();

After modification of class X, it now implements IRunnableWithProgress.
I've also added the appropriate monitor.beginTask("MyTask") etc. calls
so that it properly reports it's progress.

In order to get the code to run it appears that my object needs a handle
on the current shell, but:

PlatformUI.getWorkbench().getActiveWorkbenchWindow()

can (and does) return null; so, to get it to work I've resorted to:

final X x = new X();

Display.getDefault().syncExec(new Runnable() {
public void run() {
try {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow ww = wb.getActiveWorkbenchWindow();
ww.run(true, true, x);
} catch (Exception e) {
// ...
}
}
});

I found I needed the syncExec to avoid InvalidThreadAccess problems:

org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:2592)
at org.eclipse.swt.SWT.error(SWT.java:2522)
at org.eclipse.swt.widgets.Widget.error(Widget.java:388)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:318)
at org.eclipse.swt.widgets.Control.getEnabled(Control.java:744)
at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow. java:1458)

So now the code "works" insofar as there is a task which runs, and the
results can be used as before, however, there is no feedback during the
work, it starts, it stops, there's just no verbosity about what it's up
to - there must be something really obvious I've missed but after
trawling all the groups and articles I'm none the wiser.

Any thoughts or pointers would be hugely appreciated,
Cheers
Rich
Re: Using IRunnableWithProgress - use org.eclipse.runtime.Job [message #167920 is a reply to message #167343] Tue, 09 December 2003 05:40 Go to previous message
Eclipse UserFriend
Hi all,

It's wonderful how writing a problem out helps to solve it.

Here's the solution for the benefit of others...

I've left the "feedback code" the same where it was calling
monitor.beginTask() etc. but the class now extends the new
3.0 Job class.

// so
class X extends org.eclipse.runtime.Job {}

// and i now issue
Job j = new X();
j.schedule();

The job runs, apparently in the background, and the progress
view is appropriately populated, updated and cleared as the
job works through.

Cheers,
Rich
Previous Topic:Specifying the visibility when contributing to popupMenus
Next Topic:Plugin Parser
Goto Forum:
  


Current Time: Thu Jul 17 21:27:29 EDT 2025

Powered by FUDForum. Page generated in 0.08956 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top