JAL-4232 Disable menu items for RNA services for proteins. patch/JAL-4232-disable-unavailable-services
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Mon, 17 Jul 2023 10:46:37 +0000 (12:46 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Mon, 17 Jul 2023 10:51:20 +0000 (12:51 +0200)
src/jalview/ws2/gui/WebServicesMenuManager.java

index 3757199..f9b8c02 100644 (file)
@@ -175,6 +175,7 @@ public class WebServicesMenuManager
 
   private void addEntriesForAction(ActionI<?> action, JMenu menu, boolean isTopLevel)
   {
+    var enabled = isActionEnabled(action);
     var service = action.getWebService();
     String itemName;
     if (isTopLevel)
@@ -196,6 +197,7 @@ public class WebServicesMenuManager
       if (datastore.hasParameters() || datastore.hasPresets())
         text += " with defaults";
       JMenuItem item = new JMenuItem(text);
+      item.setEnabled(enabled);
       item.addActionListener(e -> {
         runAction(action, frame.getCurrentView(), Collections.emptyList(),
             Credentials.empty());
@@ -205,6 +207,7 @@ public class WebServicesMenuManager
     if (datastore.hasParameters())
     {
       JMenuItem item = new JMenuItem("Edit settings and run...");
+      item.setEnabled(enabled);
       item.addActionListener(e -> {
         openEditParamsDialog(datastore, null, null).thenAccept(args -> {
           if (args != null)
@@ -218,6 +221,7 @@ public class WebServicesMenuManager
     {
       final var presetsMenu = new JMenu(MessageManager.formatMessage(
           "label.run_with_preset_params", service.getName()));
+      presetsMenu.setEnabled(enabled);
       final int dismissDelay = ToolTipManager.sharedInstance()
           .getDismissDelay();
       final int QUICK_TOOLTIP = 1500;
@@ -342,6 +346,7 @@ public class WebServicesMenuManager
           for (ActionI<?> action : actions)
           {
             var item = new JMenuItem(action.getFullName());
+            item.setEnabled(isActionEnabled(action));
             item.addActionListener(e -> setAlternative(action));
             atMenu.add(item);
           }
@@ -428,6 +433,12 @@ public class WebServicesMenuManager
     }
   }
 
+  private boolean isActionEnabled(ActionI<?> action)
+  {
+    var isNa = frame.getViewport().getAlignment().isNucleotide();
+    return ((isNa && action.doAllowNucleotide()) ||
+        (!isNa && action.doAllowProtein()));
+  }
 
   private void runAction(ActionI<?> action, AlignmentViewport viewport,
       List<ArgumentI> args, Credentials credentials)