import java.util.List;
import java.util.concurrent.CompletionStage;
+import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
+import javax.swing.event.MenuEvent;
+import javax.swing.event.MenuListener;
+import jalview.api.AlignCalcManagerI2;
import jalview.api.AlignmentViewPanel;
import jalview.datamodel.AlignmentAnnotation;
import jalview.gui.AlignFrame;
import jalview.gui.AlignViewport;
import jalview.gui.WsJobParameters;
import jalview.io.FeaturesFile;
+import jalview.util.Format;
import jalview.util.MessageManager;
import jalview.ws.params.ArgumentI;
import jalview.ws.params.WsParamSetI;
@Override
public MenuEntryProviderI getMenuBuilder()
{
- return this::buildMenu;
+ if (isInteractive())
+ return this::buildInteractiveMenu;
+ else
+ return this::buildClassicMenu;
}
- protected void buildMenu(JMenu parent, AlignFrame frame)
+ protected void buildClassicMenu(JMenu parent, AlignFrame frame)
{
final var calcName = service.getName();
PollingTaskExecutor wsExecutor = frame.getViewport().getWSExecutor();
var item = new JMenuItem(MessageManager.formatMessage(
"label.calcname_with_default_settings", calcName));
item.addActionListener((event) -> {
- /* What is the purpose of AlignViewport and AlignmentViewPanel? */
- AlignViewport viewport = frame.getCurrentView();
- AlignmentViewPanel alignPanel = frame.alignPanel;
- var worker = new AnnotationServiceWorker(this, service,
- Collections.emptyList(), viewport, alignPanel, frame, frame,
- calcManager);
- if (isInteractive())
- calcManager.registerWorker(worker);
- else
- calcManager.startWorker(worker);
+ var worker = createWorker(Collections.emptyList(), frame, calcManager);
+ calcManager.startWorker(worker);
});
parent.add(item);
}
.thenAcceptAsync((arguments) -> {
if (arguments != null)
{
- AlignViewport viewport = frame.getCurrentView();
- AlignmentViewPanel alignPanel = frame.alignPanel;
- var worker = new AnnotationServiceWorker(
- AnnotationOperation.this, service, arguments, viewport,
- alignPanel, frame, frame, calcManager);
- if (isInteractive())
- calcManager.registerWorker(worker);
- else
- calcManager.startWorker(worker);
+ var worker = createWorker(arguments, frame, calcManager);
+ calcManager.startWorker(worker);
}
});
});
}
}
+ protected void buildInteractiveMenu(JMenu parent, AlignFrame frame)
+ {
+ final var calcName = service.getName();
+ final var calcManager = frame.getViewport().getCalcManager();
+ final JCheckBoxMenuItem runItem;
+ {
+ // TODO use MessageManager and set tool tip text
+ runItem = new JCheckBoxMenuItem(
+ String.format("%s calculations", calcName));
+ runItem.addActionListener((event) -> {
+ calcManager.removeWorkersForName(calcName);
+ var worker = createWorker(Collections.emptyList(), frame, calcManager);
+ calcManager.registerWorker(worker);
+ });
+ parent.add(runItem);
+ }
+ JMenuItem _editItem = null;
+ if (service.hasParameters())
+ {
+ // TODO use MessageManager and set tool tip text
+ _editItem = new JMenuItem(
+ String.format("Edit %s settings", calcName));
+ _editItem.addActionListener((event) -> {
+ openEditParamsDialog(service, null, null)
+ .thenAcceptAsync((arguments) -> {
+ if (arguments != null)
+ {
+ calcManager.removeWorkersForName(calcName);
+ var worker = createWorker(arguments, frame, calcManager);
+ calcManager.registerWorker(worker);
+ }
+ });
+ });
+ parent.add(_editItem);
+ }
+ final var editItem = _editItem;
+
+ parent.addMenuListener(new MenuListener()
+ {
+ @Override
+ public void menuSelected(MenuEvent e)
+ {
+ var isNuc = frame.getViewport().getAlignment().isNucleotide();
+ var menuEnabled = (isNuc && isNucleotideOperation()) ||
+ (!isNuc && isProteinOperation());
+ runItem.setEnabled(menuEnabled);
+ if (editItem != null)
+ editItem.setEnabled(menuEnabled);
+ boolean currentlyRunning = calcManager.getWorkersForName(calcName).size() > 0;
+ runItem.setSelected(currentlyRunning);
+ }
+
+ @Override
+ public void menuDeselected(MenuEvent e) {}
+
+ @Override
+ public void menuCanceled(MenuEvent e) {}
+ });
+ }
+
+ private AnnotationServiceWorker createWorker(
+ List<ArgumentI> arguments, AlignFrame frame, AlignCalcManagerI2 calcManager)
+ {
+ /* What is the purpose of AlignViewport and AlignmentViewPanel? */
+ AlignViewport viewport = frame.getCurrentView();
+ AlignmentViewPanel alignPanel = frame.alignPanel;
+ return new AnnotationServiceWorker(this, service,
+ arguments, viewport, alignPanel, frame, frame,
+ calcManager);
+ }
+
private CompletionStage<List<ArgumentI>> openEditParamsDialog(
WebServiceI service, WsParamSetI preset, List<ArgumentI> arguments)
{