public DomainTreeModel(Domain domain) { d_domain = domain; for (EntityCategory c : d_domain.getCategories()) { d_domain.getCategoryContents(c).addListDataListener(new CategoryListener(c)); } d_listeners = new ArrayList<TreeModelListener>(); }
public boolean isLeaf(Object node) { if (node instanceof Entity) { EntityCategory category = d_domain.getCategory(((Entity) node)); if (category != null) { return d_domain.getCategoryContents(category).contains(node); } } return false; }
private void fireTreeNodeInserted(EntityCategory category, int idx) { for (TreeModelListener l : d_listeners) { l.treeNodesInserted( new TreeModelEvent( this, new Object[] {d_root, category}, new int[] {idx}, new Object[] {d_domain.getCategoryContents(category).get(idx)})); } }
public Object getChild(Object parent, int childIndex) { if (d_root.equals(parent) && childIndex >= 0 && childIndex < d_domain.getCategories().size()) { return d_domain.getCategories().get(childIndex); } else { for (EntityCategory cat : d_domain.getCategories()) { if (isCategoryRequest(cat, parent, childIndex)) { return d_domain.getCategoryContents(cat).get(childIndex); } } } return null; }
public int getIndexOfChild(Object parent, Object child) { if (parent.equals(d_root)) { return d_domain.getCategories().indexOf(child); } else { ObservableList<? extends Entity> contents = d_domain.getCategoryContents(getCategoryNode(parent)); if (contents != null) { return contents.indexOf(child); } } return -1; }
public int getChildCount(Object parent) { if (d_root.equals(parent)) { return d_domain.getCategories().size(); } else { ObservableList<? extends Entity> contents = d_domain.getCategoryContents(getCategoryNode(parent)); if (contents != null) { return contents.size(); } } return 0; }
private boolean isCategoryRequest(EntityCategory categoryNode, Object parent, int childIndex) { return categoryNode == parent && childIndex >= 0 && childIndex < d_domain.getCategoryContents(categoryNode).size(); }