| «« Free Software Realities | Let's Talk About the "I" Word: Innovation »» |
|
About
I'm Ryan Lowe, a Software Engineering graduate living in Ottawa, Canada. I like agile software development and Ruby on Rails.
I write this blog in Canadian English and don't use a spell checker. Typos happen.
Projects
» Full-time Ruby on Rails freelancer
» Full-time with Rails since May 2005 » Former committer for RadRails (now Aptana) » I also have a few Rails side-projects in development: 1. wheretogoinTO.com Toronto nightlife 2. Hey Heads Up! TODO list and sharing 3. Layered Genealogy family history research 4. foos for foosball scoring 5. fanconcert for music fans (on hold) Hiring Rails developers? I can telecommute by the hour from Ottawa, Canada »» Email: rails AT ryanlowe DOT ca
BulletBlog
Now hosted on Hey! Heads Up -- check it out!
Syndication
Pings
Recent
Derek Lowe's (Ryan's older brother) words at Ryan's funeral
blog@ryanlowe.ca no more Forging Email Headers: Good, Bad or Ugly? Sarcastic Dictionary (Part 1 of Many) Tags Hierarchies Twisting Rails is Risky Business Risky Business? My Take on Early Alphas Whoa, it's August 2007 Closing Comments A Postscript to "Growth at the grassroots" »» All Blog Posts
Linkage
del.icio.us/ryanlowe
technorati/ryanlowe.ca/blog Aurora Roy Jim Andrew Trasker Travis Kibbee Karen Dr. Unk Ayana Van Bloggers Joel Spolsky Robert Scoble Tim Bray Dave Winer Raymond Chen James Robertson Ruby/Rails Bloggers rubyonrails.org weblog David Heinemeier Hansson Dave Thomas James Duncan Davidson Mike Clark Jamis Buck Signal vs. Noise Tobias Luetke Amy Hoy: (24)slash7 Jeremy Voorhis Eclipse Bloggers Planet Eclipse EclipseZone Luis de la Rosa Eclipse Foundation Kim Horne Billy Biggs Ian Skerrett Mike Milinkovich Bjorn Freeman-Benson Denis Roy
Archives
|
Roll Your Own ApplicationWindow OnOpenListener
JFace's ApplicationWindow object doesn't seem to have a listener that is triggered when it is opened. This is unfortunate because there are lots of things that you might want to do when the "UI is ready", like load it with data. Warning, the following explanation is from 30,000 feet ... ApplicationWindow uses the method open() to show itself. Developers usually make this method call block, meaning that code after open() doesn't execute until after the window is closed. After open(), everything is event-driven. So you can't make a call to your database after open() and expect it to affect the GUI. There is a way to get around it though. The windowing toolkit that JFace uses, SWT, is a layer on top of each operating system it is written to. SWT receives messages from the operating system and stuffs them into a queue. These are messages about if the mouse pointer moved, if a click happened or if a letter was typed. SWT then processes these events and updates the application's GUI. Do you remember me blogging about asyncExec()? This method call just puts a Runnable on SWT's queue, usually from a non-UI thread because SWT only allows the SWT thread to modify it. But who says you can't use it from the UI thread too? Here's how I did it: public static void main(String[] args) window.getShell().getDisplay().asyncExec(new Runnable() window.setBlockOnOpen(true); Display.getCurrent().dispose(); Now the task runs right after the window appears. The trick is window.create(). Usually you don't have to call it but it will initialize the Shell for you (I found that out poking around in the SWT code). Otherwise the Shell is null until open() (too late!). Without window.create(), you can't getDisplay() from the window's Shell and you can't use asyncExec(). BTW, I used this technique to put progress bars in AudioMan when it loads and saves the repository on open and exit. It looks sweet! I'll be releasing a new version of AudioMan (0.3.1) shortly. Posted at March 01, 2004 at 07:34 AM ESTLast updated March 01, 2004 at 07:34 AM EST Comments
Why not just use Display.getDefault() to get dislpay object? I'm so interested in that subject since I'm running into same problems right now :( » Posted by: Ali Zaid at March 1, 2004 09:58 PMHey! That works. I tried getCurrent() with no window.create() and I got NullPointerException .... but getDefault() works. » Posted by: Ryan at March 1, 2004 11:42 PMEither way you still have to queue the event you want to have after open() this way because open() blocks. » Posted by: Ryan at March 1, 2004 11:46 PMWell, I have to thank you allot, you saved my day, I finally solved my problem because of you wonderful articals... I had this killing thread that select from a database about 59721 Record, I have to show 1000 one in each page, still, I have no control over which (not serial), even with filters I couldn't have my gui running right, I knew about asyncExec but I did not know how to use it. I'm so Thankful » Posted by: Ali Zaid at March 2, 2004 02:32 PM |