X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fjws2%2FSequenceAnnotationWSClient.java;h=fb5f8233650753d2b2dcbfdd97ce25bb79757f8c;hb=b2f9a8d7bce642ff4011bc6d49e02bb0569fbb11;hp=d72681df9da50a17efc4fc1a1cb3fcfadc167b16;hpb=9975647d6dbd89ecc08d3f6dab4adefc71afc297;p=jalview.git diff --git a/src/jalview/ws/jws2/SequenceAnnotationWSClient.java b/src/jalview/ws/jws2/SequenceAnnotationWSClient.java index d72681d..fb5f823 100644 --- a/src/jalview/ws/jws2/SequenceAnnotationWSClient.java +++ b/src/jalview/ws/jws2/SequenceAnnotationWSClient.java @@ -1,8 +1,34 @@ -/** +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1) + * Copyright (C) 2014 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.util.MessageManager; +import jalview.ws.jws2.dm.AAConSettings; +import jalview.ws.jws2.jabaws2.Jws2Instance; +import jalview.ws.params.WsParamSetI; +import jalview.ws.uimodel.AlignAnalysisUIText; + import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; @@ -11,33 +37,15 @@ import javax.swing.JCheckBoxMenuItem; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JOptionPane; -import javax.swing.event.AncestorEvent; -import javax.swing.event.AncestorListener; import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; -import compbio.metadata.Argument; - -import jalview.api.AlignCalcWorkerI; -import jalview.bin.Cache; -import jalview.datamodel.AlignmentView; -import jalview.gui.AlignFrame; -import jalview.gui.Desktop; -import jalview.gui.JalviewDialog; -import jalview.gui.JvSwingUtils; -import jalview.ws.jws2.dm.AAConsSettings; -import jalview.ws.jws2.jabaws2.Jws2Instance; -import jalview.ws.params.WsParamSetI; - /** - * @author jprocter + * @author jprocter * */ -public class SequenceAnnotationWSClient extends Jws2Client +public class SequenceAnnotationWSClient extends Jws2Client { - - public static final String AAConsCalcId = "jabaws2.AACons"; - /** * initialise a client so its attachWSMenuEntry method can be called. */ @@ -53,44 +61,59 @@ public class SequenceAnnotationWSClient extends Jws2Client initSequenceAnnotationWSClient(sh, alignFrame, preset, editParams); } + // dan think. Do I need to change this method to run RNAalifold through the GUI + public void initSequenceAnnotationWSClient(final Jws2Instance sh, AlignFrame alignFrame, WsParamSetI preset, boolean editParams) { - if (alignFrame.getViewport().getAlignment().isNucleotide()) - { - JOptionPane.showMessageDialog(Desktop.desktop, sh.serviceType - + " can only be used\nfor amino acid alignments.", - "Wrong type of sequences!", JOptionPane.WARNING_MESSAGE); - return; - - } - if (sh.action.toLowerCase().contains("conservation")) + // dan changed! dan test. comment out if conditional +// if (alignFrame.getViewport().getAlignment().isNucleotide()) +// { +// JOptionPane.showMessageDialog(Desktop.desktop, sh.serviceType +// + " can only be used\nfor amino acid alignments.", +// "Wrong type of sequences!", JOptionPane.WARNING_MESSAGE); +// return; +// +// } + AlignAnalysisUIText aaui = sh.getAlignAnalysisUI(); + if (aaui!=null) { - // Build an AACons style client - take alignment, return annotation for + Class clientClass = aaui.getClient(); + + // Build an AACon style client - take alignment, return annotation for // columns List clnts = alignFrame.getViewport() .getCalcManager() - .getRegisteredWorkersOfClass(AAConsClient.class); + .getRegisteredWorkersOfClass(clientClass); + JabawsAlignCalcWorker worker; if (clnts == null || clnts.size() == 0) { if (!processParams(sh, editParams)) { return; } - AAConsClient worker; + try { + worker = (JabawsAlignCalcWorker) (clientClass.getConstructor( + new Class[] { Jws2Instance.class, + AlignFrame.class, WsParamSetI.class, + List.class }).newInstance(new Object[] { sh, alignFrame, this.preset, paramset})); + } catch (Exception x) + { + x.printStackTrace(); + throw new Error("Implementation error",x); + } alignFrame .getViewport() .getCalcManager() .registerWorker( - worker = new AAConsClient(sh, alignFrame, - this.preset, paramset)); + worker); alignFrame.getViewport().getCalcManager().startWorker(worker); } else { - AAConsClient worker = (AAConsClient) clnts.get(0); + worker = (JabawsAlignCalcWorker) clnts.get(0); if (editParams) { paramset = worker.getArguments(); @@ -105,7 +128,6 @@ public class SequenceAnnotationWSClient extends Jws2Client // invalid parameters) alignFrame.getViewport().getCalcManager().workerMayRun(worker); worker.updateParameters(this.preset, paramset); - } } if (sh.action.toLowerCase().contains("disorder")) @@ -123,10 +145,9 @@ public class SequenceAnnotationWSClient extends Jws2Client .startWorker( new AADisorderClient(sh, alignFrame, preset, paramset)); } - } - public SequenceAnnotationWSClient(AAConsSettings fave, + public SequenceAnnotationWSClient(AAConSettings fave, AlignFrame alignFrame, boolean b) { super(alignFrame, fave.getPreset(), fave.getJobArgset()); @@ -143,10 +164,8 @@ public class SequenceAnnotationWSClient extends Jws2Client public void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service, final AlignFrame alignFrame) { - if (service.serviceType.equals(compbio.ws.client.Services.AAConWS - .toString())) - { - registerAAConsWSInstance(wsmenu, service, alignFrame); + if (registerAAConWSInstance(wsmenu, service, alignFrame)) { + // Alignment dependent analysis calculation WS gui return; } boolean hasparams = service.hasParameters(); @@ -154,8 +173,8 @@ public class SequenceAnnotationWSClient extends Jws2Client String calcName = service.serviceType.substring(0, service.serviceType.length() - 2); - JMenuItem aacons = new JMenuItem(calcName + " Defaults"); - aacons.addActionListener(new ActionListener() + JMenuItem annotservice = new JMenuItem(MessageManager.formatMessage("label.calcname_with_default_settings", new String[]{calcName})); + annotservice.addActionListener(new ActionListener() { @Override @@ -164,22 +183,23 @@ public class SequenceAnnotationWSClient extends Jws2Client new SequenceAnnotationWSClient(service, alignFrame, null, false); } }); - wsmenu.add(aacons); + wsmenu.add(annotservice); if (hasparams) { // only add these menu options if the service has user-modifiable // arguments - aacons = new JMenuItem("Edit settings and run ..."); - aacons.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")); - aacons.addActionListener(new ActionListener() + annotservice.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new SequenceAnnotationWSClient(service, alignFrame, null, true); } }); - wsmenu.add(aacons); + wsmenu.add(annotservice); List presets = service.getParamStore().getPresets(); if (presets != null && presets.size() > 0) { @@ -208,177 +228,209 @@ public class SequenceAnnotationWSClient extends Jws2Client } } - } + else + { + annotservice = new JMenuItem(MessageManager.getString("label.view_documentation")); + if (service.docUrl != null) + { + annotservice.addActionListener(new ActionListener() + { - private final String AAconsToggle = "AACons Calculations", - AAconsToggleTooltip = "When checked, AACons calculations are updated automatically.", - AAeditSettings = "Change AACons Settings...", - AAeditSettingsTooltip = "Modify settings for AACons calculations."; + @Override + public void actionPerformed(ActionEvent arg0) + { + Desktop.instance.showUrl(service.docUrl); + } + }); + annotservice.setToolTipText("" + + JvSwingUtils.wrapTooltip("View " + service.docUrl + "") + + ""); + wsmenu.add(annotservice); + } + } + } - // private final enableAAConsCalculation(final AlignFrame alignFrame, ) - private void registerAAConsWSInstance(final JMenu wsmenu, + + private boolean registerAAConWSInstance(final JMenu wsmenu, final Jws2Instance service, final AlignFrame alignFrame) { - // register this in the AACons settings set - JCheckBoxMenuItem _aaConsEnabled = null; + final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString()); + if (aaui==null) + { + // not an instantaneous calculation GUI type service + return false; + } + // create the instaneous calculation GUI bits and update state if existing GUI elements already present + + JCheckBoxMenuItem _aaConEnabled = null; for (int i = 0; i < wsmenu.getItemCount(); i++) { JMenuItem item = wsmenu.getItem(i); if (item instanceof JCheckBoxMenuItem - && item.getText().equals(AAconsToggle)) + && item.getText().equals(aaui.getAAconToggle())) { - _aaConsEnabled = (JCheckBoxMenuItem) item; + _aaConEnabled = (JCheckBoxMenuItem) item; } } - // is there an aaCons worker already present - if so, set it to use the + // is there an aaCon worker already present - if so, set it to use the // given service handle { - List aaconsClient = alignFrame.getViewport() + List aaconClient = alignFrame.getViewport() .getCalcManager() - .getRegisteredWorkersOfClass(AAConsClient.class); - if (aaconsClient != null && aaconsClient.size() > 0) + .getRegisteredWorkersOfClass(aaui.getClient()); + if (aaconClient != null && aaconClient.size() > 0) { - AAConsClient worker = (AAConsClient) aaconsClient.get(0); + JabawsAlignCalcWorker worker = (JabawsAlignCalcWorker) aaconClient.get(0); if (!worker.service.hosturl.equals(service.hosturl)) { - // javax.swing.SwingUtilities.invokeLater(new Runnable() + // javax.swing.SwingUtilities.invokeLater(new Runnable() { - // @Override - // public void run() + // @Override + // public void run() { - removeCurrentAAConsWorkerFor(alignFrame); - buildCurrentAAConsWorkerFor(alignFrame, service); + removeCurrentAAConWorkerFor(aaui, alignFrame); + buildCurrentAAConWorkerFor(aaui, alignFrame, service); } - }//); + }// ); } } } // is there a service already registered ? there shouldn't be if we are // being called correctly - if (_aaConsEnabled == null) + if (_aaConEnabled == null) { - final JCheckBoxMenuItem aaConsEnabled = new JCheckBoxMenuItem( - AAconsToggle); - wsmenu.addMenuListener(new MenuListener() - { + final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem( + aaui.getAAconToggle()); + aaConEnabled.setToolTipText("

" + + JvSwingUtils.wrapTooltip(aaui.getAAconToggleTooltip() + "

") + + ""); + aaConEnabled.addActionListener(new ActionListener() + { @Override - public void menuSelected(MenuEvent arg0) + public void actionPerformed(ActionEvent arg0) { - wsmenu.setEnabled(!alignFrame.getViewport().getAlignment() - .isNucleotide()); - List aaconsClient = alignFrame.getViewport() + List aaconClient = alignFrame.getViewport() .getCalcManager() - .getRegisteredWorkersOfClass(AAConsClient.class); - if (aaconsClient != null && aaconsClient.size() > 0) + .getRegisteredWorkersOfClass(aaui.getClient()); + if (aaconClient != null && aaconClient.size() > 0) { - aaConsEnabled.setSelected(true); + removeCurrentAAConWorkerFor(aaui, alignFrame); } else { - aaConsEnabled.setSelected(false); + buildCurrentAAConWorkerFor(aaui, alignFrame); + } } - @Override - public void menuDeselected(MenuEvent arg0) - { - // TODO Auto-generated method stub - - } + }); + wsmenu.add(aaConEnabled); + final JMenuItem modifyParams = new JMenuItem(aaui.getAAeditSettings()); + modifyParams.setToolTipText("

" + + JvSwingUtils.wrapTooltip(aaui.getAAeditSettingsTooltip() + "

") + + ""); + modifyParams.addActionListener(new ActionListener() + { @Override - public void menuCanceled(MenuEvent arg0) + public void actionPerformed(ActionEvent arg0) { - // TODO Auto-generated method stub - + showAAConAnnotationSettingsFor(aaui, alignFrame); } }); - aaConsEnabled.setToolTipText("

" - + JvSwingUtils.wrapTooltip(AAconsToggleTooltip + "

") - + ""); - aaConsEnabled.addActionListener(new ActionListener() + wsmenu.add(modifyParams); + wsmenu.addMenuListener(new MenuListener() { + @Override - public void actionPerformed(ActionEvent arg0) + public void menuSelected(MenuEvent arg0) { - // aaConsEnabled.setSelected(!aaConsEnabled.isSelected()); - List aaconsClient = alignFrame.getViewport() + // TODO: refactor to the implementing class. + if (alignFrame.getViewport().getAlignment() + .isNucleotide() ? aaui.isNa() : aaui.isPr()) { + aaConEnabled.setEnabled(true); + modifyParams.setEnabled(true); + } + else { + aaConEnabled.setEnabled(false); + modifyParams.setEnabled(false); + } + List aaconClient = alignFrame.getViewport() .getCalcManager() - .getRegisteredWorkersOfClass(AAConsClient.class); - if (aaconsClient != null && aaconsClient.size() > 0) + .getRegisteredWorkersOfClass(aaui.getClient()); + if (aaconClient != null && aaconClient.size() > 0) { - removeCurrentAAConsWorkerFor(alignFrame); + aaConEnabled.setSelected(true); } else { - buildCurrentAAConsWorkerFor(alignFrame); - + aaConEnabled.setSelected(false); } } - }); - wsmenu.add(aaConsEnabled); - JMenuItem modifyParams = new JMenuItem(AAeditSettings); - modifyParams.setToolTipText("

" - + JvSwingUtils.wrapTooltip(AAeditSettingsTooltip + "

") - + ""); - modifyParams.addActionListener(new ActionListener() - { + @Override + public void menuDeselected(MenuEvent arg0) + { + // TODO Auto-generated method stub + + } @Override - public void actionPerformed(ActionEvent arg0) + public void menuCanceled(MenuEvent arg0) { - showAAConsAnnotationSettingsFor(alignFrame); + // TODO Auto-generated method stub + } }); - wsmenu.add(modifyParams); } + return true; } - private static void showAAConsAnnotationSettingsFor(AlignFrame alignFrame) + private static void showAAConAnnotationSettingsFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame) { /* - * preferred settings Whether AACons is automatically recalculated Which - * AACons server to use What parameters to use + * 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 - AAConsSettings fave = (AAConsSettings) alignFrame.getViewport() - .getCalcIdSettingsFor(AAConsCalcId); + AAConSettings fave = (AAConSettings) alignFrame.getViewport() + .getCalcIdSettingsFor(aaui.getCalcId()); if (fave == null) { - fave = createDefaultAAConsSettings(); + fave = createDefaultAAConSettings(aaui); } new SequenceAnnotationWSClient(fave, alignFrame, true); } - private static void buildCurrentAAConsWorkerFor(AlignFrame alignFrame) + private static void buildCurrentAAConWorkerFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame) { - buildCurrentAAConsWorkerFor(alignFrame, null); + buildCurrentAAConWorkerFor(aaui, alignFrame, null); } - private static void buildCurrentAAConsWorkerFor(AlignFrame alignFrame, + private static void buildCurrentAAConWorkerFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame, Jws2Instance service) { /* - * preferred settings Whether AACons is automatically recalculated Which - * AACons server to use What parameters to use + * preferred settings Whether AACon is automatically recalculated Which + * AACon server to use What parameters to use */ - AAConsSettings fave = (AAConsSettings) alignFrame.getViewport() - .getCalcIdSettingsFor(AAConsCalcId); + AAConSettings fave = (AAConSettings) alignFrame.getViewport() + .getCalcIdSettingsFor(aaui.getCalcId()); if (fave == null) { - fave = createDefaultAAConsSettings(service); + fave = createDefaultAAConSettings(aaui, service); } else { if (service != null && !fave.getService().hosturl.equals(service.hosturl)) { - Cache.log.debug("Changing AACons service to " + service.hosturl + Cache.log.debug("Changing AACon service to " + service.hosturl + " from " + fave.getService().hosturl); fave.setService(service); } @@ -386,12 +438,12 @@ public class SequenceAnnotationWSClient extends Jws2Client new SequenceAnnotationWSClient(fave, alignFrame, false); } - private static AAConsSettings createDefaultAAConsSettings() + private static AAConSettings createDefaultAAConSettings(AlignAnalysisUIText aaui) { - return createDefaultAAConsSettings(null); + return createDefaultAAConSettings(aaui, null); } - private static AAConsSettings createDefaultAAConsSettings( + private static AAConSettings createDefaultAAConSettings(AlignAnalysisUIText aaui, Jws2Instance service) { if (service != null) @@ -400,7 +452,7 @@ public class SequenceAnnotationWSClient extends Jws2Client compbio.ws.client.Services.AAConWS.toString())) { Cache.log - .warn("Ignoring invalid preferred service for AACons calculations (service type was " + .warn("Ignoring invalid preferred service for AACon calculations (service type was " + service.serviceType + ")"); service = null; } @@ -417,30 +469,22 @@ public class SequenceAnnotationWSClient extends Jws2Client } if (service == null) { - // get the default service for AACons + // get the default service for AACon service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null, - compbio.ws.client.Services.AAConWS.toString()); - /* - * for (Jws2Instance sv : Jws2Discoverer.getDiscoverer().getServices()) { - * if (sv.serviceType.toString().equals( - * compbio.ws.client.Services.AAConWS.toString())) { service = sv; break; - * } } - */ + aaui.getServiceType()); } if (service == null) { // TODO raise dialog box explaining error, and/or open the JABA // preferences menu. - throw new Error("No AACons service found."); + throw new Error("No AACon service found."); } - return new AAConsSettings(true, service, null, null); + return new AAConSettings(true, service, null, null); } - private static void removeCurrentAAConsWorkerFor(AlignFrame alignFrame) + private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui, AlignFrame alignFrame) { alignFrame.getViewport().getCalcManager() - .removeRegisteredWorkersOfClass(AAConsClient.class); - // AAConsClient.removeAAConsAnnotation(alignFrame.alignPanel); - + .removeRegisteredWorkersOfClass(aaui.getClient()); } }