@Nullable public FilteringTreeStructure.FilteringNode update() { final Ref<FilteringTreeStructure.FilteringNode> nodeRef = new Ref<FilteringTreeStructure.FilteringNode>(); final FileStructurePopup popup = getPopup(); popup.getTreeBuilder().refilter().doWhenProcessed(new Runnable() { @Override public void run() { getStructure().rebuild(); updateTree(); getBuilder().updateFromRoot(); TreeUtil.expandAll(getTree()); nodeRef.set(popup.selectPsiElement(popup.getCurrentElement(myFile))); getBuilder().getUi().select(nodeRef.get(), null); } }); return nodeRef.get(); }
private ConfigurableGroup getGroup(int offset) { TreePath path = myTree.getClosestPathForLocation(-myTree.getX(), -myTree.getY() + offset); SimpleNode node = myTree.getNodeFor(path); if (node instanceof FilteringTreeStructure.FilteringNode) { Object delegate = ((FilteringTreeStructure.FilteringNode)node).getDelegate(); while (delegate instanceof EditorNode) { EditorNode editor = (EditorNode)delegate; ConfigurableGroup group = editor.getGroup(); if (group != null) { return group; } delegate = editor.getParent(); } } return null; }
private FilteringTreeStructure.FilteringNode findNode(Set<PsiElement> parents, FilteringTreeStructure.FilteringNode node) { while (node != null) { boolean changed = false; for (FilteringTreeStructure.FilteringNode n : node.children()) { final PsiElement psiElement = getPsi(n); if (psiElement != null && parents.contains(psiElement)) { node = n; changed = true; break; } } if (!changed) { myAbstractTreeBuilder.select(node); if (myAbstractTreeBuilder.getSelectedElements().isEmpty()) { TreeUtil.selectFirstNode(myTree); } myInitialNodeIsLeaf = node.getChildren().length == 0; return node; } } return null; }
@Nullable private AbstractTreeNode getSelectedNode() { final TreePath path = myTree.getSelectionPath(); if (path != null) { Object component = path.getLastPathComponent(); if (component instanceof DefaultMutableTreeNode) { component = ((DefaultMutableTreeNode)component).getUserObject(); if (component instanceof FilteringTreeStructure.FilteringNode) { component = ((FilteringTreeStructure.FilteringNode)component).getDelegate(); if (component instanceof AbstractTreeNode) { return (AbstractTreeNode)component; } } } } return null; }
public FileStructureTree(Object rootElement, boolean fastExpand) { super(new DefaultMutableTreeNode(rootElement)); if (fastExpand) { Hashtable hashtable = new Hashtable() { @Override public synchronized Object get(Object key) { return Boolean.TRUE; } }; fast = ReflectionUtil.setField(JTree.class, this, Hashtable.class, "expandedState", hashtable); } else { fast = false; } //TODO[kb]: hack expanded states in getUI().treeState setRootVisible(false); setShowsRootHandles(true); setHorizontalAutoScrollingEnabled(false); HintUpdateSupply.installHintUpdateSupply(this, o -> getPsi( (FilteringTreeStructure.FilteringNode)((DefaultMutableTreeNode)o).getUserObject())); }
@Nullable private Base extractNode(Object object) { if (object instanceof DefaultMutableTreeNode) { final DefaultMutableTreeNode uiNode = (DefaultMutableTreeNode)object; final Object o = uiNode.getUserObject(); if (o instanceof FilteringTreeStructure.FilteringNode) { return (Base)((FilteringTreeStructure.FilteringNode)o).getDelegate(); } } return null; }
private Object extractUserObject(Object aNode) { Object object = ((DefaultMutableTreeNode) aNode).getUserObject(); if (object instanceof FilteringTreeStructure.FilteringNode) { return ((FilteringTreeStructure.FilteringNode) object).getDelegate(); } return object; }
@Nullable private static Object getNodeValue(DefaultMutableTreeNode mutableTreeNode) { Object userObject = mutableTreeNode.getUserObject(); if (userObject instanceof FilteringTreeStructure.FilteringNode) { userObject = ((FilteringTreeStructure.FilteringNode)userObject).getDelegate(); } return userObject instanceof AbstractTreeNode ? ((AbstractTreeNode)userObject).getValue() : null; }
@Nullable private PsiElement getPsi(FilteringTreeStructure.FilteringNode n) { final Object delegate = n.getDelegate(); if (delegate instanceof StructureViewComponent.StructureViewTreeElementWrapper) { final TreeElement value = ((StructureViewComponent.StructureViewTreeElementWrapper)delegate).getValue(); if (value instanceof StructureViewTreeElement) { final Object element = ((StructureViewTreeElement)value).getValue(); if (element instanceof PsiElement) { return (PsiElement)element; } } } return null; }
@NotNull private List<PsiElement> getPsiElementsFromSelection() { Set<Object> nodes = myAbstractTreeBuilder.getSelectedElements(); if (nodes.isEmpty()) return Collections.emptyList(); List<PsiElement> result = ContainerUtil.newArrayListWithCapacity(nodes.size()); for (Object o : nodes) { if (!(o instanceof FilteringTreeStructure.FilteringNode)) continue; ContainerUtil.addIfNotNull(result, getPsi((FilteringTreeStructure.FilteringNode)o)); } return result; }
@Override public boolean shouldBeShowing(Object value) { if (!isShouldNarrowDown()) return true; String filter = getSearchPrefix(); if (!StringUtil.equals(myLastFilter, filter)) { myVisibleParents.clear(); myLastFilter = filter; } if (filter != null) { if (myVisibleParents.contains(value)) { return true; } final String text = getSpeedSearchText(value); if (text == null) return false; if (matches(text)) { Object o = value; while (o instanceof FilteringTreeStructure.FilteringNode && (o = ((FilteringTreeStructure.FilteringNode)o).getParent()) != null) { myVisibleParents.add(o); } return true; } else { return false; } } return true; }
public MyTreeSpeedSearch() { super(myTree, new Convertor<TreePath, String>() { @Override @Nullable public String convert(TreePath path) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); final Object userObject = node.getUserObject(); if (userObject instanceof FilteringTreeStructure.FilteringNode) { return getSpeedSearchText(((FilteringTreeStructure.FilteringNode)userObject).getDelegate()); } return ""; } }, true); }
public void update() throws InterruptedException { myPopup.getTreeBuilder().refilter().doWhenProcessed(new Runnable() { @Override public void run() { getStructure().rebuild(); updateTree(); getBuilder().updateFromRoot(); TreeUtil.expandAll(getTree()); final FilteringTreeStructure.FilteringNode node = myPopup.selectPsiElement(myPopup.getCurrentElement(getFile())); getBuilder().getUi().select(node, null); } }); }
@Nullable public FilteringTreeStructure.FilteringNode selectPsiElement(PsiElement element) { Set<PsiElement> parents = getAllParents(element); FilteringTreeStructure.FilteringNode node = (FilteringTreeStructure.FilteringNode)myAbstractTreeBuilder.getRootElement(); while (node != null) { boolean changed = false; for (FilteringTreeStructure.FilteringNode n : node.children()) { final PsiElement psiElement = getPsi(n); if (psiElement != null && parents.contains(psiElement)) { node = n; changed = true; break; } } if (!changed) { myAbstractTreeBuilder.select(node); if (myAbstractTreeBuilder.getSelectedElements().isEmpty()) { TreeUtil.selectFirstNode(myTree); } myInitialNodeIsLeaf = node.getChildren().length == 0; return node; } } TreeUtil.selectFirstNode(myTree); return null; }
@Override public boolean shouldBeShowing(Object value) { if (!myShouldNarrowDown) return true; String filter = getSearchPrefix(); if (!StringUtil.equals(myLastFilter, filter)) { myVisibleParents.clear(); myLastFilter = filter; } if (filter != null) { if (myVisibleParents.contains(value)) { return true; } final String text = getSpeedSearchText(value); if (text == null) return false; if (matches(text)) { Object o = value; while (o instanceof FilteringTreeStructure.FilteringNode && (o = ((FilteringTreeStructure.FilteringNode)o).getParent()) != null) { myVisibleParents.add(o); } return true; } else { return false; } } return true; }
@Nonnull private List<PsiElement> getPsiElementsFromSelection() { Set<Object> nodes = myAbstractTreeBuilder.getSelectedElements(); if (nodes.isEmpty()) return Collections.emptyList(); List<PsiElement> result = ContainerUtil.newArrayListWithCapacity(nodes.size()); for (Object o : nodes) { if (!(o instanceof FilteringTreeStructure.FilteringNode)) continue; ContainerUtil.addIfNotNull(result, getPsi((FilteringTreeStructure.FilteringNode)o)); } return result; }
public MyTreeSpeedSearch() { super(myTree, path -> { final DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); final Object userObject = node.getUserObject(); if (userObject instanceof FilteringTreeStructure.FilteringNode) { return getSpeedSearchText(((FilteringTreeStructure.FilteringNode)userObject).getDelegate()); } return ""; }, true); }
public FilteringTreeStructure getStructure() { final FilteringTreeStructure structure = (FilteringTreeStructure)getBuilder().getTreeStructure(); assert structure != null; return structure; }
public FilteringTreeStructure.FilteringNode getRootNode() { return getStructure().getRootElement(); }
public void updateRecursively(final FilteringTreeStructure.FilteringNode node) { node.update(); for (FilteringTreeStructure.FilteringNode child : node.children()) { updateRecursively(child); } }
ActionCallback select(@Nullable final Configurable configurable) { if (myBuilder.isSelectionBeingAdjusted()) { return ActionCallback.REJECTED; } final ActionCallback callback = new ActionCallback(); myQueuedConfigurable = configurable; myQueue.queue(new Update(this) { public void run() { if (configurable == myQueuedConfigurable) { if (configurable == null) { fireSelected(null, callback); } else { myBuilder.getReady(this).doWhenDone(new Runnable() { @Override public void run() { if (configurable != myQueuedConfigurable) return; MyNode editorNode = findNode(configurable); FilteringTreeStructure.FilteringNode editorUiNode = myBuilder.getVisibleNodeFor(editorNode); if (editorUiNode == null) return; if (!myBuilder.getSelectedElements().contains(editorUiNode)) { myBuilder.select(editorUiNode, new Runnable() { public void run() { fireSelected(configurable, callback); } }); } else { myBuilder.scrollSelectionToVisible(new Runnable() { public void run() { fireSelected(configurable, callback); } }, false); } } }); } } } @Override public void setRejected() { super.setRejected(); callback.setRejected(); } }); return callback; }
ActionCallback queueSelection(final Configurable configurable) { if (myBuilder.isSelectionBeingAdjusted()) { return ActionCallback.REJECTED; } final ActionCallback callback = new ActionCallback(); myQueuedConfigurable = configurable; final Update update = new Update(this) { public void run() { if (configurable != myQueuedConfigurable) return; if (configurable == null) { myTree.getSelectionModel().clearSelection(); myFilter.myContext.fireSelected(null, OptionsTree.this); } else { myBuilder.getReady(this).doWhenDone(new Runnable() { @Override public void run() { if (configurable != myQueuedConfigurable) return; final EditorNode editorNode = myConfigurable2Node.get(configurable); FilteringTreeStructure.FilteringNode editorUiNode = myBuilder.getVisibleNodeFor(editorNode); if (editorUiNode == null) return; if (!myBuilder.getSelectedElements().contains(editorUiNode)) { myBuilder.select(editorUiNode, new Runnable() { public void run() { fireSelected(configurable, callback); } }); } else { myBuilder.scrollSelectionToVisible(new Runnable() { public void run() { fireSelected(configurable, callback); } }, false); } } }); } } @Override public void setRejected() { super.setRejected(); callback.setRejected(); } }; mySelection.queue(update); return callback; }
private void select(String element) throws Exception { FilteringTreeStructure.FilteringNode node = myBuilder.getVisibleNodeFor(findNode(element)); select(new Object[] {node}, false); }
@Override protected PsiElement getPsiElementForHint(Object selectedValue) { //noinspection ConstantConditions return getPsi((FilteringTreeStructure.FilteringNode)((DefaultMutableTreeNode)selectedValue).getUserObject()); }
protected FilteringTreeStructure getStructure() { final FilteringTreeStructure structure = (FilteringTreeStructure)getBuilder().getTreeStructure(); assert structure != null; return structure; }
protected FilteringTreeStructure.FilteringNode getRootNode() { return (FilteringTreeStructure.FilteringNode)getStructure().getRootElement(); }
protected void updateRecursively(final FilteringTreeStructure.FilteringNode node) { node.update(); for (FilteringTreeStructure.FilteringNode child : node.children()) { updateRecursively(child); } }