コード例 #1
0
    @Override
    public void customizeCellRenderer(
        JTree tree,
        Object value,
        boolean selected,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {
      InspectionTreeNode node = (InspectionTreeNode) value;

      append(
          node.toString(),
          patchAttr(
              node,
              appearsBold(node)
                  ? SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES
                  : getMainForegroundAttributes(node)));

      int problemCount = node.getProblemCount();
      if (!leaf) {
        append(
            " " + InspectionsBundle.message("inspection.problem.descriptor.count", problemCount),
            patchAttr(node, SimpleTextAttributes.GRAYED_ATTRIBUTES));
      }

      if (!node.isValid()) {
        append(
            " " + InspectionsBundle.message("inspection.invalid.node.text"),
            patchAttr(node, SimpleTextAttributes.ERROR_ATTRIBUTES));
      } else {
        setIcon(node.getIcon(expanded));
      }
    }
コード例 #2
0
    private void restorePath(ArrayList<Object> newPath, int idx) {
      if (idx >= myPath.length) return;
      InspectionTreeNode oldNode = (InspectionTreeNode) myPath[idx];

      InspectionTreeNode newRoot = (InspectionTreeNode) newPath.get(idx - 1);

      InspectionResultsViewComparator comparator = InspectionResultsViewComparator.getInstance();
      Enumeration children = newRoot.children();
      while (children.hasMoreElements()) {
        InspectionTreeNode child = (InspectionTreeNode) children.nextElement();
        if (comparator.compare(child, oldNode) == 0) {
          newPath.add(child);
          restorePath(newPath, idx + 1);
          return;
        }
      }

      // Exactly same element not found. Trying to select somewhat near.
      int count = newRoot.getChildCount();
      if (count > 0) {
        if (myIndicies[idx] < count) {
          newPath.add(newRoot.getChildAt(myIndicies[idx]));
        } else {
          newPath.add(newRoot.getChildAt(count - 1));
        }
      }
    }
コード例 #3
0
 private static void traverseDescriptors(
     InspectionTreeNode node, LinkedHashSet<CommonProblemDescriptor> descriptors) {
   if (node instanceof ProblemDescriptionNode) {
     descriptors.add(((ProblemDescriptionNode) node).getDescriptor());
   }
   for (int i = node.getChildCount() - 1; i >= 0; i--) {
     traverseDescriptors((InspectionTreeNode) node.getChildAt(i), descriptors);
   }
 }
コード例 #4
0
 private void restoreExpansionStatus(InspectionTreeNode node) {
   if (myExpandedUserObjects.contains(node.getUserObject())) {
     sortChildren(node);
     TreeNode[] pathToNode = node.getPath();
     expandPath(new TreePath(pathToNode));
     Enumeration children = node.children();
     while (children.hasMoreElements()) {
       InspectionTreeNode childNode = (InspectionTreeNode) children.nextElement();
       restoreExpansionStatus(childNode);
     }
   }
 }
コード例 #5
0
 private void sortChildren(InspectionTreeNode node) {
   final List<TreeNode> children = TreeUtil.childrenToArray(node);
   Collections.sort(children, InspectionResultsViewComparator.getInstance());
   node.removeAllChildren();
   TreeUtil.addChildrenTo(node, children);
   ((DefaultTreeModel) getModel()).reload(node);
 }
コード例 #6
0
 private int getChildIndex(InspectionTreeNode node, InspectionTreeNode child) {
   int idx = 0;
   Enumeration children = node.children();
   while (children.hasMoreElements()) {
     InspectionTreeNode ch = (InspectionTreeNode) children.nextElement();
     if (ch == child) break;
     idx++;
   }
   return idx;
 }
コード例 #7
0
 public static SimpleTextAttributes patchAttr(
     InspectionTreeNode node, SimpleTextAttributes attributes) {
   if (node.isResolved()) {
     return new SimpleTextAttributes(
         attributes.getBgColor(),
         attributes.getFgColor(),
         attributes.getWaveColor(),
         attributes.getStyle() | SimpleTextAttributes.STYLE_STRIKEOUT);
   }
   return attributes;
 }
コード例 #8
0
 private static void addElementsInNode(InspectionTreeNode node, List<RefEntity> out) {
   if (!node.isValid()) return;
   if (node instanceof RefElementNode) {
     final RefEntity element = ((RefElementNode) node).getElement();
     if (!out.contains(element)) {
       out.add(0, element);
     }
   }
   if (node instanceof ProblemDescriptionNode) {
     final RefEntity element = ((ProblemDescriptionNode) node).getElement();
     if (!out.contains(element)) {
       out.add(0, element);
     }
   }
   final Enumeration children = node.children();
   while (children.hasMoreElements()) {
     InspectionTreeNode child = (InspectionTreeNode) children.nextElement();
     addElementsInNode(child, out);
   }
 }
コード例 #9
0
 @Override
 public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
   final InspectionTreeNode node = (InspectionTreeNode) event.getPath().getLastPathComponent();
   final Object userObject = node.getUserObject();
   // TODO: never re-sort
   if (node.isValid() && !myExpandedUserObjects.contains(userObject)) {
     sortChildren(node);
     nodeStructureChanged(node);
   }
   myExpandedUserObjects.add(userObject);
   // Smart expand
   if (node.getChildCount() == 1) {
     ApplicationManager.getApplication()
         .invokeLater(
             new Runnable() {
               @Override
               public void run() {
                 expandPath(new TreePath(node.getPath()));
               }
             });
   }
 }
コード例 #10
0
    private static SimpleTextAttributes getMainForegroundAttributes(InspectionTreeNode node) {
      SimpleTextAttributes foreground = SimpleTextAttributes.REGULAR_ATTRIBUTES;
      if (node instanceof RefElementNode) {
        RefEntity refElement = ((RefElementNode) node).getElement();

        if (refElement instanceof RefElement) {
          refElement = ((RefElement) refElement).getContainingEntry();
          if (((RefElement) refElement).isEntry() && ((RefElement) refElement).isPermanentEntry()) {
            foreground = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.blue);
          }
        }
      }
      final FileStatus nodeStatus = node.getNodeStatus();
      if (nodeStatus != FileStatus.NOT_CHANGED) {
        foreground =
            new SimpleTextAttributes(
                foreground.getBgColor(),
                nodeStatus.getColor(),
                foreground.getWaveColor(),
                foreground.getStyle());
      }
      return foreground;
    }
コード例 #11
0
 @Override
 public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
   InspectionTreeNode node = (InspectionTreeNode) event.getPath().getLastPathComponent();
   myExpandedUserObjects.remove(node.getUserObject());
 }