com.intellij.usages.impl.UsageViewImpl Java Examples

The following examples show how to use com.intellij.usages.impl.UsageViewImpl. 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 vote down vote up
@NotNull
private InplaceButton createSettingsButton(@NotNull final FindUsagesHandler handler,
    @NotNull final RelativePoint popupPosition, final Editor editor, final int maxUsages,
    @NotNull final Runnable cancelAction) {
  String shortcutText = "";
  KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
  if (shortcut != null) {
    shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")";
  }
  return new InplaceButton("Settings..." + shortcutText, AllIcons.General.Settings,
      new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
              showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
            }
          });
          cancelAction.run();
        }
      }
  );
}
 
Example #2
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 6 votes vote down vote up
@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 vote down vote up
@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 vote down vote up
@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 vote down vote up
@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 vote down vote up
@NotNull
private InplaceButton createSettingsButton(@NotNull final FindUsagesHandler handler,
    @NotNull final RelativePoint popupPosition,
    final Editor editor,
    final int maxUsages,
    @NotNull final Runnable cancelAction) {
  String shortcutText = "";
  KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
  if (shortcut != null) {
    shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")";
  }
  return new InplaceButton("Settings..." + shortcutText, AllIcons.General.Settings, new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
          showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
        }
      });
      cancelAction.run();
    }
  });
}
 
Example #7
Source File: UsageContextCallHierarchyPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isAvailableFor(@Nonnull UsageView usageView) {
  UsageTarget[] targets = ((UsageViewImpl)usageView).getTargets();
  if (targets.length == 0) return false;
  UsageTarget target = targets[0];
  if (!(target instanceof PsiElementUsageTarget)) return false;
  PsiElement element = ((PsiElementUsageTarget)target).getElement();
  if (element == null || !element.isValid()) return false;

  Project project = element.getProject();
  DataContext context = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT, element, SimpleDataContext.getProjectContext(project));
  HierarchyProvider provider = BrowseHierarchyActionBase.findBestHierarchyProvider(LanguageCallHierarchy.INSTANCE, element, context);
  if (provider == null) return false;
  PsiElement providerTarget = provider.getTarget(context);
  return providerTarget != null;
}
 
Example #8
Source File: ReplaceInProjectManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void replaceUsagesUnderCommand(@Nonnull final ReplaceContext replaceContext, @Nonnull final Set<? extends Usage> usagesSet) {
  if (usagesSet.isEmpty()) {
    return;
  }

  final List<Usage> usages = new ArrayList<>(usagesSet);
  Collections.sort(usages, UsageViewImpl.USAGE_COMPARATOR);

  if (!ensureUsagesWritable(replaceContext, usages)) return;

  CommandProcessor.getInstance().executeCommand(myProject, () -> {
    final boolean success = replaceUsages(replaceContext, usages);
    final UsageView usageView = replaceContext.getUsageView();

    if (closeUsageViewIfEmpty(usageView, success)) return;
    IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(usageView.getPreferredFocusableComponent(), true));
  }, FindBundle.message("find.replace.command"), null);

  replaceContext.invalidateExcludedSetCache();
}
 
Example #9
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private static int filtered(@NotNull List<Usage> usages, @NotNull UsageViewImpl usageView) {
  int count = 0;
  for (Usage usage : usages) {
    if (!usageView.isVisible(usage)) count++;
  }
  return count;
}
 
Example #10
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
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 vote down vote up
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 #12
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private static int filtered(@NotNull List<Usage> usages, @NotNull UsageViewImpl usageView) {
  int count=0;
  for (Usage usage : usages) {
    if (!usageView.isVisible(usage)) count++;
  }
  return count;
}
 
Example #13
Source File: BaseRefactoringProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void showUsageView(@Nonnull UsageViewDescriptor viewDescriptor, @Nonnull Factory<UsageSearcher> factory, @Nonnull UsageInfo[] usageInfos) {
  UsageViewManager viewManager = UsageViewManager.getInstance(myProject);

  final PsiElement[] initialElements = viewDescriptor.getElements();
  final UsageTarget[] targets = PsiElement2UsageTargetAdapter.convert(initialElements);
  final Ref<Usage[]> convertUsagesRef = new Ref<>();
  if (!ProgressManager.getInstance()
          .runProcessWithProgressSynchronously(() -> ApplicationManager.getApplication().runReadAction(() -> convertUsagesRef.set(UsageInfo2UsageAdapter.convert(usageInfos))), "Preprocess Usages",
                                               true, myProject)) return;

  if (convertUsagesRef.isNull()) return;

  final Usage[] usages = convertUsagesRef.get();

  final UsageViewPresentation presentation = createPresentation(viewDescriptor, usages);
  if (myUsageView == null) {
    myUsageView = viewManager.showUsages(targets, usages, presentation, factory);
    customizeUsagesView(viewDescriptor, myUsageView);
  }
  else {
    myUsageView.removeUsagesBulk(myUsageView.getUsages());
    ((UsageViewImpl)myUsageView).appendUsagesInBulk(Arrays.asList(usages));
  }
  Set<UnloadedModuleDescription> unloadedModules = computeUnloadedModulesFromUseScope(viewDescriptor);
  if (!unloadedModules.isEmpty()) {
    myUsageView.appendUsage(new UnknownUsagesInUnloadedModules(unloadedModules));
  }
}
 
Example #14
Source File: FindUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static UsageView showInUsageView(@Nullable PsiElement sourceElement,
                                        @Nonnull PsiElement[] targets,
                                        @Nonnull String title,
                                        @Nonnull final Project project) {
  if (targets.length == 0) return null;
  final UsageViewPresentation presentation = new UsageViewPresentation();
  presentation.setCodeUsagesString(title);
  presentation.setTabName(title);
  presentation.setTabText(title);
  UsageTarget[] usageTargets = sourceElement == null ? UsageTarget.EMPTY_ARRAY : new UsageTarget[]{new PsiElement2UsageTargetAdapter(sourceElement)};

  PsiElement[] primary = sourceElement == null ? PsiElement.EMPTY_ARRAY : new PsiElement[]{sourceElement};
  UsageView view = UsageViewManager.getInstance(project).showUsages(usageTargets, Usage.EMPTY_ARRAY, presentation);

  SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(project);
  List<SmartPsiElementPointer> pointers = ContainerUtil.map(targets, smartPointerManager::createSmartPsiElementPointer);

  // usage view will load document/AST so still referencing all these PSI elements might lead to out of memory
  //noinspection UnusedAssignment
  targets = PsiElement.EMPTY_ARRAY;

  ProgressManager.getInstance().run(new Task.Backgroundable(project, "Updating Usage View ...") {
    @Override
    public void run(@Nonnull ProgressIndicator indicator) {
      for (final SmartPsiElementPointer pointer : pointers) {
        if (((UsageViewImpl)view).isDisposed()) break;
        ApplicationManager.getApplication().runReadAction(() -> {
          final PsiElement target = pointer.getElement();
          if (target != null) {
            view.appendUsage(UsageInfoToUsageConverter.convert(primary, new UsageInfo(target)));
          }
        });
      }
      UIUtil.invokeLaterIfNeeded(((UsageViewImpl)view)::expandAll);
    }
  });
  return view;
}
 
Example #15
Source File: BackgroundUpdaterTaskBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean tryAppendUsage(@Nonnull T element) {
  final UsageView view = myUsageView.get();
  if (view != null && !((UsageViewImpl)view).isDisposed()) {
    Usage usage = createUsage(element);
    if (usage == null) return false;
    ApplicationManager.getApplication().runReadAction(() -> view.appendUsage(usage));
    return true;
  }
  return false;
}
 
Example #16
Source File: RerunSearchAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void update(@Nonnull AnActionEvent e) {
  UsageView usageView = e.getData(UsageView.USAGE_VIEW_KEY);
  boolean enabled = usageView instanceof UsageViewImpl && ((UsageViewImpl)usageView).canPerformReRun();
  e.getPresentation().setEnabled(enabled);
}
 
Example #17
Source File: RerunSearchAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  UsageView usageView = e.getData(UsageView.USAGE_VIEW_KEY);
  if (usageView instanceof UsageViewImpl) {
    ((UsageViewImpl)usageView).refreshUsages();
  }
}
 
Example #18
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
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 #19
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
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: ShowUsagesTableCellRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
ShowUsagesTableCellRenderer(@Nonnull UsageViewImpl usageView, @Nonnull AtomicInteger outOfScopeUsages, @Nonnull SearchScope searchScope) {
  myUsageView = usageView;
  myOutOfScopeUsages = outOfScopeUsages;
  mySearchScope = searchScope;
}
 
Example #21
Source File: PsiElement2UsageTargetAdapter.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public KeyboardShortcut getShortcut() {
  return UsageViewImpl.getShowUsagesWithSettingsShortcut();
}
 
Example #22
Source File: UsageContextCallHierarchyPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public UsageContextPanel create(@Nonnull UsageView usageView) {
  return new UsageContextCallHierarchyPanel(((UsageViewImpl)usageView).getProject(), usageView.getPresentation());
}
 
Example #23
Source File: ShowUsagesTableCellRenderer.java    From dagger-intellij-plugin with Apache License 2.0 4 votes vote down vote up
ShowUsagesTableCellRenderer(@NotNull UsageViewImpl usageView) {
  myUsageView = usageView;
}
 
Example #24
Source File: ShowUsagesTableCellRenderer.java    From otto-intellij-plugin with Apache License 2.0 4 votes vote down vote up
ShowUsagesTableCellRenderer(@NotNull UsageViewImpl usageView) {
  myUsageView = usageView;
}