Ejemplo n.º 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));
      }
    }
Ejemplo n.º 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));
        }
      }
    }
Ejemplo n.º 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);
   }
 }
Ejemplo n.º 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);
     }
   }
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
   }
 }
Ejemplo n.º 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()));
               }
             });
   }
 }
Ejemplo n.º 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;
    }
Ejemplo n.º 11
0
 @Override
 public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
   InspectionTreeNode node = (InspectionTreeNode) event.getPath().getLastPathComponent();
   myExpandedUserObjects.remove(node.getUserObject());
 }