How can default ModuleRunConfiguration values be set in a SettingsEditor?

I've successfully created my own ModuleRunConfiguration/ConfigurationType. It works very well, and is configurable via a SettingsEditor. The only trouble I am having is figuring out how to get some default values placed into the SettingsEditor when a brand new Run Configuration of my new type is created. I figured IntelliJ would use the instance returned by ConfigurationFactory#createTemplateConfiguration, so I set defaults in my ModuleRunConfiguration constructor. Unfortunately, this doesn't seem to work. The constructor is never called when creating a new configuration in the IDE, and the instance returned by createTemplateConfiguration (invoked during IDE startup which DOES contain the defaults) is not used according to the debugger/instance IDs.

I also tried what seemed like a big hack: setting the defaults in the constructor of my SettingsEditor, thinking that since there was no RunConfiguration to bind it to via SettingsEditor#resetEditorFrom initially I'd have the chance to override stuff. In this case though, it turns out there IS some ModuleRunConfiguration instance being applied to the editor when the user selects a new Run Configuration in the IDE. I have no idea where the instance came from. The constructor of the ModuleRunConfiguration object is never called, and indeed the default property values that would be set in the constructor are not present in this mystery instance.

I tried analyzing the call stack when creating a new run configuration in the IDE and ended up in the constructor of com.intellij.execution.impl.ConfigurationSettingsEditor. At some point during these calls (which I can't step into as the source isn't available), a private member "d" is populated with my SettingsEditor instance, and shortly thereafter a mystery instance of my ModuleRunConfiguration is assigned to the private member "c". The defaults are not present in that instance, which leads me to believe that the constructor wasn't invoked. Perhaps the instance is some proxy, or came from some serialization mechanism?

How can I get a ModuleRunConfiguration with default properties into my SettingsEditor?

2 comments
Comment actions Permalink

Hi Daniel,

Did you try initializing your fields in SettingsEditor#resetEditorFrom ? That worked for me since that methot gets called on form initialization every time your configuration editor is displayed (both for defaults and specific run configuration).

Regards,
Martijn

0
Comment actions Permalink

We use clone() on template "defult" RunConfiguration instance to get new one with "default" values.

0

Please sign in to leave a comment.