ca.odell.glazedlists.DefaultExternalExpansionModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of glazedlists_java15 Show documentation
Show all versions of glazedlists_java15 Show documentation
Event-driven lists for dynamically filtered and sorted tables
/* 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));
}
}