private TreeWillExpandListener createTreeWillExpandListener() {
        return new TreeWillExpandListener() {
            public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
                onWillExpandOrCollapse(event, true);
            }

            public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
                onWillExpandOrCollapse(event, false);
            }

            private void onWillExpandOrCollapse(TreeExpansionEvent event, boolean expanded) throws ExpandVetoException {
                Object itemOrCategory = getItemOrCategoryFromTreeExpansionEvent(event);

                if (itemOrCategory != null) {
                    if (itemOrCategory instanceof SourceListCategory) {
                        SourceListCategory category = (SourceListCategory) itemOrCategory;
                        if (expanded) {
                            fireSourceListCategoryWillExpand(event, category);
                        } else {
                            fireSourceListCategoryWillCollapse(event, category);
                        }
                    } else if (itemOrCategory instanceof SourceListItem) {
                        SourceListItem sourceListItem = (SourceListItem) itemOrCategory;
                        if (expanded) {
                            fireSourceListItemWillExpand(event, sourceListItem);
                        } else {
                            fireSourceListItemWillCollapse(event, sourceListItem);
                        }
                    }
                }
            }
        };
    }