From 2d18ff6c5ccbd11297b80f70591dc0cb2f6aace6 Mon Sep 17 00:00:00 2001 From: kiramt Date: Fri, 9 Dec 2016 16:09:04 +0000 Subject: [PATCH] JAL-2316 Unit test updates and associated minor changes and fixes. --- resources/lang/Messages.properties | 7 +-- resources/lang/Messages_es.properties | 7 +-- src/jalview/bin/Cache.java | 4 ++ src/jalview/gui/Preferences.java | 68 ++++++++++++++++---------- src/jalview/jbgui/GPreferences.java | 11 ++++- src/jalview/urls/CustomUrlProvider.java | 8 ++- src/jalview/urls/IdentifiersUrlProvider.java | 8 +-- src/jalview/urls/UrlLinkDisplay.java | 47 ++++++++++++------ src/jalview/urls/UrlLinkTableModel.java | 40 +++++++++++++-- src/jalview/urls/UrlProvider.java | 2 + src/jalview/urls/UrlProviderImpl.java | 5 +- src/jalview/util/UrlLink.java | 11 +++++ test/jalview/urls/UrlLinkTableModelTest.java | 14 +++--- 13 files changed, 163 insertions(+), 69 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 1f5bdeb..9ffa292 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -410,7 +410,6 @@ label.couldnt_import_as_vamsas_session = Couldn't import {0} as a new vamsas ses label.vamsas_document_import_failed = Vamsas Document Import Failed label.couldnt_locate = Couldn't locate {0} label.url_not_found = URL not found -label.no_link_selected = No link selected label.new_sequence_url_link = New sequence URL link label.cannot_edit_annotations_in_wrapped_view = Cannot edit annotations in wrapped view label.wrapped_view_no_edit = Wrapped view - no edit @@ -1281,6 +1280,8 @@ action.showall = Show All label.insert = Insert: action.seq_id = $SEQUENCE_ID$ action.db_acc = $DB_ACCESSION$ -label.default = Default +label.default = On Click label.inmenu = In Menu -label.id = ID \ No newline at end of file +label.id = ID +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 \ No newline at end of file diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index b0194b9..a4b6c71 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -378,7 +378,6 @@ label.couldnt_import_as_vamsas_session = No se pudo importar {0} como una nueva label.vamsas_document_import_failed = Fallo en la importaciĆ³n del documento Vamsas label.couldnt_locate = No se pudo localizar {0} label.url_not_found = URL no encontrada -label.no_link_selected = Enlace no seleccionado label.new_sequence_url_link = Enlace a una nueva secuencia URL label.cannot_edit_annotations_in_wrapped_view = No se pueden editar anotaciones en vista envolvente label.wrapped_view_no_edit = Vista envolvente - no editar @@ -1282,6 +1281,8 @@ action.showall = Show All label.insert = Insert: action.seq_id = $SEQUENCE_ID$ action.db_acc = $DB_ACCESSION$ -label.default = Default +label.default = On Click label.inmenu = In Menu -label.id = ID \ No newline at end of file +label.id = ID +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 \ No newline at end of file diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index fe21406..6764430 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -123,6 +123,10 @@ import org.apache.log4j.SimpleLayout; *
  • SORT_ALIGNMENT (No sort|Id|Pairwise Identity)
  • *
  • SEQUENCE_LINKS list of name|URL pairs for opening a url with * $SEQUENCE_ID$
  • + *
  • STORED_LINKS list of name|url pairs which user has entered but are not + * currently used + *
  • DEFAULT_LINK name of single url to be used when user double clicks a + * sequence id (must be in SEQUENCE_LINKS or STORED_LINKS) *
  • GROUP_LINKS list of name|URL[|<separator>] tuples - see * jalview.utils.GroupURLLink for more info
  • *
  • DAS_REGISTRY_URL the registry to query
  • diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index efe1ed6..8048efe 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -128,11 +128,19 @@ public class Preferences extends GPreferences public static List groupURLLinks; static { - String inMenuString = Cache.getDefault("SEQUENCE_LINKS", - UrlConstants.DEFAULT_STRING); + // get links selected to be in the menu (SEQUENCE_LINKS) + // and links entered by the user but not selected (STORED_LINKS) + String inMenuString = Cache.getDefault("SEQUENCE_LINKS", ""); String notInMenuString = Cache.getDefault("STORED_LINKS", ""); String defaultUrl = Cache.getDefault("DEFAULT_URL", UrlConstants.DEFAULT_LABEL); + + // if both links lists are empty, add the DEFAULT_URL link + // otherwise we assume the default link is in one of the lists + if (inMenuString.isEmpty() && notInMenuString.isEmpty()) + { + inMenuString = UrlConstants.DEFAULT_STRING; + } UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl, inMenuString, notInMenuString); sequenceUrlLinks = factory.createUrlProvider(); @@ -337,10 +345,13 @@ public class Preferences extends GPreferences linkUrlTable.setRowSorter(sorter); List sortKeys = new ArrayList<>(); - sortKeys.add(new RowSorter.SortKey(3, + UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel(); + sortKeys.add(new RowSorter.SortKey(m.getDefaultColumn(), + SortOrder.DESCENDING)); + sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(), SortOrder.DESCENDING)); - sortKeys.add(new RowSorter.SortKey(2, SortOrder.DESCENDING)); - sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING)); + sortKeys.add(new RowSorter.SortKey(m.getNameColumn(), + SortOrder.ASCENDING)); sorter.setSortKeys(sortKeys); sorter.sort(); @@ -366,7 +377,8 @@ public class Preferences extends GPreferences public boolean include( Entry entry) { - String id = entry.getStringValue(4); + int col = ((UrlLinkTableModel) entry.getModel()).getIdColumn(); + String id = entry.getStringValue(col); return sequenceUrlLinks.isUserEntry(id); } }; @@ -389,24 +401,26 @@ public class Preferences extends GPreferences filterTB.getDocument().addDocumentListener(new DocumentListener() { + String caseInsensitiveFlag = "(?i)"; + @Override public void changedUpdate(DocumentEvent e) { - sorter.setRowFilter(RowFilter.regexFilter("(?i)" + sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag + filterTB.getText())); } @Override public void removeUpdate(DocumentEvent e) { - sorter.setRowFilter(RowFilter.regexFilter("(?i)" + sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag + filterTB.getText())); } @Override public void insertUpdate(DocumentEvent e) { - sorter.setRowFilter(RowFilter.regexFilter("(?i)" + sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag + filterTB.getText())); } }); @@ -416,9 +430,12 @@ public class Preferences extends GPreferences new UrlListSelectionHandler()); // set up radio buttons - linkUrlTable.getColumn("Default").setCellRenderer( + int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel()) + .getDefaultColumn(); + String onClickName = linkUrlTable.getColumnName(onClickCol); + linkUrlTable.getColumn(onClickName).setCellRenderer( new RadioButtonRenderer()); - linkUrlTable.getColumn("Default") + linkUrlTable.getColumn(onClickName) .setCellEditor(new RadioButtonEditor()); // get boolean columns and resize those to min possible @@ -872,11 +889,8 @@ public class Preferences extends GPreferences int index = linkUrlTable.getSelectedRow(); if (index == -1) { - // no row was selected - JOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString("label.no_link_selected"), - MessageManager.getString("label.no_link_selected"), - JOptionPane.WARNING_MESSAGE); + // button no longer enabled if row is not selected + Cache.log.debug("Edit with no row selected in linkUrlTable"); return; } @@ -887,7 +901,7 @@ public class Preferences extends GPreferences while (!valid) { if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link, - MessageManager.getString("label.new_sequence_url_link"), + MessageManager.getString("label.edit_sequence_url_link"), JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION) { if (link.checkValid()) @@ -911,11 +925,8 @@ public class Preferences extends GPreferences int modelIndex = -1; if (index == -1) { - // no row is selected - JOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString("label.no_link_selected"), - MessageManager.getString("label.no_link_selected"), - JOptionPane.WARNING_MESSAGE); + // button no longer enabled if row is not selected + Cache.log.debug("Delete with no row selected in linkUrlTable"); return; } else @@ -1164,9 +1175,10 @@ public class Preferences extends GPreferences int modelIndex = linkUrlTable.convertRowIndexToModel(index); // determine if the new selection is a custom url or not - if (!sequenceUrlLinks.isUserEntry((String) linkUrlTable -.getModel() - .getValueAt(modelIndex, 4))) // KM TODO do this better + int col = ((UrlLinkTableModel) linkUrlTable.getModel()) + .getNameColumn(); + if (!sequenceUrlLinks.isUserEntry((String) linkUrlTable.getModel() + .getValueAt(modelIndex, col))) { // entry is not a user-defined url and so should not be edited // disable edit and delete buttons @@ -1179,8 +1191,10 @@ public class Preferences extends GPreferences editLink.setEnabled(true); } - // BUT it's the default url, don't allow deletion - if ((boolean) linkUrlTable.getValueAt(index, 3)) + // BUT if it's the default url, don't allow deletion + col = ((UrlLinkTableModel) linkUrlTable.getModel()) + .getDefaultColumn(); + if ((boolean) linkUrlTable.getValueAt(index, col)) { deleteLink.setEnabled(false); } diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index 6fe6be2..c1737a1 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -1504,12 +1504,16 @@ public class GPreferences extends JPanel proxyPortTB.setEnabled(enabled); } + /** + * Customer renderer for JTable: supports column of radio buttons + */ public class RadioButtonRenderer extends JRadioButton implements TableCellRenderer { public RadioButtonRenderer() { setHorizontalAlignment(CENTER); + setToolTipText(MessageManager.getString("label.urltooltip")); } @Override @@ -1530,11 +1534,14 @@ public class GPreferences extends JPanel setBackground(table.getBackground()); setForeground(table.getForeground()); } - return this; } } + /** + * Customer cell editor for JTable: supports column of radio buttons in + * conjunction with renderer + */ public class RadioButtonEditor extends AbstractCellEditor implements TableCellEditor { @@ -1542,7 +1549,7 @@ public class GPreferences extends JPanel public RadioButtonEditor() { - // this.button.setHorizontalAlignment(SwingConstants.CENTER); + button.setHorizontalAlignment(SwingConstants.CENTER); this.button.addActionListener(new ActionListener() { @Override diff --git a/src/jalview/urls/CustomUrlProvider.java b/src/jalview/urls/CustomUrlProvider.java index 439d551..f4dcc0c 100644 --- a/src/jalview/urls/CustomUrlProvider.java +++ b/src/jalview/urls/CustomUrlProvider.java @@ -194,10 +194,10 @@ public class CustomUrlProvider extends UrlProviderImpl @Override public boolean setDefaultUrl(String id) { - if (id == null) + /*if (id == null) { defaultUrl = null; - } + }*/ if (selectedUrls.containsKey(id)) { defaultUrl = id; @@ -206,6 +206,10 @@ public class CustomUrlProvider extends UrlProviderImpl { defaultUrl = id; } + else + { + defaultUrl = null; + } return (defaultUrl != null); } diff --git a/src/jalview/urls/IdentifiersUrlProvider.java b/src/jalview/urls/IdentifiersUrlProvider.java index 98a5ee4..84da2d7 100644 --- a/src/jalview/urls/IdentifiersUrlProvider.java +++ b/src/jalview/urls/IdentifiersUrlProvider.java @@ -134,14 +134,14 @@ public class IdentifiersUrlProvider extends UrlProviderImpl @Override public boolean setDefaultUrl(String id) { - if (id == null) - { - defaultUrl = null; - } if (urls.containsKey(id)) { defaultUrl = id; } + else + { + defaultUrl = null; + } return urls.containsKey(id); } diff --git a/src/jalview/urls/UrlLinkDisplay.java b/src/jalview/urls/UrlLinkDisplay.java index 6a49f9e..f8584e4 100644 --- a/src/jalview/urls/UrlLinkDisplay.java +++ b/src/jalview/urls/UrlLinkDisplay.java @@ -22,6 +22,7 @@ package jalview.urls; import jalview.util.MessageManager; +import jalview.util.UrlLink; import java.util.ArrayList; import java.util.List; @@ -38,14 +39,12 @@ public class UrlLinkDisplay private String id; // id is not supplied to display, but used to identify // entries when saved - private String name; - - private String url; - private boolean isDefault; private boolean isSelected; + private UrlLink link; + // Headers for columns in table private final static List colNames = new ArrayList() { @@ -69,14 +68,14 @@ public class UrlLinkDisplay public final static int ID = 4; - public UrlLinkDisplay(String rowId, String rowName, String rowUrl, + public UrlLinkDisplay(String rowId, UrlLink rowLink, boolean rowSelected, boolean rowDefault) { id = rowId; - name = rowName; - url = rowUrl; isDefault = rowDefault; isSelected = rowSelected; + + link = rowLink; } // getters/setters @@ -87,12 +86,12 @@ public class UrlLinkDisplay public String getName() { - return name; + return link.getLabel(); } public String getUrl() { - return url; + return link.getUrlWithToken(); } public boolean getIsDefault() @@ -105,9 +104,14 @@ public class UrlLinkDisplay return isSelected; } + public void setName(String name) + { + link.setLabel(name); + } + public void setUrl(String rowUrl) { - url = rowUrl; + link = new UrlLink(rowUrl); } public void setIsDefault(boolean rowDefault) @@ -127,13 +131,13 @@ public class UrlLinkDisplay case ID: return id; case URL: - return url; + return getUrl(); case DEFAULT: return isDefault; case SELECTED: return isSelected; case NAME: - return name; + return getName(); default: return null; } @@ -147,7 +151,7 @@ public class UrlLinkDisplay id = (String) value; break; case URL: - url = (String) value; + setUrl((String) value); break; case DEFAULT: isDefault = (boolean) value; @@ -156,7 +160,7 @@ public class UrlLinkDisplay isSelected = (boolean) value; break; case NAME: - name = (String) value; + setName((String) value); break; default: // do nothing @@ -172,7 +176,20 @@ public class UrlLinkDisplay */ public boolean isEditable(int index) { - return ((index == DEFAULT) || (index == SELECTED)); + if (index == DEFAULT) + { + // default link must be a $SEQUENCE_ID$ link + // so only allow editing if it is + return (!link.usesDBAccession()); + } + else if (index == SELECTED) + { + return true; + } + else + { + return false; + } } /** diff --git a/src/jalview/urls/UrlLinkTableModel.java b/src/jalview/urls/UrlLinkTableModel.java index a18341b..a647d9e 100644 --- a/src/jalview/urls/UrlLinkTableModel.java +++ b/src/jalview/urls/UrlLinkTableModel.java @@ -21,6 +21,9 @@ package jalview.urls; +import jalview.bin.Cache; +import jalview.util.UrlLink; + import java.util.Iterator; import java.util.List; @@ -89,8 +92,14 @@ public class UrlLinkTableModel extends AbstractTableModel @Override public void tableChanged(TableModelEvent e) { - // update the UrlProvider from data list - dataProvider.setUrlData(data); + try + { + // update the UrlProvider from data list + dataProvider.setUrlData(data); + } catch (IllegalArgumentException ex) + { + Cache.log.error(ex.getMessage()); + } } }); @@ -184,7 +193,8 @@ public class UrlLinkTableModel extends AbstractTableModel public int insertRow(String name, String url) { // add a row to the data - UrlLinkDisplay u = new UrlLinkDisplay(name, name, url, true, false); + UrlLink link = new UrlLink(name, url); + UrlLinkDisplay u = new UrlLinkDisplay(name, link, true, false); int index = data.size(); data.add(u); @@ -193,4 +203,28 @@ public class UrlLinkTableModel extends AbstractTableModel return index; } + public int getDefaultColumn() + { + return UrlLinkDisplay.DEFAULT; + } + + public int getNameColumn() + { + return UrlLinkDisplay.NAME; + } + + public int getIdColumn() + { + return UrlLinkDisplay.ID; + } + + public int getUrlColumn() + { + return UrlLinkDisplay.URL; + } + + public int getSelectedColumn() + { + return UrlLinkDisplay.SELECTED; + } } diff --git a/src/jalview/urls/UrlProvider.java b/src/jalview/urls/UrlProvider.java index fcda198..7009e70 100644 --- a/src/jalview/urls/UrlProvider.java +++ b/src/jalview/urls/UrlProvider.java @@ -59,6 +59,8 @@ public class UrlProvider implements UrlProviderI // check that the defaultUrl still exists if (!setDefaultUrl(defaultUrlString)) { + // if the defaultUrl can't be found in any of the providers + // set up a custom default url chooseDefaultUrl(); } } diff --git a/src/jalview/urls/UrlProviderImpl.java b/src/jalview/urls/UrlProviderImpl.java index 2356f1d..5e85062 100644 --- a/src/jalview/urls/UrlProviderImpl.java +++ b/src/jalview/urls/UrlProviderImpl.java @@ -102,9 +102,8 @@ public abstract class UrlProviderImpl implements UrlProviderI { isSelected = selected; } - String displayLink = entry.getValue().getUrlWithToken(); - displayLinks.add(new UrlLinkDisplay(key, entry.getValue().getLabel(), - displayLink, isSelected, isDefault)); + displayLinks.add(new UrlLinkDisplay(key, entry.getValue(), + isSelected, isDefault)); } return displayLinks; } diff --git a/src/jalview/util/UrlLink.java b/src/jalview/util/UrlLink.java index 34070dd..186b682 100644 --- a/src/jalview/util/UrlLink.java +++ b/src/jalview/util/UrlLink.java @@ -104,6 +104,17 @@ public class UrlLink } /** + * Alternative constructor for separate name and link + * + * @param name + * @param url + */ + public UrlLink(String name, String url) + { + this(name + SEP + url); + } + + /** * @return the url_suffix */ public String getUrl_suffix() diff --git a/test/jalview/urls/UrlLinkTableModelTest.java b/test/jalview/urls/UrlLinkTableModelTest.java index 7c6f28e..bf13784 100644 --- a/test/jalview/urls/UrlLinkTableModelTest.java +++ b/test/jalview/urls/UrlLinkTableModelTest.java @@ -101,7 +101,7 @@ public class UrlLinkTableModelTest { * Test that the table model is correctly initialised * Display columns and default row are set; data provider listening event set up */ - @Test + @Test(groups = { "Functional" }) public void testInitialisation() { int defaultCol = 3; @@ -133,7 +133,7 @@ public class UrlLinkTableModelTest { /* * Test row and column counts */ - @Test + @Test(groups = { "Functional" }) public void testCounts() { UrlLinkTableModel m = new UrlLinkTableModel(prov); @@ -146,7 +146,7 @@ public class UrlLinkTableModelTest { /* * Test column access */ - @Test + @Test(groups = { "Functional" }) public void testColumns() { UrlLinkTableModel m = new UrlLinkTableModel(prov); @@ -171,7 +171,7 @@ public class UrlLinkTableModelTest { /* * Test row insertion */ - @Test + @Test(groups = { "Functional" }) public void testRowInsert() { UrlLinkTableModel m = new UrlLinkTableModel(prov); @@ -192,7 +192,7 @@ public class UrlLinkTableModelTest { /* * Test row deletion */ - @Test + @Test(groups = { "Functional" }) public void testRowDelete() { UrlLinkTableModel m = new UrlLinkTableModel(prov); @@ -216,7 +216,7 @@ public class UrlLinkTableModelTest { /* * Test value setting and getting */ - @Test + @Test(groups = { "Functional" }) public void testValues() { UrlLinkTableModel m = new UrlLinkTableModel(prov); @@ -265,7 +265,7 @@ public class UrlLinkTableModelTest { /* * Test cell editability */ - @Test + @Test(groups = { "Functional" }) public void testEditable() { UrlLinkTableModel m = new UrlLinkTableModel(prov); -- 1.7.10.2