Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Looking for hook to run in main UI thread after init is complete(Looking for way to run a certain code sequence in the main UI thread after initialization is complete.)
Looking for hook to run in main UI thread after init is complete [message #816267] Thu, 08 March 2012 16:21 Go to next message
Bob Beetcher is currently offline Bob BeetcherFriend
Messages: 2
Registered: July 2009
Junior Member
Because I'm not very well traveled in Eclipse java RCP development, please excuse any confusing concepts or terminology I may include with this post.

As I see it, I'm looking for help with how to ensure a particular code sequence of mine always gets run under the application's main UI thread after initialization is complete.

The code sequence I want to be run looks like this:


final IWorkbenchPage activePage =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
viewStartup(activePage);
}


where the viewStartup method contains:

activePage.showView("com.my.particular.view.id", null, IWorkbenchPage.VIEW_CREATE);

The point of the whole sequence is to trigger asynchronous loading of the view, which normally takes around 30 seconds. Currently, the view loading isn't triggered until a user selects the view which is very frustrating for them. Because the users are usually involved with other application operations for significant periods of time, loading the view in the background would be a big help. Then, when they select the view it will open immediately.

I have verified the code sequence works as desired if run under the main UI thread after initialization completes by hooking it into a couple of our application's menu options. Because there are numerous options the user might first access after initialization, it's not a robust solution to instrument this view loading through such touch points.

What would work best is to implement some hook, listener, or whatever that didn't require user action and always was run under the main UI thread after initialization was sufficiently complete to allow the code sequence of interest to run OK.

For background, here are some things I've tried that didn't work to run the code sequence.

1) Plug-in start() method: Null pointer exception. Believe this is because initialization hasn't proceeded far enough.

2) Plug-in earlyStart() method: Null pointer exception. Believe exception arises because it's not running in the main UI thread.

3) Hooking into project builder: That only runs in response to workspace changes and anyway incurs null pointer exception. Believe this is because it's not running in the main UI thread.

Our RCP is an XML authoring IDE for which user actions are usually initiated by making selections in the Navigator view. Perhaps there's a way to add a listener to that view which could be triggered off the first mouse click in the view. My lack of experience has prevented me from experimenting with something like that.

Thanks ahead of time for any suggestions you folks may be able to provide.


Re: Looking for hook to run in main UI thread after init is complete [message #820199 is a reply to message #816267] Tue, 13 March 2012 21:09 Go to previous messageGo to next message
Bob Beetcher is currently offline Bob BeetcherFriend
Messages: 2
Registered: July 2009
Junior Member
It turns out that the solution that worked for me was to make use of the org.eclipse.ui.progress.UIJob class as is suggested in this "FAQ Can I make a job run in the UI thread? - Eclipsepedia" which is available at this URL (remove blank after http:):
http: //wiki.eclipse.org/FAQ_Can_I_make_a_job_run_in_the_UI_thread%3F

What worked was to schedule, within the earlyStartup() method of the plugin implementing the view, a UIJob to access an instance of the active page for the workbench and then pass that to another thread started using the Display.asyncExec() method.

This approach allowed for always scheduling an action to run just after startup of our RCP that accesses the active page under the main UI thread but then kicks off the lengthy loading of the view to be run in a background thread.
Re: Looking for hook to run in main UI thread after init is complete [message #820220 is a reply to message #820199] Tue, 13 March 2012 21:37 Go to previous message
Eclipse UserFriend
Hi,

This may be OK in your particular case. But remember that using the
IStartup extension point means that your plugin will be started always
on every start up even if the user has none of your views open or even
if he doesn't care about your views at all but just simply has your
plugins installed. It also slows down start up because there are so many
plugins that think they need to be activated at start up even though
they may never be used.
--
Thanks,
Rich Kulp
Previous Topic:Clean/Build Issues
Next Topic:Regular expression matched by two occurrences (one occurrence inside the other)
Goto Forum:
  


Current Time: Fri Apr 19 06:17:50 GMT 2024

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

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

Back to the top