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(); }
private UsageViewImpl getUsageView() { UsageViewImpl usageView = myUsageViewRef.get(); if (usageView != null) return usageView; int usageCount = myUsageCountWithoutDefinition.get(); if (usageCount >= 2 || usageCount == 1 && myProcessPresentation.isShowPanelIfOnlyOneUsage()) { usageView = new UsageViewImpl(myProject, myPresentation, mySearchFor, mySearcherFactory); if (myUsageViewRef.compareAndSet(null, usageView)) { openView(usageView); Usage firstUsage = myFirstUsage.get(); if (firstUsage != null) { usageView.appendUsageLater(firstUsage); } } else { Disposer.dispose(usageView); } return myUsageViewRef.get(); } return null; }
public void searchAndShowUsages( @NotNull UsageTarget[] searchFor, @NotNull Factory<UsageSearcher> searcherFactory, @NotNull FindUsagesProcessPresentation processPresentation, @NotNull UsageViewPresentation presentation, UsageViewStateListener listener) { final AtomicReference<UsageViewImpl> usageView = new AtomicReference<UsageViewImpl>(); final SearchForUsagesRunnable runnable = new SearchForUsagesRunnable( usageView, presentation, searchFor, searcherFactory, processPresentation, listener); final Factory<ProgressIndicator> progressIndicatorFactory = processPresentation.getProgressIndicatorFactory(); final ProgressIndicator progressIndicator = progressIndicatorFactory != null ? progressIndicatorFactory.create() : null; ApplicationManager.getApplication() .executeOnPooledThread( new Runnable() { public void run() { try { ProgressManager.getInstance() .runProcess( new Runnable() { public void run() { runnable.searchUsages(); } }, progressIndicator); } catch (ProcessCanceledException e) { // ignore } ApplicationManager.getApplication() .invokeLater( new Runnable() { public void run() { runnable.endSearchForUsages(); } }, ModalityState.NON_MODAL); } }); }
private void endSearchForUsages() { int usageCount = myUsageCountWithoutDefinition.get(); if (usageCount == 0 && myProcessPresentation.isShowNotFoundMessage()) { ApplicationManager.getApplication() .invokeLater( new Runnable() { public void run() { final List<Action> notFoundActions = myProcessPresentation.getNotFoundActions(); final String message = UsageViewBundle.message( "dialog.no.usages.found.in", StringUtil.decapitalize(myPresentation.getUsagesString()), myPresentation.getScopeText()); if (notFoundActions == null || notFoundActions.isEmpty()) { ToolWindowManager.getInstance(myProject) .notifyByBalloon( ToolWindowId.FIND, MessageType.INFO, XmlStringUtil.escapeString(message), IconLoader.getIcon("/actions/find.png"), null); } else { List<String> titles = new ArrayList<String>(notFoundActions.size() + 1); titles.add(UsageViewBundle.message("dialog.button.ok")); for (Action action : notFoundActions) { Object value = action.getValue(FindUsagesProcessPresentation.NAME_WITH_MNEMONIC_KEY); if (value == null) value = action.getValue(Action.NAME); titles.add((String) value); } int option = Messages.showDialog( myProject, message, UsageViewBundle.message("dialog.title.information"), titles.toArray(new String[titles.size()]), 0, Messages.getInformationIcon()); if (option > 0) { notFoundActions .get(option - 1) .actionPerformed(new ActionEvent(this, 0, titles.get(option))); } } } }, ModalityState.NON_MODAL, myProject.getDisposed()); } else if (usageCount == 1 && !myProcessPresentation.isShowPanelIfOnlyOneUsage()) { SwingUtilities.invokeLater( new Runnable() { public void run() { Usage usage = myFirstUsage.get(); if (usage.canNavigate()) { usage.navigate(true); flashUsageScriptaculously(usage); } } }); } else { final UsageViewImpl usageView = myUsageViewRef.get(); if (usageView != null) usageView.setSearchInProgress(false); } if (myListener != null) { myListener.findingUsagesFinished(myUsageViewRef.get()); } }