Search in sources :

Example 11 with PopupChooserBuilder

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

the class ExecutionHelper method selectContentDescriptor.

public static void selectContentDescriptor(@NotNull final DataContext dataContext, @NotNull final Project project, @NotNull Collection<RunContentDescriptor> consoles, String selectDialogTitle, final Consumer<RunContentDescriptor> descriptorConsumer) {
    if (consoles.size() == 1) {
        RunContentDescriptor descriptor = consoles.iterator().next();
        descriptorConsumer.consume(descriptor);
        descriptorToFront(project, descriptor);
    } else if (consoles.size() > 1) {
        final JList list = new JBList(consoles);
        final Icon icon = DefaultRunExecutor.getRunExecutorInstance().getIcon();
        list.setCellRenderer(new ListCellRendererWrapper<RunContentDescriptor>() {

            @Override
            public void customize(final JList list, final RunContentDescriptor value, final int index, final boolean selected, final boolean hasFocus) {
                setText(value.getDisplayName());
                setIcon(icon);
            }
        });
        final PopupChooserBuilder builder = new PopupChooserBuilder(list);
        builder.setTitle(selectDialogTitle);
        builder.setItemChoosenCallback(() -> {
            final Object selectedValue = list.getSelectedValue();
            if (selectedValue instanceof RunContentDescriptor) {
                RunContentDescriptor descriptor = (RunContentDescriptor) selectedValue;
                descriptorConsumer.consume(descriptor);
                descriptorToFront(project, descriptor);
            }
        }).createPopup().showInBestPositionFor(dataContext);
    }
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper) JBList(com.intellij.ui.components.JBList) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder)

Example 12 with PopupChooserBuilder

use of com.intellij.openapi.ui.popup.PopupChooserBuilder in project intellij-plugins by JetBrains.

the class JstdAssertionFrameworkLineMarkerProvider method showPopup.

private static void showPopup(@NotNull MouseEvent e, @NotNull final PsiElement psiElement, final String displayName) {
    final JBList list = new JBList(getAvailableTypes());
    list.setCellRenderer(new ListCellRendererWrapper<Type>() {

        @Override
        public void customize(JList list, Type value, int index, boolean selected, boolean hasFocus) {
            setIcon(value.getIcon());
            setText(value.getTitle(displayName));
        }
    });
    PopupChooserBuilder builder = new PopupChooserBuilder(list);
    JBPopup popup = builder.setMovable(true).setItemChoosenCallback(() -> {
        int[] ids = list.getSelectedIndices();
        if (ids.length == 0)
            return;
        Type type = ObjectUtils.tryCast(list.getSelectedValue(), Type.class);
        if (type != null) {
            if (psiElement.isValid()) {
                execute(type.getExecutor(), psiElement);
            }
        }
    }).createPopup();
    popup.show(new RelativePoint(e));
}
Also used : JBList(com.intellij.ui.components.JBList) RelativePoint(com.intellij.ui.awt.RelativePoint) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 13 with PopupChooserBuilder

use of com.intellij.openapi.ui.popup.PopupChooserBuilder in project android by JetBrains.

the class AndroidAddLibraryDependencyAction method invoke.

@Override
public void invoke(@NotNull final Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    final GradleBuildModel buildModel = getGradleBuildModel(project, file);
    if (buildModel == null) {
        return;
    }
    ImmutableCollection<String> dependencies = findAllDependencies(buildModel);
    if (dependencies.isEmpty()) {
        return;
    }
    final JList list = new JBList(dependencies);
    JBPopup popup = new PopupChooserBuilder(list).setItemChoosenCallback(new Runnable() {

        @Override
        public void run() {
            for (Object selectedValue : list.getSelectedValues()) {
                if (selectedValue == null) {
                    return;
                }
                addDependency(project, buildModel, (String) selectedValue);
            }
        }
    }).createPopup();
    popup.showInBestPositionFor(editor);
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) JBList(com.intellij.ui.components.JBList) JBPopup(com.intellij.openapi.ui.popup.JBPopup) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder)

Example 14 with PopupChooserBuilder

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

the class CompareWithSelectedRevisionAction method showListPopup.

public static void showListPopup(final List<VcsFileRevision> revisions, final Project project, final Consumer<VcsFileRevision> selectedRevisionConsumer, final boolean showComments) {
    ColumnInfo[] columns = new ColumnInfo[] { REVISION_TABLE_COLUMN, DATE_TABLE_COLUMN, AUTHOR_TABLE_COLUMN };
    for (VcsFileRevision revision : revisions) {
        if (revision.getBranchName() != null) {
            columns = new ColumnInfo[] { REVISION_TABLE_COLUMN, BRANCH_TABLE_COLUMN, DATE_TABLE_COLUMN, AUTHOR_TABLE_COLUMN };
            break;
        }
    }
    final TableView<VcsFileRevision> table = new TableView<>(new ListTableModel<>(columns, revisions, 0));
    table.setShowHorizontalLines(false);
    table.setTableHeader(null);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            VcsFileRevision revision = table.getSelectedObject();
            if (revision != null) {
                selectedRevisionConsumer.consume(revision);
            }
        }
    };
    if (table.getModel().getRowCount() == 0) {
        table.clearSelection();
    }
    new SpeedSearchBase<TableView>(table) {

        @Override
        protected int getSelectedIndex() {
            return table.getSelectedRow();
        }

        @Override
        protected int convertIndexToModel(int viewIndex) {
            return table.convertRowIndexToModel(viewIndex);
        }

        @Override
        protected Object[] getAllElements() {
            return revisions.toArray();
        }

        @Override
        protected String getElementText(Object element) {
            VcsFileRevision revision = (VcsFileRevision) element;
            return revision.getRevisionNumber().asString() + " " + revision.getBranchName() + " " + revision.getAuthor();
        }

        @Override
        protected void selectElement(Object element, String selectedText) {
            VcsFileRevision revision = (VcsFileRevision) element;
            TableUtil.selectRows(myComponent, new int[] { myComponent.convertRowIndexToView(revisions.indexOf(revision)) });
            TableUtil.scrollSelectionToVisible(myComponent);
        }
    };
    table.setMinimumSize(new Dimension(300, 50));
    final PopupChooserBuilder builder = new PopupChooserBuilder(table);
    if (showComments) {
        builder.setSouthComponent(createCommentsPanel(table));
    }
    builder.setTitle(VcsBundle.message("lookup.title.vcs.file.revisions")).setItemChoosenCallback(runnable).setResizable(true).setDimensionServiceKey("Vcs.CompareWithSelectedRevision.Popup").setMinSize(new Dimension(300, 300));
    final JBPopup popup = builder.createPopup();
    popup.showCenteredInCurrentWindow(project);
}
Also used : ColumnInfo(com.intellij.util.ui.ColumnInfo) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup) TreeTableView(com.intellij.ui.dualView.TreeTableView) TableView(com.intellij.ui.table.TableView)

Example 15 with PopupChooserBuilder

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

the class CompareWithSelectedRevisionAction method showTreePopup.

private static void showTreePopup(final List<TreeItem<VcsFileRevision>> roots, final VirtualFile file, final Project project, final DiffProvider diffProvider) {
    final TreeTableView treeTable = new TreeTableView(new ListTreeTableModelOnColumns(new TreeNodeAdapter(null, null, roots), new ColumnInfo[] { BRANCH_COLUMN, REVISION_COLUMN, DATE_COLUMN, AUTHOR_COLUMN }));
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            int index = treeTable.getSelectionModel().getMinSelectionIndex();
            if (index == -1) {
                return;
            }
            VcsFileRevision revision = getRevisionAt(treeTable, index);
            if (revision != null) {
                DiffActionExecutor.showDiff(diffProvider, revision.getRevisionNumber(), file, project, VcsBackgroundableActions.COMPARE_WITH);
            }
        }
    };
    treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    new PopupChooserBuilder(treeTable).setTitle(VcsBundle.message("lookup.title.vcs.file.revisions")).setItemChoosenCallback(runnable).setSouthComponent(createCommentsPanel(treeTable)).setResizable(true).setDimensionServiceKey("Vcs.CompareWithSelectedRevision.Popup").createPopup().showCenteredInCurrentWindow(project);
    final int lastRow = treeTable.getRowCount() - 1;
    if (lastRow < 0)
        return;
    treeTable.getSelectionModel().addSelectionInterval(lastRow, lastRow);
    treeTable.scrollRectToVisible(treeTable.getCellRect(lastRow, 0, true));
}
Also used : ListTreeTableModelOnColumns(com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns) ColumnInfo(com.intellij.util.ui.ColumnInfo) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) TreeTableView(com.intellij.ui.dualView.TreeTableView)

Aggregations

PopupChooserBuilder (com.intellij.openapi.ui.popup.PopupChooserBuilder)31 JBList (com.intellij.ui.components.JBList)24 JBPopup (com.intellij.openapi.ui.popup.JBPopup)15 PsiElementListCellRenderer (com.intellij.ide.util.PsiElementListCellRenderer)5 Project (com.intellij.openapi.project.Project)4 Ref (com.intellij.openapi.util.Ref)4 RelativePoint (com.intellij.ui.awt.RelativePoint)4 NotNull (org.jetbrains.annotations.NotNull)4 MethodCellRenderer (com.intellij.ide.util.MethodCellRenderer)3 PsiClassListCellRenderer (com.intellij.ide.util.PsiClassListCellRenderer)3 PsiElement (com.intellij.psi.PsiElement)3 JBLabel (com.intellij.ui.components.JBLabel)3 Editor (com.intellij.openapi.editor.Editor)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ColoredListCellRenderer (com.intellij.ui.ColoredListCellRenderer)2 TreeTableView (com.intellij.ui.dualView.TreeTableView)2 UsageView (com.intellij.usages.UsageView)2 Alarm (com.intellij.util.Alarm)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 ColumnInfo (com.intellij.util.ui.ColumnInfo)2