JAL-3446 Dynamic menu - Moves calc sortby tree item creation to opening
[jalview.git] / src / jalview / gui / AlignFrame.java
index b69ba88..a06c6d8 100644 (file)
@@ -3966,7 +3966,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    */
   protected int _annotationScoreVectorHash;
 
-  /**
+  /**g
    * search the alignment and rebuild the sort by annotation score submenu the
    * last alignment annotation vector hash is stored to minimize cost of
    * rebuilding in subsequence calls.
@@ -4013,6 +4013,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   /**
+   * Enable (or, if desired, make visible) the By Tree 
+   * submenu only if it has at least one element (or will have).
+   * 
+   */
+  @Override
+  protected void enableSortMenuOptions()
+  {
+    List<TreePanel> treePanels = getTreePanels();
+    sortByTreeMenu.setEnabled(!treePanels.isEmpty());
+  }
+  
+  /**
    * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
    * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
    * call. Listeners are added to remove the menu item when the treePanel is
@@ -4025,24 +4037,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     sortByTreeMenu.removeAll();
 
-    List<Component> comps = PaintRefresher.components
-            .get(viewport.getSequenceSetId());
-    List<TreePanel> treePanels = new ArrayList<>();
-    for (Component comp : comps)
-    {
-      if (comp instanceof TreePanel)
-      {
-        treePanels.add((TreePanel) comp);
-      }
-    }
-
-    if (treePanels.size() < 1)
-    {
-      sortByTreeMenu.setVisible(false);
-      return;
-    }
-
-    sortByTreeMenu.setVisible(true);
+    List<TreePanel> treePanels = getTreePanels();
 
     for (final TreePanel tp : treePanels)
     {
@@ -4063,6 +4058,21 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
   }
 
+  private List<TreePanel> getTreePanels()
+  {
+    List<Component> comps = PaintRefresher.components
+            .get(viewport.getSequenceSetId());
+    List<TreePanel> treePanels = new ArrayList<>();
+    for (Component comp : comps)
+    {
+      if (comp instanceof TreePanel)
+      {
+        treePanels.add((TreePanel) comp);
+      }
+    }
+    return treePanels;
+  }
+
   public boolean sortBy(AlignmentOrder alorder, String undoname)
   {
     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();