JAL-2316 Unit test updates and associated minor changes and fixes.
[jalview.git] / src / jalview / gui / Preferences.java
index efe1ed6..8048efe 100755 (executable)
@@ -128,11 +128,19 @@ public class Preferences extends GPreferences
   public static List<String> 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<RowSorter.SortKey> 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<? extends TableModel, ? extends Object> 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);
       }