Dialog similar to "Choose Main Class"

Hi,

I have made some progress in implementing my own run type (have it showing and created the basic UI I want..). What I would like to have now is a way to create a dialog similar to "Choose Main Class". This is what you get when you click on "..." in the create new run/debug Application configuration dialog. You also get a similar dialog with the test class/package choosers for JUnit run configurations, etc. I have my own button that I would like to trigger this dialog.

So as this type of a dialog seems to repeat often in the various run configurations, I am hoping to find a class that lets me just define a filter for the classes to display (they should contain specific annotations similar to @Test in JUnit) and has everything else out of the box. Where can I find this, and are there some examples of that?

I was looking at the JUnit plugin sources for examples. It seems to implement a filter of type ClassFilter.ClassFilterWithScope and extends a browser called ClassBrowser. But I am not sure how the dialog gets built. Maybe with the EditorTextFieldWithBrowseButton class but I get lost in browsing that code.

Any ideas?

Thanks,
Teemu

0
2 comments

See the TreeClassChooserFactory class.

0

Thanks. This seems to be what I was looking for.

However, I have a small problem. I am trying first to provide the user with a list of all subclasses of a given class (EndCondition). So I do this:

    TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(project);
    final Module module = moduleSelector.getModule();
    GlobalSearchScope scope = null;
    if (module != null) {
      scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
    } else {
      scope = GlobalSearchScope.allScope(project);
    }
    PsiClass ecClass = JavaPsiFacade.getInstance(project).findClass(EndCondition.class.getName(), scope);
    TreeClassChooser chooser = factory.createInheritanceClassChooser(title, scope, ecClass, null);
    chooser.showDialog();


Which displays the dialog I was asking about. It also correctly finds and displays all the subclasses of EndCondition. But then it also displays all classes with the same name even if not subclasses of EndCondition. For example:

Time (the.correct.package) //this should be there
Time (java.sql) //should not be there
Time in DateParser (some.long.package) //should not be there
Time in DateTimeParser (some.other.long.package) //should not be there


What might I be doing wrong?


Thanks,
Teemu
0

Please sign in to leave a comment.