From 044565fb3cd7d2d3c91b7592b3e007e584e264f2 Mon Sep 17 00:00:00 2001 From: jprocter Date: Mon, 6 Sep 2010 10:53:27 +0000 Subject: [PATCH] abstracted GUI to use jalview.ws.params objects (JAL-591, JAL-633). User defined presets shown in menu - which is dynamically populated --- src/jalview/ws/jws2/Jws2Discoverer.java | 55 ++++++++++++++++++++++++++---- src/jalview/ws/jws2/MsaWSClient.java | 56 +++++++++++++++++++++++++------ src/jalview/ws/jws2/MsaWSThread.java | 4 ++- 3 files changed, 98 insertions(+), 17 deletions(-) diff --git a/src/jalview/ws/jws2/Jws2Discoverer.java b/src/jalview/ws/jws2/Jws2Discoverer.java index 2528308..eccbdaf 100644 --- a/src/jalview/ws/jws2/Jws2Discoverer.java +++ b/src/jalview/ws/jws2/Jws2Discoverer.java @@ -15,6 +15,8 @@ import java.util.Vector; import javax.swing.JMenu; import javax.swing.JMenuItem; +import javax.swing.event.MenuEvent; +import javax.swing.event.MenuListener; import org.apache.log4j.Level; @@ -22,6 +24,7 @@ import jalview.bin.Cache; import jalview.datamodel.AlignmentView; import jalview.gui.AlignFrame; import jalview.ws.WSMenuEntryProviderI; +import jalview.ws.params.ParamDatastoreI; import compbio.data.msa.MsaWS; import compbio.metadata.Option; import compbio.metadata.Preset; @@ -179,6 +182,8 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI PresetManager presets = null; + public JabaParamStore paramStore=null; + /** * non thread safe - gets the presets for this service (blocks whilst it * calls the service to get the preset set) @@ -250,6 +255,19 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI } super.finalize(); } + + public ParamDatastoreI getParamStore() + { + if (paramStore == null) + { + try { + paramStore = new JabaParamStore(this); + } catch (Exception ex) + {} + + } + return paramStore; + } }; /** @@ -287,6 +305,35 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame) { + // dynamically regenerate service list. + final JMenu jws2al = new JMenu("JABA Alignment"); + jws2al.addMenuListener(new MenuListener() { + // TODO: future: add menu listener to parent menu - so submenus are populated *before* they are selected. + @Override + public void menuSelected(MenuEvent e) + { + populateWSMenuEntry(jws2al, alignFrame); + } + + @Override + public void menuDeselected(MenuEvent e) + { + // TODO Auto-generated method stub + + } + + @Override + public void menuCanceled(MenuEvent e) + { + // TODO Auto-generated method stub + + } + + }); + wsmenu.add(jws2al); + } + private void populateWSMenuEntry(JMenu jws2al, final AlignFrame alignFrame) + { if (running || services == null || services.size() == 0) { return; @@ -297,9 +344,10 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI * eventually, JWS2 services will appear under the same align/etc submenus. * for moment we keep them separate. */ - JMenu atpoint, jws2al = new JMenu("JABA Alignment"); + JMenu atpoint; MsaWSClient msacl = new MsaWSClient(); Vector hostLabels = new Vector(); + jws2al.removeAll(); for (final Jws2Instance service : services) { atpoint = jws2al; @@ -345,11 +393,6 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI * alignFrame); } }); */ } - if (services.size() > 0) - { - wsmenu.add(jws2al); - } - } public static void main(String[] args) diff --git a/src/jalview/ws/jws2/MsaWSClient.java b/src/jalview/ws/jws2/MsaWSClient.java index 820dfb4..e025df6 100644 --- a/src/jalview/ws/jws2/MsaWSClient.java +++ b/src/jalview/ws/jws2/MsaWSClient.java @@ -19,6 +19,7 @@ package jalview.ws.jws2; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.ArrayList; import java.util.List; import javax.swing.*; @@ -27,9 +28,12 @@ import jalview.datamodel.*; import jalview.gui.*; import compbio.data.msa.MsaWS; import compbio.metadata.Argument; +import compbio.metadata.Option; import compbio.metadata.Preset; import compbio.metadata.PresetManager; import jalview.ws.jws2.Jws2Discoverer.Jws2Instance; +import jalview.ws.jws2.dm.JabaWsParamSet; +import jalview.ws.params.WsParamSetI; /** * DOCUMENT ME! @@ -60,7 +64,7 @@ public class MsaWSClient extends Jws2Client // TODO Auto-generated constructor stub } - public MsaWSClient(Jws2Discoverer.Jws2Instance sh, Preset preset, + public MsaWSClient(Jws2Discoverer.Jws2Instance sh, WsParamSetI preset, String altitle, jalview.datamodel.AlignmentView msa, boolean submitGaps, boolean preserveOrder, Alignment seqdataset, AlignFrame _alignFrame) @@ -86,7 +90,7 @@ public class MsaWSClient extends Jws2Client * DOCUMENT ME! */ - public MsaWSClient(Jws2Discoverer.Jws2Instance sh, Preset preset, + public MsaWSClient(Jws2Discoverer.Jws2Instance sh, WsParamSetI preset, List arguments, boolean editParams, String altitle, jalview.datamodel.AlignmentView msa, boolean submitGaps, boolean preserveOrder, Alignment seqdataset, @@ -108,19 +112,48 @@ public class MsaWSClient extends Jws2Client return; } server = sh.service; - this.preset = preset; + if (preset!=null) { + if (preset instanceof JabaPreset){ + this.preset = ((JabaPreset)preset).p; + } else + if (preset instanceof JabaWsParamSet) { + JabaWsParamSet pset = ((JabaWsParamSet)preset); + if (arguments!=null && arguments.size()>0) + { + // merge arguments with preset's own arguments. + List oldargs = arguments; + arguments = new ArrayList(); + for (Option opt : pset.getjabaArguments()) { + arguments.add(opt); + } + for (Argument opt: oldargs) + { + arguments.add(opt); + } + } + + }else{ + throw new Error("Implementation error: Can only instantiate Jaba parameter sets."); + } + } this.paramset = arguments; if (editParams) { + if (sh.paramStore==null) + { + sh.paramStore = new JabaParamStore(sh); + } WsJobParameters jobParams = new WsJobParameters(sh, preset); if (!jobParams.showRunDialog()) { return; } - if ((this.preset = jobParams.getPreset())==null) + WsParamSetI prset = jobParams.getPreset(); + if (prset==null) { - paramset = jobParams.getJobParams(); + paramset = JabaParamStore.getJabafromJwsArgs(jobParams.getJobParams()); } else { + this.preset = ((JabaPreset)prset).p; paramset = null; // no user supplied parameters. } } @@ -215,7 +248,7 @@ public class MsaWSClient extends Jws2Client String svcname = WebServiceName; if (svcname.endsWith("WS")) { - svcname = svcname.substring(0,svcname.length()-2); + svcname = svcname.substring(0, svcname.length() - 2); } String calcName = svcname + " "; if (canSubmitGaps()) @@ -263,15 +296,18 @@ public class MsaWSClient extends Jws2Client } }); msawsmenu.add(method); - PresetManager presets = service.getPresets(); - if (presets != null && presets.getPresets().size() > 0) + List presets = service.getParamStore().getPresets(); + if (presets != null && presets.size() > 0) { JMenu presetlist = new JMenu(calcName + "Presets"); - for (final Preset preset : (List) presets.getPresets()) + for (final WsParamSetI preset : presets) { final JMenuItem methodR = new JMenuItem(preset.getName()); - methodR.setToolTipText("

"+preset.getDescription()+"

"); + methodR.setToolTipText("

" + + (preset.isModifiable() ? "User Preset" + : "Service Preset") + "
" + + preset.getDescription() + "

"); methodR.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) diff --git a/src/jalview/ws/jws2/MsaWSThread.java b/src/jalview/ws/jws2/MsaWSThread.java index 686f516..dabe368 100644 --- a/src/jalview/ws/jws2/MsaWSThread.java +++ b/src/jalview/ws/jws2/MsaWSThread.java @@ -456,9 +456,11 @@ class MsaWSThread extends AWS2Thread implements WSClientI { boolean cancelledJob = server .cancelJob(jobs[job].getJobId()); - if (cancelledJob) + if (cancelledJob || true) { // CANCELLED_JOB + // if the Jaba server indicates the job can't be cancelled, its because its running on the server's local execution engine + // so we just close the window anyway. cancelledMessage = "Job cancelled."; ((MsaWSJob) jobs[job]).cancel(); // TODO: refactor to avoid this ugliness - wsInfo.setStatus(jobs[job].getJobnum(), -- 1.7.10.2