X

Geertjan's Blog

  • June 20, 2010

Enhanced Change Notifications for Lookup in NetBeans Platform 6.9

Geertjan Wielenga
Product Manager
A typical stumbling block for newbies to Lookup goes like this: you've created a Result object and then set a LookupListener on that object. Now you're listening to the context (of the application or of a specific window) and then... nothing happens!

You then find yourself adding the line in bold below:

@Override
public void componentOpened() {
result = Utilities.actionsGlobalContext().lookupResult(Customer.class);
result.addLookupListener(this);resultChanged(new LookupEvent(result));
}

That line in bold is for the opening of the window. At that point, there's no change in the Lookup yet. So you manually call the resultChanged method, passing in 'null' or, more elegantly, a new LookupEvent with the current Result object.

However, in 6.9, a nice enhancement was added:

http://hg.netbeans.org/main-golden/rev/d032dfa7b3cf

In other words, adding the LookupListener is all you need to do. No need to call the resultChanged anymore. I tried that today, during the training with the students in Burkina Faso... and code that would not have worked in 6.8 (i.e., code without the last line in the method above), now works perfectly in 6.9.

Should make a big difference for newbies working with Lookup in the NetBeans Platform.

In other news. The training in Burkina Faso was a success for everyone involved. Patrick Honoré Ouoba, Hyacinthe Bosso Tingueri, Emmanuel Zimian Paregueba Ouedraogo, Oumar Abdou Nassur Konombo, Constantin Drabo, and Fatimazahra Hakkou are the latest NetBeans Platform Certified Associates. We're 'meeting' (Skype, plus WebEx) again in a month, to port one of their applications to the NetBeans Platform together.

Join the discussion

Comments ( 2 )
  • Jaroslav Tulach Monday, June 21, 2010

    You don't need to call result.allItems(), but there is no guarantee you should not initialize your structures based on actual content of the lookup.


  • Janice Tuesday, October 5, 2010

    This is a welcome change. But I think we need a clear writeup on how to migrate from old code to new one. Escpecially for newbies who are looking at the old samples (like me), it will be very helpfull (Unless every samples is migrated).


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.