Esempio n. 1
0
  public UsageView searchAndShowUsages(
      @NotNull final UsageTarget[] searchFor,
      final Factory<UsageSearcher> searcherFactory,
      final boolean showPanelIfOnlyOneUsage,
      final boolean showNotFoundMessage,
      @NotNull final UsageViewPresentation presentation,
      final UsageViewStateListener listener) {
    final AtomicReference<UsageViewImpl> usageView = new AtomicReference<UsageViewImpl>();

    final FindUsagesProcessPresentation processPresentation = new FindUsagesProcessPresentation();
    processPresentation.setShowNotFoundMessage(showNotFoundMessage);
    processPresentation.setShowPanelIfOnlyOneUsage(showPanelIfOnlyOneUsage);

    Task task =
        new Task.Backgroundable(
            myProject, getProgressTitle(presentation), true, new SearchInBackgroundOption()) {
          public void run(@NotNull final ProgressIndicator indicator) {
            new SearchForUsagesRunnable(
                    usageView,
                    presentation,
                    searchFor,
                    searcherFactory,
                    processPresentation,
                    listener)
                .run();
          }

          @Override
          public DumbModeAction getDumbModeAction() {
            return DumbModeAction.CANCEL;
          }

          @Nullable
          public NotificationInfo getNotificationInfo() {
            String notification =
                usageView.get() != null
                    ? usageView.get().getUsagesCount() + " Usage(s) Found"
                    : "No Usages Found";
            return new NotificationInfo("Find Usages", "Find Usages Finished", notification);
          }
        };
    ProgressManager.getInstance().run(task);
    return usageView.get();
  }