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.
24 import jalview.util.MessageManager;
25 import jalview.util.UrlLink;
27 import java.util.ArrayList;
28 import java.util.List;
31 * UrlLink table row definition
37 public class UrlLinkDisplay
40 public static final int DATABASE = 0;
42 public static final int NAME = 1;
44 public static final int URL = 2;
46 public static final int SELECTED = 3;
48 public static final int PRIMARY = 4;
50 public static final int ID = 5;
52 // Headers for columns in table
53 @SuppressWarnings("serial")
54 private static final List<String> COLNAMES = new ArrayList<String>()
57 add(MessageManager.formatMessage("label.database"));
58 add(MessageManager.formatMessage("label.name"));
59 add(MessageManager.formatMessage("label.url"));
60 add(MessageManager.formatMessage("label.inmenu"));
61 add(MessageManager.formatMessage("label.primary"));
62 add(MessageManager.formatMessage("label.id"));
66 private String id; // id is not supplied to display, but used to identify
69 private boolean isPrimary;
71 private boolean isSelected;
75 public UrlLinkDisplay(String rowId, UrlLink rowLink, boolean rowSelected,
79 isPrimary = rowDefault;
80 isSelected = rowSelected;
91 public String getDescription()
93 return link.getLabel();
96 public String getDBName()
98 return link.getTarget();
101 public String getUrl()
103 return link.getUrlWithToken();
106 public boolean getIsPrimary()
111 public boolean getIsSelected()
116 public void setDBName(String name)
118 link.setTarget(name);
121 public void setUrl(String rowUrl)
123 link = new UrlLink(getDescription(), rowUrl, getDBName());
126 public void setDescription(String desc)
131 public void setIsDefault(boolean rowDefault)
133 isPrimary = rowDefault;
136 public void setIsSelected(boolean rowSelected)
138 isSelected = rowSelected;
141 public Object getValue(int index)
154 return getDescription();
162 public void setValue(int index, Object value)
170 setUrl((String) value);
173 isPrimary = (boolean) value;
176 isSelected = (boolean) value;
179 setDescription((String) value);
180 // deliberate fall through
182 setDBName((String) value);
190 * Identify editable columns
194 * @return whether column can be edited in table
196 public boolean isEditable(int index)
198 if (index == PRIMARY)
200 // primary link must not be a $DB_ACCESSION$ link
201 // so only allow editing if it is not
202 return (!link.usesDBAccession());
206 return index == SELECTED;
211 * Get list of column names to display in UI
213 * @return column names
215 public static List<String> getDisplayColumnNames()
217 // Display names between DESCRIPTION and ID (excludes ID)
218 return COLNAMES.subList(DATABASE, ID);