Java Code Examples for com.intellij.util.ui.tree.TreeUtil#findNodeWithObject()

The following examples show how to use com.intellij.util.ui.tree.TreeUtil#findNodeWithObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RunConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(final AnActionEvent e) {
  TreeNode defaults = TreeUtil.findNodeWithObject(DEFAULTS, myTree.getModel(), myRoot);
  if (defaults != null) {
    final ConfigurationType configurationType = getSelectedConfigurationType();
    if (configurationType != null) {
      defaults = TreeUtil.findNodeWithObject(configurationType, myTree.getModel(), defaults);
    }
    final DefaultMutableTreeNode defaultsNode = (DefaultMutableTreeNode)defaults;
    if (defaultsNode == null) {
      return;
    }
    final TreePath path = TreeUtil.getPath(myRoot, defaultsNode);
    myTree.expandPath(path);
    TreeUtil.selectInTree(defaultsNode, true, myTree);
    myTree.scrollPathToVisible(path);
  }
}
 
Example 2
Source File: RunConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void update(AnActionEvent e) {
  boolean isEnabled = TreeUtil.findNodeWithObject(DEFAULTS, myTree.getModel(), myRoot) != null;
  TreePath path = myTree.getSelectionPath();
  if (path != null) {
    Object o = path.getLastPathComponent();
    if (o instanceof DefaultMutableTreeNode && ((DefaultMutableTreeNode)o).getUserObject().equals(DEFAULTS)) {
      isEnabled = false;
    }
    o = path.getParentPath().getLastPathComponent();
    if (o instanceof DefaultMutableTreeNode && ((DefaultMutableTreeNode)o).getUserObject().equals(DEFAULTS)) {
      isEnabled = false;
    }
  }
  e.getPresentation().setEnabled(isEnabled);
}
 
Example 3
Source File: SimpleTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public TreePath getPathFor(SimpleNode node) {
  final TreeNode nodeWithObject = TreeUtil.findNodeWithObject((DefaultMutableTreeNode)getModel().getRoot(), node);
  if (nodeWithObject != null) {
    return TreeUtil.getPathFromRoot(nodeWithObject);
  }
  return null;
}
 
Example 4
Source File: ChangesViewManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void selectFile(@Nullable VirtualFile vFile) {
  if (vFile == null) return;
  Change change = ChangeListManager.getInstance(myProject).getChange(vFile);
  Object objectToFind = change != null ? change : vFile;

  DefaultMutableTreeNode root = (DefaultMutableTreeNode)myView.getModel().getRoot();
  DefaultMutableTreeNode node = TreeUtil.findNodeWithObject(root, objectToFind);
  if (node != null) {
    TreeUtil.selectNode(myView, node);
  }
}
 
Example 5
Source File: ChangesViewManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void refreshChangesViewNode(@Nonnull VirtualFile file) {
  ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
  Object userObject = changeListManager.isUnversioned(file) ? file : changeListManager.getChange(file);

  if (userObject != null) {
    DefaultMutableTreeNode root = (DefaultMutableTreeNode)myView.getModel().getRoot();
    DefaultMutableTreeNode node = TreeUtil.findNodeWithObject(root, userObject);

    if (node != null) {
      myView.getModel().nodeChanged(node);
    }
  }
}
 
Example 6
Source File: ChangesViewManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void selectChange(@Nonnull Change change) {
  DefaultMutableTreeNode root = (DefaultMutableTreeNode)myView.getModel().getRoot();
  DefaultMutableTreeNode node = TreeUtil.findNodeWithObject(root, change);
  if (node != null) {
    TreePath path = TreeUtil.getPathFromRoot(node);
    TreeUtil.selectPath(myView, path, false);
  }
}
 
Example 7
Source File: LayoutTreeComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void updateAndSelect(PackagingElementNode<?> node, final List<? extends PackagingElement<?>> toSelect) {
  myArtifactsEditor.queueValidation();
  final DefaultMutableTreeNode treeNode = TreeUtil.findNodeWithObject(myTree.getRootNode(), node);
  myTreeStructure.clearCaches();
  myBuilder.addSubtreeToUpdate(treeNode, new Runnable() {
    @Override
    public void run() {
      List<PackagingElementNode<?>> nodes = myTree.findNodes(toSelect);
      myBuilder.select(ArrayUtil.toObjectArray(nodes), null);
    }
  });
}
 
Example 8
Source File: FileTemplateTabAsTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void selectTemplate(FileTemplate template) {
  String name = template.getName();
  if (template.getExtension().length() > 0) {
    name += "." + template.getExtension();
  }

  final FileTemplateNode node = (FileTemplateNode)TreeUtil.findNodeWithObject(myRoot, name);
  if (node != null) {
    TreeUtil.selectNode(myTree, node);
    onTemplateSelected(); // this is important because we select different Template for the same node
  }
}
 
Example 9
Source File: LayoutTree.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void addSubtreeToUpdate(final PackagingElementNode elementNode) {
  final DefaultMutableTreeNode node = TreeUtil.findNodeWithObject(getRootNode(), elementNode);
  if (node != null) {
    addSubtreeToUpdate(node);
  }
}