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

The following examples show how to use com.intellij.util.ui.tree.TreeUtil#selectInTree() . 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: MasterDetailsComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void initSelection() {
  final Enumeration enumeration = myRoot.breadthFirstEnumeration();
  boolean selected = false;
  while (enumeration.hasMoreElements()) {
    final MyNode node = (MyNode)enumeration.nextElement();
    if (node instanceof MyRootNode) continue;
    final String path = getNodePathString(node);
    if (!selected && Comparing.strEqual(path, myState.getLastEditedConfigurable())) {
      TreeUtil.selectInTree(node, false, myTree);
      selected = true;
    }
  }
  if (!selected) {
    TreeUtil.selectFirstNode(myTree);
  }
  updateSelectionFromTree();
}
 
Example 2
Source File: RunConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean selectConfiguration(@Nonnull RunConfiguration configuration) {
  final Enumeration enumeration = myRoot.breadthFirstEnumeration();
  while (enumeration.hasMoreElements()) {
    final DefaultMutableTreeNode node = (DefaultMutableTreeNode)enumeration.nextElement();
    Object userObject = node.getUserObject();
    if (userObject instanceof SettingsEditorConfigurable) {
      userObject = ((SettingsEditorConfigurable)userObject).getSettings();
    }
    if (userObject instanceof RunnerAndConfigurationSettingsImpl) {
      final RunnerAndConfigurationSettings runnerAndConfigurationSettings = (RunnerAndConfigurationSettings)userObject;
      final ConfigurationType configurationType = configuration.getType();
      if (Comparing.strEqual(runnerAndConfigurationSettings.getConfiguration().getType().getId(), configurationType.getId()) &&
          Comparing.strEqual(runnerAndConfigurationSettings.getConfiguration().getName(), configuration.getName())) {
        TreeUtil.selectInTree(node, true, myTree);
        return true;
      }
    }
  }
  return false;
}
 
Example 3
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 4
Source File: MasterDetailsComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ActionCallback selectNodeInTree(final DefaultMutableTreeNode nodeToSelect, boolean center, final boolean requestFocus) {
  if (requestFocus) {
    IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(myTree);
  }
  if (nodeToSelect != null) {
    return TreeUtil.selectInTree(nodeToSelect, requestFocus, myTree, center);
  }
  else {
    return TreeUtil.selectFirstNode(myTree);
  }
}
 
Example 5
Source File: ActionsTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void selectAction(String actionId) {
  final JTree tree = myTree;

  String path = myMainGroup.getActionQualifiedPath(actionId);
  if (path == null) {
    return;
  }
  final DefaultMutableTreeNode node = getNodeForPath(path);
  if (node == null) {
    return;
  }

  TreeUtil.selectInTree(node, true, tree);
}
 
Example 6
Source File: MasterDetailsComponent.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void removePaths(final TreePath... paths) {
  MyNode parentNode = null;
  int idx = -1;
  for (TreePath path : paths) {
    final MyNode node = (MyNode)path.getLastPathComponent();
    final NamedConfigurable namedConfigurable = node.getConfigurable();
    final Object editableObject = namedConfigurable.getEditableObject();
    parentNode = (MyNode)node.getParent();
    idx = parentNode.getIndex(node);
    ((DefaultTreeModel)myTree.getModel()).removeNodeFromParent(node);
    myHasDeletedItems |= wasObjectStored(editableObject);
    fireItemsChangeListener(editableObject);
    onItemDeleted(editableObject);
    namedConfigurable.disposeUIResources();
  }

  if (paths.length > 0) {
    if (parentNode != null && idx != -1) {
      DefaultMutableTreeNode toSelect = null;
      if (idx < parentNode.getChildCount()) {
        toSelect = (DefaultMutableTreeNode) parentNode.getChildAt(idx);
      } else {
        if (idx > 0 && parentNode.getChildCount() > 0) {
          if (idx - 1 < parentNode.getChildCount()) {
            toSelect = (DefaultMutableTreeNode) parentNode.getChildAt(idx - 1);
          } else {
            toSelect = (DefaultMutableTreeNode) parentNode.getFirstChild();
          }
        } else {
          if (parentNode.isRoot() && myTree.isRootVisible()) {
            toSelect = parentNode;
          } else if (parentNode.getChildCount() > 0) {
            toSelect = (DefaultMutableTreeNode) parentNode.getFirstChild();
          }
        }
      }

      if (toSelect != null) {
        TreeUtil.selectInTree(toSelect, true, myTree);
      }
    }
    else {
      TreeUtil.selectFirstNode(myTree);
    }
  }
}