Eclipse 3.3 Startup Changes Take Three

Hopefully this will be the last post with the words “startup changes” in its title for a very long time to come.

As mentioned previously, in 3.3 we prevent unknown Runnables from executing during the startup procedure via Display.syncExec() and Display.asyncExec(). I last mentioned a strategy for avoiding use of such runnables during the initialization of editors. I believe that advice is still valid. However, there are scenarios where you may legitimately need access to these methods. Without them, for instance, Splash Screen implementors are forced to spin the event loop themselves if they want to do any clever UI work while the workbench is coming up. In an answer to this problem, we’ve added the new org.eclipse.ui.application.DisplayAccess class as API to the 3.4 stream. This class has one static method, accessDisplayDuringStartup(). Calling this method on any thread not created by the UI (ie: any user Thread) will allow that thread to access the Display.async() and Display.sync() methods as if they were one of our privileged startup threads.

For example:

[code lang="java"]package mail.example;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.application.DisplayAccess;
import org.eclipse.ui.splash.AbstractSplashHandler;

public class SplashHandlerWIthDisplayAccess extends AbstractSplashHandler {
	public void init(Shell splash) {
		super.init(splash);

		final Color[] color = new Color[] { splash.getDisplay().getSystemColor(
				SWT.COLOR_YELLOW) };
		final Canvas canvas = new Canvas(splash, SWT.NONE);
		canvas.setBounds(0, 0, splash.getSize().x, splash.getSize().y);
		canvas.addPaintListener(new PaintListener() {

			public void paintControl(PaintEvent e) {
				e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_BLACK));
				e.gc.setBackground(color[0]);
				e.gc.fillOval(0, 0, canvas.getSize().x, canvas.getSize().y);
			}
		});

		Thread worker = new Thread() {
			public void run() {
				DisplayAccess.accessDisplayDuringStartup();
				try {
					Thread.sleep(500); // sleep a little so we can see the
										// color change
				} catch (InterruptedException e) {
				}
				canvas.getDisplay().syncExec(new Runnable() {

					public void run() {
						color[0] = canvas.getDisplay().getSystemColor(
								SWT.COLOR_GREEN);
						if (!canvas.isDisposed())
							canvas.redraw();
					}
				});
			}
		};
		worker.start();
	}
}
[/code]

This simple splash handler creates a canvas on the splash shell that will initially have a yellow oval taking up the entirety of the drawing area. We then create a thread which declares that it will be used to access the display during startup. After a short nap this thread will set the color of the oval to green and cause a repaint. You can verify that without the call to DisplayAccess.accessDisplayDuringStartup() the oval will remain yellow until the splash comes down.

This entry was posted in Eclipse. Bookmark the permalink. Follow any comments here with the RSS feed for this post. Trackbacks are closed, but you can post a comment.

12 comments on “Eclipse 3.3 Startup Changes Take Three

  1. Tryggvi Larusson on said:

    Will it now be possible to do some fancy stuff in the splash screen like an irregular background with alpha channel transparency?

  2. Andrei Loskutov on said:

    Hi Kim, do you mean Eclipse 3.3 or 3.4? AFAIK, there is no DisplayAccess in 3.3 stream.

  3. pookzilla on said:

    Andrei: The change to the startup process happened in 3.3 but this new API is going to ship with 3.4. I should’ve been more clear. Thanks!

  4. pookzilla on said:

    Tryggvi: You could’ve done this already – this new API wont help you with that problem.

  5. Jay Jonas on said:

    Hi, Kim!

    How we could to do that fancy stuff in the splash screen like an irregular background with alpha channel transparency and fade in/out?

    Don’t we need 3.4 to do that? Just do we can do it now?

  6. pookzilla on said:

    Jay: that stuff would be easier with the new API in 3.4 but it can be done with 3.3. I’ll post an example sometime after EclipseCon.

  7. Jay Jonas on said:

    Thank you, Kim!

  8. hangum on said:

    Thank you, Kim~~

  9. Hi,
    How can we modify the splash screen style (transparency, opaque)?

    Thx,
    David.

  10. salish.s on said:

    hi
    I’m a beginner in eclipse .I need help in the background worker in eclipse 6.will u please help me with a login screen example ie just a login screen
    Username:
    password:
    while entering the value the authentication waiting has to done with a background worker.
    please help me. salish

  11. Severin on said:

    Thankyou for the great article! Helped me out so much :-)

    –Sev

  12. pookzilla on said:

    Honestly I have no idea. I’m on the outside of the eclipse community now and i haven’t been keeping tabs on the state of these features.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

2,660 Spam Comments Blocked so far by Spam Free Wordpress

HTML tags are not allowed.

  • About Me

    Hi! My name is Kimberly Horne and I have absolutely nothing interesting to say. Unfortunately for you I DO have an overpowering need to tinker with technology which is explains the presence of this journal. I mostly talk about games (video and tabletop), technology, tattoos, and my pets.

    If you're an Eclipse user you may find my Eclipse category more interesting.

    Similarly, if you're an Arduino nerd then maybe my projects might be of interest.

    Since I've discovered Twitter this journal has been neglected somewhat. If you really want to stalk me your best bet is to follow me on twitter.