1 package org.ozoneDB.adminGui.feature.account.groups; 8 9 import java.util.Vector ; 10 import javax.swing.event.TreeModelEvent ; 11 import javax.swing.event.TreeModelListener ; 12 import javax.swing.tree.TreeModel ; 13 import javax.swing.tree.TreePath ; 14 15 import org.ozoneDB.adminGui.feature.account.AccountItem; 16 17 18 27 29 public class GroupTreeModel implements TreeModel { 30 31 32 private Vector treeModelListeners = new Vector (); 33 34 private AccountItem rootItem = null; 35 36 37 40 public GroupTreeModel() { 41 this.rootItem = new AccountItem("Accounts", 0); 42 } 43 44 49 public void addTreeModelListener(TreeModelListener l) { 50 this.treeModelListeners.addElement(l); 51 } 52 53 58 public void removeTreeModelListener(TreeModelListener l) { 59 this.treeModelListeners.removeElement(l); 60 } 61 62 67 public Object getRoot() { 68 return this.rootItem; 69 } 70 71 78 public boolean isLeaf(Object node) { 79 AccountItem item = (AccountItem) node; 80 return item.getChildCount() == 0; 81 } 82 83 89 public int getChildCount(Object parent) { 90 AccountItem item = (AccountItem) parent; 91 return item.getChildCount(); 92 } 93 94 101 public int getIndexOfChild(Object parent, Object child) { 102 AccountItem item = (AccountItem) parent; 103 return item.getIndexOfChild((AccountItem) child); 104 } 105 106 113 public void valueForPathChanged(TreePath path, Object newValue) { 114 System.out.println("*** valueForPathChanged : " + path + " --> " + 115 newValue); 116 } 117 118 126 public Object getChild(Object parent, int index) { 127 AccountItem item = (AccountItem) parent; 128 return item.getChildAt(index); 129 } 130 131 136 public void fireTreeStructureChanged() { 137 int len = this.treeModelListeners.size(); 138 TreeModelEvent e = new TreeModelEvent (this, new Object []{rootItem}); 139 140 for (int i = 0; i < len; i++) { 141 ((TreeModelListener ) this.treeModelListeners.elementAt(i)). 142 treeStructureChanged(e); 143 } 144 } 145 146 151 public AccountItem getRootItem() { 152 return this.rootItem; 153 } 154 155 158 public void clearGroups() { 159 this.rootItem.setChildren(null); 161 } 162 163 } 165 166 | Popular Tags |