class FiltersExplorer extends BeanTreeView {

    public static final Category QUERIES = new Category(
        NbBundle.getMessage(FiltersExplorer.class, "FiltersExplorer.Queries"),
        null,
        null);
    private final Category UNSORTED = new Category(
        NbBundle.getMessage(FiltersExplorer.class, "FiltersExplorer.UnsortedCategory"),
        null,
        null);
    private ExplorerManager manager;
    private FilterLibrary filterLibrary;
    private FilterUIModel uiModel;

    public FiltersExplorer() {
    }

    public void setup(final ExplorerManager manager, FilterModel model, FilterUIModel uiModel) {<FILL_FUNCTION_BODY>}

    private void updateEnabled(final boolean enabled) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                setRootVisible(enabled);
                setEnabled(enabled);
            }
        });
    }

    private void loadExpandStatus(CategoryNode node) {
        if (uiModel == null) {
            return;
        }
        if (uiModel.isExpanded(node.getCategory())) {
            expandNode(node);
        }
        for (Node n : node.getChildren().getNodes()) {
            if (n instanceof CategoryNode) {
                loadExpandStatus((CategoryNode) n);
            }
        }
    }

    private void saveExpandStatus(CategoryNode node) {
        if (uiModel == null) {
            return;
        }
        uiModel.setExpand(node.getCategory(), isExpanded(node));
        for (Node n : node.getChildren().getNodes()) {
            if (n instanceof CategoryNode) {
                saveExpandStatus((CategoryNode) n);
            }
        }
    }

    protected class Utils implements LookupListener {

        private final Lookup.Result<FilterBuilder> lookupResult;
        private final Lookup.Result<Query> lookupResult2;

        public Utils() {
            lookupResult = filterLibrary.getLookup().lookupResult(FilterBuilder.class);
            lookupResult.addLookupListener(this);
            lookupResult2 = filterLibrary.getLookup().lookupResult(Query.class);
            lookupResult2.addLookupListener(this);
        }

        @Override
        public void resultChanged(LookupEvent ev) {
            saveExpandStatus((CategoryNode) manager.getRootContext());
            manager.setRootContext(new CategoryNode(this, null));
            loadExpandStatus((CategoryNode) manager.getRootContext());
        }

        public boolean isLeaf(Category category) {
            if (category == null) {
                return false;
            }
            if (category.equals(QUERIES)) {
                return filterLibrary.getLookup().lookupAll(Query.class).isEmpty();
            }
            for (FilterBuilder fb : filterLibrary.getLookup().lookupAll(FilterBuilder.class)) {
                if (fb.getCategory() == null && category.equals(UNSORTED)) {
                    return false;
                }
                if (fb.getCategory() != null && fb.getCategory().getParent() != null &&
                    fb.getCategory().getParent().equals(category)) {
                    return false;
                }
                if (fb.getCategory() != null && fb.getCategory().equals(category)) {
                    return false;
                }
            }
            for (CategoryBuilder cb : filterLibrary.getLookup().lookupAll(CategoryBuilder.class)) {
                if (cb.getCategory().equals(category)) {
                    return false;
                }
                if (cb.getCategory().getParent() != null && cb.getCategory().getParent().equals(category)) {
                    return false;
                }
            }
            return true;
        }

        public Object[] getChildren(Category category) {
            Set<Object> cats = new HashSet<>();

            if (category != null && category.equals(QUERIES)) {
                for (Query q : filterLibrary.getLookup().lookupAll(Query.class)) {
                    cats.add(q);
                }
            } else {
                if (category == null) {
                    cats.add(QUERIES);
                }
                //get categories from filter builders
                for (FilterBuilder fb : filterLibrary.getLookup().lookupAll(FilterBuilder.class)) {
                    if (fb.getCategory() == null) {
                        if (category == null) {
                            cats.add(UNSORTED);
                        } else if (category.equals(UNSORTED)) {
                            cats.add(fb);
                        }
                    } else if (fb.getCategory().getParent() == category) {
                        if (isValid(fb.getCategory())) {
                            cats.add(fb.getCategory());
                        }
                    } else if (fb.getCategory().getParent() != null && fb.getCategory().getParent().equals(category)) {
                        if (isValid(fb.getCategory())) {
                            cats.add(fb.getCategory());
                        }
                    } else if (fb.getCategory().equals(category)) {
                        cats.add(fb);
                    }
                }
                //get categories from cat builders
                for (CategoryBuilder cb : filterLibrary.getLookup().lookupAll(CategoryBuilder.class)) {
                    if (cb.getCategory().getParent() == category) {
                        cats.add(cb.getCategory());
                    } else if (cb.getCategory().getParent() != null &&
                        cb.getCategory().getParent().getParent() == category) {
                        cats.add(cb.getCategory().getParent());
                    } else if (cb.getCategory() == category) {
                        for (FilterBuilder fb : cb.getBuilders(uiModel.getWorkspace())) {
                            cats.add(fb);
                        }
                    }
                }
            }
            return cats.toArray();
        }

        public boolean isValid(Category category) {
            for (FilterLibraryMask mask : filterLibrary.getLookup().lookupAll(FilterLibraryMask.class)) {
                if (mask.getCategory().equals(category)) {
                    return mask.isValid();
                }
            }
            return true;
        }
    }
}

        this.manager = manager;

        this.uiModel = uiModel;
        if (model != null) {
            this.filterLibrary = model.getLibrary();
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    manager.setRootContext(new CategoryNode(new Utils(), null));
                }
            });
        } else {
            this.filterLibrary = null;
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    manager.setRootContext(new AbstractNode(Children.LEAF) {

                        @Override
                        public Action[] getActions(boolean context) {
                            return new Action[0];
                        }
                    });
                }
            });
        }
        updateEnabled(model != null);
    
<no_super_class>