예제 #1
0
파일: TreeView.java 프로젝트: jexp/idea2
  public boolean restoreSelection(TreeSelection treeSelection) {
    if (treeSelection.isEmpty()) return false;

    DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTreeModel.getRoot();
    for (int i = 0; i < root.getChildCount(); i++) {
      TreeNode node = root.getChildAt(i);
      if (node instanceof MessageNode) {
        MessageNode messageNode = (MessageNode) node;
        String[] text = messageNode.getText();
        if (text.length == 0) continue;
        if (Comparing.equal(treeSelection.mySelectedTarget, text[0])) {
          TreePath pathToSelect = new TreePath(messageNode.getPath());
          for (Enumeration enumeration = messageNode.children(); enumeration.hasMoreElements(); ) {
            Object o = enumeration.nextElement();
            if (o instanceof MessageNode) {
              messageNode = (MessageNode) o;
              if (Comparing.equal(treeSelection.mySelectedTask, text[0])) {
                pathToSelect = new TreePath(messageNode.getPath());
                break;
              }
            }
          }
          TreeUtil.selectPath(myTree, pathToSelect);
          myTree.expandPath(pathToSelect);
          return true;
        }
      }
    }

    return false;
  }
  public void expandRootChildren() {
    TreeNode root = (TreeNode) myTreeModel.getRoot();

    if (root.getChildCount() == 1) {
      myTree.expandPath(new TreePath(new Object[] {root, root.getChildAt(0)}));
    }
  }
 private static void expandNodeIfNotTooWide(Tree tree, PackageDependenciesNode node) {
   int count = node.getChildCount();
   if (count > 5) return;
   // another level of nesting
   if (count == 1 && node.getChildAt(0).getChildCount() > 5) {
     return;
   }
   tree.expandPath(new TreePath(node.getPath()));
 }
  @Override
  public void actionPerformed(AnActionEvent e) {
    final List<Descriptor> descriptors = new ArrayList<Descriptor>();
    final InspectionConfigTreeNode[] selectedNodes =
        myTree.getSelectedNodes(InspectionConfigTreeNode.class, null);
    LOG.assertTrue(selectedNodes != null);

    final List<InspectionConfigTreeNode> nodes =
        new ArrayList<InspectionConfigTreeNode>(Arrays.asList(selectedNodes));
    for (InspectionConfigTreeNode node : selectedNodes) {
      collect(descriptors, nodes, node);
    }

    final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
    final List<String> availableScopes = getAvailableScopes(project, descriptors);
    final int idx =
        Messages.showChooseDialog(
            myTree,
            "Scope:",
            "Choose Scope",
            ArrayUtil.toStringArray(availableScopes),
            availableScopes.get(0),
            Messages.getQuestionIcon());
    if (idx == -1) return;
    final NamedScope chosenScope = NamedScopesHolder.getScope(project, availableScopes.get(idx));

    for (InspectionConfigTreeNode node : nodes) {
      final Descriptor descriptor = node.getDesriptor();
      if (node.getScopeName() != null || descriptor == null) continue;
      final InspectionProfileEntry tool = descriptor.getTool(); // copy
      final ScopeToolState scopeToolState =
          getSelectedProfile()
              .addScope(
                  tool,
                  chosenScope,
                  getSelectedProfile().getErrorLevel(descriptor.getKey(), chosenScope),
                  getSelectedProfile().isToolEnabled(descriptor.getKey()));
      final Descriptor addedDescriptor = new Descriptor(scopeToolState, getSelectedProfile());
      if (node.getChildCount() == 0) {
        node.add(
            new InspectionConfigTreeNode(
                descriptor,
                getSelectedProfile().getToolDefaultState(descriptor.getKey().toString()),
                true,
                true,
                false));
      }
      node.insert(new InspectionConfigTreeNode(addedDescriptor, scopeToolState, false, false), 0);
      node.setInspectionNode(false);
      node.dropCache();
      ((DefaultTreeModel) myTree.getModel()).reload(node);
      myTree.expandPath(new TreePath(node.getPath()));
    }
    myTree.revalidate();
  }
예제 #5
0
파일: TreeView.java 프로젝트: jexp/idea2
 private void handleExpansion() {
   if (myActionsEnabled && !myTree.hasBeenExpanded(myParentPath)) {
     myTree.expandPath(myParentPath);
   }
 }