Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » The progress item(on the right of statusbar) has no effect when Job is running.
The progress item(on the right of statusbar) has no effect when Job is running. [message #453568] Thu, 03 August 2006 01:58 Go to next message
xy is currently offline xyFriend
Messages: 29
Registered: July 2009
Junior Member
The progress item has no effect when Job is running, but has effect when job
is finished(only a flash).
I use Display.getDefault().asyncExec(), but the application window is still
blocked, but the break is workable in Job instance code.

My code:
1: ApplicationWorkbenchWindowAdvisor.preWindowOpen()
configurer.setShowProgressIndicator(true);

2: The Job class
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;

public class FakeJob extends Job {

private static String JOB_NAME = "";

private static Job job = null;

public FakeJob(String name) {
super(name);
}

protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask("", 10);
for (int i = 0; i < 100; i++) {
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
monitor.subTask("" + i);
try {
Thread.sleep(1000); //the break point is workable in run method
} catch (InterruptedException e) {
e.printStackTrace();
}
monitor.worked(1);
System.out.print(1);
}
monitor.done();
return Status.OK_STATUS;
}

public static void start() {
if (job == null) {
job = new FakeJob(JOB_NAME);
job.setUser(true);
}
job.schedule();
}

public static void stop() {
if (job != null) {
job.cancel();
job = null;
}
}

}

3: invoke the Job
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {
FakeJob.start();
showBirtReport(); //this line of code invoke a remote rmi consumes
} catch (Throwable e1) {
e1.printStackTrace();
Utility.showError(e1);
} finally {
FakeJob.stop();
}
}
});
}
});

4: in my Plugin class for jasperreports
public void start(BundleContext context) throws Exception {
super.start(context);
// for running jasperreports
oldClassLoader = Thread.currentThread().getContextClassLoader();

Thread.currentThread().setContextClassLoader(ChargePlugin.cl ass.getClassLoad
er());
}

5: static initialization code for springframwork
ApplicationContext context = context = new
FileSystemXmlApplicationContext(locations) {
public ClassLoader getClassLoader() {
return getClass().getClassLoader();
}

protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
super.initBeanDefinitionReader(reader);
reader.setBeanClassLoader(getClassLoader());
}
};
Re: The progress item(on the right of statusbar) has no effect when Job is running. [message #453581 is a reply to message #453568] Thu, 03 August 2006 15:09 Go to previous message
Eclipse UserFriend
Originally posted by: wegener.cboenospam.com

xy wrote:

> The progress item has no effect when Job is running, but has effect when job
> is finished(only a flash).
> I use Display.getDefault().asyncExec(), but the application window is still
> blocked, but the break is workable in Job instance code.

...snip

The runnable that you pass to asyncExec will be executed in the GUI
thread. This means that the display will be unresponsive until the run
method returns. The purpose of asyncExec is to update the display from a
background thread, not to execute a long running process.

I take it you are trying to show the progress while the showBirtReport()
method is running. In this case, it doesn't look like you need to use the
asyncExec call at all.

You have already discovered the Job api, so you are on the right track
there. The showBirtReport() call should be in the run method of a Job.

Your button's widgetSelected method should create and schedule the
ShowBirtJob instead of calling asyncExec with a runnable.
Previous Topic:Perspective Resize
Next Topic:Help doesn't launch after exporting product
Goto Forum:
  


Current Time: Sun Oct 13 08:15:21 GMT 2024

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

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

Back to the top