@NotNull public ContextItem[] findCtxItems(String startCtxPath, String name) { String[] path = startCtxPath.split("/"); int startWith = ("/" + path[1]).startsWith(ContextPath.FILE_CTX_PRX) ? 2 : 1; TreeNode cycled = root; for (int i = startWith; i < path.length; i++) { String encodedName = "/" + path[i]; cycled = cycled.findChildByEncodedName(encodedName); if (cycled == null) { return new ContextItem[0]; } } List<ContextItem> out = new ArrayList<ContextItem>(); TreeNode[] children = name == null ? cycled.getChildren().toArray(new TreeNode[0]) : cycled.findChildrenBySuffix(name); for (TreeNode n : children) { // todo -- revise to replace using value directly with a TreeNode instance out.add(new ContextItemImpl(n.getPath(), n.getValue())); } return out.toArray(new ContextItem[out.size()]); }
/** {@inheritDoc} */ public TreeNode getNode(TreePath path) { TreeNode node = this.getModel().getRoot(); if (!node.getText().equals(path.get(0))) // Test root node return null; Iterator<String> iterator = path.iterator(); iterator.next(); // Skip root node, we already tested it above while (iterator.hasNext()) { String nodeText = iterator.next(); boolean foundMatch = false; for (TreeNode child : node.getChildren()) { if (child.getText().equals(nodeText)) { node = child; foundMatch = true; break; } } if (!foundMatch) return null; } return node; }