From 486e70a70e56b8ac23fd191c2ac9f8c7366f4fd7 Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 1 Apr 2010 14:19:25 +0000 Subject: [PATCH] refactored copy of groupURL mechanism into new Envision service discovery class. --- src/jalview/gui/AlignFrame.java | 12 +- src/jalview/gui/IdPanel.java | 2 +- src/jalview/gui/Preferences.java | 10 +- src/jalview/ws/EnfinEnvision2OneWay.java | 462 ++++++++++++++++++++++++++++++ 4 files changed, 482 insertions(+), 4 deletions(-) create mode 100644 src/jalview/ws/EnfinEnvision2OneWay.java diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 1bccb66..5529f2c 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -3778,9 +3778,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, .getServiceClient(sh); impl.attachWSMenuEntry(seqsrchmenu, this); } - // finally, add the whole shebang onto the webservices menu wsmenu.add(seqsrchmenu); } + // finally, add the whole shebang onto the webservices menu resetWebServiceMenu(); for (int i = 0, j = wsmenu.size(); i < j; i++) { @@ -3803,6 +3803,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { webService.removeAll(); build_fetchdbmenu(webService); + build_urlServiceMenu(webService); + } + + /** + * construct any groupURL type service menu entries. + * @param webService + */ + private void build_urlServiceMenu(JMenu webService) + { + jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(webService, this); } /* diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 52ac6ad..6330926 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -330,7 +330,7 @@ public class IdPanel extends JPanel implements MouseListener, jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(alignPanel, sq, - nlinks, new Vector(Preferences.groupURLLinks)); + nlinks, new Vector(Preferences.getGroupURLLinks())); pop.show(this, e.getX(), e.getY()); return; diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 6273fbc..88f438e 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -29,6 +29,7 @@ import jalview.bin.*; import jalview.io.*; import jalview.jbgui.*; import jalview.schemes.*; +import jalview.ws.EnfinEnvision2OneWay; /** * DOCUMENT ME! @@ -84,8 +85,8 @@ public class Preferences extends GPreferences */ groupURLLinks = new Vector(); - groupURLLinks.addElement("UNIPROT|EnVision2|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?tool=Jalview&workflow=Default&datasetName=JalviewIDs$DATASETID$&input=$SEQUENCEIDS$&inputType=0|,"); - groupURLLinks.addElement("Seqs|EnVision2|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?tool=Jalview&workflow=Default&datasetName=JalviewSeqs$DATASETID$&input=$SEQUENCES=/([A-Za-z]+)+/=$&inputType=1|,"); + //groupURLLinks.addElement("UNIPROT|EnVision2|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?tool=Jalview&workflow=Default&datasetName=JalviewIDs$DATASETID$&input=$SEQUENCEIDS$&inputType=0|,"); + //groupURLLinks.addElement("Seqs|EnVision2|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?tool=Jalview&workflow=Default&datasetName=JalviewSeqs$DATASETID$&input=$SEQUENCES=/([A-Za-z]+)+/=$&inputType=1|,"); } @@ -593,4 +594,9 @@ public class Preferences extends GPreferences private void jbInit() throws Exception { } + + public static Collection getGroupURLLinks() + { + return groupURLLinks; + } } diff --git a/src/jalview/ws/EnfinEnvision2OneWay.java b/src/jalview/ws/EnfinEnvision2OneWay.java new file mode 100644 index 0000000..8e596b7 --- /dev/null +++ b/src/jalview/ws/EnfinEnvision2OneWay.java @@ -0,0 +1,462 @@ +/** + * + */ +package jalview.ws; + +import jalview.bin.Cache; +import jalview.datamodel.DBRefEntry; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; +import jalview.gui.AlignFrame; +import jalview.gui.Desktop; +import jalview.util.GroupUrlLink; + +import java.awt.Cursor; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.Hashtable; +import java.util.Vector; + +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.event.MenuEvent; +import javax.swing.event.MenuListener; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * Lightweight runnable to discover dynamic 'one way' group URL services + * @author JimP + * + */ +public class EnfinEnvision2OneWay extends DefaultHandler implements Runnable,WSMenuEntryProviderI +{ + private static EnfinEnvision2OneWay groupURLLinksGatherer=null; + public static EnfinEnvision2OneWay getInstance() { + if (groupURLLinksGatherer==null) { + groupURLLinksGatherer = new EnfinEnvision2OneWay(); + } + return groupURLLinksGatherer; + } + private void waitForCompletion() { + if (groupURLLinksGatherer.isRunning()) + { + // wait around and show a visual delay indicator + Cursor oldCursor = Desktop.instance.getCursor(); + Desktop.instance.setCursor(new Cursor(Cursor.WAIT_CURSOR)); + while (groupURLLinksGatherer.isRunning()) + { + try { + Thread.sleep(100); + } catch (InterruptedException e ){}; + } + Desktop.instance.setCursor(oldCursor); + } + } + public Vector getEnvisionServiceGroupURLS() { + waitForCompletion(); + return groupURLLinks; + } + /** + * indicate if + */ + private static String BACKGROUND="BACKGROUNDPARAM"; + /** + * contains null strings or one of the above constants - indicate if this URL is a special case. + */ + private Vector additionalPar = new Vector(); + /** + * the enfin service URL + */ + private String enfinService=null; + private String description=null; + private String wfname; + /* (non-Javadoc) + * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String) + */ + public void endElement(String uri, String localName, String qName) + throws SAXException + { + +// System.err.println("End element: : '"+uri+" "+localName+" "+qName); + if (qName.equalsIgnoreCase("workflow") && description!=null && description.length()>0) + { + //groupURLLinks.addElement("UNIPROT|EnVision2|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?tool=Jalview&workflow=Default&datasetName=JalviewIDs$DATASETID$&input=$SEQUENCEIDS$&inputType=0|,"); + //groupURLLinks.addElement("Seqs|EnVision2|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?tool=Jalview&workflow=Default&datasetName=JalviewSeqs$DATASETID$&input=$SEQUENCES=/([A-Za-z]+)+/=$&inputType=1|,"); + System.err.println("Adding entry for "+wfname+" "+description); + if (wfname.toLowerCase().indexOf("funcnet")==-1) + { + groupURLdescr.addElement(description); + groupURLdescr.addElement(description); + groupURLLinks.addElement(wfname+"|"+"http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?tool=Jalview&workflow="+wfname+"&datasetName=JalviewSeqs$DATASETID$&input=$SEQUENCEIDS$&inputType=0|,"); // #"+description+"#"); + groupURLLinks.addElement(wfname+"|"+"http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?tool=Jalview&workflow="+wfname+"&datasetName=JalviewSeqs$DATASETID$&input=$SEQUENCES=/([A-Za-z]+)+/=$&inputType=1|,"); // #"+description+"#"); + } + } + } + + /* (non-Javadoc) + * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int) + */ + public void characters(char[] ch, int start, int length) + throws SAXException + { + if (description!=null) { + for (int i=start; iend) + { + continue; + } + // just collect ids from dataset sequence + // TODO: check if IDs collected from selecton group intersects with the current selection, too + SequenceI sqi = seqs[sq]; + while (sqi.getDatasetSequence()!=null) { + sqi = sqi.getDatasetSequence(); } + DBRefEntry[] dbr = sqi.getDBRef(); + if (dbr!=null && dbr.length>0) + { + for (int d=0;d0) + { + groupLinksMenu.add(linkMenus[m]); + } + } + + return groupLinksMenu; + } + return null; + } + + /// end of stuff copied from popupmenu + public void attachWSMenuEntry(final JMenu wsmenu, final AlignFrame alignFrame) + { + final JMenu enfinServiceMenu = new JMenu("Envision 2"); + wsmenu.add(enfinServiceMenu); + enfinServiceMenu.setEnabled(false); + wsmenu.addMenuListener(new MenuListener() + { + // this listener remembers when the menu was first selected, and + // doesn't rebuild the session list until it has been cleared and + // reselected again. + boolean refresh = true; + + public void menuCanceled(MenuEvent e) + { + refresh = true; + } + + public void menuDeselected(MenuEvent e) + { + refresh = true; + } + + public void menuSelected(MenuEvent e) + { + if (refresh) + { + try { + buildGroupLinkMenu(enfinServiceMenu,alignFrame); + } catch (OutOfMemoryError ex) + { + Cache.log.error("Out of memory when calculating the Envision2 links.",ex); + enfinServiceMenu.setEnabled(false); + } + refresh = false; + } + } + }); + + + } + +} -- 1.7.10.2