All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ca.odell.glazedlists.DefaultExternalExpansionModel Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
/* Glazed Lists                                                 (c) 2003-2006 */
/* http://publicobject.com/glazedlists/                      publicobject.com,*/
/*                                                     O'Dell Engineering Ltd.*/
package ca.odell.glazedlists;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * An {@link TreeList.ExpansionModel} that uses a {@link Map} to remember
 * the expanded/collapsed state of elements.
 *
 * TODO(jessewilson): USE WEAK REFERENCES
 *
 * @author Jesse Wilson
 */
public class DefaultExternalExpansionModel implements TreeList.ExpansionModel {

    /** keep track of the expanded state of each element, by its identity */
    private HashMap elementsExpandedStates = new HashMap();

    /** the {@link TreeList.ExpansionModel} to delegate to for unknown elements */
    private TreeList.ExpansionModel defaultsModel;

    public DefaultExternalExpansionModel(TreeList.ExpansionModel defaultsModel) {
        this.defaultsModel = defaultsModel;
    }

    public DefaultExternalExpansionModel() {
        this(TreeList.nodesStartExpanded());
    }

    public boolean isExpanded(E element, List path) {
        Boolean expanded = elementsExpandedStates.get(element);
        if(expanded == null) {
            expanded = Boolean.valueOf(defaultsModel.isExpanded(element, path));
            setExpanded(element, path, expanded.booleanValue());
        }
        return expanded.booleanValue();
    }

    public void setExpanded(E element, List path, boolean expanded) {
        elementsExpandedStates.put(element, Boolean.valueOf(expanded));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy