ProjectConfigurable and Template Project Settings

I've registered PomSorterConfigurable as

    <extensions defaultExtensionNs="com.intellij">
        <projectConfigurable instance="pl.itcrowd.pom_sorter.PomSorterConfigurable"/>

It works nice when project is loaded and I enter settings. But when I close project and enter settings then I'm getting NPE, because project component that should be passed to form is missing from the fake project:

    public JComponent createComponent()
        settingsForm = new SettingsForm(project.getComponent(PomSorter.class));
        return settingsForm.$$$getRootComponent$$$();

For now I'd like the PomSorter tab in project settings to be visible only when there is any project open.
I've achieved this by removing <projectConfigurable/> from <extensions/> and making PomSorterConfigurable implement ProjectComponent.

How should I proceed if I'd like to show PomSorter tab in template project settings?

The settings are kept in PomSorter, which is main project component. It implements PersistentStateComponent<PomSorter.State> and is annotated like this:

    name = PomSorter.COMPONENT_NAME,
    storages = {@Storage(
        file = "$PROJECT_FILE$")})
1 comment
Comment actions Permalink

The recommended approach is to convert your project component to a service - then it will be instantiated on demand whenever it is requested, including the default project. Alternatively, if you must have a component, you can add the <loadForDefaultProject/> tag to its registration in plugin.xml - you can find plenty of examples in the CE sources.


Please sign in to leave a comment.