Geertjan's Blog

  • May 28, 2011

Better ChildFactory

Geertjan Wielenga
Product Manager

Thanks to Jesse, here's a corrected & improved ChildFactory from a few days ago, using ChildFactory.Detachable so that you have addNotify/removeNotify to add/remove the LookupListener and thus avoid a memory leak, together with a createKeys/resultChanged that is simplified too.

private class FirstLevelChildFactory extends ChildFactory.Detachable<ResultType> implements LookupListener {
    Result<ResultSet> resultRetrievedFromYahoo;
    protected void addNotify() {
        resultRetrievedFromYahoo = Utilities.actionsGlobalContext().lookupResult(ResultSet.class);
    protected void removeNotify() {
        resultRetrievedFromYahoo = null;
    protected boolean createKeys(List<ResultType> list) {
        for (ResultSet rs : resultRetrievedFromYahoo.allInstances()) {
        return true;
    protected Node createNodeForKey(ResultType key) {
        String[] split = key.getTitle().split(" ");
        String theNextWordToBeSearched = split[split.length - 1];
        AbstractNode firstLevelNode =
                new AbstractNode(
                Children.create(new GenericChildFactory(theNextWordToBeSearched), true),
        return firstLevelNode;
    public void resultChanged(LookupEvent le) {

This is a very simple & elegant solution.

Join the discussion

Comments ( 1 )
  • Javier Ortiz Tuesday, May 17, 2016

    This seems to work fine as long as you don't remove items from the lookup. I run a lot into issues with assertions where the map amount are out of sync.

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