@Override public boolean addAll(Collection<? extends TreeNode> collection) { Iterator<TreeNode> elements = (new ArrayList<TreeNode>(collection)).iterator(); boolean changed = false; while (elements.hasNext()) { TreeNode node = elements.next(); if (node == null) { throw new NullPointerException(); } else { eraseParent(node); super.add(node); node.setParent(parent); changed = true; } } if (changed) { updateRowKeys(parent); } return (changed); }
/** * Sorts children of a node using a comparator * * @param node Node instance whose children to be sorted * @param comparator Comparator to use in sorting */ public static void sortNode(TreeNode node, Comparator comparator) { TreeNodeList children = (TreeNodeList) node.getChildren(); if (children != null && !children.isEmpty()) { Object[] childrenArray = children.toArray(); Arrays.sort(childrenArray, comparator); for (int i = 0; i < childrenArray.length; i++) { children.setSibling(i, (TreeNode) childrenArray[i]); } for (int i = 0; i < children.size(); i++) { sortNode(children.get(i), comparator); } } } }
/** * Optimized set implementation to be used in sorting * * @param index index of the element to replace * @param node node to be stored at the specified position * @return the node previously at the specified position */ @Override public TreeNode setSibling(int index, TreeNode node) { if (node == null) { throw new NullPointerException(); } else if ((index < 0) || (index >= size())) { throw new IndexOutOfBoundsException(); } else { if (!parent.equals(node.getParent())) { eraseParent(node); } TreeNode previous = get(index); super.set(index, node); node.setParent(parent); updateRowKeys(parent); return previous; } }
@Override public TreeNode remove(int index) { TreeNode node = get(index); node.setParent(null); super.remove(index); updateRowKeys(parent); return node; }
@Override public TreeNode set(int index, TreeNode node) { if (node == null) { throw new NullPointerException(); } else if ((index < 0) || (index >= size())) { throw new IndexOutOfBoundsException(); } else { if (!parent.equals(node.getParent())) { eraseParent(node); } TreeNode previous = get(index); super.set(index, node); previous.setParent(null); node.setParent(parent); updateRowKeys(parent); return previous; } }
@Override public TreeNode remove(int index) { TreeNode node = get(index); node.setParent(null); super.remove(index); updateRowKeys(parent); updateSelectionState(parent); return node; }
/** * Sorts children of a node using a comparator * * @param node Node instance whose children to be sorted * @param comparator Comparator to use in sorting */ public static void sortNode(TreeNode node, Comparator comparator) { TreeNodeList children = (TreeNodeList) node.getChildren(); if (children != null && !children.isEmpty()) { Object[] childrenArray = children.toArray(); Arrays.sort(childrenArray, comparator); for (int i = 0; i < childrenArray.length; i++) { children.setSibling(i, (TreeNode) childrenArray[i]); } for (int i = 0; i < children.size(); i++) { sortNode(children.get(i), comparator); } } } }
@Override public boolean addAll(int index, Collection<? extends TreeNode> collection) { Iterator<TreeNode> elements = (new ArrayList<TreeNode>(collection)).iterator(); boolean changed = false; while (elements.hasNext()) { TreeNode node = elements.next(); if (node == null) { throw new NullPointerException(); } else { eraseParent(node); super.add(index++, node); node.setParent(parent); changed = true; } } if (changed) { updateRowKeys(parent); } return (changed); }
@Override public boolean remove(Object object) { TreeNode node = (TreeNode) object; if (node == null) { throw new NullPointerException(); } if (super.indexOf(node) != -1) { node.clearParent(); } if (super.remove(node)) { updateRowKeys(parent); updateSelectionState(parent); return true; } else { return false; } }
/** * Optimized set implementation to be used in sorting * * @param index index of the element to replace * @param node node to be stored at the specified position * @return the node previously at the specified position */ @Override public TreeNode setSibling(int index, TreeNode node) { if (node == null) { throw new NullPointerException(); } else if ((index < 0) || (index >= size())) { throw new IndexOutOfBoundsException(); } else { if (!parent.equals(node.getParent())) { eraseParent(node); } TreeNode previous = get(index); super.set(index, node); node.setParent(parent); updateRowKeys(parent); updateSelectionState(parent); return previous; } }
@Override public TreeNode remove(int index) { TreeNode node = get(index); node.setParent(null); super.remove(index); updateRowKeys(parent); return node; }
@Override public boolean add(TreeNode node) { if (node == null) { throw new NullPointerException(); } else { eraseParent(node); boolean result = super.add(node); node.setParent(parent); updateRowKeys(parent); return result; } }
@Override public TreeNode set(int index, TreeNode node) { if (node == null) { throw new NullPointerException(); } else if ((index < 0) || (index >= size())) { throw new IndexOutOfBoundsException(); } else { if (!parent.equals(node.getParent())) { eraseParent(node); } TreeNode previous = get(index); super.set(index, node); previous.setParent(null); node.setParent(parent); updateRowKeys(parent); updateSelectionState(parent); return previous; } }
@Override public TreeNode remove(int index) { TreeNode node = get(index); node.setParent(null); super.remove(index); updateRowKeys(parent); updateSelectionState(parent); return node; }
@Override public boolean addAll(int index, Collection<? extends TreeNode> collection) { Iterator<TreeNode> elements = (new ArrayList<TreeNode>(collection)).iterator(); boolean changed = false; while (elements.hasNext()) { TreeNode node = elements.next(); if (node == null) { throw new NullPointerException(); } else { eraseParent(node); super.add(index++, node); node.setParent(parent); changed = true; } } if (changed) { updateRowKeys(parent); updateSelectionState(parent); } return (changed); }
@Override public boolean remove(Object object) { TreeNode node = (TreeNode) object; if (node == null) { throw new NullPointerException(); } if (super.indexOf(node) != -1) { node.clearParent(); } if (super.remove(node)) { updateRowKeys(parent); updateSelectionState(parent); return true; } else { return false; } }
/** * Optimized set implementation to be used in sorting * * @param index index of the element to replace * @param node node to be stored at the specified position * @return the node previously at the specified position */ public TreeNode setSibling(int index, TreeNode node) { if (node == null) { throw new NullPointerException(); } else if ((index < 0) || (index >= size())) { throw new IndexOutOfBoundsException(); } else { if (!parent.equals(node.getParent())) { eraseParent(node); } TreeNode previous = get(index); super.set(index, node); node.setParent(parent); updateRowKeys(parent); return previous; } }
@Override public void add(int index, TreeNode node) { if (node == null) { throw new NullPointerException(); } else if ((index < 0) || (index > size())) { throw new IndexOutOfBoundsException(); } else { eraseParent(node); super.add(index, node); node.setParent(parent); updateRowKeys(parent); } }