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

The following examples show how to use com.intellij.util.ui.tree.TreeUtil#traverseDepth() . 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
@Override
public boolean isModified() {
  if (myHasDeletedItems) return true;
  final boolean[] modified = new boolean[1];
  TreeUtil.traverseDepth(myRoot, new TreeUtil.Traverse() {
    @Override
    public boolean accept(Object node) {
      if (node instanceof MyNode) {
        final NamedConfigurable configurable = ((MyNode)node).getConfigurable();
        if (isInitialized(configurable) && configurable.isModified()) {
          modified[0] = true;
          return false;
        }
      }
      return true;
    }
  });
  return modified[0];
}
 
Example 2
Source File: MasterDetailsComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void clearChildren() {
  TreeUtil.traverseDepth(myRoot, new TreeUtil.Traverse() {
    @Override
    public boolean accept(Object node) {
      if (node instanceof MyNode) {
        final MyNode treeNode = ((MyNode)node);
        treeNode.getConfigurable().disposeUIResources();
        if (!(treeNode instanceof MyRootNode)) {
          treeNode.setUserObject(null);
        }
      }
      return true;
    }
  });
  myRoot.removeAllChildren();
}
 
Example 3
Source File: CustomizableActionsPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void doOKAction() {
  final ActionManager actionManager = ActionManager.getInstance();
  TreeUtil.traverseDepth((TreeNode)myTree.getModel().getRoot(), new TreeUtil.Traverse() {
    public boolean accept(Object node) {
      if (node instanceof DefaultMutableTreeNode) {
        final DefaultMutableTreeNode mutableNode = (DefaultMutableTreeNode)node;
        final Object userObject = mutableNode.getUserObject();
        if (userObject instanceof Pair) {
          String actionId = (String)((Pair)userObject).first;
          final AnAction action = actionManager.getAction(actionId);
          Icon icon = (Icon)((Pair)userObject).second;
          action.getTemplatePresentation().setIcon(icon);
          action.setDefaultIcon(icon == null);
          editToolbarIcon(actionId, mutableNode);
        }
      }
      return true;
    }
  });
  super.doOKAction();
  setCustomizationSchemaForCurrentProjects();
}
 
Example 4
Source File: BreakpointItemsTreeController.java    From consulo with Apache License 2.0 6 votes vote down vote up
public List<BreakpointItem> getSelectedBreakpoints(boolean traverse) {
  TreePath[] selectionPaths = myTreeView.getSelectionPaths();
  if (selectionPaths == null || selectionPaths.length == 0) return Collections.emptyList();

  final ArrayList<BreakpointItem> list = new ArrayList<>();
  for (TreePath selectionPath : selectionPaths) {
    TreeNode startNode = (TreeNode)selectionPath.getLastPathComponent();
    if (traverse) {
      TreeUtil.traverseDepth(startNode, node -> {
        if (node instanceof BreakpointItemNode) {
          list.add(((BreakpointItemNode)node).getBreakpointItem());
        }
        return true;
      });
    }
    else {
      if (startNode instanceof BreakpointItemNode) {
        list.add(((BreakpointItemNode)startNode).getBreakpointItem());
      }
    }
  }

  return list;
}
 
Example 5
Source File: LayoutTree.java    From consulo with Apache License 2.0 6 votes vote down vote up
public List<PackagingElementNode<?>> findNodes(final Collection<? extends PackagingElement<?>> elements) {
  final List<PackagingElementNode<?>> nodes = new ArrayList<PackagingElementNode<?>>();
  TreeUtil.traverseDepth(getRootNode(), new TreeUtil.Traverse() {
    @Override
    public boolean accept(Object node) {
      final Object userObject = ((DefaultMutableTreeNode)node).getUserObject();
      if (userObject instanceof PackagingElementNode) {
        final PackagingElementNode<?> packagingNode = (PackagingElementNode<?>)userObject;
        final List<? extends PackagingElement<?>> nodeElements = packagingNode.getPackagingElements();
        if (ContainerUtil.intersects(nodeElements, elements)) {
          nodes.add(packagingNode);
        }
      }
      return true;
    }
  });
  return nodes;
}
 
Example 6
Source File: MasterDetailsComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected static MyNode findNodeByCondition(final TreeNode root, final Condition<NamedConfigurable> condition) {
  final MyNode[] nodeToSelect = new MyNode[1];
  TreeUtil.traverseDepth(root, new TreeUtil.Traverse() {
    @Override
    public boolean accept(Object node) {
      if (condition.value(((MyNode)node).getConfigurable())) {
        nodeToSelect[0] = (MyNode)node;
        return false;
      }
      return true;
    }
  });
  return nodeToSelect[0];
}
 
Example 7
Source File: CustomizationUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void optimizeSchema(final JTree tree, final CustomActionsSchema schema) {
  //noinspection HardCodedStringLiteral
  Group rootGroup = new Group("root", null, null);
  DefaultMutableTreeNode root = new DefaultMutableTreeNode(rootGroup);
  root.removeAllChildren();
  schema.fillActionGroups(root);
  final JTree defaultTree = new Tree(new DefaultTreeModel(root));

  final ArrayList<ActionUrl> actions = new ArrayList<ActionUrl>();

  TreeUtil.traverseDepth((TreeNode)tree.getModel().getRoot(), new TreeUtil.Traverse() {
    public boolean accept(Object node) {
      DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)node;
      if (treeNode.isLeaf()) {
        return true;
      }
      final ActionUrl url = getActionUrl(new TreePath(treeNode.getPath()), 0);
      url.getGroupPath().add(((Group)treeNode.getUserObject()).getName());
      final TreePath treePath = getTreePath(defaultTree, url);
      if (treePath != null) {
        final DefaultMutableTreeNode visited = (DefaultMutableTreeNode)treePath.getLastPathComponent();
        final ActionUrl[] defaultUserObjects = getChildUserObjects(visited, url);
        final ActionUrl[] currentUserObjects = getChildUserObjects(treeNode, url);
        computeDiff(defaultUserObjects, currentUserObjects, actions);
      } else {
        //customizations at the new place
        url.getGroupPath().remove(url.getParentGroup());
        if (actions.contains(url)){
          url.getGroupPath().add(((Group)treeNode.getUserObject()).getName());
          actions.addAll(schema.getChildActions(url));
        }
      }
      return true;
    }
  });
  schema.setActions(actions);
}
 
Example 8
Source File: TemplateListPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void selectTemplate(final String lastSelectedGroup, final String lastSelectedKey) {
  TreeUtil.traverseDepth(myTreeRoot, new TreeUtil.Traverse() {
    @Override
    public boolean accept(Object node) {
      Object o = ((DefaultMutableTreeNode)node).getUserObject();
      if (lastSelectedKey == null && o instanceof TemplateGroup && Comparing.equal(lastSelectedGroup, ((TemplateGroup)o).getName()) ||
          o instanceof TemplateImpl && Comparing.equal(lastSelectedKey, ((TemplateImpl)o).getKey()) && Comparing.equal(lastSelectedGroup, ((TemplateImpl)o).getGroupName())) {
        setSelectedNode((DefaultMutableTreeNode)node);
        return false;
      }

      return true;
    }
  });
}
 
Example 9
Source File: RunConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void disposeUIResources() {
  isDisposed = true;
  for (Configurable configurable : myStoredComponents.values()) {
    configurable.disposeUIResources();
  }
  myStoredComponents.clear();

  for (Pair<UnnamedConfigurable, JComponent> each : myAdditionalSettings) {
    each.first.disposeUIResources();
  }

  TreeUtil.traverseDepth(myRoot, new TreeUtil.Traverse() {
    @Override
    public boolean accept(Object node) {
      if (node instanceof DefaultMutableTreeNode) {
        final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)node;
        final Object userObject = treeNode.getUserObject();
        if (userObject instanceof SingleConfigurationConfigurable) {
          ((SingleConfigurationConfigurable)userObject).disposeUIResources();
        }
      }
      return true;
    }
  });
  myRightPanel.removeAll();
  myProperties.setFloat(DIVIDER_PROPORTION, mySplitter.getProportion());
  mySplitter.dispose();
}
 
Example 10
Source File: InspectionRVContentProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
protected static RefElementNode addNodeToParent(@Nonnull UserObjectContainer container,
                                                @Nonnull InspectionToolPresentation presentation,
                                                final InspectionTreeNode parentNode) {
  final RefElementNode nodeToBeAdded = container.createNode(presentation);
  final Ref<Boolean> firstLevel = new Ref<Boolean>(true);
  RefElementNode prevNode = null;
  final Ref<RefElementNode> result = new Ref<RefElementNode>();
  while (true) {
    final RefElementNode currentNode = firstLevel.get() ? nodeToBeAdded : container.createNode(presentation);
    final UserObjectContainer finalContainer = container;
    final RefElementNode finalPrevNode = prevNode;
    TreeUtil.traverseDepth(parentNode, new TreeUtil.Traverse() {
      @Override
      public boolean accept(Object node) {
        if (node instanceof RefElementNode) {
          final RefElementNode refElementNode = (RefElementNode)node;
          if (finalContainer.areEqual(refElementNode.getUserObject(), finalContainer.getUserObject())) {
            if (firstLevel.get()) {
              result.set(refElementNode);
              return false;
            }
            else {
              insertByIndex(finalPrevNode, refElementNode);
              result.set(nodeToBeAdded);
              return false;
            }
          }
        }
        return true;
      }
    });
    if(!result.isNull()) return result.get();

    if (!firstLevel.get()) {
      insertByIndex(prevNode, currentNode);
    }
    final UserObjectContainer owner = container.getOwner();
    if (owner == null) {
      insertByIndex(currentNode, parentNode);
      return nodeToBeAdded;
    }
    container = owner;
    prevNode = currentNode;
    firstLevel.set(false);
  }
}
 
Example 11
Source File: OfflineInspectionRVContentProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
public QuickFixAction[] getQuickFixes(@Nonnull final InspectionToolWrapper toolWrapper, @Nonnull final InspectionTree tree) {
  final TreePath[] treePaths = tree.getSelectionPaths();
  final List<RefEntity> selectedElements = new ArrayList<RefEntity>();
  final Map<RefEntity, Set<QuickFix>> actions = new HashMap<RefEntity, Set<QuickFix>>();
  for (TreePath selectionPath : treePaths) {
    TreeUtil.traverseDepth((TreeNode)selectionPath.getLastPathComponent(), new TreeUtil.Traverse() {
      @Override
      public boolean accept(final Object node) {
        if (!((InspectionTreeNode)node).isValid()) return true;
        if (node instanceof OfflineProblemDescriptorNode) {
          final OfflineProblemDescriptorNode descriptorNode = (OfflineProblemDescriptorNode)node;
          final RefEntity element = descriptorNode.getElement();
          selectedElements.add(element);
          Set<QuickFix> quickFixes = actions.get(element);
          if (quickFixes == null) {
            quickFixes = new HashSet<QuickFix>();
            actions.put(element, quickFixes);
          }
          final CommonProblemDescriptor descriptor = descriptorNode.getDescriptor();
          if (descriptor != null) {
            final QuickFix[] fixes = descriptor.getFixes();
            if (fixes != null) {
              ContainerUtil.addAll(quickFixes, fixes);
            }
          }
        }
        else if (node instanceof RefElementNode) {
          selectedElements.add(((RefElementNode)node).getElement());
        }
        return true;
      }
    });
  }

  if (selectedElements.isEmpty()) return null;

  final RefEntity[] selectedRefElements = selectedElements.toArray(new RefEntity[selectedElements.size()]);

  GlobalInspectionContextImpl context = tree.getContext();
  InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
  return presentation.extractActiveFixes(selectedRefElements, actions);
}