Example usage for com.intellij.openapi.ui.popup PopupChooserBuilder setSettingButton

List of usage examples for com.intellij.openapi.ui.popup PopupChooserBuilder setSettingButton

Introduction

In this page you can find the example usage for com.intellij.openapi.ui.popup PopupChooserBuilder setSettingButton.

Prototype

@Override
    public PopupChooserBuilder<T> setSettingButton(Component button) 

Source Link

Usage

From source file:com.antoine.ideaplugin.greenrobot.ShowUsagesAction.java

License:Apache License

@NotNull
private JBPopup createUsagePopup(@NotNull final List<Usage> usages,
        @NotNull final UsageInfoToUsageConverter.TargetElementsDescriptor descriptor,
        @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 UsageViewPresentation presentation, @NotNull final AsyncProcessIcon processIcon,
        boolean hadMoreSeparator) {
    table.setRowHeight(PlatformIcons.CLASS_ICON.getIconHeight() + 2);
    table.setShowGrid(false);//from   w w w  .  j  a  va2  s .  co m
    table.setShowVerticalLines(false);
    table.setShowHorizontalLines(false);
    table.setTableHeader(null);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    table.setIntercellSpacing(new Dimension(0, 0));

    PopupChooserBuilder builder = new PopupChooserBuilder(table);
    final String title = presentation.getTabText();
    if (title != null) {
        String result = getFullTitle(usages, title, hadMoreSeparator, visibleNodes.size() - 1, true);
        builder.setTitle(result);
        builder.setAdText(getSecondInvocationTitle(options, handler));
    }

    builder.setMovable(true).setResizable(true);
    builder.setItemChoosenCallback(new Runnable() {
        @Override
        public void run() {
            int[] selected = table.getSelectedRows();
            for (int i : selected) {
                Object value = table.getValueAt(i, 0);
                if (value instanceof UsageNode) {
                    Usage usage = ((UsageNode) value).getUsage();
                    if (usage == MORE_USAGES_SEPARATOR) {
                        appendMoreUsages(editor, popupPosition, handler, maxUsages);
                        return;
                    }
                    navigateAndHint(usage, null, handler, popupPosition, maxUsages, options);
                }
            }
        }
    });
    final JBPopup[] popup = new JBPopup[1];

    KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
    if (shortcut != null) {
        new DumbAwareAction() {
            @Override
            public void actionPerformed(AnActionEvent e) {
                popup[0].cancel();
                showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(shortcut.getFirstKeyStroke()), table);
    }
    shortcut = getShowUsagesShortcut();
    if (shortcut != null) {
        new DumbAwareAction() {
            @Override
            public void actionPerformed(AnActionEvent e) {
                popup[0].cancel();
                searchEverywhere(options, handler, editor, popupPosition, maxUsages);
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(shortcut.getFirstKeyStroke()), table);
    }

    InplaceButton settingsButton = createSettingsButton(handler, popupPosition, editor, maxUsages,
            new Runnable() {
                @Override
                public void run() {
                    popup[0].cancel();
                }
            });

    ActiveComponent spinningProgress = new ActiveComponent() {
        @Override
        public void setActive(boolean active) {
        }

        @Override
        public JComponent getComponent() {
            return processIcon;
        }
    };
    builder.setCommandButton(new CompositeActiveComponent(spinningProgress, settingsButton));

    DefaultActionGroup toolbar = new DefaultActionGroup();
    usageView.addFilteringActions(toolbar);

    toolbar.add(UsageGroupingRuleProviderImpl.createGroupByFileStructureAction(usageView));
    toolbar.add(new AnAction("Open Find Usages Toolwindow", "Show all usages in a separate toolwindow",
            AllIcons.Toolwindows.ToolWindowFind) {
        {
            AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_USAGES);
            setShortcutSet(action.getShortcutSet());
        }

        @Override
        public void actionPerformed(AnActionEvent e) {
            hideHints();
            popup[0].cancel();
            FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager
                    .getInstance(usageView.getProject())).getFindUsagesManager();

            findUsagesManager.findUsages(handler.getPrimaryElements(), handler.getSecondaryElements(), handler,
                    options, FindSettings.getInstance().isSkipResultsWithOneUsage());
        }
    });

    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);

    popup[0] = builder.createPopup();
    JComponent content = popup[0].getContent();

    myWidth = (int) (toolBar.getPreferredSize().getWidth()
            + new JLabel(getFullTitle(usages, title, hadMoreSeparator, 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);
    }

    return popup[0];
}

From source file:com.intellij.find.actions.ShowUsagesAction.java

License:Apache License

@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) {

    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);//from w  w w.  j a v  a 2s.co  m
        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);
                showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(shortcut.getFirstKeyStroke()), table);
    }
    shortcut = getShowUsagesShortcut();
    if (shortcut != null) {
        new DumbAwareAction() {
            @Override
            public void actionPerformed(@NotNull AnActionEvent e) {
                cancel(popup);
                searchEverywhere(options, handler, editor, popupPosition, maxUsages);
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(shortcut.getFirstKeyStroke()), table);
    }

    InplaceButton settingsButton = createSettingsButton(handler, popupPosition, editor, maxUsages,
            new Runnable() {
                @Override
                public void run() {
                    cancel(popup);
                }
            });

    ActiveComponent spinningProgress = new ActiveComponent() {
        @Override
        public void setActive(boolean active) {
        }

        @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);

    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];
}

From source file:com.squareup.ideaplugin.dagger.ShowUsagesAction.java

License:Apache License

@NotNull
private JBPopup createUsagePopup(@NotNull final List<Usage> usages,
        @NotNull final UsageInfoToUsageConverter.TargetElementsDescriptor descriptor,
        @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 UsageViewPresentation presentation, @NotNull final AsyncProcessIcon processIcon,
        boolean hadMoreSeparator) {
    table.setRowHeight(PlatformIcons.CLASS_ICON.getIconHeight() + 2);
    table.setShowGrid(false);//w ww  .j  a v a2  s  . co m
    table.setShowVerticalLines(false);
    table.setShowHorizontalLines(false);
    table.setTableHeader(null);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    table.setIntercellSpacing(new Dimension(0, 0));

    PopupChooserBuilder builder = new PopupChooserBuilder(table);
    final String title = presentation.getTabText();
    if (title != null) {
        String result = getFullTitle(usages, title, hadMoreSeparator, visibleNodes.size() - 1, true);
        builder.setTitle(result);
        builder.setAdText(getSecondInvocationTitle(options, handler));
    }

    builder.setMovable(true).setResizable(true);
    builder.setItemChoosenCallback(new Runnable() {
        @Override
        public void run() {
            int[] selected = table.getSelectedRows();
            for (int i : selected) {
                Object value = table.getValueAt(i, 0);
                if (value instanceof UsageNode) {
                    Usage usage = ((UsageNode) value).getUsage();
                    if (usage == MORE_USAGES_SEPARATOR) {
                        appendMoreUsages(editor, popupPosition, handler, maxUsages);
                        return;
                    }
                    navigateAndHint(usage, null, handler, popupPosition, maxUsages, options);
                }
            }
        }
    });
    final JBPopup[] popup = new JBPopup[1];

    KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
    if (shortcut != null) {
        new DumbAwareAction() {
            @Override
            public void actionPerformed(AnActionEvent e) {
                popup[0].cancel();
                showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(shortcut.getFirstKeyStroke()), table);
    }
    shortcut = getShowUsagesShortcut();
    if (shortcut != null) {
        new DumbAwareAction() {
            @Override
            public void actionPerformed(AnActionEvent e) {
                popup[0].cancel();
                searchEverywhere(options, handler, editor, popupPosition, maxUsages);
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(shortcut.getFirstKeyStroke()), table);
    }

    InplaceButton settingsButton = createSettingsButton(handler, popupPosition, editor, maxUsages,
            new Runnable() {
                @Override
                public void run() {
                    popup[0].cancel();
                }
            });

    ActiveComponent spinningProgress = new ActiveComponent() {
        @Override
        public void setActive(boolean active) {
        }

        @Override
        public JComponent getComponent() {
            return processIcon;
        }
    };
    builder.setCommandButton(new CompositeActiveComponent(spinningProgress, settingsButton));

    DefaultActionGroup toolbar = new DefaultActionGroup();
    usageView.addFilteringActions(toolbar);

    toolbar.add(UsageGroupingRuleProviderImpl.createGroupByFileStructureAction(usageView));
    toolbar.add(new AnAction("Open Find Usages Toolwindow", "Show all usages in a separate toolwindow",
            AllIcons.Toolwindows.ToolWindowFind) {
        {
            AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_USAGES);
            setShortcutSet(action.getShortcutSet());
        }

        @Override
        public void actionPerformed(AnActionEvent e) {
            hideHints();
            popup[0].cancel();
            FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager
                    .getInstance(usageView.getProject())).getFindUsagesManager();
            findUsagesManager.findUsages(handler.getPrimaryElements(), handler.getSecondaryElements(), handler,
                    options, true);
        }
    });

    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);

    popup[0] = builder.createPopup();
    JComponent content = popup[0].getContent();

    myWidth = (int) (toolBar.getPreferredSize().getWidth()
            + new JLabel(getFullTitle(usages, title, hadMoreSeparator, 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);
    }

    return popup[0];
}