Run Configuration - Update to Map Stored Property in UI does not allow "Apply"

Answered

I am trying to use a StoredProperty<Map<String, String>> in my RunConfigurationOptions in order to store a number of dynamic entries in my run configuration settings and then display them on my UI accordingly

My options class looks as follows:

public class CustomRunConfigurationOptions extends RunConfigurationOptions {
    private final StoredProperty<Map<String, String>> options = this.<String, String>map().provideDelegate(this, "options");

    public String getOption(String option) {
        return options.getValue(this).getOrDefault(option, "");
    }

    public void setOption(String option, String value) {
        options.getValue(this).put(option, value);
    }
}

I then have the following NestedGroupFragment in my SettingsEditor:

public class CustomOptionsFragment extends NestedGroupFragment<CustomRunConfiguration> {
    public CustomOptionsFragment() {
        super("custom.id",
                "Name placeholder",
                "option",
                Predicates.alwaysFalse());
    }

    @Override
    protected List<SettingsEditorFragment<CustomRunConfiguration, ?>> createChildren() {
        SettingsEditorFragment<CustomRunConfiguration, LabeledComponent<RawCommandLineEditor>> option =
                new SettingsEditorFragment<>(
                        "custom.id.option",
                        "Option",
                        null,
                        LabeledComponent.create(new RawCommandLineEditor(), "Option:", BorderLayout.WEST),
                        (runConfiguration, rawCommandLineEditorLabeledComponent) -> rawCommandLineEditorLabeledComponent.getComponent().setText(runConfiguration.getOption("option")),
                        (runConfiguration, rawCommandLineEditorLabeledComponent) -> runConfiguration.setOption("option", rawCommandLineEditorLabeledComponent.getComponent().getText()),
                        Predicates.alwaysTrue());

        return Arrays.asList(option);
    }
}

The problem is, when I type in the RawCommandLineEditor field in my UI, then the “Apply” button is greyed out and will not let me click it. However, if I have a regular stored property in my options, such as a StoredProperty<String>, and call setValue on it, then that allows me to press the “Apply” button normally.

Is there a way to achieve what I'm looking for?

0
2 comments

Hi Marcus,

Please try using com.intellij.serialization.stateProperties.MapStoredProperty<String, String> instead of StoredProperty parameterized with Map<String, String>.

0

It seems the compiler complains when I try that, since this.<String, String>map().provideDelegate() returns StoredProperty<Map<String, String>> instead of MapStoredProperty<String, String>

I think I figured out the solution though, which was that I needed 1:1 getters and setters for the field, i.e.

    public String getOptions() {
        return options.getValue(this);
    }

    public void setOptions(Map<String, String> map) {
        options.setValue(this, map);
    }

    instead of what I had before with getting individual entries. Appreciate the help though!

0

Please sign in to leave a comment.