package org.apache.wicket.examples.tree.content;
import java.util.Optional;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.examples.tree.Foo;
import org.apache.wicket.extensions.markup.html.repeater.tree.AbstractTree;
import org.apache.wicket.extensions.markup.html.repeater.tree.ITreeProvider;
import org.apache.wicket.extensions.markup.html.repeater.tree.content.CheckedFolder;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
@author
public class CheckedSelectableFolderContent extends SelectableFolderContent
{
private static final long serialVersionUID = 1L;
public CheckedSelectableFolderContent(ITreeProvider<Foo> provider)
{
super(provider);
}
@Override
public Component newContentComponent(String id, final AbstractTree<Foo> tree, IModel<Foo> model)
{
return new CheckedFolder<Foo>(id, tree, model)
{
private static final long serialVersionUID = 1L;
@Override
protected IModel<Boolean> newCheckBoxModel(final IModel<Foo> model)
{
return new PropertyModel<>(model, "quux");
}
@Override
protected void onUpdate(AjaxRequestTarget target)
{
Foo foo = getModelObject();
while (!foo.getQuux() && foo.getParent() != null)
{
foo = foo.getParent();
}
tree.updateBranch(foo, target);
}
@Override
protected boolean isClickable()
{
return true;
}
@Override
protected void onClick(Optional<AjaxRequestTarget> targetOptional)
{
CheckedSelectableFolderContent.this.select(getModelObject(), tree, targetOptional);
}
@Override
protected boolean isSelected()
{
return CheckedSelectableFolderContent.this.isSelected(getModelObject());
}
};
}
}