X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fjws2%2FSequenceAnnotationWSClient.java;h=d57eae40b5d1c38721a3fbaf90204a19cd49f8c0;hb=e1476d3c4ebb1c8f6b3ec7d46bb824b23987960e;hp=e62950383a26c91896310c784c664ddff8056e57;hpb=b2290fc7943376b99d2528c233d941d4394d261b;p=jalview.git diff --git a/src/jalview/ws/jws2/SequenceAnnotationWSClient.java b/src/jalview/ws/jws2/SequenceAnnotationWSClient.java index e629503..d57eae4 100644 --- a/src/jalview/ws/jws2/SequenceAnnotationWSClient.java +++ b/src/jalview/ws/jws2/SequenceAnnotationWSClient.java @@ -1,8 +1,31 @@ -/** +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8) + * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle + * + * 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 . */ 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.ws.params.WsParamSetI; + import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; @@ -11,31 +34,17 @@ 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.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 jimp + * @author jprocter * */ public class SequenceAnnotationWSClient extends Jws2Client { - public static final String AAConsCalcId = "jabaws2.AACons"; + public static final String AAConCalcId = "jabaws2.AACon"; /** * initialise a client so its attachWSMenuEntry method can be called. @@ -51,7 +60,7 @@ public class SequenceAnnotationWSClient extends Jws2Client super(alignFrame, preset, null); initSequenceAnnotationWSClient(sh, alignFrame, preset, editParams); } - + public void initSequenceAnnotationWSClient(final Jws2Instance sh, AlignFrame alignFrame, WsParamSetI preset, boolean editParams) { @@ -65,31 +74,31 @@ public class SequenceAnnotationWSClient extends Jws2Client } if (sh.action.toLowerCase().contains("conservation")) { - // Build an AACons style client - take alignment, return annotation for + // Build an AACon style client - take alignment, return annotation for // columns List clnts = alignFrame.getViewport() .getCalcManager() - .getRegisteredWorkersOfClass(AAConsClient.class); + .getRegisteredWorkersOfClass(AAConClient.class); if (clnts == null || clnts.size() == 0) { if (!processParams(sh, editParams)) { return; } - AAConsClient worker; + AAConClient worker; alignFrame .getViewport() .getCalcManager() .registerWorker( - worker = new AAConsClient(sh, alignFrame, this.preset, - paramset)); + worker = new AAConClient(sh, alignFrame, + this.preset, paramset)); alignFrame.getViewport().getCalcManager().startWorker(worker); } else { - AAConsClient worker = (AAConsClient) clnts.get(0); + AAConClient worker = (AAConClient) clnts.get(0); if (editParams) { paramset = worker.getArguments(); @@ -125,11 +134,12 @@ public class SequenceAnnotationWSClient extends Jws2Client } - public SequenceAnnotationWSClient(AAConsSettings fave, + public SequenceAnnotationWSClient(AAConSettings fave, AlignFrame alignFrame, boolean b) { super(alignFrame, fave.getPreset(), fave.getJobArgset()); - initSequenceAnnotationWSClient(fave.getService(), alignFrame, fave.getPreset(), b); + initSequenceAnnotationWSClient(fave.getService(), alignFrame, + fave.getPreset(), b); } /* @@ -144,7 +154,7 @@ public class SequenceAnnotationWSClient extends Jws2Client if (service.serviceType.equals(compbio.ws.client.Services.AAConWS .toString())) { - registerAAConsWSInstance(wsmenu, service, alignFrame); + registerAAConWSInstance(wsmenu, service, alignFrame); return; } boolean hasparams = service.hasParameters(); @@ -152,8 +162,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(calcName + " Defaults"); + annotservice.addActionListener(new ActionListener() { @Override @@ -162,22 +172,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("Edit settings and run ..."); + annotservice + .setToolTipText("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) { @@ -206,36 +217,78 @@ public class SequenceAnnotationWSClient extends Jws2Client } } - } + else + { + annotservice = new JMenuItem("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 SequenceAnnotationWSClient preferredAAConsClient = null; + 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 final enableAAConsCalculation(final AlignFrame alignFrame, ) - private void registerAAConsWSInstance(final JMenu wsmenu, + private void registerAAConWSInstance(final JMenu wsmenu, final Jws2Instance service, final AlignFrame alignFrame) { - // register this in the AACons settings set - JCheckBoxMenuItem _aaConsEnabled = null; + // 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(AAconsToggle)) + && item.getText().equals(AAconToggle)) { - _aaConsEnabled = (JCheckBoxMenuItem) item; + _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 ? - if (_aaConsEnabled == null) + // is there a service already registered ? there shouldn't be if we are + // being called correctly + if (_aaConEnabled == null) { - final JCheckBoxMenuItem aaConsEnabled = new JCheckBoxMenuItem( - AAconsToggle); + final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem( + AAconToggle); wsmenu.addMenuListener(new MenuListener() { @@ -244,16 +297,16 @@ public class SequenceAnnotationWSClient extends Jws2Client { 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(AAConClient.class); + if (aaconClient != null && aaconClient.size() > 0) { - aaConsEnabled.setSelected(true); + aaConEnabled.setSelected(true); } else { - aaConsEnabled.setSelected(false); + aaConEnabled.setSelected(false); } } @@ -271,31 +324,30 @@ public class SequenceAnnotationWSClient extends Jws2Client } }); - aaConsEnabled.setToolTipText("

" - + JvSwingUtils.wrapTooltip(AAconsToggleTooltip + "

") + aaConEnabled.setToolTipText("

" + + JvSwingUtils.wrapTooltip(AAconToggleTooltip + "

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

" + JvSwingUtils.wrapTooltip(AAeditSettingsTooltip + "

") @@ -306,72 +358,109 @@ public class SequenceAnnotationWSClient extends Jws2Client @Override public void actionPerformed(ActionEvent arg0) { - showAAConsAnnotationSettingsFor(alignFrame); + showAAConAnnotationSettingsFor(alignFrame); } }); wsmenu.add(modifyParams); } - } - private static void showAAConsAnnotationSettingsFor(AlignFrame alignFrame) + private static void showAAConAnnotationSettingsFor(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); - if (fave==null) + AAConSettings fave = (AAConSettings) alignFrame.getViewport() + .getCalcIdSettingsFor(AAConCalcId); + if (fave == null) { - fave = createDefaultAAConsSettings(); + fave = createDefaultAAConSettings(); } new SequenceAnnotationWSClient(fave, alignFrame, true); } - private static void buildCurrentAAConsWorkerFor(AlignFrame alignFrame) + + private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame) + { + buildCurrentAAConWorkerFor(alignFrame, null); + } + + private static void buildCurrentAAConWorkerFor(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); - if (fave==null) + AAConSettings fave = (AAConSettings) alignFrame.getViewport() + .getCalcIdSettingsFor(AAConCalcId); + if (fave == null) { - fave = createDefaultAAConsSettings(); + 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 AAConsSettings createDefaultAAConsSettings() + private static AAConSettings createDefaultAAConSettings() { - Jws2Instance service=null; - // set sensible defaults - for (Jws2Instance sv: Jws2Discoverer.getDiscoverer().getServices()) { - if (sv.serviceType.toString().equals(compbio.ws.client.Services.AAConWS.toString())) + 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 { - service = sv; - break; + // 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) + if (service == null) { - // TODO raise dialog box explaining error, and/or open the JABA preferences menu. - throw new Error("No AACons service found."); + // get the default service for AACon + service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null, + compbio.ws.client.Services.AAConWS.toString()); } - return new AAConsSettings(true, service, null, null); + 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 removeCurrentAAConsWorkerFor(AlignFrame alignFrame) + private static void removeCurrentAAConWorkerFor(AlignFrame alignFrame) { alignFrame.getViewport().getCalcManager() - .removeRegisteredWorkersOfClass(AAConsClient.class); - // AAConsClient.removeAAConsAnnotation(alignFrame.alignPanel); - + .removeRegisteredWorkersOfClass(AAConClient.class); } }