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

The following examples show how to use com.intellij.util.ui.tree.TreeUtil#traverse() . 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: CoverageSuiteChooserDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
private List<CoverageSuite> collectSelectedSuites() {
  final List<CoverageSuite> suites = new ArrayList<CoverageSuite>();
  TreeUtil.traverse(myRootNode, new TreeUtil.Traverse() {
    @Override
    public boolean accept(Object treeNode) {
      if (treeNode instanceof CheckedTreeNode && ((CheckedTreeNode)treeNode).isChecked()) {
        final Object userObject = ((CheckedTreeNode)treeNode).getUserObject();
        if (userObject instanceof CoverageSuite) {
          suites.add((CoverageSuite)userObject);
        }
      }
      return true;
    }
  });
  return suites;
}
 
Example 2
Source File: NamedItemsListEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
protected UnnamedConfigurable getItemConfigurable(final T item) {
  final Ref<UnnamedConfigurable> result = new Ref<UnnamedConfigurable>();
  TreeUtil.traverse((TreeNode)myTree.getModel().getRoot(), new TreeUtil.Traverse() {
    @Override
    public boolean accept(Object node) {
      final NamedConfigurable configurable = (NamedConfigurable)((DefaultMutableTreeNode)node).getUserObject();
      if (configurable.getEditableObject() == item) {
        result.set(((ItemConfigurable)configurable).myConfigurable);
        return false;
      }
      else {
        return true;
      }
    }
  });
  return result.get();
}
 
Example 3
Source File: ChangesTreeList.java    From consulo with Apache License 2.0 6 votes vote down vote up
private int findRowContainingFile(@Nonnull TreeNode root, @Nonnull final VirtualFile toSelect) {
  final Ref<Integer> row = Ref.create(-1);
  TreeUtil.traverse(root, node -> {
    if (node instanceof DefaultMutableTreeNode) {
      Object userObject = ((DefaultMutableTreeNode)node).getUserObject();
      if (userObject instanceof Change) {
        if (matches((Change)userObject, toSelect)) {
          TreeNode[] path = ((DefaultMutableTreeNode)node).getPath();
          row.set(getRowForPath(new TreePath(path)));
        }
      }
    }

    return row.get() == -1;
  });
  return row.get();
}
 
Example 4
Source File: MasterDetailsComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredUIAccess
public void apply() throws ConfigurationException {
  processRemovedItems();
  final ConfigurationException[] ex = new ConfigurationException[1];
  TreeUtil.traverse(myRoot, new TreeUtil.Traverse() {
    @Override
    public boolean accept(Object node) {
      if (node instanceof MyNode) {
        try {
          final NamedConfigurable configurable = ((MyNode)node).getConfigurable();
          if (isInitialized(configurable) && configurable.isModified()) {
            configurable.apply();
          }
        }
        catch (ConfigurationException e) {
          ex[0] = e;
          return false;
        }
      }
      return true;
    }
  });
  if (ex[0] != null) {
    throw ex[0];
  }
  myHasDeletedItems = false;
}
 
Example 5
Source File: UpdateInfoTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
int getFilteredFilesCount() {
  Pair<PackageSetBase, NamedScopesHolder> scopeFilter = getScopeFilter();
  int[] result = new int[1];
  TreeUtil.traverse(myRoot, node -> {
    if (node instanceof FileTreeNode) {
      if (((FileTreeNode)node).acceptFilter(scopeFilter, true)) {
        result[0]++;
      }
    }
    return true;
  });
  return result[0];
}
 
Example 6
Source File: ChangesTreeList.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void select(final List<T> changes) {
  final List<TreePath> treeSelection = new ArrayList<>(changes.size());
  TreeUtil.traverse(getRoot(), node -> {
    @SuppressWarnings("unchecked")
    final T change = (T) ((DefaultMutableTreeNode) node).getUserObject();
    if (changes.contains(change)) {
      treeSelection.add(new TreePath(((DefaultMutableTreeNode) node).getPath()));
    }
    return true;
  });
  setSelectionPaths(treeSelection.toArray(new TreePath[treeSelection.size()]));
  if (treeSelection.size() == 1) scrollPathToVisible(treeSelection.get(0));
}