/*
* xulfaces : bring XUL power to Java
*
* Copyright (C) 2005 Olivier SCHMITT
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.xulfaces.rubis.admin.controller.user;
import java.util.ArrayList;
import java.util.Collection;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import org.xulfaces.rubis.TreeController;
import org.xulfaces.rubis.admin.dao.ItemDAO;
import org.xulfaces.rubis.model.User;
public class ItemsTreeController extends TreeController {
private ItemDAO itemDAO;
private UsersTreeController usersTreeController;
public ItemsTreeController(){
super();
}
public ItemDAO getItemDAO() {
return itemDAO;
}
public void setItemDAO(ItemDAO itemDAO) {
this.itemDAO = itemDAO;
}
public UsersTreeController getUsersTreeController() {
return usersTreeController;
}
public void setUsersTreeController(UsersTreeController usersTreeController) {
this.usersTreeController = usersTreeController;
}
public void clear(){
setTreeModel(buildTreeModelFromCollection(new ArrayList()));
}
public void showItems(){
TreePath selectionPath[] = getUsersTreeController().getTreeView().getSelectionPath();
if(selectionPath != null){
for(int i=0; i < selectionPath.length; i++){
TreePath treePath = selectionPath[i];
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();
if(treeNode.getParent() != null){
User user = (User) treeNode.getUserObject();
if(user != null){
Collection items = getItemDAO().getItemsForSeller(user);
setTreeModel(buildTreeModelFromCollection(items));
}
}
}
}
}
}