class FilterUIModel {

    private final Workspace workspace;
    private final List<Query> expandedQueryNodes;
    private final List<Query> expandedParametersNodes;
    private final List<Category> expandedCategoryNodes;
    private final List<ChangeListener> listeners;
    private Query selectedQuery;

    public FilterUIModel(Workspace workspace) {
        this.workspace = workspace;
        listeners = new ArrayList<>();
        expandedQueryNodes = new ArrayList<>();
        expandedCategoryNodes = new ArrayList<>();
        expandedParametersNodes = new ArrayList<>();
    }

    public Workspace getWorkspace() {
        return workspace;
    }

    public Query getSelectedQuery() {
        return selectedQuery;
    }

    public void setSelectedQuery(Query query) {
        selectedQuery = query;
        fireChangeEvent();
    }

    public Query getSelectedRoot() {<FILL_FUNCTION_BODY>}

    public void setExpand(Query query, boolean expanded, boolean parametersExpanded) {
        if (expanded && !expandedQueryNodes.contains(query)) {
            expandedQueryNodes.add(query);
        } else if (!expanded) {
            expandedQueryNodes.remove(query);
        }

        if (parametersExpanded && !expandedParametersNodes.contains(query)) {
            expandedParametersNodes.add(query);
        } else if (!parametersExpanded) {
            expandedParametersNodes.remove(query);
        }
    }

    public void setExpand(Category category, boolean expanded) {
        if (expanded && !expandedCategoryNodes.contains(category)) {
            expandedCategoryNodes.add(category);
        } else if (!expanded) {
            expandedCategoryNodes.remove(category);
        }
    }

    public boolean isExpanded(Query query) {
        return expandedQueryNodes.contains(query);
    }

    public boolean isParametersExpanded(Query query) {
        return expandedParametersNodes.contains(query);
    }

    public boolean isExpanded(Category category) {
        return expandedCategoryNodes.contains(category);
    }

    public void addChangeListener(ChangeListener listener) {
        if (!listeners.contains(listener)) {
            listeners.add(listener);
        }
    }

    public void removeChangeListener(ChangeListener listener) {
        listeners.remove(listener);
    }

    private void fireChangeEvent() {
        ChangeEvent evt = new ChangeEvent(this);
        for (ChangeListener listener : listeners) {
            listener.stateChanged(evt);
        }
    }
}

        if (selectedQuery != null) {
            Query root = selectedQuery;
            while (root.getParent() != null) {
                root = root.getParent();
            }
            return root;
        }
        return null;
    
<no_super_class>