コード例 #1
0
ファイル: TreeState.java プロジェクト: jexp/idea2
  private static DefaultMutableTreeNode findMatchedChild(
      DefaultMutableTreeNode parent, PathElement pathElement) {

    for (int j = 0; j < parent.getChildCount(); j++) {
      final TreeNode child = parent.getChildAt(j);
      if (!(child instanceof DefaultMutableTreeNode)) continue;
      final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child;
      final Object userObject = childNode.getUserObject();
      if (pathElement.matchedWithByObject(userObject)) return childNode;
    }

    for (int j = 0; j < parent.getChildCount(); j++) {
      final TreeNode child = parent.getChildAt(j);
      if (!(child instanceof DefaultMutableTreeNode)) continue;
      final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child;
      final Object userObject = childNode.getUserObject();
      if (!(userObject instanceof NodeDescriptor)) continue;
      final NodeDescriptor nodeDescriptor = (NodeDescriptor) userObject;
      if (pathElement.matchedWith(nodeDescriptor)) return childNode;
    }

    if (parent.getChildCount() > 0) {
      int index = pathElement.myItemIndex;
      if (index >= parent.getChildCount()) {
        index = parent.getChildCount() - 1;
      }
      final TreeNode child = parent.getChildAt(index);
      if (child instanceof DefaultMutableTreeNode) {
        return (DefaultMutableTreeNode) child;
      }
    }

    return null;
  }
コード例 #2
0
ファイル: TreeState.java プロジェクト: jexp/idea2
  private static boolean applyTo(
      final int positionInPath,
      final List<PathElement> path,
      final Object root,
      final TreeFacade tree) {
    if (!(root instanceof DefaultMutableTreeNode)) return false;

    final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) root;

    final Object userObject = treeNode.getUserObject();
    final PathElement pathElement = path.get(positionInPath);

    if (userObject instanceof NodeDescriptor) {
      if (!pathElement.matchedWith((NodeDescriptor) userObject)) return false;
    } else {
      if (!pathElement.matchedWithByObject(userObject)) return false;
    }

    tree.expand(treeNode)
        .doWhenDone(
            new Runnable() {
              public void run() {
                if (positionInPath == path.size() - 1) {
                  return;
                }

                for (int j = 0; j < treeNode.getChildCount(); j++) {
                  final TreeNode child = treeNode.getChildAt(j);
                  final boolean resultFromChild = applyTo(positionInPath + 1, path, child, tree);
                  if (resultFromChild) {
                    break;
                  }
                }
              }
            });

    return true;
  }