コード例 #1
0
 private static void expandNodeIfNotTooWide(Tree tree, PackageDependenciesNode node) {
   int count = node.getChildCount();
   if (count > 5) return;
   // another level of nesting
   if (count == 1 && node.getChildAt(0).getChildCount() > 5) {
     return;
   }
   tree.expandPath(new TreePath(node.getPath()));
 }
コード例 #2
0
 private Set<PsiFile> getSelectedScope(final Tree tree) {
   TreePath[] paths = tree.getSelectionPaths();
   if (paths == null) return EMPTY_FILE_SET;
   Set<PsiFile> result = new HashSet<PsiFile>();
   for (TreePath path : paths) {
     PackageDependenciesNode node = (PackageDependenciesNode) path.getLastPathComponent();
     node.fillFiles(result, !mySettings.UI_FLATTEN_PACKAGES);
   }
   return result;
 }
コード例 #3
0
 private static void expandFirstLevel(Tree tree) {
   PackageDependenciesNode root = (PackageDependenciesNode) tree.getModel().getRoot();
   int count = root.getChildCount();
   if (count < 10) {
     for (int i = 0; i < count; i++) {
       PackageDependenciesNode child = (PackageDependenciesNode) root.getChildAt(i);
       expandNodeIfNotTooWide(tree, child);
     }
   }
 }
コード例 #4
0
 public void actionPerformed(AnActionEvent e) {
   PackageDependenciesNode node = myRightTree.getSelectedNode();
   if (node != null) {
     PsiElement elt = node.getPsiElement();
     if (elt != null) {
       DependencyUISettings.getInstance().UI_FILTER_LEGALS = false;
       mySettings.UI_FILTER_LEGALS = false;
       selectElementInLeftTree(elt);
     }
   }
 }
コード例 #5
0
 public Object getData(String dataId) {
   PackageDependenciesNode node = getSelectedNode();
   if (PlatformDataKeys.NAVIGATABLE.is(dataId)) {
     return node;
   }
   if (LangDataKeys.PSI_ELEMENT.is(dataId) && node != null) {
     final PsiElement element = node.getPsiElement();
     return element != null && element.isValid() ? element : null;
   }
   return null;
 }
コード例 #6
0
  private void selectElementInLeftTree(PsiElement elt) {
    PsiManager manager = PsiManager.getInstance(myProject);

    PackageDependenciesNode root = (PackageDependenciesNode) myLeftTree.getModel().getRoot();
    Enumeration enumeration = root.breadthFirstEnumeration();
    while (enumeration.hasMoreElements()) {
      PackageDependenciesNode child = (PackageDependenciesNode) enumeration.nextElement();
      if (manager.areElementsEquivalent(child.getPsiElement(), elt)) {
        myLeftTree.setSelectionPath(
            new TreePath(((DefaultTreeModel) myLeftTree.getModel()).getPathToRoot(child)));
        break;
      }
    }
  }
コード例 #7
0
 @Nullable
 @NonNls
 public Object getData(@NonNls String dataId) {
   if (LangDataKeys.PSI_ELEMENT.is(dataId)) {
     final PackageDependenciesNode selectedNode = myRightTree.getSelectedNode();
     if (selectedNode != null) {
       final PsiElement element = selectedNode.getPsiElement();
       return element != null && element.isValid() ? element : null;
     }
   }
   if (PlatformDataKeys.HELP_ID.is(dataId)) {
     return "dependency.viewer.tool.window";
   }
   return null;
 }
コード例 #8
0
 private void traverseToLeaves(
     final PackageDependenciesNode treeNode,
     final StringBuffer denyRules,
     final StringBuffer allowRules) {
   final Enumeration enumeration = treeNode.breadthFirstEnumeration();
   while (enumeration.hasMoreElements()) {
     PsiElement childPsiElement =
         ((PackageDependenciesNode) enumeration.nextElement()).getPsiElement();
     if (myIllegalDependencies.containsKey(childPsiElement)) {
       final Map<DependencyRule, Set<PsiFile>> illegalDeps =
           myIllegalDependencies.get(childPsiElement);
       for (final DependencyRule rule : illegalDeps.keySet()) {
         if (rule.isDenyRule()) {
           if (denyRules.indexOf(rule.getDisplayText()) == -1) {
             denyRules.append(rule.getDisplayText());
             denyRules.append("\n");
           }
         } else {
           if (allowRules.indexOf(rule.getDisplayText()) == -1) {
             allowRules.append(rule.getDisplayText());
             allowRules.append("\n");
           }
         }
       }
     }
   }
 }
コード例 #9
0
    public void customizeCellRenderer(
        JTree tree,
        Object value,
        boolean selected,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {
      if (value instanceof PackageDependenciesNode) {
        PackageDependenciesNode node = (PackageDependenciesNode) value;
        if (expanded) {
          setIcon(node.getOpenIcon());
        } else {
          setIcon(node.getClosedIcon());
        }

        setForeground(
            selected && hasFocus
                ? UIUtil.getTreeSelectionForeground()
                : UIUtil.getTreeForeground());
        if (!(selected && hasFocus)
            && node.hasMarked()
            && !DependencyUISettings.getInstance().UI_FILTER_LEGALS) {
          setForeground(node.hasUnmarked() ? PARTIAL_INCLUDED : WHOLE_INCLUDED);
        }
        append(node.toString(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
        final String locationString = node.getComment();
        if (!StringUtil.isEmpty(locationString)) {
          append(" (" + locationString + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
        }
      }
    }
コード例 #10
0
 public void customizeCellRenderer(
     JTree tree,
     Object value,
     boolean selected,
     boolean expanded,
     boolean leaf,
     int row,
     boolean hasFocus) {
   PackageDependenciesNode node = (PackageDependenciesNode) value;
   if (node.isValid()) {
     setIcon(node.getIcon());
   } else {
     append(
         UsageViewBundle.message("node.invalid") + " ", SimpleTextAttributes.ERROR_ATTRIBUTES);
   }
   append(
       node.toString(),
       node.hasMarked() && !selected
           ? SimpleTextAttributes.ERROR_ATTRIBUTES
           : SimpleTextAttributes.REGULAR_ATTRIBUTES);
   append(node.getPresentableFilesCount(), SimpleTextAttributes.GRAYED_ATTRIBUTES);
 }
コード例 #11
0
 public void update(AnActionEvent e) {
   PackageDependenciesNode node = myRightTree.getSelectedNode();
   e.getPresentation().setEnabled(node != null && node.canSelectInLeftTree(myDependencies));
 }