From 40f8e76e5d28e2c2fe5fddab72fe797a696bed8a Mon Sep 17 00:00:00 2001 From: kiramt Date: Fri, 16 Dec 2016 21:03:35 +0000 Subject: [PATCH] JAL-2316 Added database name column to URL links table in preferences --- help/html/webServices/urllinks.html | 18 +- resources/lang/Messages.properties | 6 +- resources/lang/Messages_es.properties | 6 +- src/jalview/gui/Preferences.java | 18 +- src/jalview/jbgui/GPreferences.java | 306 +++++++++++++++----------- src/jalview/urls/CustomUrlProvider.java | 22 +- src/jalview/urls/IdentifiersUrlProvider.java | 3 +- src/jalview/urls/UrlLinkDisplay.java | 33 ++- src/jalview/urls/UrlLinkTableModel.java | 7 +- src/jalview/util/UrlLink.java | 29 ++- test/jalview/urls/UrlLinkDisplayTest.java | 54 ++++- 11 files changed, 317 insertions(+), 185 deletions(-) diff --git a/help/html/webServices/urllinks.html b/help/html/webServices/urllinks.html index d99633a..0da8a4d 100644 --- a/help/html/webServices/urllinks.html +++ b/help/html/webServices/urllinks.html @@ -27,14 +27,14 @@ Opening URLs from Jalview
Both the applet and the desktop application are able to open URLs as 'popups' in your web browser.
Double-clicking on the ID of a sequence - will open the URL designated for 'popups' in the "Connections" tab of the Jalview desktop preferences. This is by default the EMBL-EBI site, but you can easily configure your own sequence URL links.

- Other links for a sequence either derived from any other configured + Other links for a sequence, either derived from any other configured URL links, or imported from the sequence's annotation, are accessed by right clicking to open the sequence pop-up menu, and selecting from the Links submenu. @@ -48,24 +48,24 @@ parameters.

By default, the list of available links in the preferences dialog box - contains the item "EMBL-EBI Search", - which is set as the URL which opens on double-clicking on a sequence ID, and as a - menu item in the Links menu. This link will show a web page in your default + contains the item "EMBL-EBI Search". + This link is initially configured so that it is the URL which opens on double-clicking on a sequence ID. It is also a + menu item in the "Link" menu. When clicked, this link will show a web page in your default browser with the selected sequence id as part of the URL.
- Also by default, the list of available links contains persistent URLs for many common + Also by default, the list of available links in the preferences dialog box contains persistent URLs for many common bioinformatics databases. These links are downloaded by Jalview from the identifiers.org website, and the names and URLs are not user editable.
- The list of links is sortable, by clicking on the headers of the table. The list + The list of links can be sorted by clicking on the headers of the table. The list can be filtered using the free text search box below the table, or the "Custom Only" button, which displays only user-defined links.

- In the preferences dialog box, the links which appear in the Links menu + In the preferences dialog box, the links which appear in the "Link" menu can be configured by selecting or deselecting links in the "In Menu" column. The names of selected links will be displayed - on new menu items under the "Link" menu when you right + as menu items under the "Link" menu when you right click on a sequence id.
You can configure which link is used when double-clicking on a sequence by selecting or deselecting links in the "On Click" column. Exactly one diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 295dec4..0bac4a6 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1285,8 +1285,10 @@ action.db_acc = $DB_ACCESSION$ label.primary = On Click label.inmenu = In Menu label.id = ID +label.database = Database label.urltooltip = Only one url, which must use a sequence id, can be selected for the 'On Click' option label.edit_sequence_url_link = Edit sequence URL link -warn.name_cannot_be_duplicate = URL names must be unique and cannot be MIRIAM ids +warn.name_cannot_be_duplicate = User-defined URL names must be unique and cannot be MIRIAM ids label.invalid_name = Invalid Name ! -label.output_seq_details = Output Sequence Details to list all database references \ No newline at end of file +label.output_seq_details = Output Sequence Details to list all database references +label.urllinks = Links \ No newline at end of file diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index 1ed7ab0..87498d2 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1286,8 +1286,10 @@ action.db_acc = $DB_ACCESSION$ label.primary = On Click label.inmenu = In Menu label.id = ID +label.database = Database label.urltooltip = Only one url, which must use a sequence id, can be selected for the 'On Click' option label.edit_sequence_url_link = Edit sequence URL link -warn.name_cannot_be_duplicate = URL names must be unique and cannot be MIRIAM ids +warn.name_cannot_be_duplicate = User-defined URL names must be unique and cannot be MIRIAM ids label.invalid_name = Invalid Name ! -label.output_seq_details = Seleccionar Detalles de la secuencia para ver todas \ No newline at end of file +label.output_seq_details = Seleccionar Detalles de la secuencia para ver todas +label.urllinks = Links \ No newline at end of file diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index c5bff31..fbf31ff 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -902,8 +902,13 @@ public class Preferences extends GPreferences return; } - link.setName(linkUrlTable.getValueAt(index, 0).toString()); - link.setURL(linkUrlTable.getValueAt(index, 1).toString()); + int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel()) + .getNameColumn(); + int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel()) + .getUrlColumn(); + String oldName = linkUrlTable.getValueAt(index, nameCol).toString(); + link.setName(oldName); + link.setURL(linkUrlTable.getValueAt(index, urlCol).toString()); boolean valid = false; while (!valid) @@ -914,11 +919,12 @@ public class Preferences extends GPreferences { if (link.checkValid()) { - if (((UrlLinkTableModel) linkUrlTable.getModel()) - .isUniqueName(link.getName())) + if ((oldName.equals(link.getName())) + || (((UrlLinkTableModel) linkUrlTable.getModel()) + .isUniqueName(link.getName()))) { - linkUrlTable.setValueAt(link.getName(), index, 0); - linkUrlTable.setValueAt(link.getURL(), index, 1); + linkUrlTable.setValueAt(link.getName(), index, nameCol); + linkUrlTable.setValueAt(link.getURL(), index, urlCol); valid = true; } else diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index c1737a1..dda06b4 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -298,6 +298,9 @@ public class GPreferences extends JPanel tabbedPane.add(initConnectionsTab(), MessageManager.getString("label.connections")); + tabbedPane.add(initLinksTab(), + MessageManager.getString("label.urllinks")); + tabbedPane.add(initOutputTab(), MessageManager.getString("label.output")); @@ -519,135 +522,54 @@ public class GPreferences extends JPanel }); JPanel proxyPanel = initConnTabProxyPanel(); - JPanel linkPanel = initConnTabUrlLinks(); initConnTabCheckboxes(); - // Add URL link panel - connectTab.add(linkPanel, new GridBagConstraints(0, 0, 2, 1, 2.0, 2.0, - GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets( - 16, 0, 0, 12), 359, 32)); - // Add default Browser text box - connectTab.add(browserLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, + connectTab.add(browserLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, - new Insets(10, 0, 0, 0), 5, 1)); + new Insets(10, 0, 5, 5), 5, 1)); + defaultBrowser.setFont(LABEL_FONT); + defaultBrowser.setText(""); - connectTab.add(defaultBrowser, new GridBagConstraints(1, 1, 1, 1, 1.0, - 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, - new Insets(10, 0, 0, 10), 307, 1)); + connectTab.add(defaultBrowser, new GridBagConstraints(1, 0, 1, 1, 1.0, + 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(10, 0, 5, 10), 30, 1)); // Add proxy server panel - connectTab.add(proxyPanel, new GridBagConstraints(0, 2, 2, 1, 1.0, 0.0, + connectTab.add(proxyPanel, new GridBagConstraints(0, 1, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, - new Insets(10, 0, 0, 12), 4, 10)); + new Insets(10, 0, 5, 12), 4, 10)); // Add usage stats, version check and questionnaire checkboxes - connectTab.add(usagestats, new GridBagConstraints(0, 3, 1, 1, 1.0, 0.0, + connectTab.add(usagestats, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, - new Insets(0, 2, 4, 2), 70, 1)); - connectTab.add(questionnaire, new GridBagConstraints(1, 3, 1, 1, 1.0, + new Insets(0, 2, 5, 5), 70, 1)); + connectTab.add(questionnaire, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, - new Insets(0, 2, 4, 10), 70, 1)); - connectTab.add(versioncheck, new GridBagConstraints(0, 4, 1, 1, 1.0, + new Insets(0, 2, 5, 10), 70, 1)); + connectTab.add(versioncheck, new GridBagConstraints(0, 3, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, - new Insets(0, 2, 4, 2), 70, 1)); - return connectTab; - } - - /** - * Initialises the proxy server panel in the Connections tab - * - * @return the proxy server panel - */ - private JPanel initConnTabProxyPanel() - { - // Label for server text box - serverLabel.setText(MessageManager.getString("label.address")); - serverLabel.setHorizontalAlignment(SwingConstants.RIGHT); - serverLabel.setFont(LABEL_FONT); - - // Proxy server and port text boxes - proxyServerTB.setFont(LABEL_FONT); - proxyPortTB.setFont(LABEL_FONT); - - // Label for Port text box - portLabel.setFont(LABEL_FONT); - portLabel.setHorizontalAlignment(SwingConstants.RIGHT); - portLabel.setText(MessageManager.getString("label.port")); + new Insets(0, 2, 5, 5), 70, 1)); - // Use proxy server checkbox - useProxy.setFont(LABEL_FONT); - useProxy.setHorizontalAlignment(SwingConstants.RIGHT); - useProxy.setHorizontalTextPosition(SwingConstants.LEADING); - useProxy.setText(MessageManager.getString("label.use_proxy_server")); - useProxy.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - useProxy_actionPerformed(); - } - }); + // Add padding so the panel doesn't look ridiculous + JPanel spacePanel = new JPanel(); + connectTab.add(spacePanel, new GridBagConstraints(0, 4, 1, 1, 1.0, 1.0, + GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, + 0, 0, 5), 70, 1)); - // Make proxy server panel - JPanel proxyPanel = new JPanel(); - TitledBorder titledBorder1 = new TitledBorder( - MessageManager.getString("label.proxy_server")); - proxyPanel.setBorder(titledBorder1); - proxyPanel.setLayout(new GridBagLayout()); - proxyPanel.add(serverLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, - 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, - new Insets(0, 2, 2, 0), 5, 0)); - proxyPanel.add(portLabel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, - GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, - 0, 2, 0), 11, 0)); - proxyPanel.add(useProxy, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, - GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, - 2, 5, 185), 2, -4)); - proxyPanel.add(proxyPortTB, new GridBagConstraints(3, 1, 1, 1, 1.0, - 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, - new Insets(0, 2, 2, 2), 54, 1)); - proxyPanel.add(proxyServerTB, new GridBagConstraints(1, 1, 1, 1, 1.0, - 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, - new Insets(0, 2, 2, 0), 263, 1)); - - return proxyPanel; - } - - /** - * Initialises the checkboxes in the Connections tab - */ - private void initConnTabCheckboxes() - { - // Usage stats checkbox label - usagestats.setText(MessageManager - .getString("label.send_usage_statistics")); - usagestats.setFont(LABEL_FONT); - usagestats.setHorizontalAlignment(SwingConstants.RIGHT); - usagestats.setHorizontalTextPosition(SwingConstants.LEADING); - - // Questionnaire checkbox label - questionnaire.setText(MessageManager - .getString("label.check_for_questionnaires")); - questionnaire.setFont(LABEL_FONT); - questionnaire.setHorizontalAlignment(SwingConstants.RIGHT); - questionnaire.setHorizontalTextPosition(SwingConstants.LEADING); - - // Check for latest version checkbox label - versioncheck.setText(MessageManager - .getString("label.check_for_latest_version")); - versioncheck.setFont(LABEL_FONT); - versioncheck.setHorizontalAlignment(SwingConstants.RIGHT); - versioncheck.setHorizontalTextPosition(SwingConstants.LEADING); + return connectTab; } /** - * Initialises the URL links panel in the Connection tab + * Initialises the Links tabbed panel. * - * @return the URL links panel + * @return */ - private JPanel initConnTabUrlLinks() + private JPanel initLinksTab() { + JPanel linkTab = new JPanel(); + linkTab.setLayout(new GridBagLayout()); + // Set up table for Url links linkUrlTable.setFillsViewportHeight(true); linkUrlTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); @@ -672,35 +594,39 @@ public class GPreferences extends JPanel // Put the Url links panel together // Buttons go at top right, resizing only resizes the blank space vertically - JPanel buttonPanel = initConnTabUrlButtons(); + JPanel buttonPanel = initLinkTabUrlButtons(); GridBagConstraints linkConstraints1 = new GridBagConstraints(); - linkConstraints1.gridx = 1; + linkConstraints1.insets = new Insets(0, 0, 5, 0); + linkConstraints1.gridx = 0; linkConstraints1.gridy = 0; - linkConstraints1.fill = GridBagConstraints.VERTICAL; - linkPanel.add(buttonPanel, linkConstraints1); + linkConstraints1.weightx = 1.0; + linkConstraints1.fill = GridBagConstraints.HORIZONTAL; + linkTab.add(buttonPanel, linkConstraints1); // Links table goes at top left, resizing resizes the table GridBagConstraints linkConstraints2 = new GridBagConstraints(); + linkConstraints2.insets = new Insets(0, 0, 5, 5); linkConstraints2.gridx = 0; - linkConstraints2.gridy = 0; + linkConstraints2.gridy = 1; linkConstraints2.weightx = 1.0; linkConstraints2.weighty = 1.0; linkConstraints2.fill = GridBagConstraints.BOTH; - linkPanel.add(linkScrollPane, linkConstraints2); + linkTab.add(linkScrollPane, linkConstraints2); // Filter box and buttons goes at bottom left, resizing resizes the text box - JPanel filterPanel = initConnTabFilterPanel(); + JPanel filterPanel = initLinkTabFilterPanel(); GridBagConstraints linkConstraints3 = new GridBagConstraints(); + linkConstraints3.insets = new Insets(0, 0, 0, 5); linkConstraints3.gridx = 0; - linkConstraints3.gridy = 1; + linkConstraints3.gridy = 2; linkConstraints3.weightx = 1.0; linkConstraints3.fill = GridBagConstraints.HORIZONTAL; - linkPanel.add(filterPanel, linkConstraints3); + linkTab.add(filterPanel, linkConstraints3); - return linkPanel; + return linkTab; } - private JPanel initConnTabFilterPanel() + private JPanel initLinkTabFilterPanel() { // Filter textbox and reset button JLabel filterLabel = new JLabel( @@ -717,6 +643,7 @@ public class GPreferences extends JPanel // Panel for filter functionality JPanel filterPanel = new JPanel(new GridBagLayout()); + filterPanel.setBorder(new TitledBorder("Filter")); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; @@ -726,21 +653,21 @@ public class GPreferences extends JPanel filterPanel.add(filterLabel, gbc); GridBagConstraints gbc1 = new GridBagConstraints(); - gbc1.gridx = 0; gbc1.gridx = 1; + gbc1.gridwidth = 2; gbc1.fill = GridBagConstraints.HORIZONTAL; gbc1.anchor = GridBagConstraints.WEST; gbc1.weightx = 1.0; filterPanel.add(filterTB, gbc1); GridBagConstraints gbc2 = new GridBagConstraints(); - gbc2.gridx = 2; + gbc2.gridx = 3; gbc2.fill = GridBagConstraints.NONE; gbc2.anchor = GridBagConstraints.WEST; filterPanel.add(doReset, gbc2); GridBagConstraints gbc3 = new GridBagConstraints(); - gbc3.gridx = 3; + gbc3.gridx = 4; gbc3.fill = GridBagConstraints.NONE; gbc3.anchor = GridBagConstraints.WEST; filterPanel.add(userOnly, gbc3); @@ -748,11 +675,20 @@ public class GPreferences extends JPanel return filterPanel; } - private JPanel initConnTabUrlButtons() + private JPanel initLinkTabUrlButtons() { // Buttons for new / edit / delete Url links JButton newLink = new JButton(); newLink.setText(MessageManager.getString("action.new")); + + editLink.setText(MessageManager.getString("action.edit")); + + deleteLink.setText(MessageManager.getString("action.delete")); + + // no current selection, so initially disable delete/edit buttons + editLink.setEnabled(false); + deleteLink.setEnabled(false); + newLink.addActionListener(new java.awt.event.ActionListener() { @Override @@ -782,24 +718,126 @@ public class GPreferences extends JPanel } }); - // no current selection, so initially disable delete/edit buttons - editLink.setEnabled(false); - deleteLink.setEnabled(false); + JPanel buttonPanel = new JPanel(new GridBagLayout()); + buttonPanel.setBorder(new TitledBorder("Edit links")); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridx = 0; + gbc.gridy = 0; + gbc.fill = GridBagConstraints.NONE; + buttonPanel.add(newLink, gbc); + + GridBagConstraints gbc1 = new GridBagConstraints(); + gbc1.gridx = 1; + gbc1.gridy = 0; + gbc1.fill = GridBagConstraints.NONE; + buttonPanel.add(editLink, gbc1); - // Panels for new/edit/delete link buttons - // buttonContent prevents the buttons from being resized when the window is - JPanel buttonContent = new JPanel(new GridLayout(0, 1, 0, 0)); - JPanel buttonPanel = new JPanel(new BorderLayout()); + GridBagConstraints gbc2 = new GridBagConstraints(); + gbc2.gridx = 2; + gbc2.gridy = 0; + gbc2.fill = GridBagConstraints.NONE; + buttonPanel.add(deleteLink, gbc2); - buttonContent.add(newLink, null); - buttonContent.add(editLink, null); - buttonContent.add(deleteLink, null); - buttonPanel.add(buttonContent, BorderLayout.NORTH); + GridBagConstraints gbc3 = new GridBagConstraints(); + gbc3.gridx = 3; + gbc3.gridy = 0; + gbc3.fill = GridBagConstraints.HORIZONTAL; + gbc3.weightx = 1.0; + JPanel spacePanel = new JPanel(); + spacePanel.setBorder(null); + buttonPanel.add(spacePanel, gbc3); return buttonPanel; } /** + * Initialises the proxy server panel in the Connections tab + * + * @return the proxy server panel + */ + private JPanel initConnTabProxyPanel() + { + // Label for server text box + serverLabel.setText(MessageManager.getString("label.address")); + serverLabel.setHorizontalAlignment(SwingConstants.RIGHT); + serverLabel.setFont(LABEL_FONT); + + // Proxy server and port text boxes + proxyServerTB.setFont(LABEL_FONT); + proxyPortTB.setFont(LABEL_FONT); + + // Label for Port text box + portLabel.setFont(LABEL_FONT); + portLabel.setHorizontalAlignment(SwingConstants.RIGHT); + portLabel.setText(MessageManager.getString("label.port")); + + // Use proxy server checkbox + useProxy.setFont(LABEL_FONT); + useProxy.setHorizontalAlignment(SwingConstants.RIGHT); + useProxy.setHorizontalTextPosition(SwingConstants.LEADING); + useProxy.setText(MessageManager.getString("label.use_proxy_server")); + useProxy.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + useProxy_actionPerformed(); + } + }); + + // Make proxy server panel + JPanel proxyPanel = new JPanel(); + TitledBorder titledBorder1 = new TitledBorder( + MessageManager.getString("label.proxy_server")); + proxyPanel.setBorder(titledBorder1); + proxyPanel.setLayout(new GridBagLayout()); + proxyPanel.add(serverLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, + 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, + new Insets(0, 2, 2, 0), 5, 0)); + proxyPanel.add(portLabel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, + GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, + 0, 2, 0), 11, 0)); + proxyPanel.add(useProxy, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, + GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, + 2, 5, 185), 2, -4)); + proxyPanel.add(proxyPortTB, new GridBagConstraints(3, 1, 1, 1, 1.0, + 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, + new Insets(0, 2, 2, 2), 54, 1)); + proxyPanel.add(proxyServerTB, new GridBagConstraints(1, 1, 1, 1, 1.0, + 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, + new Insets(0, 2, 2, 0), 263, 1)); + + return proxyPanel; + } + + /** + * Initialises the checkboxes in the Connections tab + */ + private void initConnTabCheckboxes() + { + // Usage stats checkbox label + usagestats.setText(MessageManager + .getString("label.send_usage_statistics")); + usagestats.setFont(LABEL_FONT); + usagestats.setHorizontalAlignment(SwingConstants.RIGHT); + usagestats.setHorizontalTextPosition(SwingConstants.LEADING); + + // Questionnaire checkbox label + questionnaire.setText(MessageManager + .getString("label.check_for_questionnaires")); + questionnaire.setFont(LABEL_FONT); + questionnaire.setHorizontalAlignment(SwingConstants.RIGHT); + questionnaire.setHorizontalTextPosition(SwingConstants.LEADING); + + // Check for latest version checkbox label + versioncheck.setText(MessageManager + .getString("label.check_for_latest_version")); + versioncheck.setFont(LABEL_FONT); + versioncheck.setHorizontalAlignment(SwingConstants.RIGHT); + versioncheck.setHorizontalTextPosition(SwingConstants.LEADING); + } + + /** * Initialises the parent panel which contains the tabbed sections. * * @return diff --git a/src/jalview/urls/CustomUrlProvider.java b/src/jalview/urls/CustomUrlProvider.java index 0471e4b..b10d816 100644 --- a/src/jalview/urls/CustomUrlProvider.java +++ b/src/jalview/urls/CustomUrlProvider.java @@ -130,7 +130,7 @@ public class CustomUrlProvider extends UrlProviderImpl { url = url + SEP + st.nextToken(); } - urls.put(name, new UrlLink(name + SEP + url)); + urls.put(name, new UrlLink(name, url, name)); } } upgradeOldLinks(urls); @@ -150,7 +150,8 @@ public class CustomUrlProvider extends UrlProviderImpl { Map.Entry pair = it.next(); urls.put(pair.getKey(), - new UrlLink(pair.getKey() + SEP + pair.getValue())); + new UrlLink(pair.getKey(), pair.getValue(), + pair.getKey())); } upgradeOldLinks(urls); return urls; @@ -165,7 +166,9 @@ public class CustomUrlProvider extends UrlProviderImpl if (urls.containsKey(SRS_LABEL)) { urls.remove(SRS_LABEL); - urls.put(UrlConstants.DEFAULT_LABEL, new UrlLink(UrlConstants.DEFAULT_STRING)); + UrlLink link = new UrlLink(UrlConstants.DEFAULT_STRING); + link.setDescription(UrlConstants.DEFAULT_LABEL); + urls.put(UrlConstants.DEFAULT_LABEL, link); } } @@ -295,12 +298,14 @@ public class CustomUrlProvider extends UrlProviderImpl if (link.getIsSelected()) { selurls.put(link.getId(), - new UrlLink(link.getName() + SEP + link.getUrl())); + new UrlLink(link.getName(), link.getUrl(), link.getName())); } else { - unselurls.put(link.getId(), new UrlLink(link.getName() + SEP - + link.getUrl())); + unselurls + .put(link.getId(), + new UrlLink(link.getName(), link.getUrl(), link + .getName())); } // sort out primary and selected ids if (link.getIsPrimary()) @@ -321,8 +326,9 @@ public class CustomUrlProvider extends UrlProviderImpl if ((!nonselectedUrls.containsKey(UrlConstants.DEFAULT_LABEL)) && (!selectedUrls.containsKey(UrlConstants.DEFAULT_LABEL))) { - selectedUrls.put(UrlConstants.DEFAULT_LABEL, new UrlLink( - UrlConstants.DEFAULT_STRING)); + UrlLink link = new UrlLink(UrlConstants.DEFAULT_STRING); + link.setDescription(UrlConstants.DEFAULT_LABEL); + selectedUrls.put(UrlConstants.DEFAULT_LABEL, link); } primaryUrl = UrlConstants.DEFAULT_LABEL; return UrlConstants.DEFAULT_LABEL; diff --git a/src/jalview/urls/IdentifiersUrlProvider.java b/src/jalview/urls/IdentifiersUrlProvider.java index 51d181d..0219b54 100644 --- a/src/jalview/urls/IdentifiersUrlProvider.java +++ b/src/jalview/urls/IdentifiersUrlProvider.java @@ -94,7 +94,8 @@ public class IdentifiersUrlProvider extends UrlProviderImpl String url = (String) item.get("url") + "/" + DELIM + DB_ACCESSION + DELIM; - UrlLink link = new UrlLink((String) item.get("name") + SEP + url); + UrlLink link = new UrlLink((String) item.get("name"), url, + (String) item.get("prefix")); idData.put((String) item.get("id"), link); } } catch (FileNotFoundException e) diff --git a/src/jalview/urls/UrlLinkDisplay.java b/src/jalview/urls/UrlLinkDisplay.java index 5991d76..814370e 100644 --- a/src/jalview/urls/UrlLinkDisplay.java +++ b/src/jalview/urls/UrlLinkDisplay.java @@ -49,6 +49,7 @@ public class UrlLinkDisplay private final static List colNames = new ArrayList() { { + add(MessageManager.formatMessage("label.database")); add(MessageManager.formatMessage("label.name")); add(MessageManager.formatMessage("label.url")); add(MessageManager.formatMessage("label.inmenu")); @@ -58,15 +59,17 @@ public class UrlLinkDisplay }; // column positions - public final static int NAME = 0; + public final static int DATABASE = 0; - public final static int URL = 1; + public final static int NAME = 1; - public final static int SELECTED = 2; + public final static int URL = 2; - public final static int PRIMARY = 3; + public final static int SELECTED = 3; - public final static int ID = 4; + public final static int PRIMARY = 4; + + public final static int ID = 5; public UrlLinkDisplay(String rowId, UrlLink rowLink, boolean rowSelected, boolean rowDefault) @@ -89,6 +92,11 @@ public class UrlLinkDisplay return link.getLabel(); } + public String getDBName() + { + return link.getDBName(); + } + public String getUrl() { return link.getUrlWithToken(); @@ -111,7 +119,12 @@ public class UrlLinkDisplay public void setUrl(String rowUrl) { - link = new UrlLink(getName(), rowUrl); + link = new UrlLink(getName(), rowUrl, getName()); + } + + public void setDescription(String desc) + { + link.setDescription(desc); } public void setIsDefault(boolean rowDefault) @@ -138,6 +151,8 @@ public class UrlLinkDisplay return isSelected; case NAME: return getName(); + case DATABASE: + return getDBName(); default: return null; } @@ -160,6 +175,8 @@ public class UrlLinkDisplay isSelected = (boolean) value; break; case NAME: + setDescription((String) value); + case DATABASE: setName((String) value); break; default: @@ -199,7 +216,7 @@ public class UrlLinkDisplay */ public static List getDisplayColumnNames() { - // Display names between NAME and ID (excludes ID) - return colNames.subList(NAME, ID); + // Display names between DESCRIPTION and ID (excludes ID) + return colNames.subList(DATABASE, ID); } } diff --git a/src/jalview/urls/UrlLinkTableModel.java b/src/jalview/urls/UrlLinkTableModel.java index 71f7640..d6d26b5 100644 --- a/src/jalview/urls/UrlLinkTableModel.java +++ b/src/jalview/urls/UrlLinkTableModel.java @@ -223,7 +223,7 @@ public class UrlLinkTableModel extends AbstractTableModel public int insertRow(String name, String url) { // add a row to the data - UrlLink link = new UrlLink(name, url); + UrlLink link = new UrlLink(name, url, name); UrlLinkDisplay u = new UrlLinkDisplay(name, link, true, false); int index = data.size(); data.add(u); @@ -243,6 +243,11 @@ public class UrlLinkTableModel extends AbstractTableModel return UrlLinkDisplay.NAME; } + public int getDatabaseColumn() + { + return UrlLinkDisplay.DATABASE; + } + public int getIdColumn() { return UrlLinkDisplay.ID; diff --git a/src/jalview/util/UrlLink.java b/src/jalview/util/UrlLink.java index 186b682..d95edb2 100644 --- a/src/jalview/util/UrlLink.java +++ b/src/jalview/util/UrlLink.java @@ -53,6 +53,8 @@ public class UrlLink private String label; + private String dbname; + private String regexReplace; private boolean dynamic = false; @@ -104,14 +106,19 @@ public class UrlLink } /** - * Alternative constructor for separate name and link + * Alternative constructor for separate name, link and description * * @param name + * The string used to match the link to a DB reference id * @param url + * The url to link to + * @param desc + * The description of the associated target DB */ - public UrlLink(String name, String url) + public UrlLink(String name, String url, String desc) { this(name + SEP + url); + dbname = desc; } /** @@ -146,6 +153,14 @@ public class UrlLink return label; } + /** + * @return the name of this link's associated database + */ + public String getDBName() + { + return dbname; + } + public String getUrlWithToken() { String var = (usesDBaccession ? DB_ACCESSION : SEQUENCE_ID); @@ -212,6 +227,16 @@ public class UrlLink } /** + * Set the description + * + * @param desc + */ + public void setDescription(String desc) + { + this.dbname = desc; + } + + /** * return one or more URL strings by applying regex to the given idstring * * @param idstring diff --git a/test/jalview/urls/UrlLinkDisplayTest.java b/test/jalview/urls/UrlLinkDisplayTest.java index 2a773b0..e8a585c 100644 --- a/test/jalview/urls/UrlLinkDisplayTest.java +++ b/test/jalview/urls/UrlLinkDisplayTest.java @@ -12,21 +12,24 @@ public class UrlLinkDisplayTest { @Test(groups = { "Functional" }) public void testDisplayColumnNames() { - // 4 column names returned although 5 names internal to UrlLinkDisplay + // 5 column names returned although 6 names internal to UrlLinkDisplay List names = UrlLinkDisplay.getDisplayColumnNames(); - Assert.assertEquals(names.size(), 4); + Assert.assertEquals(names.size(), 5); } @Test(groups = { "Functional" }) public void getValue() { UrlLink link = new UrlLink("Test Url", - "http://identifiers.org/$DB_ACCESSION$"); + "http://identifiers.org/$DB_ACCESSION$", + "TestName"); UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false); Assert.assertFalse((boolean) u.getValue(UrlLinkDisplay.PRIMARY)); Assert.assertEquals(u.getValue(UrlLinkDisplay.ID), "Test"); - Assert.assertEquals(u.getValue(UrlLinkDisplay.NAME), "Test Url"); + Assert.assertEquals(u.getValue(UrlLinkDisplay.DATABASE), "Test Url"); + Assert.assertEquals(u.getValue(UrlLinkDisplay.NAME), + "TestName"); Assert.assertFalse((boolean) u.getValue(UrlLinkDisplay.SELECTED)); Assert.assertEquals(u.getValue(UrlLinkDisplay.URL), "http://identifiers.org/$DB_ACCESSION$"); @@ -39,7 +42,8 @@ public class UrlLinkDisplayTest { // default only editable if link contains $SEQUENCE_ID$ UrlLink link = new UrlLink("Test Url", - "http://identifiers.org/$DB_ACCESSION$"); + "http://identifiers.org/$DB_ACCESSION$", + "TestName"); UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false); Assert.assertFalse(u.isEditable(UrlLinkDisplay.PRIMARY)); @@ -47,9 +51,10 @@ public class UrlLinkDisplayTest { Assert.assertFalse(u.isEditable(UrlLinkDisplay.ID)); Assert.assertFalse(u.isEditable(UrlLinkDisplay.URL)); Assert.assertFalse(u.isEditable(UrlLinkDisplay.NAME)); + Assert.assertFalse(u.isEditable(UrlLinkDisplay.DATABASE)); UrlLink vlink = new UrlLink("Test Sequence ID Url", - "http://myurl/$SEQUENCE_ID$"); + "http://myurl/$SEQUENCE_ID$", "TestName"); UrlLinkDisplay v = new UrlLinkDisplay("Test", vlink, false, false); Assert.assertTrue(v.isEditable(UrlLinkDisplay.PRIMARY)); @@ -57,13 +62,15 @@ public class UrlLinkDisplayTest { Assert.assertFalse(v.isEditable(UrlLinkDisplay.ID)); Assert.assertFalse(v.isEditable(UrlLinkDisplay.URL)); Assert.assertFalse(v.isEditable(UrlLinkDisplay.NAME)); + Assert.assertFalse(v.isEditable(UrlLinkDisplay.DATABASE)); } @Test(groups = { "Functional" }) public void testName() { UrlLink link = new UrlLink("Test Url", - "http://identifiers.org/$DB_ACCESSION$"); + "http://identifiers.org/$DB_ACCESSION$", + "TestName"); UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false); // Name initially as input in link @@ -75,10 +82,27 @@ public class UrlLinkDisplayTest { } @Test(groups = { "Functional" }) + public void testDescription() + { + UrlLink link = new UrlLink("Test Url", + "http://identifiers.org/$DB_ACCESSION$", + "TestName"); + UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false); + + // Desc initially as input in link + Assert.assertEquals(u.getDBName(), "TestName"); + + // Setting updates name + u.setDescription("New Desc"); + Assert.assertEquals(u.getDBName(), "New Desc"); + } + + @Test(groups = { "Functional" }) public void testUrl() { UrlLink link = new UrlLink("Test Url", - "http://identifiers.org/$DB_ACCESSION$"); + "http://identifiers.org/$DB_ACCESSION$", + "TestName"); UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false); // Url initially as input in link @@ -93,12 +117,15 @@ public class UrlLinkDisplayTest { public void testGetSetValue() { UrlLink link = new UrlLink("Test Url", - "http://identifiers.org/$DB_ACCESSION$"); + "http://identifiers.org/$DB_ACCESSION$", + "TestName"); UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false); Assert.assertFalse((boolean) u.getValue(UrlLinkDisplay.PRIMARY)); Assert.assertFalse((boolean) u.getValue(UrlLinkDisplay.SELECTED)); - Assert.assertEquals(u.getValue(UrlLinkDisplay.NAME), "Test Url"); + Assert.assertEquals(u.getValue(UrlLinkDisplay.DATABASE), "Test Url"); + Assert.assertEquals(u.getValue(UrlLinkDisplay.NAME), + "TestName"); Assert.assertEquals(u.getValue(UrlLinkDisplay.ID), "Test"); Assert.assertEquals(u.getValue(UrlLinkDisplay.URL), "http://identifiers.org/$DB_ACCESSION$"); @@ -109,8 +136,11 @@ public class UrlLinkDisplayTest { u.setValue(UrlLinkDisplay.SELECTED, true); Assert.assertTrue((boolean) u.getValue(UrlLinkDisplay.SELECTED)); - u.setValue(UrlLinkDisplay.NAME, "New Name"); - Assert.assertEquals(u.getValue(UrlLinkDisplay.NAME), "New Name"); + u.setValue(UrlLinkDisplay.NAME, "New Desc"); + Assert.assertEquals(u.getValue(UrlLinkDisplay.NAME), "New Desc"); + + u.setValue(UrlLinkDisplay.DATABASE, "New Name"); + Assert.assertEquals(u.getValue(UrlLinkDisplay.DATABASE), "New Name"); u.setValue(UrlLinkDisplay.ID, "New ID"); Assert.assertEquals(u.getValue(UrlLinkDisplay.ID), "New ID"); -- 1.7.10.2