return;
}
- // DEFAULT LINK IS FIRST IN THE LINK LIST
+ // get the sequence details
int seq = alignPanel.seqPanel.findSeq(e);
SequenceI sq = av.getAlignment().getSequenceAt(seq);
if (sq == null)
return;
}
String id = sq.getName();
+
+ // get the default url with the sequence details filled in
String url = urlProvider.getDefaultUrl(id);
String target = urlProvider.getDefaultTarget(id);
-
- /* String target = null;
- String url = null;
- int i = 0;
- while (url == null && i < links.size())
- {
- // DEFAULT LINK IS FIRST IN THE LINK LIST
- // BUT IF ITS A REGEX AND DOES NOT MATCH THE NEXT ONE WILL BE TRIED
- url = links.elementAt(i++).toString();
- jalview.util.UrlLink urlLink = null;
- try
- {
- urlLink = new UrlLink(url);
- target = urlLink.getTarget();
- } catch (Exception foo)
- {
- System.err.println("Exception for URLLink '" + url + "'");
- foo.printStackTrace();
- url = null;
- continue;
- }
-
- if (urlLink.usesDBAccession())
- {
- // this URL requires an accession id, not the name of a sequence
- url = null;
- continue;
- }
-
- if (!urlLink.isValid())
- {
- System.err.println(urlLink.getInvalidMessage());
- url = null;
- continue;
- }
-
- String urls[] = urlLink.makeUrls(id, true);
- if (urls == null || urls[0] == null || urls[0].length() < 1)
- {
- url = null;
- continue;
- }
- // just take first URL made from regex
- url = urls[1];
- }*/
try
{
alignPanel.alignFrame.showURL(url, target);
// build a new links menu based on the current links + any non-positional
// features
- Vector<String> nlinks = urlProvider.getLinksForDisplay();
+ Vector<String> nlinks = urlProvider.getLinksForMenu();
SequenceFeature sf[] = sq == null ? null : sq.getSequenceFeatures();
for (int sl = 0; sf != null && sl < sf.length; sl++)
import jalview.jbgui.GSplitFrame;
import jalview.jbgui.GStructureViewer;
import jalview.structure.StructureSelectionManager;
-import jalview.urls.UrlProviderI;
import jalview.util.ImageMaker;
import jalview.util.MessageManager;
import jalview.util.Platform;
+import jalview.util.UrlConstants;
import jalview.viewmodel.AlignmentViewport;
import jalview.ws.params.ParamManager;
// check what the actual links are - if it's just the default don't
// bother with the warning
Vector<String> links = Preferences.sequenceUrlLinks
- .getLinksForDisplay();
+ .getLinksForMenu();
// only need to check links if there is one with a
// SEQUENCE_ID which is not the default EMBL_EBI link
{
String link = li.next();
if (link.contains(SEQUENCE_ID)
- && !link.equals(UrlProviderI.DEFAULT_STRING))
+ && !link.equals(UrlConstants.DEFAULT_STRING))
{
check = true;
int barPos = link.indexOf("|");
Sequence sq = (Sequence) av.getAlignment().getSequenceAt(seq2);
// build a new links menu based on the current links + any non-positional
// features
- Vector<String> nlinks = Preferences.sequenceUrlLinks
- .getLinksForDisplay(); // new
- // Vector<String>(Preferences.sequenceURLLinks);
+ Vector<String> nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
SequenceFeature sfs[] = sq == null ? null : sq.getSequenceFeatures();
if (sfs != null)
{
import jalview.urls.UrlProviderI;
import jalview.util.MessageManager;
import jalview.util.Platform;
+import jalview.util.UrlConstants;
import jalview.ws.sifts.SiftsSettings;
import java.awt.BorderLayout;
static
{
String string = Cache.getDefault("SEQUENCE_LINKS",
- UrlProviderI.DEFAULT_STRING);
- sequenceUrlLinks = new UrlProvider(UrlProviderI.DEFAULT_LABEL, string);
-
- List<String> colNames = new ArrayList<String>();
- // colNames.add("ID");
- // TODO KM add to properties file
- colNames.add("URL");
- colNames.add("In Menu");
- colNames.add("Default");
- dataModel = new UrlLinkTableModel(sequenceUrlLinks, colNames, "ID");
+ UrlConstants.DEFAULT_STRING);
+ sequenceUrlLinks = new UrlProvider(UrlConstants.DEFAULT_LABEL, string);
+ dataModel = new UrlLinkTableModel(sequenceUrlLinks);
/**
* TODO: reformulate groupURL encoding so two or more can be stored in the
@Override
public void newLink_actionPerformed(ActionEvent e)
{
-
GSequenceLink link = new GSequenceLink();
boolean valid = false;
while (!valid)
boolean valid = false;
while (!valid)
{
-
if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
MessageManager.getString("label.new_sequence_url_link"),
JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION)
{
if (link.checkValid())
{
-
linkUrlTable.setValueAt(link.getName(), index, 0);
linkUrlTable.setValueAt(link.getURL(), index, 1);
valid = true;
import static jalview.util.UrlConstants.SEQUENCE_ID;
import jalview.util.MessageManager;
+import jalview.util.UrlConstants;
import jalview.util.UrlLink;
import java.util.ArrayList;
*/
public class CustomUrlProvider extends UrlProviderImpl
{
-
- // minimum length of substitution in url link string
- private static final int MIN_SUBST_LENGTH = 4;
-
// Default sequence URL link label for SRS
private static final String SRS_LABEL = "SRS";
if (urls.containsKey(SRS_LABEL))
{
urls.remove(SRS_LABEL);
- urls.put(DEFAULT_LABEL, new UrlLink(DEFAULT_STRING));
+ urls.put(UrlConstants.DEFAULT_LABEL, new UrlLink(UrlConstants.DEFAULT_STRING));
}
}
@Override
- public Vector<String> getLinksForDisplay()
+ public Vector<String> getLinksForMenu()
{
Vector<String> links = new Vector<String>();
Iterator<Map.Entry<String, UrlLink>> it = urls.entrySet().iterator();
}
@Override
- public void setUrlLinks(Vector<String> names, Vector<String> urlstrings)
- {
- HashMap<String, UrlLink> newurls = new HashMap<String, UrlLink>();
-
- // should check that lists are same length but this function is likely
- // to change once the Preferences dialog is rebuilt
-
- for (int i = 0; i < names.size(); ++i)
- {
- // don't allow MIRIAM ids as custom url names (as the links will overwrite
- // each other)
- // unlikely user would try to do this, but...
- if (isMiriamId(names.elementAt(i)))
- {
- throw new IllegalArgumentException(MessageManager.formatMessage(
- "exception.url_cannot_have_miriam_id", names.elementAt(i)));
- }
- // don't allow duplicate key names as entries will be overwritten
- if (newurls.containsKey(names.elementAt(i)))
- {
- throw new IllegalArgumentException(MessageManager.formatMessage(
- "exception.url_cannot_have_duplicate_id",
- names.elementAt(i)));
- }
- newurls.put(names.elementAt(i), new UrlLink(names.elementAt(i) + SEP
- + urlstrings.elementAt(i)));
- }
-
- // don't update until we're sure this set is ok
- urls = newurls;
-
- }
-
- @Override
public void setUrlData(List<UrlLinkDisplay> links)
{
HashMap<String, UrlLink> newurls = new HashMap<String, UrlLink>();
{
// unilaterally set the default id to the EMBL_EBI link
- if (!urls.containsKey(DEFAULT_LABEL))
+ if (!urls.containsKey(UrlConstants.DEFAULT_LABEL))
{
- urls.put(DEFAULT_LABEL, new UrlLink(DEFAULT_STRING));
+ urls.put(UrlConstants.DEFAULT_LABEL, new UrlLink(UrlConstants.DEFAULT_STRING));
}
- defaultUrl = DEFAULT_LABEL;
- return DEFAULT_LABEL;
+ defaultUrl = UrlConstants.DEFAULT_LABEL;
+ return UrlConstants.DEFAULT_LABEL;
}
}
// list of selected urls
private ArrayList<String> selectedUrls;
+ /*
+ * Location of file for identifiers.org download
+ */
+ public static final String ID_ORG_FILE = System.getProperty("user.home")
+ + File.separatorChar + ".jalview_identifiers";
+
public IdentifiersUrlProvider(String cachedUrlList, String idFileName)
{
try
}
@Override
- public String getDefaultUrl()
- {
- return defaultUrl;
- }
-
- @Override
public boolean setDefaultUrl(String id)
{
if (selectedUrls.contains(id))
}
@Override
- public Vector<String> getLinksForDisplay()
+ public Vector<String> getLinksForMenu()
{
Vector<String> links = new Vector<String>();
for (String key : selectedUrls)
@Override
public String getDefaultUrl(String seqid)
{
- return urls.get(defaultUrl).get("url") + "/" + seqid;
+ if (seqid.length() < MIN_SUBST_LENGTH)
+ {
+ return null;
+ }
+ else if (defaultUrl == null)
+ {
+ return null;
+ }
+ else
+ {
+ return urls.get(defaultUrl).get("url") + "/" + seqid;
+ }
}
@Override
}
@Override
- public void setUrlLinks(Vector<String> names, Vector<String> urls)
- {
- // ignores urls, only uses names (as ids)
- checkSelectionMatchesUrls(names);
- }
-
- @Override
public String chooseDefaultUrl()
{
// TODO Auto-generated method stub
package jalview.urls;
-import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
* @param keyColName
* name of column corresponding to keys in baseData
*/
- public UrlLinkTableModel(UrlProviderI baseData,
- List<String> displayColNames,
- String keyColName)
+ public UrlLinkTableModel(UrlProviderI baseData)
{
dataProvider = baseData;
data = baseData.getLinksForTable();
- displayColumns = new ArrayList<String>();
- displayColumns.add(keyColName);
- displayColumns.addAll(displayColNames);
+ displayColumns = baseData.getDisplayColumnNames();
// find the default row
defaultRow = 0;
// Specific reference to custom URL link provider
private UrlProviderI customProvider;
+ // List of columns which this provider will supply
+ private List<String> colNames = new ArrayList<String>();
+
/**
* Construct URL provider from string of cached URLs, and set default URL
*
providers = new ArrayList<UrlProviderI>();
UrlProviderI idProvider = new IdentifiersUrlProvider(cachedUrlList,
- ID_ORG_FILE);
+ IdentifiersUrlProvider.ID_ORG_FILE);
customProvider = new CustomUrlProvider(cachedUrlList);
providers.add(idProvider);
providers.add(customProvider);
+ setUpColumns();
+
// check that the defaultUrl still exists
if (!setDefaultUrl(defaultUrlString))
{
providers = new ArrayList<UrlProviderI>();
UrlProviderI idProvider = new IdentifiersUrlProvider(null,
- ID_ORG_FILE);
+ IdentifiersUrlProvider.ID_ORG_FILE);
customProvider = new CustomUrlProvider(urlList);
providers.add(idProvider);
providers.add(customProvider);
+ setUpColumns();
+
// check that the defaultUrl still exists
if (!setDefaultUrl(defaultUrlString))
{
}
}
- @Override
- public String getDefaultUrl()
+ private void setUpColumns()
{
- String defaultUrl = null;
- for (UrlProviderI p : providers)
- {
- defaultUrl = p.getDefaultUrl();
- if (defaultUrl != null)
- {
- return defaultUrl;
- }
- }
-
- // no provider has a default set, just choose one
- if (defaultUrl == null)
- {
- defaultUrl = chooseDefaultUrl();
- }
- return defaultUrl;
+ colNames.add("Name");
+ colNames.add("URL");
+ colNames.add("In Menu");
+ colNames.add("Default");
+ colNames.add("ID");
}
@Override
}
@Override
- public Vector<String> getLinksForDisplay()
+ public Vector<String> getLinksForMenu()
{
Vector<String> fullLinks = new Vector<String>();
for (UrlProviderI p : providers)
{
- List<String> links = p.getLinksForDisplay();
+ List<String> links = p.getLinksForMenu();
if (links != null)
{
// will obliterate links with same keys from different providers
}
return target;
}
-
- @Override
- public void setUrlLinks(Vector<String> names, Vector<String> urls)
- {
- // only allow custom urls to be updated by user
- customProvider.setUrlLinks(names, urls);
- }
@Override
public String chooseDefaultUrl()
{
return customProvider.isUserEntry(id);
}
+
+ @Override
+ public List<String> getDisplayColumnNames()
+ {
+ return colNames.subList(0, 4);
+ }
}
*/
package jalview.urls;
-import java.io.File;
import java.util.List;
import java.util.Vector;
public interface UrlProviderI
{
- /*
- * Default sequence URL link label for EMBL-EBI search
- */
- public static final String DEFAULT_LABEL = "EMBL-EBI Search";
-
- /*
- * Default sequence URL link string for EMBL-EBI search
- */
- public static final String DEFAULT_STRING = DEFAULT_LABEL
- + "|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$";
-
- /*
- * Location of file for identifiers.org download
- */
- public static final String ID_ORG_FILE = System.getProperty("user.home")
- + File.separatorChar + ".jalview_identifiers";
-
/**
* Get names and urls in as strings for display
*
*/
- Vector<String> getLinksForDisplay();
+ Vector<String> getLinksForMenu();
/**
* Get names and urls as strings for display
void setUrlData(List<UrlLinkDisplay> links);
/**
- * Get the id of the default URL
- *
- * @return id of the default URL
- */
- String getDefaultUrl();
-
- /**
* Get the link for the default URL
*
* @seqid sequence id for which to build link
String writeUrlsAsString();
/**
- * Set URL links from pair of collections
- *
- * @param names
- * @param urls
- */
- void setUrlLinks(Vector<String> names, Vector<String> urls)
- throws IllegalArgumentException;
-
- /**
* Choose the default URL in the event of the selected default being
* unavailable
*
* Determine if id is for a user-defined URL
*/
boolean isUserEntry(String id);
+
+ /**
+ * Get list of column names to display in UI
+ *
+ * @return column names
+ */
+ List<String> getDisplayColumnNames();
}
{
private static final Pattern MIRIAM_PATTERN = Pattern
.compile("^MIR:\\d{8}$");
+
+ // minimum length of substitution in url link string
+ protected static final int MIN_SUBST_LENGTH = 4;
+
protected String defaultUrl;
@Override
- public Vector<String> getLinksForDisplay()
+ public Vector<String> getLinksForMenu()
{
// TODO Auto-generated method stub
return null;
}
@Override
- public String getDefaultUrl()
- {
- return defaultUrl;
- }
-
- @Override
public String getDefaultUrl(String seqid)
{
// TODO Auto-generated method stub
}
@Override
- public void setUrlLinks(Vector<String> names, Vector<String> urls)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
public String chooseDefaultUrl()
{
// TODO Auto-generated method stub
return !isMiriamId(id);
}
+ @Override
+ public List<String> getDisplayColumnNames()
+ {
+ return null;
+ }
+
}
public static final String DELIM = "$";
/*
+ * Default sequence URL link label for EMBL-EBI search
+ */
+ public static final String DEFAULT_LABEL = "EMBL-EBI Search";
+
+ /*
+ * Default sequence URL link string for EMBL-EBI search
+ */
+ public static final String DEFAULT_STRING = DEFAULT_LABEL
+ + "|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$";
+
+ /*
* not instantiable
*/
private UrlConstants()
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
+import jalview.util.UrlConstants;
+
import java.util.Arrays;
import java.util.HashMap;
import java.util.Vector;
"TEST|http://someurl.blah/$DB_ACCESSION$",
"ANOTHER|http://test/t$SEQUENCE_ID$",
"TEST2|http://address/$SEQUENCE_ID$",
- UrlProviderI.DEFAULT_STRING };
+ UrlConstants.DEFAULT_STRING };
private static final Vector<String> displayLinks = new Vector<String>(
Arrays.asList(dlinks));
// default url can be set
assertTrue(customProv.setDefaultUrl("ANOTHER"));
- String result = customProv.getDefaultUrl();
- assertEquals("ANOTHER", result);
+
+ // supplied replacement id must be more than 4 chars
+ String result = customProv.getDefaultUrl("123");
+ assertEquals(null, result);
// default url can be retrieved given a sequence id
result = customProv.getDefaultUrl("seqid");
// if there is no default url it sets the default to null
assertFalse(customProv.setDefaultUrl("No default"));
- result = customProv.getDefaultUrl();
+ result = customProv.getDefaultUrl("testid");
assertEquals(null, result);
// choosing the default picks the DEFAULT_STRING option
customProv.chooseDefaultUrl();
result = customProv.getDefaultUrl("seqid");
assertEquals(
- UrlProviderI.DEFAULT_STRING.split("\\|")[1].split("\\$")[0]
+ UrlConstants.DEFAULT_STRING.split("\\|")[1].split("\\$")[0]
+ "seqid",
result);
}
{
// creation from cached url list works + old links upgraded
UrlProviderI customProv = new CustomUrlProvider(cachedList);
- assertTrue(displayLinks.containsAll(customProv.getLinksForDisplay()));
+ assertTrue(displayLinks.containsAll(customProv.getLinksForMenu()));
// creation from map works + old links upgraded
UrlProviderI customProv2 = new CustomUrlProvider(urlMap);
- assertTrue(displayLinks.containsAll(customProv2.getLinksForDisplay()));
+ assertTrue(displayLinks.containsAll(customProv2.getLinksForMenu()));
// writing url links as a string works
// because UrlProvider does not guarantee order of links, we can't just
// compare the output of writeUrlsAsString to a string, hence the hoops here
String result = customProv.writeUrlsAsString();
UrlProviderI up = new CustomUrlProvider(result);
- assertTrue(displayLinks.containsAll(up.getLinksForDisplay()));
+ assertTrue(displayLinks.containsAll(up.getLinksForMenu()));
result = customProv2.writeUrlsAsString();
UrlProviderI up2 = new CustomUrlProvider(result);
- assertTrue(displayLinks.containsAll(up2.getLinksForDisplay()));
-
- // resetting urls from a pair of lists works
- customProv.setUrlLinks(names, urls);
- assertTrue(displayLinks2.containsAll(customProv.getLinksForDisplay()));
-
- customProv2.setUrlLinks(names, urls);
- assertTrue(displayLinks2.containsAll(customProv2.getLinksForDisplay()));
+ assertTrue(displayLinks.containsAll(up2.getLinksForMenu()));
}
}
+ "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]";
private static final String[] dlinks = {
- "MIR:00000005|http://identifiers.org/uniprot/$DB_ACCESSION$",
- "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$",
- "MIR:00000372|http://identifiers.org/ena.embl/$DB_ACCESSION$"};
+ "UniProt Knowledgebase|http://identifiers.org/uniprot/$DB_ACCESSION$",
+ "InterPro|http://identifiers.org/interpro/$DB_ACCESSION$",
+ "ENA|http://identifiers.org/ena.embl/$DB_ACCESSION$" };
private static final String[] dlinks1 = {
"MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$",
String idList = "MIR:00000005|MIR:00000011|MIR:00000372";
UrlProviderI idProv = new IdentifiersUrlProvider(idList, testfile);
- assertTrue(displayLinks.containsAll(idProv.getLinksForDisplay()));
+ assertTrue(displayLinks.containsAll(idProv.getLinksForMenu()));
// because UrlProvider does not guarantee order of links, we can't just
// compare the output of writeUrlsAsString to a string, hence the hoops here
String result = idProv.writeUrlsAsString();
UrlProviderI up = new IdentifiersUrlProvider(result, testfile);
- assertTrue(displayLinks.containsAll(up.getLinksForDisplay()));
+ assertTrue(displayLinks.containsAll(up.getLinksForMenu()));
}
UrlProviderI idProv = new IdentifiersUrlProvider(idList, testfile);
// initially no default
- assertEquals(null, idProv.getDefaultUrl());
+ assertEquals(null, idProv.getDefaultUrl("seqid"));
// set and then retrieve default
assertTrue(idProv.setDefaultUrl("MIR:00000005"));
- assertEquals("MIR:00000005", idProv.getDefaultUrl());
- assertEquals("http://identifiers.org/uniprot/id",
- idProv.getDefaultUrl("id"));
+ assertEquals("http://identifiers.org/uniprot/seqid",
+ idProv.getDefaultUrl("seqid"));
+
+ // ids less than length 4 return null
+ assertEquals(null,
+ idProv.getDefaultUrl("123"));
// attempt to set bad default
assertFalse(idProv.setDefaultUrl("MIR:00001234"));
// default set to null (as default should have been set elsewhere)
- assertEquals(null, idProv.getDefaultUrl());
+ assertEquals(null, idProv.getDefaultUrl("seqid"));
// chooseDefaultUrl not implemented for IdentifiersUrlProvider
assertEquals(null, idProv.chooseDefaultUrl());
}
-
- /*
- * Test url setting works
- */
- @Test(groups = { "Functional" })
- public void testSetUrlLinks()
- {
- // creation from cached id list
- String idList = "MIR:00000005|MIR:00000011|MIR:00000372";
- UrlProviderI idProv = new IdentifiersUrlProvider(idList, testfile);
-
- // set url links
- String[] ids = { "MIR:00000372", "MIR:00000011" };
- Vector<String> names = new Vector<String>(Arrays.asList(ids));
- Vector<String> urls = null;
- idProv.setUrlLinks(names, urls);
- Vector<String> result = idProv.getLinksForDisplay();
- assertEquals(displayLinks1.size(), result.size());
- assertTrue(displayLinks1.containsAll(result));
-
- //set default url then reset url links, default should be unset if not present
- String[] moreids = { "MIR:00000005", "MIR:00000011" };
- names = new Vector<String>(Arrays.asList(moreids));
- idProv.setDefaultUrl("MIR:00000372");
- idProv.setUrlLinks(names, urls);
- result = idProv.getLinksForDisplay();
- assertEquals(displayLinks2.size(), result.size());
- assertTrue(displayLinks2.containsAll(result));
- assertEquals(null, idProv.getDefaultUrl());
-
- }
}