private TreeExpansionListener createTreeExpansionListener() {
        return new TreeExpansionListener() {
            public void treeExpanded(TreeExpansionEvent event) {
                onExpandedOrCollapsed(event, true);
            }

            public void treeCollapsed(TreeExpansionEvent event) {
                onExpandedOrCollapsed(event, false);
            }

            private void onExpandedOrCollapsed(TreeExpansionEvent event, boolean expanded) {
                Object itemOrCategory = getItemOrCategoryFromTreeExpansionEvent(event);

                if (itemOrCategory != null) {
                    if (itemOrCategory instanceof SourceListCategory) {
                        SourceListCategory category = (SourceListCategory) itemOrCategory;
                        if (expanded) {
                            fireSourceListCategoryExpanded(category);
                        } else {
                            fireSourceListCategoryCollapsed(category);
                        }
                    } else if (itemOrCategory instanceof SourceListItem) {
                        SourceListItem sourceListItem = (SourceListItem) itemOrCategory;
                        if (expanded) {
                            fireSourceListItemExpanded(sourceListItem);
                        } else {
                            fireSourceListItemCollapsed(sourceListItem);
                        }
                    }
                }
            }
        };
    }