private void createComponents(final Saisons saisons, final Object selectedItem,
final boolean isNew, final Object subCategory)
{
final TreeModel treeModel = this.convertToTreeModel(saisons);
final Tree tree = new Tree("tree", treeModel)
{
/**
*
*/
private static final long serialVersionUID = -7692224335434128747L;
@Override
protected String renderNode(TreeNode node)
{
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node;
Object userObject = treeNode.getUserObject();
String caption = null;
if (userObject instanceof Saison)
{
caption = ((Saison) userObject).getNom();
}
else if (userObject instanceof Evenement)
{
caption = ((Evenement) userObject).getEndroit();
}
else if (userObject instanceof Course)
{
caption = ((Course) userObject).getNom();
}
else if (userObject instanceof Saisons)
{
caption = "Saisons";
}
return caption;
}
/*
* (non-Javadoc)
*
* @see wicket.extensions.markup.html.tree.DefaultAbstractTree#onNodeLinkClicked(wicket.ajax.AjaxRequestTarget,
* javax.swing.tree.TreeNode)
*/
@Override
protected void onNodeLinkClicked(AjaxRequestTarget requestTarget,
TreeNode treeNode)
{
// Puisque la méthode est appelée si le noeud est sélectionné
// ou désélectionné, il faut valider si le noeud est
// sélectionné.
if (this.getTreeState().getSelectedNodes().contains(treeNode))
{
Map<Parameters, Object> params = new HashMap<Parameters, Object>();
DefaultMutableTreeNode mutableTreeNode = (DefaultMutableTreeNode) treeNode;
params.put(GestionEvenementsPanel.Parameters.SELECTED_ITEM,
mutableTreeNode.getUserObject());
params.put(GestionEvenementsPanel.Parameters.IS_NEW, false);
GestionEvenementsPanel.this.setResponsePage(new HomePage(
GestionEvenementsPanel.class, params));
}
super.onNodeLinkClicked(requestTarget, treeNode);
}
};
tree.setLinkType(LinkType.REGULAR);
this.add(tree);
this.add(new GestionEvenementsContentPanel("contentPanel",
selectedItem, isNew, subCategory));
}