@Override
 protected String getElementText(@NotNull Object element) {
   if (!(element instanceof UsageNode)) return element.toString();
   UsageNode node = (UsageNode) element;
   if (node instanceof StringNode) return "";
   Usage usage = node.getUsage();
   if (usage == MORE_USAGES_SEPARATOR) return "";
   GroupNode group = (GroupNode) node.getParent();
   return usage.getPresentation().getPlainText() + group;
 }
 @Override
 public void excludeUsages(@NotNull Usage[] usages) {
   for (Usage usage : usages) {
     final UsageNode node = myUsageNodes.get(usage);
     if (node != NULL_NODE && node != null) {
       node.setUsageExcluded(true);
     }
   }
   updateImmediately();
 }
 @NotNull
 private Set<Usage> getReadOnlyUsages() {
   final Set<Usage> result = new THashSet<Usage>();
   final Set<Map.Entry<Usage, UsageNode>> usages = myUsageNodes.entrySet();
   for (Map.Entry<Usage, UsageNode> entry : usages) {
     Usage usage = entry.getKey();
     UsageNode node = entry.getValue();
     if (node != null && node != NULL_NODE && !node.isExcluded() && usage.isReadOnly()) {
       result.add(usage);
     }
   }
   return result;
 }
 public void restore() {
   final UsageNode node = myUsageNodes.get(myUsage);
   if (node == NULL_NODE || node == null) {
     return;
   }
   final DefaultMutableTreeNode parentGroupingNode = (DefaultMutableTreeNode) node.getParent();
   if (parentGroupingNode != null) {
     final TreePath treePath = new TreePath(parentGroupingNode.getPath());
     myTree.expandPath(treePath);
     if (mySelected) {
       myTree.addSelectionPath(treePath.pathByAddingChild(node));
     }
   }
 }
  private static void collectUsages(
      @NotNull DefaultMutableTreeNode node, @NotNull Set<Usage> usages) {
    if (node instanceof UsageNode) {
      UsageNode usageNode = (UsageNode) node;
      final Usage usage = usageNode.getUsage();
      usages.add(usage);
    }

    Enumeration enumeration = node.children();
    while (enumeration.hasMoreElements()) {
      DefaultMutableTreeNode child = (DefaultMutableTreeNode) enumeration.nextElement();
      collectUsages(child, usages);
    }
  }
  @Override
  public void selectUsages(@NotNull Usage[] usages) {
    List<TreePath> paths = new LinkedList<TreePath>();

    for (Usage usage : usages) {
      final UsageNode node = myUsageNodes.get(usage);

      if (node != NULL_NODE && node != null) {
        paths.add(new TreePath(node.getPath()));
      }
    }

    myTree.setSelectionPaths(paths.toArray(new TreePath[paths.size()]));
    if (!paths.isEmpty()) myTree.scrollPathToVisible(paths.get(0));
  }
 private void addUsageNodes(
     @NotNull GroupNode root,
     @NotNull final UsageViewImpl usageView,
     @NotNull List<UsageNode> outNodes) {
   for (UsageNode node : root.getUsageNodes()) {
     Usage usage = node.getUsage();
     if (usageView.isVisible(usage)) {
       node.setParent(root);
       outNodes.add(node);
     }
   }
   for (GroupNode groupNode : root.getSubGroups()) {
     groupNode.setParent(root);
     addUsageNodes(groupNode, usageView, outNodes);
   }
 }
  @Override
  @NotNull
  public Set<Usage> getExcludedUsages() {
    Set<Usage> result = new THashSet<Usage>();
    for (Map.Entry<Usage, UsageNode> entry : myUsageNodes.entrySet()) {
      UsageNode node = entry.getValue();
      Usage usage = entry.getKey();
      if (node == NULL_NODE || node == null) {
        continue;
      }
      if (node.isExcluded()) {
        result.add(usage);
      }
    }

    return result;
  }
        @Override
        public int compare(UsageNode c1, UsageNode c2) {
          if (c1 instanceof StringNode) return 1;
          if (c2 instanceof StringNode) return -1;
          Usage o1 = c1.getUsage();
          Usage o2 = c2.getUsage();
          if (o1 == MORE_USAGES_SEPARATOR) return 1;
          if (o2 == MORE_USAGES_SEPARATOR) return -1;

          VirtualFile v1 = UsageListCellRenderer.getVirtualFile(o1);
          VirtualFile v2 = UsageListCellRenderer.getVirtualFile(o2);
          String name1 = v1 == null ? null : v1.getName();
          String name2 = v2 == null ? null : v2.getName();
          int i = Comparing.compare(name1, name2);
          if (i != 0) return i;

          if (o1 instanceof Comparable && o2 instanceof Comparable) {
            return ((Comparable) o1).compareTo(o2);
          }

          FileEditorLocation loc1 = o1.getLocation();
          FileEditorLocation loc2 = o2.getLocation();
          return Comparing.compare(loc1, loc2);
        }