Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 17:27:16 GMT
  2. Package jalview.urls

File UrlLinkDisplay.java

 

Coverage histogram

../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
59
17
1
220
141
30
0.51
3.47
17
1.76

Classes

Class Line # Actions
UrlLinkDisplay 37 59 30
0.910256491%
 

Contributing tests

This file is covered by 21 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21   
22    package jalview.urls;
23   
24    import jalview.util.MessageManager;
25    import jalview.util.UrlLink;
26   
27    import java.util.ArrayList;
28    import java.util.List;
29   
30    /**
31    * UrlLink table row definition
32    *
33    * @author $author$
34    * @version $Revision$
35    */
36   
 
37    public class UrlLinkDisplay
38    {
39    // column positions
40    public static final int DATABASE = 0;
41   
42    public static final int NAME = 1;
43   
44    public static final int URL = 2;
45   
46    public static final int SELECTED = 3;
47   
48    public static final int PRIMARY = 4;
49   
50    public static final int ID = 5;
51   
52    // Headers for columns in table
53    @SuppressWarnings("serial")
54    private static final List<String> COLNAMES = new ArrayList<String>()
55    {
 
56  10 toggle {
57  10 add(MessageManager.formatMessage("label.database"));
58  10 add(MessageManager.formatMessage("label.name"));
59  10 add(MessageManager.formatMessage("label.url"));
60  10 add(MessageManager.formatMessage("label.inmenu"));
61  10 add(MessageManager.formatMessage("label.primary"));
62  10 add(MessageManager.formatMessage("label.id"));
63    }
64    };
65   
66    private String id; // id is not supplied to display, but used to identify
67    // entries when saved
68   
69    private boolean isPrimary;
70   
71    private boolean isSelected;
72   
73    private UrlLink link;
74   
 
75  6357 toggle public UrlLinkDisplay(String rowId, UrlLink rowLink, boolean rowSelected,
76    boolean rowDefault)
77    {
78  6357 id = rowId;
79  6357 isPrimary = rowDefault;
80  6357 isSelected = rowSelected;
81   
82  6357 link = rowLink;
83    }
84   
85    // getters/setters
 
86  436 toggle public String getId()
87    {
88  436 return id;
89    }
90   
 
91  127 toggle public String getDescription()
92    {
93  127 return link.getLabel();
94    }
95   
 
96  24 toggle public String getDBName()
97    {
98  24 return link.getTarget();
99    }
100   
 
101  67 toggle public String getUrl()
102    {
103  67 return link.getUrlWithToken();
104    }
105   
 
106  6383 toggle public boolean getIsPrimary()
107    {
108  6383 return isPrimary;
109    }
110   
 
111  92 toggle public boolean getIsSelected()
112    {
113  92 return isSelected;
114    }
115   
 
116  6 toggle public void setDBName(String name)
117    {
118  6 link.setTarget(name);
119    }
120   
 
121  3 toggle public void setUrl(String rowUrl)
122    {
123  3 link = new UrlLink(getDescription(), rowUrl, getDBName());
124    }
125   
 
126  3 toggle public void setDescription(String desc)
127    {
128  3 link.setLabel(desc);
129    }
130   
 
131  0 toggle public void setIsDefault(boolean rowDefault)
132    {
133  0 isPrimary = rowDefault;
134    }
135   
 
136  0 toggle public void setIsSelected(boolean rowSelected)
137    {
138  0 isSelected = rowSelected;
139    }
140   
 
141  74 toggle public Object getValue(int index)
142    {
143  74 switch (index)
144    {
145  3 case ID:
146  3 return id;
147  8 case URL:
148  8 return getUrl();
149  27 case PRIMARY:
150  27 return isPrimary;
151  7 case SELECTED:
152  7 return isSelected;
153  10 case NAME:
154  10 return getDescription();
155  19 case DATABASE:
156  19 return getDBName();
157  0 default:
158  0 return null;
159    }
160    }
161   
 
162  13 toggle public void setValue(int index, Object value)
163    {
164  13 switch (index)
165    {
166  1 case ID:
167  1 id = (String) value;
168  1 break;
169  2 case URL:
170  2 setUrl((String) value);
171  2 break;
172  3 case PRIMARY:
173  3 isPrimary = (boolean) value;
174  3 break;
175  2 case SELECTED:
176  2 isSelected = (boolean) value;
177  2 break;
178  2 case NAME:
179  2 setDescription((String) value);
180    // deliberate fall through
181  3 case DATABASE:
182  5 setDBName((String) value);
183  5 break;
184  0 default:
185    // do nothing
186    }
187    }
188   
189    /**
190    * Identify editable columns
191    *
192    * @param index
193    * index of column
194    * @return whether column can be edited in table
195    */
 
196  62 toggle public boolean isEditable(int index)
197    {
198  62 if (index == PRIMARY)
199    {
200    // primary link must not be a $DB_ACCESSION$ link
201    // so only allow editing if it is not
202  12 return (!link.usesDBAccession());
203    }
204    else
205    {
206  50 return index == SELECTED;
207    }
208    }
209   
210    /**
211    * Get list of column names to display in UI
212    *
213    * @return column names
214    */
 
215  20 toggle public static List<String> getDisplayColumnNames()
216    {
217    // Display names between DESCRIPTION and ID (excludes ID)
218  20 return COLNAMES.subList(DATABASE, ID);
219    }
220    }