private void setStructureViewSelection(@NotNull final String propertyName) { if (myStructureViewComponent.isDisposed()) { return; } JTree tree = myStructureViewComponent.getTree(); if (tree == null) { return; } Object root = tree.getModel().getRoot(); if (AbstractTreeUi.isLoadingChildrenFor(root)) { mySelectionChangeAlarm.cancelAllRequests(); mySelectionChangeAlarm.addRequest( new Runnable() { @Override public void run() { mySelectionChangeAlarm.cancelAllRequests(); setStructureViewSelection(propertyName); } }, 500); return; } Stack<TreeElement> toCheck = ContainerUtilRt.newStack(); toCheck.push(myStructureViewComponent.getTreeModel().getRoot()); while (!toCheck.isEmpty()) { TreeElement element = toCheck.pop(); PsiElement value = element instanceof ResourceBundlePropertyStructureViewElement ? ((ResourceBundlePropertyStructureViewElement) element).getValue() : null; if (value instanceof IProperty && propertyName.equals(((IProperty) value).getUnescapedKey())) { myStructureViewComponent.select(value, true); selectionChanged(); return; } else { for (TreeElement treeElement : element.getChildren()) { toCheck.push(treeElement); } } } }
@NotNull private Collection<DefaultMutableTreeNode> getSelectedNodes() { if (!isValid()) { return Collections.emptyList(); } JTree tree = myStructureViewComponent.getTree(); if (tree == null) return Collections.emptyList(); TreePath[] selected = tree.getSelectionModel().getSelectionPaths(); if (selected == null || selected.length == 0) return Collections.emptyList(); return ContainerUtil.map( selected, new Function<TreePath, DefaultMutableTreeNode>() { @Override public DefaultMutableTreeNode fun(TreePath treePath) { return (DefaultMutableTreeNode) treePath.getLastPathComponent(); } }); }