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