com.intellij.usages.impl.UsageNode Java Examples
The following examples show how to use
com.intellij.usages.impl.UsageNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 6 votes |
@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); }
Example #2
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 6 votes |
@NotNull private static MyModel setTableModel(@NotNull JTable table, @NotNull UsageViewImpl usageView, @NotNull final List<UsageNode> data) { ApplicationManager.getApplication().assertIsDispatchThread(); final int columnCount = calcColumnCount(data); MyModel model = table.getModel() instanceof MyModel ? (MyModel) table.getModel() : null; if (model == null || model.getColumnCount() != columnCount) { model = new MyModel(data, columnCount); table.setModel(model); ShowUsagesTableCellRenderer renderer = new ShowUsagesTableCellRenderer(usageView); for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) { TableColumn column = table.getColumnModel().getColumn(i); column.setCellRenderer(renderer); } } return model; }
Example #3
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 6 votes |
@NotNull private static List<UsageNode> collectData(@NotNull List<Usage> usages, @NotNull Collection<UsageNode> visibleNodes, @NotNull UsageViewImpl usageView, @NotNull UsageViewPresentation presentation) { @NotNull List<UsageNode> data = new ArrayList<UsageNode>(); int filtered = filtered(usages, usageView); if (filtered != 0) { data.add(createStringNode(UsageViewBundle.message("usages.were.filtered.out", filtered))); } data.addAll(visibleNodes); if (data.isEmpty()) { String progressText = UsageViewManagerImpl.getProgressTitle(presentation); data.add(createStringNode(progressText)); } Collections.sort(data, USAGE_NODE_COMPARATOR); return data; }
Example #4
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 6 votes |
@NotNull private static List<UsageNode> collectData(@NotNull List<Usage> usages, @NotNull Collection<UsageNode> visibleNodes, @NotNull UsageViewImpl usageView, @NotNull UsageViewPresentation presentation) { @NotNull List<UsageNode> data = new ArrayList<UsageNode>(); int filtered = filtered(usages, usageView); if (filtered != 0) { data.add(createStringNode(UsageViewBundle.message("usages.were.filtered.out", filtered))); } data.addAll(visibleNodes); if (data.isEmpty()) { String progressText = UsageViewManagerImpl.getProgressTitle(presentation); data.add(createStringNode(progressText)); } Collections.sort(data, USAGE_NODE_COMPARATOR); return data; }
Example #5
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 6 votes |
@NotNull private static MyModel setTableModel(@NotNull JTable table, @NotNull UsageViewImpl usageView, @NotNull final List<UsageNode> data) { ApplicationManager.getApplication().assertIsDispatchThread(); final int columnCount = calcColumnCount(data); MyModel model = table.getModel() instanceof MyModel ? (MyModel)table.getModel() : null; if (model == null || model.getColumnCount() != columnCount) { model = new MyModel(data, columnCount); table.setModel(model); ShowUsagesTableCellRenderer renderer = new ShowUsagesTableCellRenderer(usageView); for (int i=0;i<table.getColumnModel().getColumnCount();i++) { TableColumn column = table.getColumnModel().getColumn(i); column.setCellRenderer(renderer); } } return model; }
Example #6
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 6 votes |
@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); }
Example #7
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 5 votes |
@Override protected void selectElement(Object element, String selectedText) { List<UsageNode> data = ((MyModel)getTable().getModel()).getItems(); int i = data.indexOf(element); if (i == -1) return; final int viewRow = getTable().convertRowIndexToView(i); getTable().getSelectionModel().setSelectionInterval(viewRow, viewRow); TableUtil.scrollSelectionToVisible(getTable()); }
Example #8
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 5 votes |
@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; }
Example #9
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 5 votes |
@Override @Nullable protected PsiElement getPsiElementForHint(Object selectedValue) { if (selectedValue instanceof UsageNode) { final Usage usage = ((UsageNode)selectedValue).getUsage(); if (usage instanceof UsageInfo2UsageAdapter) { final PsiElement element = ((UsageInfo2UsageAdapter)usage).getElement(); if (element != null) { final PsiElement view = UsageToPsiElementProvider.findAppropriateParentFrom(element); return view == null ? element : view; } } } return null; }
Example #10
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 5 votes |
private void addUsageNodes(@NotNull GroupNode root, @NotNull final UsageViewImpl usageView, @NotNull List<UsageNode> outNodes) { for (UsageNode node : root.getUsageNodes()) { Usage usage = node.getUsage(); if (usageView.isVisible(usage)) { node.setParent(root); outNodes.add(node); } } for (GroupNode groupNode : root.getSubGroups()) { groupNode.setParent(root); addUsageNodes(groupNode, usageView, outNodes); } }
Example #11
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 5 votes |
private static int updateModel(@NotNull MyModel tableModel, @NotNull List<UsageNode> listOld, @NotNull List<UsageNode> listNew, int oldSelection) { UsageNode[] oa = listOld.toArray(new UsageNode[listOld.size()]); UsageNode[] na = listNew.toArray(new UsageNode[listNew.size()]); List<ModelDiff.Cmd> cmds = ModelDiff.createDiffCmds(tableModel, oa, na); int selection = oldSelection; if (cmds != null) { for (ModelDiff.Cmd cmd : cmds) { selection = cmd.translateSelection(selection); cmd.apply(); } } return selection; }
Example #12
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 5 votes |
private void rebuildPopup(@NotNull final UsageViewImpl usageView, @NotNull final List<Usage> usages, @NotNull List<UsageNode> nodes, @NotNull final JTable table, @NotNull final JBPopup popup, @NotNull final UsageViewPresentation presentation, @NotNull final RelativePoint popupPosition, boolean findUsagesInProgress) { ApplicationManager.getApplication().assertIsDispatchThread(); boolean shouldShowMoreSeparator = usages.contains(MORE_USAGES_SEPARATOR); if (shouldShowMoreSeparator) { nodes.add(MORE_USAGES_SEPARATOR_NODE); } String title = presentation.getTabText(); String fullTitle = getFullTitle(usages, title, shouldShowMoreSeparator, nodes.size() - (shouldShowMoreSeparator ? 1 : 0), findUsagesInProgress); ((AbstractPopup)popup).setCaption(fullTitle); List<UsageNode> data = collectData(usages, nodes, usageView, presentation); MyModel tableModel = setTableModel(table, usageView, data); List<UsageNode> existingData = tableModel.getItems(); int row = table.getSelectedRow(); int newSelection = updateModel(tableModel, existingData, data, row == -1 ? 0 : row); if (newSelection < 0 || newSelection >= tableModel.getRowCount()) { TableScrollingUtil.ensureSelectionExists(table); newSelection = table.getSelectedRow(); } else { table.getSelectionModel().setSelectionInterval(newSelection, newSelection); } TableScrollingUtil.ensureIndexIsVisible(table, newSelection, 0); setSizeAndDimensions(table, popup, popupPosition, data); }
Example #13
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 5 votes |
@Override public void addToModel(int idx, Object element) { UsageNode node = element instanceof UsageNode ? (UsageNode)element : createStringNode(element); if (idx < getRowCount()) { insertRow(idx, node); } else { addRow(node); } }
Example #14
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 5 votes |
@Override protected void selectElement(Object element, String selectedText) { List<UsageNode> data = ((MyModel) getTable().getModel()).getItems(); int i = data.indexOf(element); if (i == -1) return; final int viewRow = getTable().convertRowIndexToView(i); getTable().getSelectionModel().setSelectionInterval(viewRow, viewRow); TableUtil.scrollSelectionToVisible(getTable()); }
Example #15
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 5 votes |
@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; }
Example #16
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 5 votes |
@Nullable protected PsiElement getPsiElementForHint(Object selectedValue) { if (selectedValue instanceof UsageNode) { final Usage usage = ((UsageNode) selectedValue).getUsage(); if (usage instanceof UsageInfo2UsageAdapter) { final PsiElement element = ((UsageInfo2UsageAdapter) usage).getElement(); if (element != null) { final PsiElement view = UsageToPsiElementProvider.findAppropriateParentFrom(element); return view == null ? element : view; } } } return null; }
Example #17
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 5 votes |
private void addUsageNodes(@NotNull GroupNode root, @NotNull final UsageViewImpl usageView, @NotNull List<UsageNode> outNodes) { for (UsageNode node : root.getUsageNodes()) { Usage usage = node.getUsage(); if (usageView.isVisible(usage)) { node.setParent(root); outNodes.add(node); } } for (GroupNode groupNode : root.getSubGroups()) { groupNode.setParent(root); addUsageNodes(groupNode, usageView, outNodes); } }
Example #18
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 5 votes |
private static int updateModel(@NotNull MyModel tableModel, @NotNull List<UsageNode> listOld, @NotNull List<UsageNode> listNew, int oldSelection) { UsageNode[] oa = listOld.toArray(new UsageNode[listOld.size()]); UsageNode[] na = listNew.toArray(new UsageNode[listNew.size()]); List<ModelDiff.Cmd> cmds = ModelDiff.createDiffCmds(tableModel, oa, na); int selection = oldSelection; if (cmds != null) { for (ModelDiff.Cmd cmd : cmds) { selection = cmd.translateSelection(selection); cmd.apply(); } } return selection; }
Example #19
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 5 votes |
private void rebuildPopup(@NotNull final UsageViewImpl usageView, @NotNull final List<Usage> usages, @NotNull List<UsageNode> nodes, @NotNull final JTable table, @NotNull final JBPopup popup, @NotNull final UsageViewPresentation presentation, @NotNull final RelativePoint popupPosition, boolean findUsagesInProgress) { ApplicationManager.getApplication().assertIsDispatchThread(); boolean shouldShowMoreSeparator = usages.contains(MORE_USAGES_SEPARATOR); if (shouldShowMoreSeparator) { nodes.add(MORE_USAGES_SEPARATOR_NODE); } String title = presentation.getTabText(); String fullTitle = getFullTitle(usages, title, shouldShowMoreSeparator, nodes.size() - (shouldShowMoreSeparator ? 1 : 0), findUsagesInProgress); ((AbstractPopup) popup).setCaption(fullTitle); List<UsageNode> data = collectData(usages, nodes, usageView, presentation); MyModel tableModel = setTableModel(table, usageView, data); List<UsageNode> existingData = tableModel.getItems(); int row = table.getSelectedRow(); int newSelection = updateModel(tableModel, existingData, data, row == -1 ? 0 : row); if (newSelection < 0 || newSelection >= tableModel.getRowCount()) { TableScrollingUtil.ensureSelectionExists(table); newSelection = table.getSelectedRow(); } else { table.getSelectionModel().setSelectionInterval(newSelection, newSelection); } TableScrollingUtil.ensureIndexIsVisible(table, newSelection, 0); setSizeAndDimensions(table, popup, popupPosition, data); }
Example #20
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 5 votes |
@Override public void addToModel(int idx, Object element) { UsageNode node = element instanceof UsageNode ? (UsageNode) element : createStringNode(element); if (idx < getRowCount()) { insertRow(idx, node); } else { addRow(node); } }
Example #21
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 4 votes |
@NotNull private static UsageNode createStringNode(@NotNull final Object string) { return new StringNode(string); }
Example #22
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 4 votes |
private MyModel(@NotNull List<UsageNode> data, int cols) { super(cols(cols), data, 0); }
Example #23
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 4 votes |
private static int calcColumnCount(@NotNull List<UsageNode> data) { return data.isEmpty() || data.get(0) instanceof StringNode ? 1 : 3; }
Example #24
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 4 votes |
private void setSizeAndDimensions(@NotNull JTable table, @NotNull JBPopup popup, @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) { JComponent content = popup.getContent(); Window window = SwingUtilities.windowForComponent(content); Dimension d = window.getSize(); int width = calcMaxWidth(table); width = (int) Math.max(d.getWidth(), width); Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize(); width = Math.max((int) headerSize.getWidth(), width); width = Math.max(myWidth, width); if (myWidth == -1) myWidth = width; int newWidth = Math.max(width, d.width + width - myWidth); myWidth = newWidth; int rowsToShow = Math.min(30, data.size()); Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow); Rectangle rectangle = fitToScreen(dimension, popupPosition, table); dimension = rectangle.getSize(); Point location = window.getLocation(); if (!location.equals(rectangle.getLocation())) { window.setLocation(rectangle.getLocation()); } if (!data.isEmpty()) { TableScrollingUtil.ensureSelectionExists(table); } table.setSize(dimension); //table.setPreferredSize(dimension); //table.setMaximumSize(dimension); //table.setPreferredScrollableViewportSize(dimension); Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize(); int newHeight = (int) (dimension.height + headerSize.getHeight() + footerSize.getHeight()) + 4/* invisible borders, margins etc*/; Dimension newDim = new Dimension(dimension.width, newHeight); window.setSize(newDim); window.setMinimumSize(newDim); window.setMaximumSize(newDim); window.validate(); window.repaint(); table.revalidate(); table.repaint(); }
Example #25
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 4 votes |
private void setSizeAndDimensions(@NotNull JTable table, @NotNull JBPopup popup, @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) { JComponent content = popup.getContent(); Window window = SwingUtilities.windowForComponent(content); Dimension d = window.getSize(); int width = calcMaxWidth(table); width = (int)Math.max(d.getWidth(), width); Dimension headerSize = ((AbstractPopup)popup).getHeaderPreferredSize(); width = Math.max((int)headerSize.getWidth(), width); width = Math.max(myWidth, width); if (myWidth == -1) myWidth = width; int newWidth = Math.max(width, d.width + width - myWidth); myWidth = newWidth; int rowsToShow = Math.min(30, data.size()); Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow); Rectangle rectangle = fitToScreen(dimension, popupPosition, table); dimension = rectangle.getSize(); Point location = window.getLocation(); if (!location.equals(rectangle.getLocation())) { window.setLocation(rectangle.getLocation()); } if (!data.isEmpty()) { TableScrollingUtil.ensureSelectionExists(table); } table.setSize(dimension); //table.setPreferredSize(dimension); //table.setMaximumSize(dimension); //table.setPreferredScrollableViewportSize(dimension); Dimension footerSize = ((AbstractPopup)popup).getFooterPreferredSize(); int newHeight = (int)(dimension.height + headerSize.getHeight() + footerSize.getHeight()) + 4/* invisible borders, margins etc*/; Dimension newDim = new Dimension(dimension.width, newHeight); window.setSize(newDim); window.setMinimumSize(newDim); window.setMaximumSize(newDim); window.validate(); window.repaint(); table.revalidate(); table.repaint(); }
Example #26
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 4 votes |
private static int calcColumnCount(@NotNull List<UsageNode> data) { return data.isEmpty() || data.get(0) instanceof StringNode ? 1 : 3; }
Example #27
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 4 votes |
private MyModel(@NotNull List<UsageNode> data, int cols) { super(cols(cols), data, 0); }
Example #28
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 4 votes |
@NotNull private static UsageNode createStringNode(@NotNull final Object string) { return new StringNode(string); }