JAL-1603 if Chimera selected in Preferences, warn if not installed/found
[jalview.git] / src / jalview / gui / Preferences.java
index ad3c072..bdc83e5 100755 (executable)
@@ -22,6 +22,7 @@ package jalview.gui;
 
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
 import jalview.bin.Cache;
+import jalview.gui.Help.HelpId;
 import jalview.gui.StructureViewer.Viewer;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
@@ -39,15 +40,19 @@ import java.awt.event.ActionListener;
 import java.awt.event.MouseEvent;
 import java.io.File;
 import java.util.Collection;
+import java.util.List;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
+import javax.help.HelpSetException;
 import javax.swing.JColorChooser;
 import javax.swing.JFileChooser;
 import javax.swing.JInternalFrame;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 
+import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
+
 /**
  * DOCUMENT ME!
  * 
@@ -585,9 +590,8 @@ public class Preferences extends GPreferences
 
     dasSource.saveProperties(Cache.applicationProperties);
     wsPrefs.updateAndRefreshWsMenuConfig(false);
-
     Cache.saveProperties();
-
+    Desktop.instance.doConfigureStructurePrefs();
     try
     {
       frame.setClosed(true);
@@ -597,7 +601,8 @@ public class Preferences extends GPreferences
   }
 
   /**
-   * Do any necessary validation before saving settings.
+   * Do any necessary validation before saving settings. Return focus to the
+   * first tab which fails validation.
    * 
    * @return
    */
@@ -880,4 +885,53 @@ public class Preferences extends GPreferences
     return true;
   }
 
+  /**
+   * If Chimera is selected, check it can be found on default or user-specified
+   * path, if not show a warning/help dialog.
+   */
+  @Override
+  protected void structureViewer_actionPerformed(String selectedItem)
+  {
+    if (!selectedItem.equals(Viewer.CHIMERA.name()))
+    {
+      return;
+    }
+    boolean found = false;
+
+    /*
+     * Try user-specified and standard paths for Chimera executable.
+     */
+    List<String> paths = StructureManager.getChimeraPaths();
+    paths.add(0, chimeraPath.getText());
+    for (String path : paths)
+    {
+      if (new File(path.trim()).canExecute())
+      {
+        found = true;
+        break;
+      }
+    }
+    if (!found)
+    {
+      String[] options =
+      { "OK", "Help" };
+      int showHelp = JOptionPane.showInternalOptionDialog(
+              Desktop.desktop,
+              JvSwingUtils.wrapTooltip(true,
+                      MessageManager.getString("label.chimera_missing")),
+              "", JOptionPane.YES_NO_OPTION,
+              JOptionPane.WARNING_MESSAGE, null, options, options[0]);
+      if (showHelp == JOptionPane.NO_OPTION)
+      {
+        try
+        {
+          Help.showHelpWindow(HelpId.StructureViewer);
+        } catch (HelpSetException e)
+        {
+          e.printStackTrace();
+        }
+      }
+    }
+  }
+
 }