public static boolean hasReadOnlyUsages(final Collection<Usage> usages) { for (Usage usage : usages) { if (usage.isReadOnly()) return true; } return false; }
@Override protected String getElementText(@NotNull Object element) { if (!(element instanceof UsageNode)) return element.toString(); UsageNode node = (UsageNode) element; if (node instanceof StringNode) return ""; Usage usage = node.getUsage(); if (usage == MORE_USAGES_SEPARATOR) return ""; GroupNode group = (GroupNode) node.getParent(); return usage.getPresentation().getPlainText() + group; }
@NotNull private Set<Usage> getReadOnlyUsages() { final Set<Usage> result = new THashSet<Usage>(); final Set<Map.Entry<Usage, UsageNode>> usages = myUsageNodes.entrySet(); for (Map.Entry<Usage, UsageNode> entry : usages) { Usage usage = entry.getKey(); UsageNode node = entry.getValue(); if (node != null && node != NULL_NODE && !node.isExcluded() && usage.isReadOnly()) { result.add(usage); } } return result; }
@Override public int compare(UsageNode c1, UsageNode c2) { if (c1 instanceof StringNode) return 1; if (c2 instanceof StringNode) return -1; Usage o1 = c1.getUsage(); Usage o2 = c2.getUsage(); if (o1 == MORE_USAGES_SEPARATOR) return 1; if (o2 == MORE_USAGES_SEPARATOR) return -1; VirtualFile v1 = UsageListCellRenderer.getVirtualFile(o1); VirtualFile v2 = UsageListCellRenderer.getVirtualFile(o2); String name1 = v1 == null ? null : v1.getName(); String name2 = v2 == null ? null : v2.getName(); int i = Comparing.compare(name1, name2); if (i != 0) return i; if (o1 instanceof Comparable && o2 instanceof Comparable) { return ((Comparable) o1).compareTo(o2); } FileEditorLocation loc1 = o1.getLocation(); FileEditorLocation loc2 = o2.getLocation(); return Comparing.compare(loc1, loc2); }
private void navigateAndHint( @NotNull Usage usage, @Nullable final String hint, @NotNull final FindUsagesHandler handler, @NotNull final RelativePoint popupPosition, final int maxUsages, @NotNull final FindUsagesOptions options) { usage.navigate(true); if (hint == null) return; final Editor newEditor = getEditorFor(usage); if (newEditor == null) return; final Project project = handler.getProject(); // opening editor is performing in invokeLater IdeFocusManager.getInstance(project) .doWhenFocusSettlesDown( new Runnable() { @Override public void run() { newEditor .getScrollingModel() .runActionOnScrollingFinished( new Runnable() { @Override public void run() { // after new editor created, some editor resizing events are still // bubbling. To prevent hiding hint, invokeLater this IdeFocusManager.getInstance(project) .doWhenFocusSettlesDown( new Runnable() { @Override public void run() { if (newEditor.getComponent().isShowing()) { showHint( hint, newEditor, popupPosition, handler, maxUsages, options); } } }); } }); } }); }
public UsageNode doAppendUsage(@NotNull Usage usage) { // invoke in ReadAction to be be sure that usages are not invalidated while the tree is being // built ApplicationManager.getApplication().assertReadAccessAllowed(); if (!usage.isValid()) { // because the view is built incrementally, the usage may be already invalid, so need to // filter such cases return null; } UsageNode node = myBuilder.appendUsage(usage); myUsageNodes.put(usage, node == null ? NULL_NODE : node); if (!myIsFirstVisibleUsageFound && node != null) { // first visible usage found; myIsFirstVisibleUsageFound = true; showNode(node); } return node; }
@Nullable private static Editor getEditorFor(@NotNull Usage usage) { FileEditorLocation location = usage.getLocation(); FileEditor newFileEditor = location == null ? null : location.getEditor(); return newFileEditor instanceof TextEditor ? ((TextEditor) newFileEditor).getEditor() : null; }