use of com.intellij.openapi.ui.popup.PopupChooserBuilder in project intellij-community by JetBrains.
the class CreateFromUsageBaseFix method chooseTargetClass.
private void chooseTargetClass(List<PsiClass> classes, final Editor editor) {
final PsiClass firstClass = classes.get(0);
final Project project = firstClass.getProject();
final JList list = new JBList(classes);
PsiElementListCellRenderer renderer = new PsiClassListCellRenderer();
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setCellRenderer(renderer);
final PopupChooserBuilder builder = new PopupChooserBuilder(list);
renderer.installSpeedSearch(builder);
final PsiClass preselection = AnonymousTargetClassPreselectionUtil.getPreselection(classes, firstClass);
if (preselection != null) {
list.setSelectedValue(preselection, true);
}
Runnable runnable = () -> {
int index = list.getSelectedIndex();
if (index < 0)
return;
final PsiClass aClass = (PsiClass) list.getSelectedValue();
AnonymousTargetClassPreselectionUtil.rememberSelection(aClass, firstClass);
CommandProcessor.getInstance().executeCommand(project, () -> doInvoke(project, aClass), getText(), null);
};
builder.setTitle(QuickFixBundle.message("target.class.chooser.title")).setItemChoosenCallback(runnable).createPopup().showInBestPositionFor(editor);
}
use of com.intellij.openapi.ui.popup.PopupChooserBuilder in project intellij-community by JetBrains.
the class GroovyStaticImportMethodFix method chooseAndImport.
private void chooseAndImport(Editor editor) {
final JList list = new JBList(getCandidates().toArray(new PsiMethod[getCandidates().size()]));
list.setCellRenderer(new MethodCellRenderer(true));
new PopupChooserBuilder(list).setTitle(QuickFixBundle.message("static.import.method.choose.method.to.import")).setMovable(true).setItemChoosenCallback(() -> {
PsiMethod selectedValue = (PsiMethod) list.getSelectedValue();
if (selectedValue == null)
return;
LOG.assertTrue(selectedValue.isValid());
doImport(selectedValue);
}).createPopup().showInBestPositionFor(editor);
}
use of com.intellij.openapi.ui.popup.PopupChooserBuilder in project intellij-community by JetBrains.
the class GrCreateFromUsageBaseFix method chooseClass.
private void chooseClass(List<PsiClass> classes, Editor editor) {
final Project project = classes.get(0).getProject();
final JList list = new JBList(classes);
PsiElementListCellRenderer renderer = new PsiClassListCellRenderer();
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setCellRenderer(renderer);
final PopupChooserBuilder builder = new PopupChooserBuilder(list);
renderer.installSpeedSearch(builder);
Runnable runnable = () -> {
int index = list.getSelectedIndex();
if (index < 0)
return;
final PsiClass aClass = (PsiClass) list.getSelectedValue();
CommandProcessor.getInstance().executeCommand(project, () -> ApplicationManager.getApplication().runWriteAction(() -> invokeImpl(project, aClass)), getText(), null);
};
builder.setTitle(QuickFixBundle.message("target.class.chooser.title")).setItemChoosenCallback(runnable).createPopup().showInBestPositionFor(editor);
}
use of com.intellij.openapi.ui.popup.PopupChooserBuilder in project intellij-community by JetBrains.
the class ExternalProjectPathField method createPanel.
@NotNull
public static MyPathAndProjectButtonPanel createPanel(@NotNull final Project project, @NotNull final ProjectSystemId externalSystemId) {
final EditorTextField textField = createTextField(project, externalSystemId);
final FixedSizeButton selectRegisteredProjectButton = new FixedSizeButton();
selectRegisteredProjectButton.setIcon(AllIcons.Actions.Module);
String tooltipText = ExternalSystemBundle.message("run.configuration.tooltip.choose.registered.project", externalSystemId.getReadableName());
selectRegisteredProjectButton.setToolTipText(tooltipText);
selectRegisteredProjectButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final Ref<JBPopup> popupRef = new Ref<>();
final Tree tree = buildRegisteredProjectsTree(project, externalSystemId);
tree.setBorder(IdeBorderFactory.createEmptyBorder(8));
Runnable treeSelectionCallback = () -> {
TreePath path = tree.getSelectionPath();
if (path != null) {
Object lastPathComponent = path.getLastPathComponent();
if (lastPathComponent instanceof ExternalSystemNode) {
Object e1 = ((ExternalSystemNode) lastPathComponent).getDescriptor().getElement();
if (e1 instanceof ExternalProjectPojo) {
ExternalProjectPojo pojo = (ExternalProjectPojo) e1;
textField.setText(pojo.getPath());
Editor editor = textField.getEditor();
if (editor != null) {
collapseIfPossible(editor, externalSystemId, project);
}
}
}
}
popupRef.get().closeOk(null);
};
JBPopup popup = new PopupChooserBuilder(tree).setTitle(ExternalSystemBundle.message("run.configuration.title.choose.registered.project", externalSystemId.getReadableName())).setResizable(true).setItemChoosenCallback(treeSelectionCallback).setAutoselectOnMouseMove(true).setCloseOnEnter(false).createPopup();
popupRef.set(popup);
popup.showUnderneathOf(selectRegisteredProjectButton);
}
});
return new MyPathAndProjectButtonPanel(textField, selectRegisteredProjectButton);
}
use of com.intellij.openapi.ui.popup.PopupChooserBuilder in project intellij-community by JetBrains.
the class ImplementAbstractMethodHandler method invoke.
public void invoke() {
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
final PsiElement[][] result = new PsiElement[1][];
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> ApplicationManager.getApplication().runReadAction(() -> {
final PsiClass psiClass = myMethod.getContainingClass();
if (!psiClass.isValid())
return;
if (!psiClass.isEnum()) {
result[0] = getClassImplementations(psiClass);
} else {
final List<PsiElement> enumConstants = new ArrayList<>();
for (PsiField field : psiClass.getFields()) {
if (field instanceof PsiEnumConstant) {
final PsiEnumConstantInitializer initializingClass = ((PsiEnumConstant) field).getInitializingClass();
if (initializingClass != null) {
PsiMethod method = initializingClass.findMethodBySignature(myMethod, true);
if (method == null || !method.getContainingClass().equals(initializingClass)) {
enumConstants.add(initializingClass);
}
} else {
enumConstants.add(field);
}
}
}
result[0] = PsiUtilCore.toPsiElementArray(enumConstants);
}
}), CodeInsightBundle.message("intention.implement.abstract.method.searching.for.descendants.progress"), true, myProject);
if (result[0] == null)
return;
if (result[0].length == 0) {
Messages.showMessageDialog(myProject, CodeInsightBundle.message("intention.implement.abstract.method.error.no.classes.message"), CodeInsightBundle.message("intention.implement.abstract.method.error.no.classes.title"), Messages.getInformationIcon());
return;
}
if (result[0].length == 1) {
implementInClass(new Object[] { result[0][0] });
return;
}
final MyPsiElementListCellRenderer elementListCellRenderer = new MyPsiElementListCellRenderer();
elementListCellRenderer.sort(result[0]);
myList = new JBList(result[0]);
myList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
final Runnable runnable = () -> {
int index = myList.getSelectedIndex();
if (index < 0)
return;
implementInClass(myList.getSelectedValues());
};
myList.setCellRenderer(elementListCellRenderer);
final PopupChooserBuilder builder = new PopupChooserBuilder(myList);
elementListCellRenderer.installSpeedSearch(builder);
builder.setTitle(CodeInsightBundle.message("intention.implement.abstract.method.class.chooser.title")).setItemChoosenCallback(runnable).createPopup().showInBestPositionFor(myEditor);
}
Aggregations