public final void changeView(@NotNull final String typeName) { myCurrentViewType = typeName; final PsiElement element = mySmartPsiElementPointer.getElement(); if (element == null || !isApplicableElement(element)) { return; } if (myContent != null) { final String displayName = getContentDisplayName(typeName, element); if (displayName != null) { myContent.setDisplayName(displayName); } } myCardLayout.show(myTreePanel, typeName); if (!myBuilders.containsKey(typeName)) { try { setWaitCursor(); // create builder final JTree tree = myType2TreeMap.get(typeName); final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode("")); tree.setModel(model); final HierarchyTreeStructure structure = createHierarchyTreeStructure(typeName, element); if (structure == null) { return; } final Comparator<NodeDescriptor> comparator = getComparator(); final HierarchyTreeBuilder builder = new HierarchyTreeBuilder(myProject, tree, model, structure, comparator); myBuilders.put(typeName, builder); Disposer.register(this, builder); Disposer.register(builder, () -> myBuilders.remove(typeName)); final HierarchyNodeDescriptor descriptor = structure.getBaseDescriptor(); builder.select(descriptor, () -> builder.expand(descriptor, null)); } finally { restoreCursor(); } } getCurrentTree().requestFocus(); }
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(); } }); }