import jalview.datamodel.*;
import jalview.io.*;
import jalview.schemes.*;
+import jalview.util.UrlLink;
/**
* DOCUMENT ME!
if (links != null && links.size() > 0)
{
JMenu linkMenu = new JMenu("Link");
- JMenuItem item;
+
for (int i = 0; i < links.size(); i++)
{
String link = links.elementAt(i).toString();
- final String label = link.substring(0, link.indexOf("|"));
- item = new JMenuItem(label);
- final String url;
-
- if (link.indexOf("$SEQUENCE_ID$") > -1)
+ UrlLink urlLink = null;
+ try {
+ urlLink = new UrlLink(link);
+ } catch (Exception foo) {
+ jalview.bin.Cache.log.error("Exception for URLLink '"+link+"'",foo);
+ continue;
+ };
+ if (!urlLink.isValid())
{
- String id = seq.getName();
- if (id.indexOf("|") > -1)
- {
- id = id.substring(id.lastIndexOf("|") + 1);
- }
-
- url = link.substring(link.indexOf("|") + 1,
- link.indexOf("$SEQUENCE_ID$"))
- + id +
- link.substring(link.indexOf("$SEQUENCE_ID$") + 13);
+ jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
+ continue;
}
- else
+ final String label = urlLink.getLabel();
+ if (urlLink.isDynamic())
{
- url = link.substring(link.lastIndexOf("|") + 1);
- }
- item.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(ActionEvent e)
+ // collect matching db-refs
+ DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(seq.getDBRef(), new String[]{urlLink.getTarget()});
+ // collect id string too
+ String id = seq.getName();
+ if (dbr!=null)
{
- showLink(url);
+ for (int r=0;r<dbr.length; r++)
+ {
+ if (id!=null && dbr[r].getAccessionId().equals(id))
+ {
+ // suppress duplicate link creation for the bare sequence ID string with this link
+ id = null;
+ }
+ // create Bare ID link for this RUL
+ String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(), true);
+ if (urls!=null)
+ {
+ for (int u=0; u<urls.length; u+=2)
+ {
+ addshowLink(linkMenu, label+"|"+urls[u],urls[u+1]);
+ }
+ }
+ }
}
- });
-
- linkMenu.add(item);
+ if (id!=null)
+ {
+ // create Bare ID link for this RUL
+ String[] urls = urlLink.makeUrls(id, true);
+ if (urls!=null)
+ {
+ for (int u=0; u<urls.length; u+=2)
+ {
+ addshowLink(linkMenu, label, urls[u+1]);
+ }
+ }
+ }
+ } else
+ {
+ // Add a non-dynamic link
+ addshowLink(linkMenu, label, urlLink.getUrl_prefix());
+ }
}
if (sequence != null)
{
}
/**
+ * add a show URL menu item to the given linkMenu
+ * @param linkMenu
+ * @param label - menu label string
+ * @param url - url to open
+ */
+ private void addshowLink(JMenu linkMenu, String label, final String url)
+ {
+ JMenuItem item = new JMenuItem(label);
+ item.setToolTipText("open URL: "+url);
+ item.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ new Thread(new Runnable() {
+
+ public void run()
+ {
+ showLink(url);
+ }
+
+ }).start();
+ }
+ });
+
+ linkMenu.add(item);
+ }
+
+ /**
* DOCUMENT ME!
*
* @throws Exception DOCUMENT ME!
String[] omitHidden = null;
- if (ap.av.hasHiddenColumns)
- {
- System.out.println("PROMPT USER HERE");
- omitHidden = ap.av.getViewAsString(true);
+ System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens or we simply trust the user wants wysiwig behaviour
+ SequenceGroup sg = ap.av.getSelectionGroup();
+ ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
+ omitHidden = ap.av.getViewAsString(true);
+ Alignment oal = new Alignment(ap.av.getSequenceSelection());
+ AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
+ for (int i=0; i<nala.length; i++)
+ {
+ AlignmentAnnotation na =nala[i];
+ oal.addAnnotation(na);
}
-
cap.setText(new FormatAdapter().formatSequences(
- e.getActionCommand(),
- ap.av.getSelectionAsNewSequence(),
- omitHidden));
+ e.getActionCommand(),
+ oal,
+ omitHidden, csel, sg));
+ oal=null;
}
public void pdbFromFile_actionPerformed()
public void discoverPDB_actionPerformed()
{
- SequenceI[] sequences =
- ap.av.selectionGroup == null ?
- new Sequence[]{sequence}
- : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment);
-
- new jalview.ws.DBRefFetcher(sequences,
- ap.alignFrame).fetchDBRefs(false);
+
+ final SequenceI[] sequences =
+ ((ap.av.selectionGroup == null)
+ ? new Sequence[]{sequence}
+ : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment));
+ Thread discpdb = new Thread(new Runnable() {
+ public void run()
+ {
+
+ new jalview.ws.DBRefFetcher(sequences,
+ ap.alignFrame).fetchDBRefs(false);
+ }
+
+ });
+ discpdb.start();
}
public void sequenceFeature_actionPerformed()