Example usage for com.intellij.openapi.ui.popup ListPopup show

List of usage examples for com.intellij.openapi.ui.popup ListPopup show

Introduction

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

Prototype

void show(@NotNull RelativePoint point);

Source Link

Document

Shows the popup at the specified point.

Usage

From source file:com.intellij.debugger.actions.JvmSmartStepIntoHandler.java

License:Apache License

/**
 * Override this if you haven't PsiMethod, like in Kotlin.
 *
 * @param position/* w w w .j  av  a 2  s. com*/
 * @param session
 * @param fileEditor
 * @return false to continue for another handler or for default action (step into)
 */
public boolean doSmartStep(SourcePosition position, final DebuggerSession session, TextEditor fileEditor) {
    final List<SmartStepTarget> targets = findSmartStepTargets(position);
    if (!targets.isEmpty()) {
        final SmartStepTarget firstTarget = targets.get(0);
        if (targets.size() == 1) {
            session.stepInto(true, createMethodFilter(firstTarget));
        } else {
            final Editor editor = fileEditor.getEditor();
            final PsiMethodListPopupStep popupStep = new PsiMethodListPopupStep(editor, targets,
                    new PsiMethodListPopupStep.OnChooseRunnable() {
                        public void execute(SmartStepTarget chosenTarget) {
                            session.stepInto(true, createMethodFilter(chosenTarget));
                        }
                    });
            final ListPopup popup = new ListPopupImpl(popupStep) {
                @Override
                protected JComponent createContent() {
                    registerExtraHandleShortcuts(XDebuggerActions.STEP_INTO);
                    registerExtraHandleShortcuts(XDebuggerActions.SMART_STEP_INTO);
                    return super.createContent();
                }

                private void registerExtraHandleShortcuts(String actionName) {
                    AnAction action = ActionManager.getInstance().getAction(actionName);
                    KeyStroke stroke = KeymapUtil.getKeyStroke(action.getShortcutSet());
                    if (stroke != null) {
                        registerAction("handleSelection " + stroke, stroke, new AbstractAction() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                handleSelect(true);
                            }
                        });
                    }
                }
            };
            popup.addListSelectionListener(new ListSelectionListener() {
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    popupStep.getScopeHighlighter().dropHighlight();
                    if (!e.getValueIsAdjusting()) {
                        final SmartStepTarget selectedTarget = (SmartStepTarget) ((JBList) e.getSource())
                                .getSelectedValue();
                        if (selectedTarget != null) {
                            highlightTarget(popupStep, selectedTarget);
                        }
                    }
                }
            });
            highlightTarget(popupStep, firstTarget);
            final RelativePoint point = DebuggerUIUtil.calcPopupLocation(editor, position.getLine());
            popup.show(point);
        }
        return true;
    }
    return false;
}

From source file:com.intellij.execution.actions.BaseRunConfigurationAction.java

License:Apache License

@Override
public void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final ConfigurationContext context = ConfigurationContext.getFromContext(dataContext);
    final RunnerAndConfigurationSettings existing = context.findExisting();
    if (existing == null) {
        final List<ConfigurationFromContext> producers = getConfigurationsFromContext(context);
        if (producers.isEmpty())
            return;
        if (producers.size() > 1) {
            final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
            Collections.sort(producers, ConfigurationFromContext.NAME_COMPARATOR);
            final ListPopup popup = JBPopupFactory.getInstance()
                    .createListPopup(new BaseListPopupStep<ConfigurationFromContext>(
                            ExecutionBundle.message("configuration.action.chooser.title"), producers) {
                        @Override
                        @NotNull/*  w ww. j a  v a2s  .c om*/
                        public String getTextFor(final ConfigurationFromContext producer) {
                            return producer.getConfigurationType().getDisplayName();
                        }

                        @Override
                        public Icon getIconFor(final ConfigurationFromContext producer) {
                            return producer.getConfigurationType().getIcon();
                        }

                        @Override
                        public PopupStep onChosen(final ConfigurationFromContext producer,
                                final boolean finalChoice) {
                            perform(producer, context);
                            return FINAL_CHOICE;
                        }
                    });
            final InputEvent event = e.getInputEvent();
            if (event instanceof MouseEvent) {
                popup.show(new RelativePoint((MouseEvent) event));
            } else if (editor != null) {
                popup.showInBestPositionFor(editor);
            } else {
                popup.showInBestPositionFor(dataContext);
            }
        } else {
            perform(producers.get(0), context);
        }
        return;
    }

    perform(context);
}

From source file:com.intellij.execution.impl.BeforeRunStepsPanel.java

License:Apache License

void doAddAction(AnActionButton button) {
    if (isUnknown()) {
        return;//from   w w  w  .  j a va  2s  .com
    }

    final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
    final BeforeRunTaskProvider<BeforeRunTask>[] providers = Extensions
            .getExtensions(BeforeRunTaskProvider.EXTENSION_POINT_NAME, myRunConfiguration.getProject());
    Set<Key> activeProviderKeys = getActiveProviderKeys();

    DefaultActionGroup actionGroup = new DefaultActionGroup(null, false);
    for (final BeforeRunTaskProvider<BeforeRunTask> provider : providers) {
        if (provider.createTask(myRunConfiguration) == null)
            continue;
        if (activeProviderKeys.contains(provider.getId()) && provider.isSingleton())
            continue;
        AnAction providerAction = new AnAction(provider.getName(), null, provider.getIcon()) {
            @Override
            public void actionPerformed(AnActionEvent e) {
                BeforeRunTask task = provider.createTask(myRunConfiguration);
                if (task != null) {
                    provider.configureTask(myRunConfiguration, task);
                    if (!provider.canExecuteTask(myRunConfiguration, task))
                        return;
                } else {
                    return;
                }
                task.setEnabled(true);

                Set<RunConfiguration> configurationSet = new HashSet<RunConfiguration>();
                getAllRunBeforeRuns(task, configurationSet);
                if (configurationSet.contains(myRunConfiguration)) {
                    JOptionPane.showMessageDialog(BeforeRunStepsPanel.this,
                            ExecutionBundle.message("before.launch.panel.cyclic_dependency_warning",
                                    myRunConfiguration.getName(), provider.getDescription(task)),
                            ExecutionBundle.message("warning.common.title"), JOptionPane.WARNING_MESSAGE);
                    return;
                }
                addTask(task);
                myListener.fireStepsBeforeRunChanged();
            }
        };
        actionGroup.add(providerAction);
    }
    final ListPopup popup = popupFactory.createActionGroupPopup(
            ExecutionBundle.message("add.new.run.configuration.acrtion.name"), actionGroup,
            SimpleDataContext.getProjectContext(myRunConfiguration.getProject()), false, false, false, null, -1,
            Condition.TRUE);
    popup.show(button.getPreferredPopupPoint());
}

From source file:com.intellij.ide.actions.ShowFilePathAction.java

License:Apache License

public static void show(final VirtualFile file, final MouseEvent e) {
    show(file, new ShowAction() {
        @Override/*  w  ww .  j a v a  2  s. c om*/
        public void show(final ListPopup popup) {
            if (e.getComponent().isShowing()) {
                popup.show(new RelativePoint(e));
            }
        }
    });
}

From source file:com.intellij.uiDesigner.actions.SurroundPopupAction.java

License:Apache License

protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection,
        final AnActionEvent e) {
    final ListPopup groupPopup = JBPopupFactory.getInstance().createActionGroupPopup(
            UIDesignerBundle.message("surround.with.popup.title"), myActionGroup, e.getDataContext(),
            JBPopupFactory.ActionSelectionAid.ALPHA_NUMBERING, true);

    final JComponent component = (JComponent) e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
    if (component instanceof ComponentTree) {
        groupPopup.show(JBPopupFactory.getInstance().guessBestPopupLocation(component));
    } else {/*  w  w w  .  j  av a  2 s . c  om*/
        RadComponent selComponent = selection.get(0);
        FormEditingUtil.showPopupUnderComponent(groupPopup, selComponent);
    }
}

From source file:consulo.restclient.actions.HistoryAction.java

License:Apache License

@RequiredDispatchThread
@Override// ww  w  .  ja  v  a 2 s  . co m
public void actionPerformed(@NotNull AnActionEvent e) {
    final Project project = e.getProject();

    DefaultActionGroup actionGroup = new DefaultActionGroup();

    RestClientHistoryManager clientHistoryManager = RestClientHistoryManager.getInstance(e.getProject());

    final RequestBean requestBean = clientHistoryManager.getRequests().get(RestClientHistoryManager.LAST);

    for (final Map.Entry<String, RequestBean> entry : RestClientHistoryManager.getInstance(e.getProject())
            .getRequests().entrySet()) {
        if (entry.getValue() == requestBean) {
            continue;
        }

        AnAction anAction = new AnAction(entry.getKey()) {
            @RequiredDispatchThread
            @Override
            public void actionPerformed(@NotNull AnActionEvent anActionEvent) {

                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        RestClientPanel.getInstance(project).setRequestBean(entry.getValue());
                    }
                });
            }
        };
        actionGroup.add(anAction);
    }

    if (requestBean != null) {
        AnAction anAction = new AnAction(RestClientHistoryManager.LAST) {
            @RequiredDispatchThread
            @Override
            public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        RestClientPanel.getInstance(project).setRequestBean(requestBean);
                    }
                });
            }
        };
        actionGroup.add(anAction);
    }

    DataContext dataContext = e.getDataContext();
    ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, actionGroup, dataContext,
            JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false);

    if (e.getInputEvent() instanceof MouseEvent) {
        popup.show(new RelativePoint((MouseEvent) e.getInputEvent()));
    } else {

        popup.showInBestPositionFor(e.getDataContext());
    }
}

From source file:krasa.cpu.CpuUsagePanel.java

License:Apache License

public CpuUsagePanel(Project project) {
    refreshColors();//from   ww w. j av a 2 s.  c  o m
    this.myProject = project;
    this.projectName = project.getName();

    setOpaque(false);
    setFocusable(false);
    setToolTipText("IDE CPU usage / System CPU usage");

    setBorder(StatusBarWidget.WidgetBorder.INSTANCE);
    updateUI();

    new UiNotifyConnector(this, new Activatable() {

        @Override
        public void showNotify() {
            CpuUsageManager.register(CpuUsagePanel.this);
        }

        @Override
        public void hideNotify() {
            CpuUsageManager.unregister(CpuUsagePanel.this);
        }
    });
    MouseAdapter mouseAdapter = new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isLeftMouseButton(e)) {
                CpuUsageManager.update();
                final DataContext context = DataManager.getInstance().getDataContext(CpuUsagePanel.this);
                ActionManager.getInstance().getAction("TakeThreadDump").actionPerformed(new AnActionEvent(e,
                        context, ActionPlaces.UNKNOWN, new Presentation(""), ActionManager.getInstance(), 0));
            } else if (SwingUtilities.isRightMouseButton(e)) {
                final DataContext context = DataManager.getInstance().getDataContext(CpuUsagePanel.this);
                ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, getActionGroup(),
                        context, JBPopupFactory.ActionSelectionAid.MNEMONICS, false);

                Dimension dimension = popup.getContent().getPreferredSize();
                Point at = new Point(0, -dimension.height);
                popup.show(new RelativePoint(e.getComponent(), at));
            }
        }
    };
    addMouseListener(mouseAdapter);
}

From source file:net.groboclown.idea.p4ic.ui.P4MultipleConnectionWidget.java

License:Apache License

private void showPopup(@NotNull MouseEvent event) {
    // it isn't getting bubbled up to the parent
    DataContext dataContext = getContext();
    final ListPopup popup = createListPopup(dataContext);
    if (popup.isVisible()) {
        popup.cancel();//from   w ww .j a va 2  s .c  o m
        return;
    }
    final Dimension dimension = popup.getContent().getPreferredSize();
    final Point at = new Point(0, -dimension.height);
    popup.show(new RelativePoint(event.getComponent(), at));
    Disposer.register(this, popup); // destroy popup on unexpected project close
}

From source file:org.community.intellij.plugins.communitycase.history.wholeTree.BasePopupAction.java

License:Apache License

protected void doAction(MouseEvent e) {
    final DefaultActionGroup group = createActionGroup();
    final DataContext parent = DataManager.getInstance().getDataContext((Component) myPanel.getParent());
    final DataContext dataContext = SimpleDataContext.getSimpleContext(PlatformDataKeys.PROJECT.getName(),
            myProject, parent);// ww  w . java2s.co  m
    final ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, group, dataContext,
            JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true, new Runnable() {
                @Override
                public void run() {
                    // todo ?
                }
            }, 20);
    if (e != null) {
        popup.show(new RelativePoint(e));
    } else {
        final Dimension dimension = popup.getContent().getPreferredSize();
        final Point at = new Point(-dimension.width / 2, -dimension.height);
        popup.show(new RelativePoint(myLabel, at));
    }
}

From source file:org.intellij.xquery.runner.ui.datasources.DataSourceTypesListPopupGuiTest.java

License:Apache License

@Override
protected PanelTestingFrame getPanelTestingFrame() {
    executor = mock(XQueryDataSourceTypeBasedActionExecutor.class);
    popup = new DataSourceTypesListPopup(executor);
    final ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(popup);

    mainPanel = (JPanel) listPopup.getContent();
    listPopup.show((Component) null);
    return new PanelTestingFrame(mainPanel);
}