JAL-3904 override buildActionMenu to add in additional menu actions after rebuild
authorJim Procter <j.procter@dundee.ac.uk>
Mon, 18 Oct 2021 12:18:59 +0000 (13:18 +0100)
committerJim Procter <j.procter@dundee.ac.uk>
Mon, 18 Oct 2021 12:18:59 +0000 (13:18 +0100)
src/jalview/gui/ChimeraViewFrame.java
src/jalview/gui/PymolViewer.java
src/jalview/gui/StructureViewerBase.java

index e3c65da..364a3b4 100644 (file)
@@ -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,7 +101,7 @@ public class ChimeraViewFrame extends StructureViewerBase
     });
     viewerActionMenu.add(writeFeatures);
 
-    final JMenu fetchAttributes = new JMenu(
+    fetchAttributes = new JMenu(
             MessageManager.getString("label.fetch_chimera_attributes"));
     fetchAttributes.setToolTipText(
             MessageManager.getString("label.fetch_chimera_attributes_tip"));
@@ -113,7 +116,15 @@ 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 the structure viewer for its residue attribute names and add them as
    * items off the attributes menu
index c5a4c9a..8dd2fc0 100644 (file)
@@ -348,7 +348,7 @@ public class PymolViewer extends StructureViewerBase
   {
     return "PyMOL";
   }
-
+  JMenuItem writeFeatures = null;
   @Override
   protected void initMenus()
   {
@@ -357,7 +357,7 @@ public class PymolViewer 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"));
@@ -371,6 +371,13 @@ public class PymolViewer extends StructureViewerBase
     });
     viewerActionMenu.add(writeFeatures);
   }
+  
+  @Override
+  protected void buildActionMenu()
+  {
+    super.buildActionMenu();
+    viewerActionMenu.add(writeFeatures);
+  }
 
   protected void sendFeaturesToPymol()
   {
index f5d350c..4f746cb 100644 (file)
@@ -221,6 +221,10 @@ public abstract class StructureViewerBase extends GStructureViewer
       _alignwith.add(ap);
     }
     ;
+    // TODO: refactor to allow concrete classes to register buttons for adding
+    // here
+    // currently have to override to add buttons back in after they are cleared
+    // in this loop
     for (Component c : viewerActionMenu.getMenuComponents())
     {
       if (c != alignStructs)
@@ -1279,6 +1283,8 @@ public abstract class StructureViewerBase extends GStructureViewer
   @Override
   public boolean hasViewerActionsMenu()
   {
-    return viewerActionMenu!=null && viewerActionMenu.isEnabled() && viewerActionMenu.getItemCount()>0 && viewerActionMenu.isVisible();
+    return viewerActionMenu != null && viewerActionMenu.isEnabled()
+            && viewerActionMenu.getItemCount() > 0
+            && viewerActionMenu.isVisible();
   }
 }