package io.protostuff.jetbrains.plugin.settings;

import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import java.util.Objects;
import javax.swing.JComponent;
import org.jetbrains.annotations.Nls;

public class ProtobufSettingsConfigurable implements Configurable {

    private final ProtobufSettings settings;
    private final Project project;

    private SettingsForm settingsForm;


    public ProtobufSettingsConfigurable(Project project) {
        this.project = project;
        this.settings = ProtobufSettings.getInstance(project);
    }

    @Nls
    @Override
    public String getDisplayName() {
        return "Protobuf Support";
    }

    @Override
    public String getHelpTopic() {
        return null;
    }

    @Override
    public JComponent createComponent() {
        settingsForm = new SettingsForm(project, settings);
        return settingsForm.getPanel();
    }

    @Override
    public boolean isModified() {
        return !Objects.equals(settings, settingsForm.getSettings());
    }

    @Override
    public void apply() throws ConfigurationException {
        settings.copyFrom(settingsForm.getSettings());
    }

    @Override
    public void reset() {
        settingsForm.reset(settings);
    }

    @Override
    public void disposeUIResources() {
        settingsForm = null;
    }


}

@@ -292,16 +292,59 @@
 ons.Nls;
+%0Aimport org.jetbrains.annotations.Nullable;
 %0A%0Apublic
@@ -487,16 +487,30 @@
 oject;%0A%0A
+    @Nullable%0A
     priv
@@ -1107,16 +1107,56 @@
   return
+ settingsForm != null%0A                &&
  !Object
@@ -1280,16 +1280,56 @@
 ption %7B%0A
+        if (settingsForm != null) %7B%0A    
         
@@ -1367,32 +1367,42 @@
 getSettings());%0A
+        %7D%0A
     %7D%0A%0A    @Over
@@ -1428,24 +1428,64 @@
 d reset() %7B%0A
+        if (settingsForm != null) %7B%0A    
         sett
@@ -1506,24 +1506,34 @@
 (settings);%0A
+        %7D%0A
     %7D%0A%0A    @

Fix NullPointerException in ProtobufSettingsConfigurable