import jalview.datamodel.*;
import jalview.io.*;
import jalview.schemes.*;
+import jalview.util.GroupUrlLink;
import jalview.util.UrlLink;
/**
// JMenuItem annotationMenuItem = new JMenuItem();
+ JMenu groupLinksMenu;
+
/**
* Creates a new PopupMenu object.
*
* @param seq
* DOCUMENT ME!
*/
- public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
+ public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
+ {
+ this(ap, seq, links, null);
+ }
+ /**
+ *
+ * @param ap
+ * @param seq
+ * @param links
+ * @param groupLinks
+ */
+ public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links, Vector groupLinks)
{
// /////////////////////////////////////////////////////////
// If this is activated from the sequence panel, the user may want to
showText.setSelected(sg.getDisplayText());
showColourText.setSelected(sg.getColourText());
showBoxes.setSelected(sg.getDisplayBoxes());
+ // add any groupURLs to the groupURL submenu and make it visible
+ if (groupLinks!=null && groupLinks.size()>0) {
+ buildGroupURLMenu(sg, groupLinks);
+ }
}
else
{
if (links != null && links.size() > 0)
{
+
JMenu linkMenu = new JMenu("Link");
Vector linkset = new Vector();
for (int i = 0; i < links.size(); i++)
}
}
}
+
+ private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks)
+ {
+
+ // TODO: usability: thread off the generation of group url content so root menu appears asap
+ // sequence only URLs
+ // ID/regex match URLs
+ groupLinksMenu = new JMenu("Group Link");
+ JMenu[] linkMenus = new JMenu[] { null, new JMenu("IDS"), new JMenu("Sequences"), new JMenu("IDS and Sequences")}; // three types of url that might be created.
+ SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
+ String[][] idandseqs = GroupUrlLink.formStrings(seqs);
+ Hashtable commonDbrefs = new Hashtable();
+ for (int sq = 0; sq<seqs.length;sq++) {
+
+ int start = seqs[sq].findPosition(sg.getStartRes()),end=seqs[sq].findPosition(sg.getEndRes());
+ // 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;d<dbr.length;d++)
+ {
+ String src =dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase();
+ Object[] sarray = (Object[]) commonDbrefs.get(src);
+ if (sarray==null)
+ {
+ sarray = new Object[2];
+ sarray[0] = new int[] { 0 };
+ sarray[1] = new String[seqs.length];
+
+ commonDbrefs.put(src,sarray);
+ }
+
+ if (((String[])sarray[1])[sq]==null) {
+ if (!dbr[d].hasMap() || (dbr[d].getMap().locateMappedRange(start, end)!=null)) {
+ ((String[])sarray[1])[sq] = dbr[d].getAccessionId();
+ ((int[])sarray[0])[0]++;
+ }
+ }
+ }
+ }
+ }
+ // now create group links for all distinct ID/sequence sets.
+ boolean addMenu = false; // indicates if there are any group links to give to user
+ for (int i = 0; i < groupLinks.size(); i++) {
+ String link = groupLinks.elementAt(i).toString();
+ GroupUrlLink urlLink = null;
+ try
+ {
+ urlLink = new GroupUrlLink(link);
+ } catch (Exception foo)
+ {
+ jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link
+ + "'", foo);
+ continue;
+ }
+ ;
+ if (!urlLink.isValid())
+ {
+ jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
+ continue;
+ }
+ final String label = urlLink.getLabel();
+ boolean usingNames = false;
+ // Now see which parts of the group apply for this URL
+ String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget());
+ Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase());
+ String[] seqstr,ids; // input to makeUrl
+ if (idset!=null)
+ {
+ int numinput = ((int[])idset[0])[0];
+ String[] allids = ((String[])idset[1]);
+ seqstr = new String[numinput];
+ ids = new String[numinput];
+ for (int sq=0,idcount=0;sq<seqs.length;sq++)
+ {
+ if (allids[sq]!=null) {
+ ids[idcount] = allids[sq];
+ seqstr[idcount++] = idandseqs[1][sq];
+ }
+ }
+ } else {
+ // just use the id/seq set
+ seqstr = idandseqs[1];
+ ids = idandseqs[0];
+ usingNames=true;
+ }
+ // and try and make the groupURL!
+
+ Object[] urlset = urlLink.makeUrls(ids,seqstr, "FromJalview"+System.currentTimeMillis(),false);
+ if (urlset!=null)
+ {
+ System.out.println(urlLink.getGroupURLType() +" "+((String[])urlset[3])[0]);
+ // first two bits ofurlLink type bitfield are sequenceids and sequences
+ // TODO: FUTURE: ensure the groupURL menu structure can be generalised
+ addshowLink(linkMenus[urlLink.getGroupURLType() & 3], label + "("+(usingNames ? "Names" : ltarget)+")", ((String[])urlset[3])[0]);
+ addMenu = true;
+ }
+ }
+ if (addMenu)
+ {
+ groupLinksMenu = new JMenu("Group Links");
+ for (int m=0;m<linkMenus.length; m++)
+ {
+ if (linkMenus[m]!=null && linkMenus[m].getMenuComponentCount()>0)
+ {
+ groupLinksMenu.add(linkMenus[m]);
+ }
+ }
+
+ groupMenu.add(groupLinksMenu);
+ }
+ }
/**
* add a show URL menu item to the given linkMenu