JAL-2316 Unit test updates and associated minor changes and fixes.
[jalview.git] / src / jalview / urls / UrlLinkDisplay.java
index 6a49f9e..f8584e4 100644 (file)
@@ -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<String> colNames = new ArrayList<String>()
   {
@@ -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;
+    }
   }
 
   /**