JAL-3619 fix up error messages and try to bail quietly if the viewer doesn’t open
[jalview.git] / src / jalview / gui / ChimeraViewFrame.java
index 0e5675c..3a17ea3 100644 (file)
@@ -38,7 +38,7 @@ import javax.swing.event.InternalFrameEvent;
 
 import jalview.api.AlignmentViewPanel;
 import jalview.api.FeatureRenderer;
-import jalview.bin.Cache;
+import jalview.bin.Console;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.StructureViewerModel;
@@ -73,7 +73,10 @@ public class ChimeraViewFrame extends StructureViewerBase
 
   private int myHeight = 150;
 
-  /**
+  private JMenuItem writeFeatures=null;
+
+  private JMenu fetchAttributes=null;
+/**
    * Initialise menu options.
    */
   @Override
@@ -84,7 +87,7 @@ public class ChimeraViewFrame extends StructureViewerBase
     savemenu.setVisible(false); // not yet implemented
     viewMenu.add(fitToWindow);
 
-    JMenuItem writeFeatures = new JMenuItem(
+    writeFeatures = new JMenuItem(
             MessageManager.getString("label.create_viewer_attributes"));
     writeFeatures.setToolTipText(MessageManager
             .getString("label.create_viewer_attributes_tip"));
@@ -98,10 +101,10 @@ public class ChimeraViewFrame extends StructureViewerBase
     });
     viewerActionMenu.add(writeFeatures);
 
-    final JMenu fetchAttributes = new JMenu(
-            MessageManager.getString("label.fetch_chimera_attributes"));
+    fetchAttributes = new JMenu(
+            MessageManager.formatMessage("label.fetch_viewer_attributes",getViewerName()));
     fetchAttributes.setToolTipText(
-            MessageManager.getString("label.fetch_chimera_attributes_tip"));
+            MessageManager.formatMessage("label.fetch_viewer_attributes_tip",getViewerName()));
     fetchAttributes.addMouseListener(new MouseAdapter()
     {
 
@@ -113,10 +116,18 @@ public class ChimeraViewFrame extends StructureViewerBase
     });
     viewerActionMenu.add(fetchAttributes);
   }
-
+  @Override
+  protected void buildActionMenu()
+  {
+    super.buildActionMenu();
+    // add these back in after menu is refreshed
+    viewerActionMenu.add(writeFeatures);
+    viewerActionMenu.add(fetchAttributes);
+    
+  };
   /**
-   * Query Chimera for its residue attribute names and add them as items off the
-   * attributes menu
+   * Query the structure viewer for its residue attribute names and add them as
+   * items off the attributes menu
    * 
    * @param attributesMenu
    */
@@ -133,7 +144,11 @@ public class ChimeraViewFrame extends StructureViewerBase
         @Override
         public void actionPerformed(ActionEvent e)
         {
-          getChimeraAttributes(attName);
+          if (getBinding().copyStructureAttributesToFeatures(attName,
+                  getAlignmentPanel()) > 0)
+          {
+            getAlignmentPanel().getFeatureRenderer().featuresAdded();
+          }
         }
       });
       attributesMenu.add(menuItem);
@@ -141,17 +156,6 @@ public class ChimeraViewFrame extends StructureViewerBase
   }
 
   /**
-   * Read residues in Chimera with the given attribute name, and set as features
-   * on the corresponding sequence positions (if any)
-   * 
-   * @param attName
-   */
-  protected void getChimeraAttributes(String attName)
-  {
-    jmb.copyStructureAttributesToFeatures(attName, getAlignmentPanel());
-  }
-
-  /**
    * Sends command(s) to the structure viewer to create residue attributes for
    * visible Jalview features
    */
@@ -160,7 +164,7 @@ public class ChimeraViewFrame extends StructureViewerBase
     // todo pull up?
     int count = jmb.sendFeaturesToViewer(getAlignmentPanel());
     statusBar.setText(
-            MessageManager.formatMessage("label.attributes_set", count));
+            MessageManager.formatMessage("label.attributes_set", count, getViewerName()));
   }
 
   /**
@@ -327,6 +331,7 @@ public class ChimeraViewFrame extends StructureViewerBase
                       getViewerName()),
               MessageManager.getString("label.error_loading_file"),
               JvOptionPane.ERROR_MESSAGE);
+      jmb.closeViewer(true);
       this.dispose();
       return;
     }
@@ -437,9 +442,15 @@ public class ChimeraViewFrame extends StructureViewerBase
           initChimera();
         } catch (Exception ex)
         {
-          Cache.log.error("Couldn't open Chimera viewer!", ex);
+          Console.error("Couldn't open Chimera viewer!", ex);
         }
       }
+      if (!jmb.isViewerRunning())
+      {
+        // nothing to do
+        // TODO: ensure we tidy up JAL-3619
+        return;
+      }
       int num = -1;
       for (PDBEntry pe : filePDB)
       {
@@ -482,12 +493,12 @@ public class ChimeraViewFrame extends StructureViewerBase
                     oomerror);
           } catch (Exception ex)
           {
-            Cache.log.error(
+            Console.error(
                     "Couldn't open " + pe.getFile() + " in Chimera viewer!",
                     ex);
           } finally
           {
-            Cache.log.debug("File locations are " + files);
+            Console.debug("File locations are " + files);
           }
         }
       }
@@ -498,7 +509,8 @@ public class ChimeraViewFrame extends StructureViewerBase
 
       /*
        * ensure that any newly discovered features (e.g. RESNUM)
-       * are added to any open feature settings dialog
+       * are notified to the FeatureRenderer (and added to any 
+       * open feature settings dialog)
        */
       FeatureRenderer fr = getBinding().getFeatureRenderer(null);
       if (fr != null)
@@ -543,12 +555,6 @@ public class ChimeraViewFrame extends StructureViewerBase
   }
 
   @Override
-  protected void fitToWindow_actionPerformed()
-  {
-    jmb.focusView();
-  }
-
-  @Override
   public ViewerType getViewerType()
   {
     return ViewerType.CHIMERA;