Search in sources :

Example 6 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.

the class PsiElementListNavigator method openTargets.

public static void openTargets(MouseEvent e, NavigatablePsiElement[] targets, String title, final String findUsagesTitle, ListCellRenderer listRenderer, @Nullable ListBackgroundUpdaterTask listUpdaterTask) {
    JBPopup popup = navigateOrCreatePopup(targets, title, findUsagesTitle, listRenderer, listUpdaterTask);
    if (popup != null) {
        if (listUpdaterTask != null) {
            Alarm alarm = new Alarm(popup);
            alarm.addRequest(() -> popup.show(new RelativePoint(e)), 300);
            ProgressManager.getInstance().run(listUpdaterTask);
        } else {
            popup.show(new RelativePoint(e));
        }
    }
}
Also used : Alarm(com.intellij.util.Alarm) RelativePoint(com.intellij.ui.awt.RelativePoint) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 7 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.

the class PsiElementListNavigator method navigateOrCreatePopup.

/**
   * listUpdaterTask should be started after alarm is initialized so one-item popup won't blink
   */
@Nullable
public static JBPopup navigateOrCreatePopup(@NotNull final NavigatablePsiElement[] targets, final String title, final String findUsagesTitle, final ListCellRenderer listRenderer, @Nullable final ListBackgroundUpdaterTask listUpdaterTask, @NotNull final Consumer<Object[]> consumer) {
    if (targets.length == 0)
        return null;
    if (targets.length == 1 && (listUpdaterTask == null || listUpdaterTask.isFinished())) {
        consumer.consume(targets);
        return null;
    }
    final CollectionListModel<NavigatablePsiElement> model = new CollectionListModel<>(targets);
    final JBList list = new JBList(model);
    HintUpdateSupply.installSimpleHintUpdateSupply(list);
    list.setTransferHandler(new TransferHandler() {

        @Nullable
        @Override
        protected Transferable createTransferable(JComponent c) {
            final Object[] selectedValues = list.getSelectedValues();
            final PsiElement[] copy = new PsiElement[selectedValues.length];
            for (int i = 0; i < selectedValues.length; i++) {
                copy[i] = (PsiElement) selectedValues[i];
            }
            return new PsiCopyPasteManager.MyTransferable(copy);
        }

        @Override
        public int getSourceActions(JComponent c) {
            return COPY;
        }
    });
    list.setCellRenderer(listRenderer);
    list.setFont(EditorUtil.getEditorFont());
    final PopupChooserBuilder builder = new PopupChooserBuilder(list);
    if (listRenderer instanceof PsiElementListCellRenderer) {
        ((PsiElementListCellRenderer) listRenderer).installSpeedSearch(builder);
    }
    PopupChooserBuilder popupChooserBuilder = builder.setTitle(title).setMovable(true).setResizable(true).setItemChoosenCallback(() -> {
        int[] ids = list.getSelectedIndices();
        if (ids == null || ids.length == 0)
            return;
        Object[] selectedElements = list.getSelectedValues();
        consumer.consume(selectedElements);
    }).setCancelCallback(() -> {
        HintUpdateSupply.hideHint(list);
        if (listUpdaterTask != null) {
            listUpdaterTask.cancelTask();
        }
        return true;
    });
    final Ref<UsageView> usageView = new Ref<>();
    if (findUsagesTitle != null) {
        popupChooserBuilder = popupChooserBuilder.setCouldPin(popup -> {
            final List<NavigatablePsiElement> items = model.getItems();
            usageView.set(FindUtil.showInUsageView(null, items.toArray(new PsiElement[items.size()]), findUsagesTitle, targets[0].getProject()));
            popup.cancel();
            return false;
        });
    }
    final JBPopup popup = popupChooserBuilder.createPopup();
    builder.getScrollPane().setBorder(null);
    builder.getScrollPane().setViewportBorder(null);
    if (listUpdaterTask != null) {
        listUpdaterTask.init((AbstractPopup) popup, list, usageView);
    }
    return popup;
}
Also used : EditorUtil(com.intellij.openapi.editor.ex.util.EditorUtil) Transferable(java.awt.datatransfer.Transferable) PsiCopyPasteManager(com.intellij.ide.PsiCopyPasteManager) PsiElement(com.intellij.psi.PsiElement) Logger(com.intellij.openapi.diagnostic.Logger) ProgressManager(com.intellij.openapi.progress.ProgressManager) JBList(com.intellij.ui.components.JBList) AbstractPopup(com.intellij.ui.popup.AbstractPopup) CollectionListModel(com.intellij.ui.CollectionListModel) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup) MouseEvent(java.awt.event.MouseEvent) ListBackgroundUpdaterTask(com.intellij.codeInsight.navigation.ListBackgroundUpdaterTask) HintUpdateSupply(com.intellij.ui.popup.HintUpdateSupply) UsageView(com.intellij.usages.UsageView) Nullable(org.jetbrains.annotations.Nullable) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) List(java.util.List) FindUtil(com.intellij.find.FindUtil) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) RelativePoint(com.intellij.ui.awt.RelativePoint) PsiElementListCellRenderer(com.intellij.ide.util.PsiElementListCellRenderer) Consumer(com.intellij.util.Consumer) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) Transferable(java.awt.datatransfer.Transferable) PsiCopyPasteManager(com.intellij.ide.PsiCopyPasteManager) UsageView(com.intellij.usages.UsageView) Ref(com.intellij.openapi.util.Ref) JBList(com.intellij.ui.components.JBList) JBList(com.intellij.ui.components.JBList) List(java.util.List) CollectionListModel(com.intellij.ui.CollectionListModel) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup) Nullable(org.jetbrains.annotations.Nullable) PsiElement(com.intellij.psi.PsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) PsiElementListCellRenderer(com.intellij.ide.util.PsiElementListCellRenderer) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.

the class ShowImplementationsAction method showImplementations.

protected void showImplementations(@NotNull PsiElement[] impls, @NotNull final Project project, final String text, final Editor editor, final PsiFile file, final PsiElement element, boolean invokedFromEditor, boolean invokedByShortcut) {
    if (impls.length == 0)
        return;
    FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKDEFINITION_FEATURE);
    if (LookupManager.getInstance(project).getActiveLookup() != null) {
        FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKDEFINITION_LOOKUP_FEATURE);
    }
    int index = 0;
    if (invokedFromEditor && file != null && impls.length > 1) {
        final VirtualFile virtualFile = file.getVirtualFile();
        final PsiFile containingFile = impls[0].getContainingFile();
        if (virtualFile != null && containingFile != null && virtualFile.equals(containingFile.getVirtualFile())) {
            final PsiFile secondContainingFile = impls[1].getContainingFile();
            if (secondContainingFile != containingFile) {
                index = 1;
            }
        }
    }
    final Ref<UsageView> usageView = new Ref<>();
    final String title = CodeInsightBundle.message("implementation.view.title", text);
    JBPopup popup = SoftReference.dereference(myPopupRef);
    if (popup != null && popup.isVisible() && popup instanceof AbstractPopup) {
        final ImplementationViewComponent component = (ImplementationViewComponent) ((AbstractPopup) popup).getComponent();
        ((AbstractPopup) popup).setCaption(title);
        component.update(impls, index);
        updateInBackground(editor, element, component, title, (AbstractPopup) popup, usageView);
        if (invokedByShortcut) {
            ((AbstractPopup) popup).focusPreferredComponent();
        }
        return;
    }
    final ImplementationViewComponent component = new ImplementationViewComponent(impls, index);
    if (component.hasElementsToShow()) {
        final PopupUpdateProcessor updateProcessor = new PopupUpdateProcessor(project) {

            @Override
            public void updatePopup(Object lookupItemObject) {
                final PsiElement element = lookupItemObject instanceof PsiElement ? (PsiElement) lookupItemObject : DocumentationManager.getInstance(project).getElementFromLookup(editor, file);
                updateElementImplementations(element, editor, project, file);
            }
        };
        popup = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component.getPreferredFocusableComponent()).setProject(project).addListener(updateProcessor).addUserData(updateProcessor).setDimensionServiceKey(project, DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(invokedFromEditor && LookupManager.getActiveLookup(editor) == null).setTitle(title).setCouldPin(popup1 -> {
            usageView.set(component.showInUsageView());
            popup1.cancel();
            myTaskRef = null;
            return false;
        }).setCancelCallback(() -> {
            ImplementationsUpdaterTask task = SoftReference.dereference(myTaskRef);
            if (task != null) {
                task.cancelTask();
            }
            return Boolean.TRUE;
        }).createPopup();
        updateInBackground(editor, element, component, title, (AbstractPopup) popup, usageView);
        PopupPositionManager.positionPopupInBestPosition(popup, editor, DataManager.getInstance().getDataContext());
        component.setHint(popup, title);
        myPopupRef = new WeakReference<>(popup);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) java.util(java.util) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonNls(org.jetbrains.annotations.NonNls) Computable(com.intellij.openapi.util.Computable) ReadAction(com.intellij.openapi.application.ReadAction) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) CodeInsightBundle(com.intellij.codeInsight.CodeInsightBundle) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) PopupUpdateProcessor(com.intellij.ui.popup.PopupUpdateProcessor) ImplementationSearcher(com.intellij.codeInsight.navigation.ImplementationSearcher) FeatureUsageTracker(com.intellij.featureStatistics.FeatureUsageTracker) Project(com.intellij.openapi.project.Project) PopupPositionManager(com.intellij.ui.popup.PopupPositionManager) Logger(com.intellij.openapi.diagnostic.Logger) WeakReference(java.lang.ref.WeakReference) DataManager(com.intellij.ide.DataManager) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ProgressManager(com.intellij.openapi.progress.ProgressManager) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) SoftReference(com.intellij.reference.SoftReference) LookupManager(com.intellij.codeInsight.lookup.LookupManager) AbstractPopup(com.intellij.ui.popup.AbstractPopup) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) JBPopup(com.intellij.openapi.ui.popup.JBPopup) BackgroundUpdaterTask(com.intellij.codeInsight.navigation.BackgroundUpdaterTask) TestOnly(org.jetbrains.annotations.TestOnly) Reference(java.lang.ref.Reference) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) UsageView(com.intellij.usages.UsageView) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SymbolPresentationUtil(com.intellij.psi.presentation.java.SymbolPresentationUtil) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) TargetElementUtil(com.intellij.codeInsight.TargetElementUtil) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) Ref(com.intellij.openapi.util.Ref) AbstractPopup(com.intellij.ui.popup.AbstractPopup) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) UsageView(com.intellij.usages.UsageView) Ref(com.intellij.openapi.util.Ref) PopupUpdateProcessor(com.intellij.ui.popup.PopupUpdateProcessor) JBPopup(com.intellij.openapi.ui.popup.JBPopup) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement)

Example 9 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.

the class ShowUsagesAction method showElementUsages.

private void showElementUsages(final Editor editor, @NotNull final RelativePoint popupPosition, @NotNull final FindUsagesHandler handler, final int maxUsages, @NotNull final FindUsagesOptions options) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    final UsageViewSettings usageViewSettings = UsageViewSettings.getInstance();
    final UsageViewSettings savedGlobalSettings = new UsageViewSettings();
    savedGlobalSettings.loadState(usageViewSettings);
    usageViewSettings.loadState(myUsageViewSettings);
    final Project project = handler.getProject();
    UsageViewManager manager = UsageViewManager.getInstance(project);
    FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
    final UsageViewPresentation presentation = findUsagesManager.createPresentation(handler, options);
    presentation.setDetachedMode(true);
    UsageViewImpl usageView = (UsageViewImpl) manager.createUsageView(UsageTarget.EMPTY_ARRAY, Usage.EMPTY_ARRAY, presentation, null);
    if (editor != null) {
        PsiReference reference = TargetElementUtil.findReference(editor);
        if (reference != null) {
            UsageInfo2UsageAdapter origin = new UsageInfo2UsageAdapter(new UsageInfo(reference));
            usageView.setOriginUsage(origin);
        }
    }
    Disposer.register(usageView, () -> {
        myUsageViewSettings.loadState(usageViewSettings);
        usageViewSettings.loadState(savedGlobalSettings);
    });
    final MyTable table = new MyTable();
    final AsyncProcessIcon processIcon = new AsyncProcessIcon("xxx");
    addUsageNodes(usageView.getRoot(), usageView, new ArrayList<>());
    final List<Usage> usages = new ArrayList<>();
    final Set<UsageNode> visibleNodes = new LinkedHashSet<>();
    final List<UsageNode> data = collectData(usages, visibleNodes, usageView, presentation);
    final AtomicInteger outOfScopeUsages = new AtomicInteger();
    setTableModel(table, usageView, data, outOfScopeUsages, options.searchScope);
    boolean isPreviewMode = Boolean.TRUE == PreviewManager.SERVICE.preview(handler.getProject(), UsagesPreviewPanelProvider.ID, Pair.create(usageView, table), false);
    Runnable itemChosenCallback = prepareTable(table, editor, popupPosition, handler, maxUsages, options, isPreviewMode);
    @Nullable final JBPopup popup = isPreviewMode ? null : createUsagePopup(usages, visibleNodes, handler, editor, popupPosition, maxUsages, usageView, options, table, itemChosenCallback, presentation, processIcon);
    if (popup != null) {
        Disposer.register(popup, usageView);
        // show popup only if find usages takes more than 300ms, otherwise it would flicker needlessly
        Alarm alarm = new Alarm(usageView);
        alarm.addRequest(() -> showPopupIfNeedTo(popup, popupPosition), 300);
    }
    final PingEDT pingEDT = new PingEDT("Rebuild popup in EDT", o -> popup != null && popup.isDisposed(), 100, () -> {
        if (popup != null && popup.isDisposed())
            return;
        final List<UsageNode> nodes = new ArrayList<>();
        List<Usage> copy;
        synchronized (usages) {
            // open up popup as soon as several usages 've been found
            if (popup != null && !popup.isVisible() && (usages.size() <= 1 || !showPopupIfNeedTo(popup, popupPosition))) {
                return;
            }
            addUsageNodes(usageView.getRoot(), usageView, nodes);
            copy = new ArrayList<>(usages);
        }
        rebuildTable(usageView, copy, nodes, table, popup, presentation, popupPosition, !processIcon.isDisposed(), outOfScopeUsages, options.searchScope);
    });
    final MessageBusConnection messageBusConnection = project.getMessageBus().connect(usageView);
    messageBusConnection.subscribe(UsageFilteringRuleProvider.RULES_CHANGED, pingEDT::ping);
    final UsageTarget[] myUsageTarget = { new PsiElement2UsageTargetAdapter(handler.getPsiElement()) };
    Processor<Usage> collect = usage -> {
        if (!UsageViewManagerImpl.isInScope(usage, options.searchScope)) {
            if (outOfScopeUsages.getAndIncrement() == 0) {
                visibleNodes.add(USAGES_OUTSIDE_SCOPE_NODE);
                usages.add(USAGES_OUTSIDE_SCOPE_SEPARATOR);
            }
            return true;
        }
        synchronized (usages) {
            if (visibleNodes.size() >= maxUsages)
                return false;
            if (UsageViewManager.isSelfUsage(usage, myUsageTarget))
                return true;
            UsageNode node = ReadAction.compute(() -> usageView.doAppendUsage(usage));
            usages.add(usage);
            if (node != null) {
                visibleNodes.add(node);
                boolean continueSearch = true;
                if (visibleNodes.size() == maxUsages) {
                    visibleNodes.add(MORE_USAGES_SEPARATOR_NODE);
                    usages.add(MORE_USAGES_SEPARATOR);
                    continueSearch = false;
                }
                pingEDT.ping();
                return continueSearch;
            }
        }
        return true;
    };
    final ProgressIndicator indicator = FindUsagesManager.startProcessUsages(handler, handler.getPrimaryElements(), handler.getSecondaryElements(), collect, options, () -> ApplicationManager.getApplication().invokeLater(() -> {
        Disposer.dispose(processIcon);
        Container parent = processIcon.getParent();
        if (parent != null) {
            parent.remove(processIcon);
            parent.repaint();
        }
        // repaint title
        pingEDT.ping();
        synchronized (usages) {
            if (visibleNodes.isEmpty()) {
                if (usages.isEmpty()) {
                    String text = UsageViewBundle.message("no.usages.found.in", searchScopePresentableName(options));
                    hint(editor, text, handler, popupPosition, maxUsages, options, false);
                    cancel(popup);
                }
            // else all usages filtered out
            } else if (visibleNodes.size() == 1) {
                if (usages.size() == 1) {
                    //the only usage
                    Usage usage = visibleNodes.iterator().next().getUsage();
                    if (usage == USAGES_OUTSIDE_SCOPE_SEPARATOR) {
                        hint(editor, UsageViewManagerImpl.outOfScopeMessage(outOfScopeUsages.get(), options.searchScope), handler, popupPosition, maxUsages, options, true);
                    } else {
                        String message = UsageViewBundle.message("show.usages.only.usage", searchScopePresentableName(options));
                        navigateAndHint(usage, message, handler, popupPosition, maxUsages, options);
                    }
                    cancel(popup);
                } else {
                    assert usages.size() > 1 : usages;
                    // usage view can filter usages down to one
                    Usage visibleUsage = visibleNodes.iterator().next().getUsage();
                    if (areAllUsagesInOneLine(visibleUsage, usages)) {
                        String hint = UsageViewBundle.message("all.usages.are.in.this.line", usages.size(), searchScopePresentableName(options));
                        navigateAndHint(visibleUsage, hint, handler, popupPosition, maxUsages, options);
                        cancel(popup);
                    }
                }
            } else {
                if (popup != null) {
                    String title = presentation.getTabText();
                    boolean shouldShowMoreSeparator = visibleNodes.contains(MORE_USAGES_SEPARATOR_NODE);
                    String fullTitle = getFullTitle(usages, title, shouldShowMoreSeparator, visibleNodes.size() - (shouldShowMoreSeparator ? 1 : 0), false);
                    ((AbstractPopup) popup).setCaption(fullTitle);
                }
            }
        }
    }, project.getDisposed()));
    if (popup != null) {
        Disposer.register(popup, indicator::cancel);
    }
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) AllIcons(com.intellij.icons.AllIcons) MessageType(com.intellij.openapi.ui.MessageType) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ColumnInfo(com.intellij.util.ui.ColumnInfo) FileEditorLocation(com.intellij.openapi.fileEditor.FileEditorLocation) TableCellRenderer(javax.swing.table.TableCellRenderer) ReadAction(com.intellij.openapi.application.ReadAction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AsyncProcessIcon(com.intellij.util.ui.AsyncProcessIcon) Disposer(com.intellij.openapi.util.Disposer) MouseAdapter(java.awt.event.MouseAdapter) FeatureUsageTracker(com.intellij.featureStatistics.FeatureUsageTracker) TextEditor(com.intellij.openapi.fileEditor.TextEditor) com.intellij.usages.impl(com.intellij.usages.impl) HintUtil(com.intellij.codeInsight.hint.HintUtil) FindManagerImpl(com.intellij.find.impl.FindManagerImpl) PreviewManager(com.intellij.openapi.preview.PreviewManager) PsiReference(com.intellij.psi.PsiReference) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) AbstractPopup(com.intellij.ui.popup.AbstractPopup) KeyEvent(java.awt.event.KeyEvent) FileEditor(com.intellij.openapi.fileEditor.FileEditor) KeymapUtil(com.intellij.openapi.keymap.KeymapUtil) com.intellij.ui(com.intellij.ui) HintUpdateSupply(com.intellij.ui.popup.HintUpdateSupply) FindManager(com.intellij.find.FindManager) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) XmlStringUtil(com.intellij.xml.util.XmlStringUtil) FindSettings(com.intellij.find.FindSettings) NotNull(org.jetbrains.annotations.NotNull) RelativePoint(com.intellij.ui.awt.RelativePoint) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) UsagesPreviewPanelProvider(com.intellij.find.UsagesPreviewPanelProvider) NonNls(org.jetbrains.annotations.NonNls) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UsageInfo(com.intellij.usageView.UsageInfo) SearchScope(com.intellij.psi.search.SearchScope) KeyAdapter(java.awt.event.KeyAdapter) AtomicReference(java.util.concurrent.atomic.AtomicReference) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) Comparing(com.intellij.openapi.util.Comparing) com.intellij.find.findUsages(com.intellij.find.findUsages) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) ListTableModel(com.intellij.util.ui.ListTableModel) DataManager(com.intellij.ide.DataManager) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) PlatformIcons(com.intellij.util.PlatformIcons) UsageFilteringRuleProvider(com.intellij.usages.rules.UsageFilteringRuleProvider) StringUtil(com.intellij.openapi.util.text.StringUtil) TableColumn(javax.swing.table.TableColumn) com.intellij.usages(com.intellij.usages) AsyncEditorLoader(com.intellij.openapi.fileEditor.impl.text.AsyncEditorLoader) ModelDiff(com.intellij.ide.util.gotoByName.ModelDiff) Editor(com.intellij.openapi.editor.Editor) PopupUtil(com.intellij.openapi.ui.popup.util.PopupUtil) JBPopup(com.intellij.openapi.ui.popup.JBPopup) UsageViewUtil(com.intellij.usageView.UsageViewUtil) MouseEvent(java.awt.event.MouseEvent) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) JBTable(com.intellij.ui.table.JBTable) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) Pair(com.intellij.openapi.util.Pair) TargetElementUtil(com.intellij.codeInsight.TargetElementUtil) UsageViewBundle(com.intellij.usageView.UsageViewBundle) Navigatable(com.intellij.pom.Navigatable) HintManager(com.intellij.codeInsight.hint.HintManager) TransactionGuard(com.intellij.openapi.application.TransactionGuard) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) JBPopup(com.intellij.openapi.ui.popup.JBPopup) UsageInfo(com.intellij.usageView.UsageInfo) AbstractPopup(com.intellij.ui.popup.AbstractPopup) AsyncProcessIcon(com.intellij.util.ui.AsyncProcessIcon) PsiReference(com.intellij.psi.PsiReference) FindManagerImpl(com.intellij.find.impl.FindManagerImpl) Project(com.intellij.openapi.project.Project) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Alarm(com.intellij.util.Alarm) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.

the class ShowUsagesAction method createUsagePopup.

@NotNull
private JBPopup createUsagePopup(@NotNull final List<Usage> usages, @NotNull Set<UsageNode> visibleNodes, @NotNull final FindUsagesHandler handler, final Editor editor, @NotNull final RelativePoint popupPosition, final int maxUsages, @NotNull final UsageViewImpl usageView, @NotNull final FindUsagesOptions options, @NotNull final JTable table, @NotNull final Runnable itemChoseCallback, @NotNull final UsageViewPresentation presentation, @NotNull final AsyncProcessIcon processIcon) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    PopupChooserBuilder builder = new PopupChooserBuilder(table);
    final String title = presentation.getTabText();
    if (title != null) {
        String result = getFullTitle(usages, title, false, visibleNodes.size() - 1, true);
        builder.setTitle(result);
        builder.setAdText(getSecondInvocationTitle(options, handler));
    }
    builder.setMovable(true).setResizable(true);
    builder.setMovable(true).setResizable(true);
    builder.setItemChoosenCallback(itemChoseCallback);
    final JBPopup[] popup = new JBPopup[1];
    KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
    if (shortcut != null) {
        new DumbAwareAction() {

            @Override
            public void actionPerformed(@NotNull AnActionEvent e) {
                cancel(popup[0]);
                showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
            }

            @Override
            public boolean startInTransaction() {
                return true;
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(shortcut.getFirstKeyStroke()), table);
    }
    shortcut = getShowUsagesShortcut();
    if (shortcut != null) {
        new DumbAwareAction() {

            @Override
            public void actionPerformed(@NotNull AnActionEvent e) {
                cancel(popup[0]);
                searchEverywhere(options, handler, editor, popupPosition, maxUsages);
            }

            @Override
            public boolean startInTransaction() {
                return true;
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(shortcut.getFirstKeyStroke()), table);
    }
    InplaceButton settingsButton = createSettingsButton(handler, popupPosition, editor, maxUsages, () -> cancel(popup[0]));
    ActiveComponent spinningProgress = new ActiveComponent.Adapter() {

        @Override
        public JComponent getComponent() {
            return processIcon;
        }
    };
    final DefaultActionGroup pinGroup = new DefaultActionGroup();
    final ActiveComponent pin = createPinButton(handler, usageView, options, popup, pinGroup);
    builder.setCommandButton(new CompositeActiveComponent(spinningProgress, settingsButton, pin));
    DefaultActionGroup toolbar = new DefaultActionGroup();
    usageView.addFilteringActions(toolbar);
    toolbar.add(UsageGroupingRuleProviderImpl.createGroupByFileStructureAction(usageView));
    ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.USAGE_VIEW_TOOLBAR, toolbar, true);
    actionToolbar.setReservePlaceAutoPopupIcon(false);
    final JComponent toolBar = actionToolbar.getComponent();
    toolBar.setOpaque(false);
    builder.setSettingButton(toolBar);
    builder.setCancelKeyEnabled(false);
    popup[0] = builder.createPopup();
    JComponent content = popup[0].getContent();
    myWidth = (int) (toolBar.getPreferredSize().getWidth() + new JLabel(getFullTitle(usages, title, false, visibleNodes.size() - 1, true)).getPreferredSize().getWidth() + settingsButton.getPreferredSize().getWidth());
    myWidth = -1;
    for (AnAction action : toolbar.getChildren(null)) {
        action.unregisterCustomShortcutSet(usageView.getComponent());
        action.registerCustomShortcutSet(action.getShortcutSet(), content);
    }
    for (AnAction action : pinGroup.getChildren(null)) {
        action.unregisterCustomShortcutSet(usageView.getComponent());
        action.registerCustomShortcutSet(action.getShortcutSet(), content);
    }
    return popup[0];
}
Also used : MouseAdapter(java.awt.event.MouseAdapter) KeyAdapter(java.awt.event.KeyAdapter) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JBPopup (com.intellij.openapi.ui.popup.JBPopup)76 Project (com.intellij.openapi.project.Project)21 NotNull (org.jetbrains.annotations.NotNull)20 RelativePoint (com.intellij.ui.awt.RelativePoint)19 JBList (com.intellij.ui.components.JBList)18 PopupChooserBuilder (com.intellij.openapi.ui.popup.PopupChooserBuilder)15 Editor (com.intellij.openapi.editor.Editor)13 PsiElement (com.intellij.psi.PsiElement)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Nullable (org.jetbrains.annotations.Nullable)8 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)7 Ref (com.intellij.openapi.util.Ref)7 DocumentationManager (com.intellij.codeInsight.documentation.DocumentationManager)6 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)6 AbstractPopup (com.intellij.ui.popup.AbstractPopup)6 ActionEvent (java.awt.event.ActionEvent)6 List (java.util.List)6 javax.swing (javax.swing)6 Disposable (com.intellij.openapi.Disposable)5 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)5