JAL-2316 Added UrlProvider factories. Tidied up labelling.
[jalview.git] / src / jalview / urls / UrlProvider.java
index 9e8d7bc..f93656f 100644 (file)
@@ -24,7 +24,6 @@ import static jalview.util.UrlConstants.SEP;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 import java.util.Vector;
 
 /**
@@ -42,30 +41,20 @@ public class UrlProvider implements UrlProviderI
   // 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
+   * Constructor for UrlProvider composite
    * 
    * @param defaultUrlString
-   *          id of the current default URL
-   * @param cachedUrlList
-   *          string listing current active URLs, expected to be custom URLs
-   *          separated by |, or ids of URLs
+   *          id of default url
+   * @param allProviders
+   *          list of UrlProviders this provider gives access to
    */
-  public UrlProvider(String defaultUrlString, String cachedUrlList)
+  public UrlProvider(String defaultUrlString,
+          List<UrlProviderI> allProviders)
   {
-    // create all the UrlProviders we need
-    providers = new ArrayList<UrlProviderI>();
-    
-    UrlProviderI idProvider = new IdentifiersUrlProvider(cachedUrlList,
-            IdentifiersUrlProvider.ID_ORG_FILE);
-    customProvider = new CustomUrlProvider(cachedUrlList);
-    providers.add(idProvider);
-    providers.add(customProvider);
+    providers = allProviders;
 
-    setUpColumns();
+    customProvider = findCustomProvider();
 
     // check that the defaultUrl still exists
     if (!setDefaultUrl(defaultUrlString))
@@ -73,42 +62,23 @@ public class UrlProvider implements UrlProviderI
       chooseDefaultUrl();
     }
   }
-  
-  /**
-   * Construct URL provider from a map of (label,url) pairs, and set default URL
-   * 
-   * @param defaultUrlString
-   *          id of the current default URL
-   * @param urlList
-   *          vector of (label, url) pairs
+
+  /*
+   * Store ref to custom url provider
    */
-  public UrlProvider(String defaultUrlString, Map<String, String> urlList)
+  private UrlProviderI findCustomProvider()
   {
-    // create all the UrlProviders we need
-    providers = new ArrayList<UrlProviderI>();
-
-    UrlProviderI idProvider = new IdentifiersUrlProvider(null,
-            IdentifiersUrlProvider.ID_ORG_FILE);
-    customProvider = new CustomUrlProvider(urlList);
-    providers.add(idProvider);
-    providers.add(customProvider);
-
-    setUpColumns();
-
-    // check that the defaultUrl still exists
-    if (!setDefaultUrl(defaultUrlString))
+    for (UrlProviderI p : providers)
     {
-      chooseDefaultUrl();
+      if (p.getClass().equals(CustomUrlProvider.class))
+      {
+        return p;
+      }
     }
-  }
 
-  private void setUpColumns()
-  {
-    colNames.add("Name");
-    colNames.add("URL");
-    colNames.add("In Menu");
-    colNames.add("Default");
-    colNames.add("ID");
+    System.out
+            .println("Error initialising UrlProvider - no custom url provider");
+    return null;
   }
   
   @Override
@@ -225,10 +195,4 @@ public class UrlProvider implements UrlProviderI
   {
     return customProvider.isUserEntry(id);
   }
-
-  @Override
-  public List<String> getDisplayColumnNames()
-  {
-    return colNames.subList(0, 4);
-  }
 }