X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fjws2%2FSequenceAnnotationWSClient.java;h=29343f2bf66f7ed6e2c1ad1e6d831a720c938537;hb=c41398473f1493a06f28da53be50630a0f6e6f6d;hp=bf20cd4d0073b1f5bc929ac3c766110e445f5150;hpb=b57a02c25e335d033c97f8a6bacd6b54f62bd2b6;p=jalview.git diff --git a/src/jalview/ws/jws2/SequenceAnnotationWSClient.java b/src/jalview/ws/jws2/SequenceAnnotationWSClient.java index bf20cd4..29343f2 100644 --- a/src/jalview/ws/jws2/SequenceAnnotationWSClient.java +++ b/src/jalview/ws/jws2/SequenceAnnotationWSClient.java @@ -1,27 +1,43 @@ -/** +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.ws.jws2; import jalview.api.AlignCalcWorkerI; -import jalview.bin.Cache; import jalview.gui.AlignFrame; import jalview.gui.Desktop; import jalview.gui.JvSwingUtils; -import jalview.ws.jws2.dm.AAConSettings; -import jalview.ws.jws2.jabaws2.Jws2Instance; +import jalview.util.MessageManager; +import jalview.ws.api.ServiceWithParameters; +import jalview.ws.params.AutoCalcSetting; import jalview.ws.params.WsParamSetI; +import jalview.ws.uimodel.AlignAnalysisUIText; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; +import java.util.Locale; + -import javax.swing.JCheckBoxMenuItem; import javax.swing.JMenu; import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.event.MenuEvent; -import javax.swing.event.MenuListener; /** * @author jprocter @@ -29,9 +45,6 @@ import javax.swing.event.MenuListener; */ public class SequenceAnnotationWSClient extends Jws2Client { - - public static final String AAConCalcId = "jabaws2.AACon"; - /** * initialise a client so its attachWSMenuEntry method can be called. */ @@ -40,90 +53,131 @@ public class SequenceAnnotationWSClient extends Jws2Client // TODO Auto-generated constructor stub } - public SequenceAnnotationWSClient(final Jws2Instance sh, + public SequenceAnnotationWSClient(final ServiceWithParameters sh, AlignFrame alignFrame, WsParamSetI preset, boolean editParams) { super(alignFrame, preset, null); initSequenceAnnotationWSClient(sh, alignFrame, preset, editParams); } - public void initSequenceAnnotationWSClient(final Jws2Instance sh, - AlignFrame alignFrame, WsParamSetI preset, boolean editParams) + // dan think. Do I need to change this method to run RNAalifold through the + // GUI + + private void initSequenceAnnotationWSClient(final ServiceWithParameters sh, + AlignFrame alignFrame, final WsParamSetI preset, boolean editParams) { - if (alignFrame.getViewport().getAlignment().isNucleotide()) + // dan changed! dan test. comment out if conditional + // if (alignFrame.getViewport().getAlignment().isNucleotide()) + // { + // JvOptionPane.showMessageDialog(Desktop.desktop, sh.serviceType + // + " can only be used\nfor amino acid alignments.", + // "Wrong type of sequences!", JvOptionPane.WARNING_MESSAGE); + // return; + // + // } + AlignAnalysisUIText aaui = sh.getAlignAnalysisUI(); + if (aaui != null) { - JOptionPane.showMessageDialog(Desktop.desktop, sh.serviceType - + " can only be used\nfor amino acid alignments.", - "Wrong type of sequences!", JOptionPane.WARNING_MESSAGE); - return; + Class clientClass = aaui.getClient(); - } - if (sh.action.toLowerCase().contains("conservation")) - { // Build an AACon style client - take alignment, return annotation for // columns List clnts = alignFrame.getViewport() - .getCalcManager() - .getRegisteredWorkersOfClass(AAConClient.class); - if (clnts == null || clnts.size() == 0) + .getCalcManager() + .getWorkersOfClass(SeqAnnotationServiceCalcWorker.class); + + SeqAnnotationServiceCalcWorker tmpworker = null; + if (clnts != null) { - if (!processParams(sh, editParams)) + for (AlignCalcWorkerI _worker : clnts) { - return; + tmpworker = (SeqAnnotationServiceCalcWorker) _worker; + if (tmpworker.hasService() + && tmpworker.getService().getClass().equals(clientClass)) + { + break; + } + tmpworker = null; } - AAConClient worker; - alignFrame - .getViewport() - .getCalcManager() - .registerWorker( - worker = new AAConClient(sh, alignFrame, - this.preset, paramset)); - alignFrame.getViewport().getCalcManager().startWorker(worker); + } + final var worker = tmpworker; + if (worker == null) + { + processParams(sh, editParams).thenAccept((startJob) -> { + if (startJob) + { + final SeqAnnotationServiceCalcWorker worker_; + try + { + worker_ = new SeqAnnotationServiceCalcWorker(sh, alignFrame, this.preset, + paramset); + } catch (Exception x) + { + x.printStackTrace(); + throw new Error( + MessageManager.getString("error.implementation_error"), + x); + } + alignFrame.getViewport().getCalcManager().registerWorker(worker_); + // also starts the worker + startSeqAnnotationWorker(sh, alignFrame, preset, editParams); + } + }); } else { - AAConClient worker = (AAConClient) clnts.get(0); + WsParamSetI preset_; if (editParams) { paramset = worker.getArguments(); - preset = worker.getPreset(); + preset_ = worker.getPreset(); } - - if (!processParams(sh, editParams, true)) + else { - return; + preset_ = preset; } - // reinstate worker if it was blacklisted (might have happened due to - // invalid parameters) - alignFrame.getViewport().getCalcManager().workerMayRun(worker); - worker.updateParameters(this.preset, paramset); - + processParams(sh, editParams, true).thenAccept((startJob) -> { + if (startJob) + { + // reinstate worker if it was blacklisted (might have happened due + // to + // invalid parameters) + alignFrame.getViewport().getCalcManager().enableWorker(worker); + worker.updateParameters(this.preset, paramset); + startSeqAnnotationWorker(sh, alignFrame, preset_, editParams); + } + }); } } - if (sh.action.toLowerCase().contains("disorder")) + else + { + startSeqAnnotationWorker(sh, alignFrame, preset, editParams); + } + } + + private void startSeqAnnotationWorker(ServiceWithParameters sh, + AlignFrame alignFrame, WsParamSetI preset, boolean editParams) + { + if (!sh.isInteractiveUpdate()) { // build IUPred style client. take sequences, returns annotation per // sequence. - if (!processParams(sh, editParams)) - { - return; - } - - alignFrame - .getViewport() - .getCalcManager() - .startWorker( - new AADisorderClient(sh, alignFrame, preset, paramset)); + processParams(sh, editParams).thenAccept((startJob) -> { + if (startJob) + { + alignFrame.getViewport().getCalcManager().startWorker( + new SeqAnnotationServiceCalcWorker(sh, alignFrame, preset, paramset)); + } + }); } - } - public SequenceAnnotationWSClient(AAConSettings fave, + public SequenceAnnotationWSClient(AutoCalcSetting fave, AlignFrame alignFrame, boolean b) { - super(alignFrame, fave.getPreset(), fave.getJobArgset()); + super(alignFrame, fave.getPreset(), fave.getArgumentSet()); initSequenceAnnotationWSClient(fave.getService(), alignFrame, fave.getPreset(), b); } @@ -134,28 +188,36 @@ public class SequenceAnnotationWSClient extends Jws2Client * @see jalview.ws.jws2.Jws2Client#attachWSMenuEntry(javax.swing.JMenu, * jalview.ws.jws2.jabaws2.Jws2Instance, jalview.gui.AlignFrame) */ - public void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service, + @Override + public void attachWSMenuEntry(JMenu wsmenu, + final ServiceWithParameters service, final AlignFrame alignFrame) { - if (service.serviceType.equals(compbio.ws.client.Services.AAConWS - .toString())) + if (Jws2ClientFactory.registerAAConWSInstance(wsmenu, + service, alignFrame)) { - registerAAConWSInstance(wsmenu, service, alignFrame); + // Alignment dependent analysis calculation WS gui return; } boolean hasparams = service.hasParameters(); - // Assume name ends in WS - String calcName = service.serviceType.substring(0, - service.serviceType.length() - 2); + String calcName = service.getName(); + if (calcName.endsWith("WS")) + { + // Remove "WS" suffix + calcName = calcName.substring(0, calcName.length() - 2); + } - JMenuItem annotservice = new JMenuItem(calcName + " Defaults"); + JMenuItem annotservice = new JMenuItem(MessageManager.formatMessage( + "label.calcname_with_default_settings", new String[] + { calcName })); annotservice.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - new SequenceAnnotationWSClient(service, alignFrame, null, false); + new SequenceAnnotationWSClient(service, alignFrame, + null, false); } }); wsmenu.add(annotservice); @@ -163,36 +225,44 @@ public class SequenceAnnotationWSClient extends Jws2Client { // only add these menu options if the service has user-modifiable // arguments - annotservice = new JMenuItem("Edit settings and run ..."); - annotservice - .setToolTipText("View and change parameters before running calculation"); + annotservice = new JMenuItem( + MessageManager.getString("label.edit_settings_and_run")); + annotservice.setToolTipText(MessageManager.getString( + "label.view_and_change_parameters_before_running_calculation")); annotservice.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - new SequenceAnnotationWSClient(service, alignFrame, null, true); + new SequenceAnnotationWSClient(service, alignFrame, + null, true); } }); wsmenu.add(annotservice); List presets = service.getParamStore().getPresets(); if (presets != null && presets.size() > 0) { - JMenu presetlist = new JMenu("Run " + calcName + "with preset"); + JMenu presetlist = new JMenu(MessageManager + .formatMessage("label.run_with_preset", new String[] + { calcName })); for (final WsParamSetI preset : presets) { final JMenuItem methodR = new JMenuItem(preset.getName()); - methodR.setToolTipText("

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

") + ""); + methodR.setToolTipText(JvSwingUtils.wrapTooltip(true, "" + + (preset.isModifiable() + ? MessageManager.getString("label.user_preset") + : MessageManager + .getString("label.service_preset")) + + "
" + preset.getDescription())); methodR.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - new SequenceAnnotationWSClient(service, alignFrame, preset, + new SequenceAnnotationWSClient(service, + alignFrame, preset, false); } @@ -205,8 +275,9 @@ public class SequenceAnnotationWSClient extends Jws2Client } else { - annotservice = new JMenuItem("View documentation"); - if (service.docUrl != null) + annotservice = new JMenuItem( + MessageManager.getString("label.view_documentation")); + if (service != null && service.hasDocumentationUrl()) { annotservice.addActionListener(new ActionListener() { @@ -214,239 +285,16 @@ public class SequenceAnnotationWSClient extends Jws2Client @Override public void actionPerformed(ActionEvent arg0) { - Desktop.instance.showUrl(service.docUrl); + Desktop.getInstance().showUrl(service.getDocumentationUrl()); } }); - annotservice.setToolTipText("" - + JvSwingUtils.wrapTooltip("View " + service.docUrl + "") - + ""); + annotservice.setToolTipText( + JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage( + "label.view_service_doc_url", new String[] + { service.getDocumentationUrl(), + service.getDocumentationUrl() }))); wsmenu.add(annotservice); } } } - - private final String AAconToggle = "AACon Calculations", - AAconToggleTooltip = "When checked, AACon calculations are updated automatically.", - AAeditSettings = "Change AACon Settings...", - AAeditSettingsTooltip = "Modify settings for AACon calculations."; - - private void registerAAConWSInstance(final JMenu wsmenu, - final Jws2Instance service, final AlignFrame alignFrame) - { - // register this in the AACon settings set - JCheckBoxMenuItem _aaConEnabled = null; - for (int i = 0; i < wsmenu.getItemCount(); i++) - { - JMenuItem item = wsmenu.getItem(i); - if (item instanceof JCheckBoxMenuItem - && item.getText().equals(AAconToggle)) - { - _aaConEnabled = (JCheckBoxMenuItem) item; - } - } - // is there an aaCon worker already present - if so, set it to use the - // given service handle - { - List aaconClient = alignFrame.getViewport() - .getCalcManager() - .getRegisteredWorkersOfClass(AAConClient.class); - if (aaconClient != null && aaconClient.size() > 0) - { - AAConClient worker = (AAConClient) aaconClient.get(0); - if (!worker.service.hosturl.equals(service.hosturl)) - { - // javax.swing.SwingUtilities.invokeLater(new Runnable() - { - // @Override - // public void run() - { - removeCurrentAAConWorkerFor(alignFrame); - buildCurrentAAConWorkerFor(alignFrame, service); - } - }// ); - } - } - } - - // is there a service already registered ? there shouldn't be if we are - // being called correctly - if (_aaConEnabled == null) - { - final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem( - AAconToggle); - wsmenu.addMenuListener(new MenuListener() - { - - @Override - public void menuSelected(MenuEvent arg0) - { - wsmenu.setEnabled(!alignFrame.getViewport().getAlignment() - .isNucleotide()); - List aaconClient = alignFrame.getViewport() - .getCalcManager() - .getRegisteredWorkersOfClass(AAConClient.class); - if (aaconClient != null && aaconClient.size() > 0) - { - aaConEnabled.setSelected(true); - } - else - { - aaConEnabled.setSelected(false); - } - } - - @Override - public void menuDeselected(MenuEvent arg0) - { - // TODO Auto-generated method stub - - } - - @Override - public void menuCanceled(MenuEvent arg0) - { - // TODO Auto-generated method stub - - } - }); - aaConEnabled.setToolTipText("

" - + JvSwingUtils.wrapTooltip(AAconToggleTooltip + "

") - + ""); - aaConEnabled.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent arg0) - { - List aaconClient = alignFrame.getViewport() - .getCalcManager() - .getRegisteredWorkersOfClass(AAConClient.class); - if (aaconClient != null && aaconClient.size() > 0) - { - removeCurrentAAConWorkerFor(alignFrame); - } - else - { - buildCurrentAAConWorkerFor(alignFrame); - - } - } - - }); - wsmenu.add(aaConEnabled); - JMenuItem modifyParams = new JMenuItem(AAeditSettings); - modifyParams.setToolTipText("

" - + JvSwingUtils.wrapTooltip(AAeditSettingsTooltip + "

") - + ""); - modifyParams.addActionListener(new ActionListener() - { - - @Override - public void actionPerformed(ActionEvent arg0) - { - showAAConAnnotationSettingsFor(alignFrame); - } - }); - wsmenu.add(modifyParams); - - } - } - - private static void showAAConAnnotationSettingsFor(AlignFrame alignFrame) - { - /* - * preferred settings Whether AACon is automatically recalculated Which - * AACon server to use What parameters to use - */ - // could actually do a class search for this too - AAConSettings fave = (AAConSettings) alignFrame.getViewport() - .getCalcIdSettingsFor(AAConCalcId); - if (fave == null) - { - fave = createDefaultAAConSettings(); - } - new SequenceAnnotationWSClient(fave, alignFrame, true); - - } - - private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame) - { - buildCurrentAAConWorkerFor(alignFrame, null); - } - - private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame, - Jws2Instance service) - { - /* - * preferred settings Whether AACon is automatically recalculated Which - * AACon server to use What parameters to use - */ - AAConSettings fave = (AAConSettings) alignFrame.getViewport() - .getCalcIdSettingsFor(AAConCalcId); - if (fave == null) - { - fave = createDefaultAAConSettings(service); - } - else - { - if (service != null - && !fave.getService().hosturl.equals(service.hosturl)) - { - Cache.log.debug("Changing AACon service to " + service.hosturl - + " from " + fave.getService().hosturl); - fave.setService(service); - } - } - new SequenceAnnotationWSClient(fave, alignFrame, false); - } - - private static AAConSettings createDefaultAAConSettings() - { - return createDefaultAAConSettings(null); - } - - private static AAConSettings createDefaultAAConSettings( - Jws2Instance service) - { - if (service != null) - { - if (!service.serviceType.toString().equals( - compbio.ws.client.Services.AAConWS.toString())) - { - Cache.log - .warn("Ignoring invalid preferred service for AACon calculations (service type was " - + service.serviceType + ")"); - service = null; - } - else - { - // check service is actually in the list of currently avaialable - // services - if (!Jws2Discoverer.getDiscoverer().getServices().contains(service)) - { - // it isn't .. - service = null; - } - } - } - if (service == null) - { - // get the default service for AACon - service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null, - compbio.ws.client.Services.AAConWS.toString()); - } - if (service == null) - { - // TODO raise dialog box explaining error, and/or open the JABA - // preferences menu. - throw new Error("No AACon service found."); - } - return new AAConSettings(true, service, null, null); - } - - private static void removeCurrentAAConWorkerFor(AlignFrame alignFrame) - { - alignFrame.getViewport().getCalcManager() - .removeRegisteredWorkersOfClass(AAConClient.class); - } }