private void syncBrowser() {
   if (myTree.getSelectionModel().getSelectionCount() != 1) {
     myBrowser.showEmpty();
   } else {
     TreePath pathSelected = myTree.getSelectionModel().getLeadSelectionPath();
     if (pathSelected != null) {
       final InspectionTreeNode node = (InspectionTreeNode) pathSelected.getLastPathComponent();
       if (node instanceof RefElementNode) {
         final RefElementNode refElementNode = (RefElementNode) node;
         final CommonProblemDescriptor problem = refElementNode.getProblem();
         final RefEntity refSelected = refElementNode.getElement();
         if (problem != null) {
           showInBrowser(refSelected, problem);
         } else {
           showInBrowser(refSelected);
         }
       } else if (node instanceof ProblemDescriptionNode) {
         final ProblemDescriptionNode problemNode = (ProblemDescriptionNode) node;
         showInBrowser(problemNode.getElement(), problemNode.getDescriptor());
       } else if (node instanceof InspectionNode) {
         showInBrowser(((InspectionNode) node).getToolWrapper());
       } else {
         myBrowser.showEmpty();
       }
     }
   }
 }
 public boolean updateView(boolean strict) {
   if (!strict && !myGlobalInspectionContext.getUIOptions().FILTER_RESOLVED_ITEMS) {
     myTree.repaint();
     return false;
   }
   clearTree();
   boolean resultsFound = buildTree();
   myTree.restoreExpansionAndSelection();
   return resultsFound;
 }
 @NotNull
 private InspectionTreeNode getRelativeRootNode(
     boolean isGroupedBySeverity, HighlightDisplayLevel level) {
   if (isGroupedBySeverity) {
     InspectionSeverityGroupNode severityGroupNode = mySeverityGroupNodes.get(level);
     if (severityGroupNode == null) {
       InspectionSeverityGroupNode newNode = new InspectionSeverityGroupNode(myProject, level);
       severityGroupNode = ConcurrencyUtil.cacheOrGet(mySeverityGroupNodes, level, newNode);
       if (severityGroupNode == newNode) {
         InspectionTreeNode root = myTree.getRoot();
         addChildNodeInEDT(root, severityGroupNode);
       }
     }
     return severityGroupNode;
   }
   return myTree.getRoot();
 }
  private void popupInvoked(Component component, int x, int y) {
    final TreePath path = myTree.getLeadSelectionPath();

    if (path == null) return;

    final DefaultActionGroup actions = new DefaultActionGroup();
    final ActionManager actionManager = ActionManager.getInstance();
    actions.add(actionManager.getAction(IdeActions.ACTION_EDIT_SOURCE));
    actions.add(actionManager.getAction(IdeActions.ACTION_FIND_USAGES));

    actions.add(myIncludeAction);
    actions.add(myExcludeAction);

    actions.addSeparator();

    final InspectionToolWrapper toolWrapper = myTree.getSelectedToolWrapper();
    if (toolWrapper != null) {
      final QuickFixAction[] quickFixes = myProvider.getQuickFixes(toolWrapper, myTree);
      if (quickFixes != null) {
        for (QuickFixAction quickFixe : quickFixes) {
          actions.add(quickFixe);
        }
      }
      final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
      if (key == null) return; // e.g. DummyEntryPointsTool

      // options
      actions.addSeparator();
      actions.add(new EditSettingsAction());
      final List<AnAction> options = new InspectionsOptionsToolbarAction(this).createActions();
      for (AnAction action : options) {
        actions.add(action);
      }
    }

    actions.addSeparator();
    actions.add(actionManager.getAction(IdeActions.GROUP_VERSION_CONTROLS));

    final ActionPopupMenu menu =
        actionManager.createActionPopupMenu(ActionPlaces.CODE_INSPECTION, actions);
    menu.getComponent().show(component, x, y);
  }
  @Override
  public Object getData(String dataId) {
    if (PlatformDataKeys.HELP_ID.is(dataId)) return HELP_ID;
    if (DATA_KEY.is(dataId)) return this;
    if (myTree == null) return null;
    TreePath[] paths = myTree.getSelectionPaths();

    if (paths == null || paths.length == 0) return null;

    if (paths.length > 1) {
      if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
        return collectPsiElements();
      }
      return null;
    }

    TreePath path = paths[0];

    InspectionTreeNode selectedNode = (InspectionTreeNode) path.getLastPathComponent();

    if (selectedNode instanceof RefElementNode) {
      final RefElementNode refElementNode = (RefElementNode) selectedNode;
      RefEntity refElement = refElementNode.getElement();
      if (refElement == null) return null;
      final RefEntity item = refElement.getRefManager().getRefinedElement(refElement);

      if (!item.isValid()) return null;

      PsiElement psiElement = item instanceof RefElement ? ((RefElement) item).getElement() : null;
      if (psiElement == null) return null;

      final CommonProblemDescriptor problem = refElementNode.getProblem();
      if (problem != null) {
        if (problem instanceof ProblemDescriptor) {
          psiElement = ((ProblemDescriptor) problem).getPsiElement();
          if (psiElement == null) return null;
        } else {
          return null;
        }
      }

      if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
        return getSelectedNavigatable(problem, psiElement);
      } else if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        return psiElement.isValid() ? psiElement : null;
      }
    } else if (selectedNode instanceof ProblemDescriptionNode
        && CommonDataKeys.NAVIGATABLE.is(dataId)) {
      return getSelectedNavigatable(((ProblemDescriptionNode) selectedNode).getDescriptor());
    }

    return null;
  }
  private PsiElement[] collectPsiElements() {
    RefEntity[] refElements = myTree.getSelectedElements();
    List<PsiElement> psiElements = new ArrayList<PsiElement>();
    for (RefEntity refElement : refElements) {
      PsiElement psiElement =
          refElement instanceof RefElement ? ((RefElement) refElement).getElement() : null;
      if (psiElement != null && psiElement.isValid()) {
        psiElements.add(psiElement);
      }
    }

    return PsiUtilCore.toPsiElementArray(psiElements);
  }
  private void initTreeListeners() {
    myTree
        .getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {
              @Override
              public void valueChanged(TreeSelectionEvent e) {
                syncBrowser();
                if (isAutoScrollMode()) {
                  OpenSourceUtil.openSourcesFrom(
                      DataManager.getInstance().getDataContext(InspectionResultsView.this), false);
                }
              }
            });

    EditSourceOnDoubleClickHandler.install(myTree);

    myTree.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
              OpenSourceUtil.openSourcesFrom(
                  DataManager.getInstance().getDataContext(InspectionResultsView.this), false);
            }
          }
        });

    myTree.addMouseListener(
        new PopupHandler() {
          @Override
          public void invokePopup(Component comp, int x, int y) {
            popupInvoked(comp, x, y);
          }
        });

    SmartExpander.installOn(myTree);
  }
 private InspectionProfile guessProfileToSelect(
     final InspectionProjectProfileManager profileManager) {
   final Set<InspectionProfile> profiles = new HashSet<InspectionProfile>();
   final RefEntity[] selectedElements = myTree.getSelectedElements();
   for (RefEntity selectedElement : selectedElements) {
     if (selectedElement instanceof RefElement) {
       final RefElement refElement = (RefElement) selectedElement;
       final PsiElement element = refElement.getElement();
       if (element != null) {
         profiles.add(profileManager.getInspectionProfile());
       }
     }
   }
   if (profiles.isEmpty()) {
     return (InspectionProfile) profileManager.getProjectProfileImpl();
   }
   return profiles.iterator().next();
 }
 public boolean isSingleToolInSelection() {
   return myTree != null && myTree.getSelectedToolWrapper() != null;
 }
 private void clearTree() {
   myTree.removeAllNodes();
   mySeverityGroupNodes.clear();
 }