List of usage examples for com.intellij.openapi.ui.popup PopupChooserBuilder setCommandButton
public PopupChooserBuilder<T> setCommandButton(@NotNull ActiveComponent commandButton)
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);// w w w . j a v a 2 s. c o 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);//ww w. j a v a 2 s .c om 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.intellij.ui.popup.util.MasterDetailPopupBuilder.java
License:Apache License
public JBPopup createMasterDetailPopup() { setupRenderer();//from w w w .j a va2s . c o m myPathLabel = new JLabel(" "); myPathLabel.setHorizontalAlignment(SwingConstants.RIGHT); final Font font = myPathLabel.getFont(); myPathLabel.setFont(font.deriveFont((float) 10)); if (myDetailView == null) { myDetailView = new DetailViewImpl(myProject); } JPanel footerPanel = new JPanel(new BorderLayout()) { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(BORDER_COLOR); g.drawLine(0, 0, getWidth(), 0); } }; Runnable runnable = new Runnable() { @Override public void run() { IdeFocusManager.getInstance(myProject).doWhenFocusSettlesDown(new Runnable() { @Override public void run() { Object[] values = getSelectedItems(); if (values.length == 1) { myDelegate.itemChosen((ItemWrapper) values[0], myProject, myPopup, false); } else { for (Object value : values) { if (value instanceof ItemWrapper) { myDelegate.itemChosen((ItemWrapper) value, myProject, myPopup, false); } } } } }); } }; footerPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); footerPanel.add(myPathLabel); JComponent toolBar = null; if (myActions != null) { myActionToolbar = ActionManager.getInstance().createActionToolbar("", myActions, true); myActionToolbar.setReservePlaceAutoPopupIcon(false); myActionToolbar.setMinimumButtonSize(new Dimension(20, 20)); toolBar = myActionToolbar.getComponent(); toolBar.setOpaque(false); } final PopupChooserBuilder builder = createInnerBuilder().setMovable(true).setResizable(true) .setAutoselectOnMouseMove(false).setSettingButton(toolBar).setSouthComponent(footerPanel) .setCancelOnWindowDeactivation(myCancelOnWindowDeactivation) .setCancelOnClickOutside(myCancelOnClickOutside) .setUseDimensionServiceForXYLocation(myUseDimensionServiceForXYLocation); if (myDoneRunnable != null) { ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent event) { myDoneRunnable.run(); } }; //native button is pretty enough if ((SystemInfo.isMacOSLion || SystemInfo.isMacOSMountainLion) && !UIUtil.isUnderDarcula()) { final JButton done = new JButton("Done"); done.setMnemonic('o'); done.addActionListener(actionListener); builder.setCommandButton(new ActiveComponent() { @Override public void setActive(boolean active) { } @Override public JComponent getComponent() { return done; } }); } else { builder.setCommandButton(new InplaceButton( new IconButton("Close", AllIcons.Actions.CloseNew, AllIcons.Actions.CloseNewHovered), actionListener)); } } String title = myDelegate.getTitle(); if (title != null) { builder.setTitle(title); } builder.setItemChoosenCallback(runnable).setCloseOnEnter(myCloseOnEnter).setMayBeParent(true) .setDimensionServiceKey(myDimensionServiceKey).setFilteringEnabled(new Function<Object, String>() { @Override public String fun(Object o) { return ((ItemWrapper) o).speedSearchText(); } }); if (myMinSize != null) { builder.setMinSize(myMinSize); } myPopup = builder.createPopup(); builder.getScrollPane().setBorder(IdeBorderFactory.createBorder(SideBorder.RIGHT)); myPopup.addListener(new JBPopupListener() { @Override public void beforeShown(LightweightWindowEvent event) { } @Override public void onClosed(LightweightWindowEvent event) { myDetailView.clearEditor(); } }); if (myDoneRunnable != null) { new AnAction("Done") { @Override public void actionPerformed(AnActionEvent e) { myDoneRunnable.run(); } }.registerCustomShortcutSet(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK, myPopup.getContent()); } return myPopup; }
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);/*from w w w. java 2 s . c om*/ 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]; }