com.inmethod.grid.treegrid.TreeGrid Maven / Gradle / Ivy
package com.inmethod.grid.treegrid;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.tree.AbstractTree;
import org.apache.wicket.extensions.markup.html.tree.DefaultTreeState;
import org.apache.wicket.extensions.markup.html.tree.ITreeState;
import org.apache.wicket.extensions.markup.html.tree.ITreeStateListener;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import com.inmethod.grid.IGridColumn;
import com.inmethod.grid.common.AbstractGrid;
/**
* Advanced grid with a tree. Supports resizable and reorderable columns.
*
* @param
* tree model object type
* @param
* node model object type
*
* @author Matej Knopp
*/
public class TreeGrid
extends AbstractGrid
{
private static final long serialVersionUID = 1L;
/**
* Creates a new {@link TreeGrid} instance.
*
* @param id
* component id
* @param model
* model used to access the {@link TreeModel}
* @param columns
* list of {@link IGridColumn}s.
*/
public TreeGrid(String id, IModel model, List> columns)
{
super(id, model, columns);
WebMarkupContainer bodyContainer = (WebMarkupContainer)get("form:bodyContainer");
bodyContainer.add(body = new TreeGridBody("body", model)
{
private static final long serialVersionUID = 1L;
@Override
protected Collection> getActiveColumns()
{
return TreeGrid.this.getActiveColumns();
}
@Override
protected void rowPopulated(WebMarkupContainer item)
{
TreeGrid.this.onRowPopulated(item);
}
@Override
protected ITreeState newTreeState()
{
return TreeGrid.this.newTreeState();
}
});
getTreeState().addTreeStateListener(new TreeStateListener());
}
private ITreeState newTreeState()
{
return new DefaultTreeState()
{
private static final long serialVersionUID = 1L;
@Override
public boolean isNodeSelected(Object node)
{
if (!isAutoSelectChildren())
{
return super.isNodeSelected(node);
}
else
{
// check if any parent of the node is selected
Object parent = node;
while (parent != null)
{
if (super.isNodeSelected(parent))
{
return true;
}
parent = getTree().getParentNode(parent);
}
}
return false;
}
private void deselectChildNodes(Object node)
{
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy