Show classes from a package in a dialog box Follow
Iam writing a plugin. I want to show all the classes of a package in a dialog box so that user can select a class, how can i do this.
I tried TreeClassChooser , it is showing all the claases in project. Can anyone pls help.
Please sign in to leave a comment.
psiPackage = JavaPsiFacade.getInstance(project).findPackage()
psiPackage.getClasses()
This would get you the list of classes; e.g. com.intellij.ide.util.PsiElementListCellRenderer could be used as renderer.
Anna
Thanks for your reply, i tried it and iam able to show the classes using following lines
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
builder.
setTitle("Select Class").
setModalContext(true).
setItemChoosenCallback(runnable).
createPopup().
showInBestPositionFor(editor);
}
});
But having another issue now, the control goes back to the calling method even before i select the class, i want to select the class first and then then the control has to go back to calling method, how can i do this
Can you pls help
Sure, you don't have selected class before you show popup.
The call is not blocking so you need to perform everything which relys on selectedin inside your "runnable"
Sorry I didnot get you. I have written the code for what should happen once the class is selected inside setItemChoosenCallback(runnable), but the contol goes back to the main method before this is executed, and when i select the class, the statements get executed and nothing happens..
Everything depending on selection should be in the callback. Controlflow would return back immediately exactly as you described. You may find a lot of examples of such code in our code base, just search for popup creation and you'll get them!
Hi,
I tried different ways, still dint get what i want, is it related to ModalityState. What ModalityStae should i specify