3a828e79447558fbcce95038bb2257b7024a6214
[jalview.git] / src / jalview / ws2 / gui / MenuEntryProviderI.java
1 package jalview.ws2.gui;
2
3 import java.util.List;
4 import java.util.concurrent.CompletionStage;
5
6 import javax.swing.JMenu;
7
8 import jalview.gui.AlignFrame;
9 import jalview.gui.WsJobParameters;
10 import jalview.util.MessageManager;
11 import jalview.ws.params.ArgumentI;
12 import jalview.ws.params.ParamDatastoreI;
13 import jalview.ws.params.WsParamSetI;
14
15 /**
16  * Functional interface provided by {@link jalview.ws2.operations.Operation}
17  * instances to construct the menu entry for the operations. The instances are
18  * passed to the {@link jalview.gui.WebServicesMenuBuilder} and called during
19  * menu construction.
20  * 
21  * @author mmwarowny
22  */
23 @FunctionalInterface
24 public interface MenuEntryProviderI
25 {
26   /**
27    * Build menu entries directly under the given menu. This method is called by
28    * {@link jalview.gui.WebServicesMenuBuilder} during menu construction.
29    * 
30    * @param parent
31    *          parent menu
32    * @param frame
33    *          current alignFrame
34    */
35   public void buildMenu(JMenu parent, AlignFrame frame);
36
37   static CompletionStage<List<ArgumentI>> openEditParamsDialog(
38       ParamDatastoreI paramStore, WsParamSetI preset,
39       List<ArgumentI> arguments)
40   {
41     WsJobParameters jobParams;
42     if (preset == null && arguments != null && arguments.size() > 0)
43       jobParams = new WsJobParameters(paramStore, preset, arguments);
44     else
45       jobParams = new WsJobParameters(paramStore, preset, null);
46     if (preset != null)
47     {
48       jobParams.setName(MessageManager.getString(
49           "label.adjusting_parameters_for_calculation"));
50     }
51     var stage = jobParams.showRunDialog();
52     return stage.thenApply((startJob) -> {
53       if (startJob)
54       {
55         if (jobParams.getPreset() == null)
56         {
57           return jobParams.getJobParams();
58         }
59         else
60         {
61           return jobParams.getPreset().getArguments();
62         }
63       }
64       else
65       {
66         return null;
67       }
68     });
69   }
70
71 }