Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.urls

File UrlLinkDisplay.java

 

Coverage histogram

../../img/srcFileCovDistChart0.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.00%
 

Contributing tests

No tests hitting this source file were found.

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  0 toggle {
57  0 add(MessageManager.formatMessage("label.database"));
58  0 add(MessageManager.formatMessage("label.name"));
59  0 add(MessageManager.formatMessage("label.url"));
60  0 add(MessageManager.formatMessage("label.inmenu"));
61  0 add(MessageManager.formatMessage("label.primary"));
62  0 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  0 toggle public UrlLinkDisplay(String rowId, UrlLink rowLink, boolean rowSelected,
76    boolean rowDefault)
77    {
78  0 id = rowId;
79  0 isPrimary = rowDefault;
80  0 isSelected = rowSelected;
81   
82  0 link = rowLink;
83    }
84   
85    // getters/setters
 
86  0 toggle public String getId()
87    {
88  0 return id;
89    }
90   
 
91  0 toggle public String getDescription()
92    {
93  0 return link.getLabel();
94    }
95   
 
96  0 toggle public String getDBName()
97    {
98  0 return link.getTarget();
99    }
100   
 
101  0 toggle public String getUrl()
102    {
103  0 return link.getUrlWithToken();
104    }
105   
 
106  0 toggle public boolean getIsPrimary()
107    {
108  0 return isPrimary;
109    }
110   
 
111  0 toggle public boolean getIsSelected()
112    {
113  0 return isSelected;
114    }
115   
 
116  0 toggle public void setDBName(String name)
117    {
118  0 link.setTarget(name);
119    }
120   
 
121  0 toggle public void setUrl(String rowUrl)
122    {
123  0 link = new UrlLink(getDescription(), rowUrl, getDBName());
124    }
125   
 
126  0 toggle public void setDescription(String desc)
127    {
128  0 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  0 toggle public Object getValue(int index)
142    {
143  0 switch (index)
144    {
145  0 case ID:
146  0 return id;
147  0 case URL:
148  0 return getUrl();
149  0 case PRIMARY:
150  0 return isPrimary;
151  0 case SELECTED:
152  0 return isSelected;
153  0 case NAME:
154  0 return getDescription();
155  0 case DATABASE:
156  0 return getDBName();
157  0 default:
158  0 return null;
159    }
160    }
161   
 
162  0 toggle public void setValue(int index, Object value)
163    {
164  0 switch (index)
165    {
166  0 case ID:
167  0 id = (String) value;
168  0 break;
169  0 case URL:
170  0 setUrl((String) value);
171  0 break;
172  0 case PRIMARY:
173  0 isPrimary = (boolean) value;
174  0 break;
175  0 case SELECTED:
176  0 isSelected = (boolean) value;
177  0 break;
178  0 case NAME:
179  0 setDescription((String) value);
180    // deliberate fall through
181  0 case DATABASE:
182  0 setDBName((String) value);
183  0 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  0 toggle public boolean isEditable(int index)
197    {
198  0 if (index == PRIMARY)
199    {
200    // primary link must not be a $DB_ACCESSION$ link
201    // so only allow editing if it is not
202  0 return (!link.usesDBAccession());
203    }
204    else
205    {
206  0 return index == SELECTED;
207    }
208    }
209   
210    /**
211    * Get list of column names to display in UI
212    *
213    * @return column names
214    */
 
215  0 toggle public static List<String> getDisplayColumnNames()
216    {
217    // Display names between DESCRIPTION and ID (excludes ID)
218  0 return COLNAMES.subList(DATABASE, ID);
219    }
220    }