Home » Eclipse Projects » Eclipse Platform » Status Bar and setMessage 
| Status Bar and setMessage [message #334051] | 
Fri, 16 January 2009 10:52   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Hi, 
 
I have an action that can take a while to complete so I wanted to put some  
feedback in the status bar showing when the action started and when it  
completed.   
 
The main problem is that this code only causes "Pasting Completed" to be  
shown.  Any ideas as to get this code to show "Pasting Started" at the  
beginning, then do the file copying, and show Pasting Completed at the  
end?    
 
Just to see what would happen, I removed the last "Pasted Completed" line  
and ran it.  The run method did all its work and then showed "Pasting  
Started" when it was done.  Anyway, not sure why setMessage seems to be  
called last no matter where it is in the program flow.  Any suggestions?   
Thanks, 
 
 
pasteAction = new Action(){ 
 public void run(){ 
 
 getViewSite().getActionBars().getStatusLineManager().setMess age( "Pasting  
Started"); 
 
// do some work that could take a while 
 
 getViewSite().getActionBars().getStatusLineManager().setMess age( "Pasting  
Completed"); 
 
 
 } 
 
};
 |  
 |  
  |   |   |  
| Re: Status Bar and setMessage [message #334078 is a reply to message #334053] | 
Mon, 19 January 2009 10:14    | 
 
Eclipse User  | 
 | 
 | 
   | 
 
I made the code look like the following: 
 
 
pasteAction = new Action(){ 
public void run(){ 
  
Job myjob = new Job("A Job") { 
	protected IStatus run(IProgressMonitor monitor) { 
	System.out.println("In the background job"); 
	 getViewSite().getActionBars().getStatusLineManager().setMess age( "Start  
Pasting"); 
	return Status.OK_STATUS; 
	} 
}; 
myjob.setPriority(Job.SHORT); 
myjob.schedule();  
  
// do some work that could take a while 
 
 getViewSite().getActionBars().getStatusLineManager().setMess age( "Pasting  
Completed"); 
  
 
 } 
  
 }; 
 
But now this time I get a thread access violation in addition to it  
appearing to run at the end of the method instead of the beginning.  Is  
there a different way to do this?  Yes, I do have this running in a class  
that extends ViewPart.  If this doesn't work as a job how would I run it?   
Why would it be blocked?  Thanks, 
 
Andy 
 
 
Derek wrote: 
 
> Looks like you are running your code in the UI thread and thus blocking  
> any updates. You should be running your long-running code in another  
> thread, or use a Job to do it. 
 
> Andy wrote: 
>> Hi, 
>>  
>> I have an action that can take a while to complete so I wanted to put  
>> some feedback in the status bar showing when the action started and when  
>> it completed.  
>> The main problem is that this code only causes "Pasting Completed" to be  
>> shown.  Any ideas as to get this code to show "Pasting Started" at the  
>> beginning, then do the file copying, and show Pasting Completed at the  
>> end?   
>> Just to see what would happen, I removed the last "Pasted Completed"  
>> line and ran it.  The run method did all its work and then showed  
>> "Pasting Started" when it was done.  Anyway, not sure why setMessage  
>> seems to be called last no matter where it is in the program flow.  Any  
>> suggestions?  Thanks, 
>>  
>>  
>> pasteAction = new Action(){ 
>> public void run(){ 
>>  
>>  getViewSite().getActionBars().getStatusLineManager().setMess age( "Pasting  
>> Started"); 
>>  
>> // do some work that could take a while 
>>  
>>  getViewSite().getActionBars().getStatusLineManager().setMess age( "Pasting  
>> Completed"); 
>>  
>>  
>> } 
>>  
>> }; 
>>
 |  
 |  
  |  
| Re: Status Bar and setMessage [message #334096 is a reply to message #334078] | 
Tue, 20 January 2009 10:56    | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: wegener.cboenospam.com 
 
You've got the wrong thing in the job.  You need to place the long running 
work in the run method of the job and the "Start" code should be invoked 
after scheduling the job.  Wrap the "Completed" code in a Display.asyncExec 
call and put it in the jobs run method after the long running work. 
 
"Andy " <andrewnbenjamin@hotmail.com> wrote in message 
news:26c2ecc53c6641797339d5b48dec3886$1@www.eclipse.org... 
> I made the code look like the following: 
> 
> 
> pasteAction = new Action(){ 
> public void run(){ 
> 
> Job myjob = new Job("A Job") { 
> protected IStatus run(IProgressMonitor monitor) { 
> System.out.println("In the background job"); 
>  getViewSite().getActionBars().getStatusLineManager().setMess age( "Start 
> Pasting"); 
> return Status.OK_STATUS; 
> } 
> }; 
> myjob.setPriority(Job.SHORT); 
> myjob.schedule(); 
> 
> // do some work that could take a while 
> 
>  getViewSite().getActionBars().getStatusLineManager().setMess age( "Pasting 
> Completed"); 
> 
> 
>  } 
> 
>  }; 
> 
> But now this time I get a thread access violation in addition to it 
> appearing to run at the end of the method instead of the beginning.  Is 
> there a different way to do this?  Yes, I do have this running in a class 
> that extends ViewPart.  If this doesn't work as a job how would I run it? 
> Why would it be blocked?  Thanks, 
> 
> Andy 
> 
> 
> Derek wrote: 
> 
> > Looks like you are running your code in the UI thread and thus blocking 
> > any updates. You should be running your long-running code in another 
> > thread, or use a Job to do it. 
> 
> > Andy wrote: 
> >> Hi, 
> >> 
> >> I have an action that can take a while to complete so I wanted to put 
> >> some feedback in the status bar showing when the action started and 
when 
> >> it completed. 
> >> The main problem is that this code only causes "Pasting Completed" to 
be 
> >> shown.  Any ideas as to get this code to show "Pasting Started" at the 
> >> beginning, then do the file copying, and show Pasting Completed at the 
> >> end? 
> >> Just to see what would happen, I removed the last "Pasted Completed" 
> >> line and ran it.  The run method did all its work and then showed 
> >> "Pasting Started" when it was done.  Anyway, not sure why setMessage 
> >> seems to be called last no matter where it is in the program flow.  Any 
> >> suggestions?  Thanks, 
> >> 
> >> 
> >> pasteAction = new Action(){ 
> >> public void run(){ 
> >> 
> >> 
 getViewSite().getActionBars().getStatusLineManager().setMess age( "Pasting 
> >> Started"); 
> >> 
> >> // do some work that could take a while 
> >> 
> >> 
 getViewSite().getActionBars().getStatusLineManager().setMess age( "Pasting 
> >> Completed"); 
> >> 
> >> 
> >> } 
> >> 
> >> }; 
> >> 
> 
> 
> 
>
 |  
 |  
  |  
| Re: Status Bar and setMessage [message #334122 is a reply to message #334096] | 
Wed, 21 January 2009 10:06    | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Dave, 
 
Thanks for the suggestions.  The issue that I am having is that Job  
doesn't appear to work because it yields a thread error.  I switched to  
using a UIJob and that allowed it to run, but the side effect was that  
Eclipse appeared not to fork and run the UI and the thread in parallel,  
but instead to just execute down the job path and ignore the rest of the  
code in the UI thread.   
 
My code looks like this now: 
 
 getViewSite().getActionBars().getStatusLineManager().setMess age( "Start  
Pasting"); 
System.out.println("At the beginning"); 
 
UIJob job = new UIJob("My Job") { 
	public IStatus runInUIThread(IProgressMonitor monitor) { 
		System.out.println("In the job"); 
                // Do the long running work here 
								 
		return Status.OK_STATUS; 
		} 
	}; 
	job.setPriority(Job.SHORT); 
	job.schedule(); // start as soon as possible 
				  				 
	 PlatformUI.getWorkbench().getDisplay().asyncExec((Runnable)j ob); 
 
 
 getViewSite().getActionBars().getStatusLineManager().setMess age( "End  
Pasting"); 
System.out.println("At the end"); 
 
When I look at the console the output is  
 
At the beginning 
In the job  
 
and then when all the stuff completes in the job "Start Pasting", not "End  
Pasting", shows up in the status line.   
 
So there are still two problems 
 
1) How do I get the status bar to update at the beginning of the method so  
that it displays "Start Pasting" *prior* to me doing the copy?  Whether I  
used another thread or not it still won't display feedback to the user  
while it does the work, only after everything is done. 
 
2) Why doesn't async execute like it should?  Instead it just goes down  
the new thread path and that is it. 
 
At this point am I doing something wrong or is this a bug?   
 
Thanks, 
 
Andy 
 
 
 
 
 
 
 
 
 
Dave Wegener wrote: 
 
> You've got the wrong thing in the job.  You need to place the long running 
> work in the run method of the job and the "Start" code should be invoked 
> after scheduling the job.  Wrap the "Completed" code in a Display.asyncExec 
> call and put it in the jobs run method after the long running work. 
 
> "Andy " <andrewnbenjamin@hotmail.com> wrote in message 
> news:26c2ecc53c6641797339d5b48dec3886$1@www.eclipse.org... 
>> I made the code look like the following: 
>> 
>> 
>> pasteAction = new Action(){ 
>> public void run(){ 
>> 
>> Job myjob = new Job("A Job") { 
>> protected IStatus run(IProgressMonitor monitor) { 
>> System.out.println("In the background job"); 
>>  getViewSite().getActionBars().getStatusLineManager().setMess age( "Start 
>> Pasting"); 
>> return Status.OK_STATUS; 
>> } 
>> }; 
>> myjob.setPriority(Job.SHORT); 
>> myjob.schedule(); 
>> 
>> // do some work that could take a while 
>> 
>>  getViewSite().getActionBars().getStatusLineManager().setMess age( "Pasting 
>> Completed"); 
>> 
>> 
>>  } 
>> 
>>  }; 
>> 
>> But now this time I get a thread access violation in addition to it 
>> appearing to run at the end of the method instead of the beginning.  Is 
>> there a different way to do this?  Yes, I do have this running in a class 
>> that extends ViewPart.  If this doesn't work as a job how would I run it? 
>> Why would it be blocked?  Thanks, 
>> 
>> Andy 
>> 
>> 
>> Derek wrote: 
>> 
>> > Looks like you are running your code in the UI thread and thus blocking 
>> > any updates. You should be running your long-running code in another 
>> > thread, or use a Job to do it. 
>> 
>> > Andy wrote: 
>> >> Hi, 
>> >> 
>> >> I have an action that can take a while to complete so I wanted to put 
>> >> some feedback in the status bar showing when the action started and 
> when 
>> >> it completed. 
>> >> The main problem is that this code only causes "Pasting Completed" to 
> be 
>> >> shown.  Any ideas as to get this code to show "Pasting Started" at the 
>> >> beginning, then do the file copying, and show Pasting Completed at the 
>> >> end? 
>> >> Just to see what would happen, I removed the last "Pasted Completed" 
>> >> line and ran it.  The run method did all its work and then showed 
>> >> "Pasting Started" when it was done.  Anyway, not sure why setMessage 
>> >> seems to be called last no matter where it is in the program flow.  Any 
>> >> suggestions?  Thanks, 
>> >> 
>> >> 
>> >> pasteAction = new Action(){ 
>> >> public void run(){ 
>> >> 
>> >> 
>  getViewSite().getActionBars().getStatusLineManager().setMess age( "Pasting 
>> >> Started"); 
>> >> 
>> >> // do some work that could take a while 
>> >> 
>> >> 
>  getViewSite().getActionBars().getStatusLineManager().setMess age( "Pasting 
>> >> Completed"); 
>> >> 
>> >> 
>> >> } 
>> >> 
>> >> }; 
>> >> 
>> 
>> 
>> 
>>
 |  
 |  
  |  
| Re: Status Bar and setMessage [message #334124 is a reply to message #334122] | 
Wed, 21 January 2009 10:40   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: wegener.cboenospam.com 
 
You are scheduling and executing the job.  You should only be doing one of 
these.  Long running processes should not be executed on the UI thread. 
When the process is executing, your UI will be frozen.  The UI thread should 
only be used when you need to access a UI element.  This would include 
setting the message on the status line.  If the results of the long running 
code need to be displayed on the GUI, you will need to wrap the UI updates 
in a runnable that gets passed to Display.asyncExec(). 
 
UIJob job = new UIJob() { 
    public IStatus run(IProgressMonitor monitor) { 
    //do the long running work here 
 
    Runnable results = new Runnable() { 
        public void run(){ 
              // update UI elements here; 
             statusLineManager.setMessage("End Pasting"); 
       } 
    }; 
    display.asyncExec(results); 
    } 
}; 
job.schedule(); 
 
 
 
"Andy " <andrewnbenjamin@hotmail.com> wrote in message 
news:96ffaa211fcefc497e6b2b91538c91ed$1@www.eclipse.org... 
> Dave, 
> 
> Thanks for the suggestions.  The issue that I am having is that Job 
> doesn't appear to work because it yields a thread error.  I switched to 
> using a UIJob and that allowed it to run, but the side effect was that 
> Eclipse appeared not to fork and run the UI and the thread in parallel, 
> but instead to just execute down the job path and ignore the rest of the 
> code in the UI thread. 
> 
> My code looks like this now: 
> 
>  getViewSite().getActionBars().getStatusLineManager().setMess age( "Start 
> Pasting"); 
> System.out.println("At the beginning"); 
> 
> UIJob job = new UIJob("My Job") { 
> public IStatus runInUIThread(IProgressMonitor monitor) { 
> System.out.println("In the job"); 
>                 // Do the long running work here 
> 
> return Status.OK_STATUS; 
> } 
> }; 
> job.setPriority(Job.SHORT); 
> job.schedule(); // start as soon as possible 
> 
>  PlatformUI.getWorkbench().getDisplay().asyncExec((Runnable)j ob); 
> 
> 
>  getViewSite().getActionBars().getStatusLineManager().setMess age( "End 
> Pasting"); 
> System.out.println("At the end"); 
> 
> When I look at the console the output is 
> 
> At the beginning 
> In the job 
> 
> and then when all the stuff completes in the job "Start Pasting", not "End 
> Pasting", shows up in the status line. 
> 
> So there are still two problems 
> 
> 1) How do I get the status bar to update at the beginning of the method so 
> that it displays "Start Pasting" *prior* to me doing the copy?  Whether I 
> used another thread or not it still won't display feedback to the user 
> while it does the work, only after everything is done. 
> 
> 2) Why doesn't async execute like it should?  Instead it just goes down 
> the new thread path and that is it. 
> 
> At this point am I doing something wrong or is this a bug? 
> 
> Thanks, 
> 
> Andy 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Dave Wegener wrote: 
> 
> > You've got the wrong thing in the job.  You need to place the long 
running 
> > work in the run method of the job and the "Start" code should be invoked 
> > after scheduling the job.  Wrap the "Completed" code in a 
Display.asyncExec 
> > call and put it in the jobs run method after the long running work. 
> 
> > "Andy " <andrewnbenjamin@hotmail.com> wrote in message 
> > news:26c2ecc53c6641797339d5b48dec3886$1@www.eclipse.org... 
> >> I made the code look like the following: 
> >> 
> >> 
> >> pasteAction = new Action(){ 
> >> public void run(){ 
> >> 
> >> Job myjob = new Job("A Job") { 
> >> protected IStatus run(IProgressMonitor monitor) { 
> >> System.out.println("In the background job"); 
> >>  getViewSite().getActionBars().getStatusLineManager().setMess age( "Start 
> >> Pasting"); 
> >> return Status.OK_STATUS; 
> >> } 
> >> }; 
> >> myjob.setPriority(Job.SHORT); 
> >> myjob.schedule(); 
> >> 
> >> // do some work that could take a while 
> >> 
> >> 
 getViewSite().getActionBars().getStatusLineManager().setMess age( "Pasting 
> >> Completed"); 
> >> 
> >> 
> >>  } 
> >> 
> >>  }; 
> >> 
> >> But now this time I get a thread access violation in addition to it 
> >> appearing to run at the end of the method instead of the beginning.  Is 
> >> there a different way to do this?  Yes, I do have this running in a 
class 
> >> that extends ViewPart.  If this doesn't work as a job how would I run 
it? 
> >> Why would it be blocked?  Thanks, 
> >> 
> >> Andy 
> >> 
> >> 
> >> Derek wrote: 
> >> 
> >> > Looks like you are running your code in the UI thread and thus 
blocking 
> >> > any updates. You should be running your long-running code in another 
> >> > thread, or use a Job to do it. 
> >> 
> >> > Andy wrote: 
> >> >> Hi, 
> >> >> 
> >> >> I have an action that can take a while to complete so I wanted to 
put 
> >> >> some feedback in the status bar showing when the action started and 
> > when 
> >> >> it completed. 
> >> >> The main problem is that this code only causes "Pasting Completed" 
to 
> > be 
> >> >> shown.  Any ideas as to get this code to show "Pasting Started" at 
the 
> >> >> beginning, then do the file copying, and show Pasting Completed at 
the 
> >> >> end? 
> >> >> Just to see what would happen, I removed the last "Pasted Completed" 
> >> >> line and ran it.  The run method did all its work and then showed 
> >> >> "Pasting Started" when it was done.  Anyway, not sure why setMessage 
> >> >> seems to be called last no matter where it is in the program flow. 
Any 
> >> >> suggestions?  Thanks, 
> >> >> 
> >> >> 
> >> >> pasteAction = new Action(){ 
> >> >> public void run(){ 
> >> >> 
> >> >> 
> >  getViewSite().getActionBars().getStatusLineManager().setMess age( "Pasting 
> >> >> Started"); 
> >> >> 
> >> >> // do some work that could take a while 
> >> >> 
> >> >> 
> >  getViewSite().getActionBars().getStatusLineManager().setMess age( "Pasting 
> >> >> Completed"); 
> >> >> 
> >> >> 
> >> >> } 
> >> >> 
> >> >> }; 
> >> >> 
> >> 
> >> 
> >> 
> >> 
> 
>
 |  
 |  
  |   
Goto Forum:
 
 Current Time: Tue Nov 04 00:26:38 EST 2025 
 Powered by  FUDForum. Page generated in 0.51262 seconds  
 |