github.com/ijc/docker-app@v0.6.1-0.20181012090447-c7ca8bc483fb/integrations/intellij/src/main/java/SettingsDialog.java (about)

     1  import javax.swing.*;
     2  import java.awt.event.*;
     3  import com.intellij.openapi.project.Project;
     4  import com.intellij.ide.util.PropertiesComponent;
     5  
     6  public class SettingsDialog extends JDialog {
     7      private JPanel contentPane;
     8      private JButton buttonOK;
     9      private JButton buttonCancel;
    10      private JTextField tKubeconfig;
    11      private JTextArea tOverrides;
    12      private JRadioButton oSwarm;
    13      private JRadioButton oKubernetes;
    14      private JTextField tNamespace;
    15      private JTextField tStackName;
    16      private boolean validated;
    17  
    18      public SettingsDialog() {
    19          setContentPane(contentPane);
    20          setModal(true);
    21          getRootPane().setDefaultButton(buttonOK);
    22  
    23          buttonOK.addActionListener(new ActionListener() {
    24              public void actionPerformed(ActionEvent e) {
    25                  onOK();
    26              }
    27          });
    28  
    29          buttonCancel.addActionListener(new ActionListener() {
    30              public void actionPerformed(ActionEvent e) {
    31                  onCancel();
    32              }
    33          });
    34  
    35          // call onCancel() when cross is clicked
    36          setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    37          addWindowListener(new WindowAdapter() {
    38              public void windowClosing(WindowEvent e) {
    39                  onCancel();
    40              }
    41          });
    42  
    43          // call onCancel() on ESCAPE
    44          contentPane.registerKeyboardAction(new ActionListener() {
    45              public void actionPerformed(ActionEvent e) {
    46                  onCancel();
    47              }
    48          }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    49      }
    50  
    51      public void load(Project project) {
    52          PropertiesComponent pc = PropertiesComponent.getInstance(project);
    53          String orchestrator = pc.getValue("docker_app_orchestrator");
    54          if (orchestrator != null && orchestrator.equals("kubernetes")) {
    55              oKubernetes.setSelected(true);
    56          } else {
    57              oSwarm.setSelected(true);
    58          }
    59          tKubeconfig.setText(pc.getValue("docker_app_kubeconfig"));
    60          tOverrides.setText(pc.getValue("docker_app_overrides"));
    61          tNamespace.setText(pc.getValue("docker_app_namespace"));
    62          tStackName.setText(pc.getValue("docker_app_name"));
    63      }
    64      public void save(Project project) {
    65          if (!validated)
    66              return;
    67          PropertiesComponent pc = PropertiesComponent.getInstance(project);
    68          pc.setValue("docker_app_orchestrator", oKubernetes.isSelected()? "kubernetes" : "swarm");
    69          pc.setValue("docker_app_kubeconfig", tKubeconfig.getText());
    70          pc.setValue("docker_app_overrides", tOverrides.getText());
    71          pc.setValue("docker_app_namespace", tNamespace.getText());
    72          pc.setValue("docker_app_name", tStackName.getText());
    73      }
    74      private void onOK() {
    75          // add your code here
    76          validated = true;
    77          dispose();
    78      }
    79  
    80      private void onCancel() {
    81          // add your code here if necessary
    82          validated = false;
    83          dispose();
    84      }
    85  }