2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import static jalview.util.UrlConstants.SEP;
25 import java.util.ArrayList;
26 import java.util.List;
28 import java.util.Vector;
32 * Implements the UrlProviderI interface for a composite UrlProvider object
37 public class UrlProvider implements UrlProviderI
39 // List of actual URL link providers
40 private List<UrlProviderI> providers;
42 // Specific reference to custom URL link provider
43 private UrlProviderI customProvider;
45 // List of columns which this provider will supply
46 private List<String> colNames = new ArrayList<String>();
49 * Construct URL provider from string of cached URLs, and set default URL
51 * @param defaultUrlString
52 * id of the current default URL
53 * @param cachedUrlList
54 * string listing current active URLs, expected to be custom URLs
55 * separated by |, or ids of URLs
57 public UrlProvider(String defaultUrlString, String cachedUrlList)
59 // create all the UrlProviders we need
60 providers = new ArrayList<UrlProviderI>();
62 UrlProviderI idProvider = new IdentifiersUrlProvider(cachedUrlList,
63 IdentifiersUrlProvider.ID_ORG_FILE);
64 customProvider = new CustomUrlProvider(cachedUrlList);
65 providers.add(idProvider);
66 providers.add(customProvider);
70 // check that the defaultUrl still exists
71 if (!setDefaultUrl(defaultUrlString))
78 * Construct URL provider from a map of (label,url) pairs, and set default URL
80 * @param defaultUrlString
81 * id of the current default URL
83 * vector of (label, url) pairs
85 public UrlProvider(String defaultUrlString, Map<String, String> urlList)
87 // create all the UrlProviders we need
88 providers = new ArrayList<UrlProviderI>();
90 UrlProviderI idProvider = new IdentifiersUrlProvider(null,
91 IdentifiersUrlProvider.ID_ORG_FILE);
92 customProvider = new CustomUrlProvider(urlList);
93 providers.add(idProvider);
94 providers.add(customProvider);
98 // check that the defaultUrl still exists
99 if (!setDefaultUrl(defaultUrlString))
105 private void setUpColumns()
107 colNames.add("Name");
109 colNames.add("In Menu");
110 colNames.add("Default");
115 public boolean setDefaultUrl(String id)
117 for (UrlProviderI p : providers)
119 if (p.setDefaultUrl(id))
128 public String writeUrlsAsString()
131 for (UrlProviderI p : providers)
133 result += p.writeUrlsAsString();
137 result = result.substring(0, result.length() - 1);
142 public Vector<String> getLinksForMenu()
144 Vector<String> fullLinks = new Vector<String>();
145 for (UrlProviderI p : providers)
147 List<String> links = p.getLinksForMenu();
150 // will obliterate links with same keys from different providers
151 // must have checks in place to prevent user from duplicating ids
152 fullLinks.addAll(links);
159 public List<UrlLinkDisplay> getLinksForTable()
161 ArrayList<UrlLinkDisplay> displayLinks = new ArrayList<UrlLinkDisplay>();
162 for (UrlProviderI p : providers)
164 displayLinks.addAll(p.getLinksForTable());
170 public void setUrlData(List<UrlLinkDisplay> links)
172 for (UrlProviderI p : providers)
179 public String getDefaultUrl(String seqid)
182 for (UrlProviderI p : providers)
184 if (p.getDefaultUrl(seqid) == null)
190 link = p.getDefaultUrl(seqid);
198 public String getDefaultTarget(String seqid)
200 String target = null;
201 for (UrlProviderI p : providers)
203 if (p.getDefaultTarget(seqid) == null)
209 target = p.getDefaultTarget(seqid);
217 public String chooseDefaultUrl()
219 // choose a custom url default
220 return customProvider.chooseDefaultUrl();
224 public boolean isUserEntry(String id)
226 return customProvider.isUserEntry(id);
230 public List<String> getDisplayColumnNames()
232 return colNames.subList(0, 4);