private Object getCompareObject(Object o) { if (o instanceof TreeNode) return ((TreeNode) o).getData(); return o; }
/** Creates a tree with the specified note as the root. * @param root the root (cannot be null). * @param emptyChildAsLeaf whether to treat the zero size of children node as a leaf node. * @since 6.0.3 */ public DefaultTreeModel(TreeNode<E> root, boolean emptyChildAsLeaf) { super(root); TreeNode<E> parent = root.getParent(); if (parent != null) parent.remove(root); root.setModel(this); _emptyleaf = emptyChildAsLeaf; }
public TreeNode<E> getChild(TreeNode<E> parent, int index) { return parent.getChildAt(index); }
public boolean isLeaf(TreeNode<E> node) { boolean isLeaf = node.isLeaf(); if (!isLeaf && _emptyleaf) return node.getChildCount() == 0; return isLeaf; }
/** * Returns the path from the child, where the path indicates the child is * placed in the whole tree. * @param child the node we are interested in * @since 6.0.0 */ public int[] getPath(TreeNode<E> child) { final TreeNode<E> root = getRoot(); List<Integer> p = new ArrayList<Integer>(); while (root != child) { TreeNode<E> parent = child.getParent(); if (parent != null) { for (int i = 0, j = parent.getChildCount(); i < j; i++) { if (parent.getChildAt(i) == child) { p.add(0, i); break; } } child = parent; } else break; // ZK-838 } final Integer[] objs = p.toArray(new Integer[p.size()]); final int[] path = new int[objs.length]; for (int i = 0; i < objs.length; i++) path[i] = objs[i].intValue(); return path; }
/** Checks if p is one of ancestors of this node. */ private static boolean isAncestor(TreeNode p, TreeNode c) { do { if (p == c) return true; } while ((c = c.getParent()) != null); return false; }
public int getIndexOfChild(TreeNode<E> parent, TreeNode<E> child) { return parent.getIndex(child); }
public int getChildCount(TreeNode<E> parent) { return parent.getChildCount(); }
@SuppressWarnings("rawtypes") private void sort0(TreeNode<E> node, Comparator<TreeNode<E>> cmpr) { if (node.getChildren() == null) return; if (node instanceof DefaultTreeNode) ((TreeNodeChildrenList) node.getChildren()).treeSort(cmpr); else Collections.sort(node.getChildren(), cmpr); for (TreeNode<E> child : node.getChildren()) sort0(child, cmpr); }
@SuppressWarnings("unchecked") public Object clone() { final DefaultTreeNode clone; try { clone = (DefaultTreeNode) super.clone(); } catch (CloneNotSupportedException e) { throw new InternalError(); } clone._parent = null; if (_children != null) { final TreeNodeChildrenList newkids = clone.new TreeNodeChildrenList(); clone._children = newkids; for (final TreeNode node : _children) { final DefaultTreeNode child = (DefaultTreeNode) node.clone(); //recursively child._parent = clone; newkids._list.add(child); //added directly without firing events... } } return clone; }
private void buildModel(TreeNode<Object> rootNode, List<TermMatch> matches) { if (matches.isEmpty()) { rootNode.add(new DefaultTreeNode<Object>(null)); } else { for (TermMatch match : matches) { boolean synonyms = rgrpLookupMode.getSelectedIndex() == 1; TreeNode<Object> parentNode = synonyms ? new DefaultTreeNode<Object>(match) : new DefaultTreeNode<Object>(match, null, false); rootNode.add(parentNode); if (!synonyms) { for (TermType type : RENDERED_TERM_TYPES) { for (Term term : match.getTerms(type)) { parentNode.add(new DefaultTreeNode<Object>(term)); } } } } } }
public void setData(E data) { _data = data; DefaultTreeModel<E> model = getModel(); TreeNode<E> parent = getParent(); if (model != null && parent != null) { int index = parent.getIndex(this); model.fireEvent(TreeDataEvent.CONTENTS_CHANGED, model.getPath(parent), index, index); } }
private Object getCompareObject(Object o) { if (o instanceof TreeNode) return ((TreeNode) o).getData(); return o; }
@Override protected void renderItem(Treeitem item, TreeNode<Object> treeNode) { Object data = treeNode.getData(); Treerow treeRow = new Treerow(); item.appendChild(treeRow); item.setOpen(false); item.addForward(Events.ON_DOUBLE_CLICK, item.getTree(), Events.ON_OK); if (data == null) { createCell(treeRow, "No matches found.").setSpan(3); item.setDisabled(true); } else if (data instanceof TermMatch) { TermMatch match = (TermMatch) data; createCell(treeRow, match.getTerm(TermType.PROBLEM).getTermText()); createCell(treeRow, formatParentTerms(match.getParentTerms())); createCell(treeRow, StrUtil.fromList(Arrays.asList(match.getMappedICDs()), "\n")); } else if (data instanceof Term) { Term term = (Term) data; createCell(treeRow, term.getTermText()).setSpan(2); createCell(treeRow, WordUtils.capitalizeFully(term.getTermType().name())); } }