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())); }
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; }
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); } } }
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); } } }
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; }
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; } } }
@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; }
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"); } } } } } }
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); }
public void update(AnActionEvent e) { PackageDependenciesNode node = myRightTree.getSelectedNode(); e.getPresentation().setEnabled(node != null && node.canSelectInLeftTree(myDependencies)); }