Merge branch 'Release_2_8_2_Branch' of https://source.jalview.org/git/jalview.git...
[jalview.git] / src / jalview / gui / Preferences.java
index 09f3686..b082bc6 100755 (executable)
@@ -291,17 +291,7 @@ public class Preferences extends GPreferences
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        if (chimeraPath.getText().trim().length() > 0)
-        {
-          File f = new File(chimeraPath.getText());
-          if (!f.canExecute())
-          {
-            JOptionPane.showInternalMessageDialog(Desktop.desktop,
-                    MessageManager.getString("label.invalid_path"),
-                    MessageManager.getString("label.invalid_name"),
-                    JOptionPane.ERROR_MESSAGE);
-          }
-        }
+        validateChimeraPath();
       }
     });
 
@@ -376,6 +366,11 @@ public class Preferences extends GPreferences
    */
   public void ok_actionPerformed(ActionEvent e)
   {
+    if (!validateSettings())
+    {
+      return;
+    }
+
     /*
      * Save Visual settings
      */
@@ -601,6 +596,27 @@ public class Preferences extends GPreferences
   }
 
   /**
+   * Do any necessary validation before saving settings.
+   * 
+   * @return
+   */
+  private boolean validateSettings()
+  {
+    if (!validateStructure())
+    {
+      structureTab.requestFocusInWindow();
+      return false;
+    }
+    return true;
+  }
+
+  @Override
+  protected boolean validateStructure()
+  {
+    return validateChimeraPath();
+
+  }
+  /**
    * DOCUMENT ME!
    */
   public void startupFileTextfield_mouseClicked()
@@ -842,4 +858,25 @@ public class Preferences extends GPreferences
     userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
   }
 
+  /**
+   * Returns true if chimera path is to a valid executable, else show an error
+   * dialog.
+   */
+  private boolean validateChimeraPath()
+  {
+    if (chimeraPath.getText().trim().length() > 0)
+    {
+      File f = new File(chimeraPath.getText());
+      if (!f.canExecute())
+      {
+        JOptionPane.showInternalMessageDialog(Desktop.desktop,
+                MessageManager.getString("label.invalid_chimera_path"),
+                MessageManager.getString("label.invalid_name"),
+                JOptionPane.ERROR_MESSAGE);
+        return false;
+      }
+    }
+    return true;
+  }
+
 }