1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
package jalview.urls; |
23 |
|
|
24 |
|
import jalview.bin.Console; |
25 |
|
import jalview.urls.api.UrlProviderI; |
26 |
|
import jalview.util.UrlLink; |
27 |
|
|
28 |
|
import java.util.Iterator; |
29 |
|
import java.util.List; |
30 |
|
|
31 |
|
import javax.swing.RowFilter.Entry; |
32 |
|
import javax.swing.event.TableModelEvent; |
33 |
|
import javax.swing.event.TableModelListener; |
34 |
|
import javax.swing.table.AbstractTableModel; |
35 |
|
import javax.swing.table.TableModel; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@author |
41 |
|
@version |
42 |
|
|
43 |
|
|
|
|
| 73.5% |
Uncovered Elements: 22 (83) |
Complexity: 28 |
Complexity Density: 0.56 |
|
44 |
|
public class UrlLinkTableModel extends AbstractTableModel |
45 |
|
{ |
46 |
|
|
47 |
|
private List<UrlLinkDisplay> data; |
48 |
|
|
49 |
|
|
50 |
|
private UrlProviderI dataProvider; |
51 |
|
|
52 |
|
|
53 |
|
private List<String> displayColumns; |
54 |
|
|
55 |
|
|
56 |
|
private int primaryRow; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
@param |
62 |
|
|
63 |
|
@param |
64 |
|
|
65 |
|
|
66 |
|
@param |
67 |
|
|
68 |
|
@param |
69 |
|
|
70 |
|
|
|
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
71 |
14 |
public UrlLinkTableModel(UrlProviderI baseData)... |
72 |
|
{ |
73 |
14 |
dataProvider = baseData; |
74 |
14 |
data = baseData.getLinksForTable(); |
75 |
14 |
displayColumns = UrlLinkDisplay.getDisplayColumnNames(); |
76 |
|
|
77 |
|
|
78 |
14 |
primaryRow = 0; |
79 |
14 |
Iterator<UrlLinkDisplay> it = data.iterator(); |
80 |
3165 |
while (it.hasNext()) |
81 |
|
{ |
82 |
3165 |
if (it.next().getIsPrimary()) |
83 |
|
{ |
84 |
14 |
break; |
85 |
|
} |
86 |
|
else |
87 |
|
{ |
88 |
3151 |
primaryRow++; |
89 |
|
} |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
14 |
this.addTableModelListener(new TableModelListener() |
94 |
|
{ |
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
95 |
9 |
@Override... |
96 |
|
public void tableChanged(TableModelEvent e) |
97 |
|
{ |
98 |
9 |
try |
99 |
|
{ |
100 |
|
|
101 |
9 |
dataProvider.setUrlData(data); |
102 |
|
} catch (IllegalArgumentException ex) |
103 |
|
{ |
104 |
0 |
Console.error(ex.getMessage()); |
105 |
|
} |
106 |
|
} |
107 |
|
}); |
108 |
|
|
109 |
|
} |
110 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
111 |
68 |
@Override... |
112 |
|
public int getRowCount() |
113 |
|
{ |
114 |
68 |
if (data == null) |
115 |
|
{ |
116 |
0 |
return 0; |
117 |
|
} |
118 |
|
else |
119 |
|
{ |
120 |
68 |
return data.size(); |
121 |
|
} |
122 |
|
} |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
124 |
1 |
@Override... |
125 |
|
public int getColumnCount() |
126 |
|
{ |
127 |
1 |
return displayColumns.size(); |
128 |
|
} |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
55 |
@Override... |
131 |
|
public Object getValueAt(int rowIndex, int columnIndex) |
132 |
|
{ |
133 |
55 |
return data.get(rowIndex).getValue(columnIndex); |
134 |
|
} |
135 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
50 |
@Override... |
137 |
|
public boolean isCellEditable(int rowIndex, int columnIndex) |
138 |
|
{ |
139 |
50 |
return data.get(rowIndex).isEditable(columnIndex); |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
@param |
147 |
|
@return |
148 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
149 |
10 |
public boolean isRowEditable(int rowIndex)... |
150 |
|
{ |
151 |
|
|
152 |
10 |
return (dataProvider.isUserEntry(data.get(rowIndex).getId())); |
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
@param |
159 |
|
|
160 |
|
@return |
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
162 |
10 |
public boolean isRowDeletable(int rowIndex)... |
163 |
|
{ |
164 |
|
|
165 |
10 |
return (dataProvider.isUserEntry(data.get(rowIndex).getId()) |
166 |
|
&& !data.get(rowIndex).getIsPrimary()); |
167 |
|
} |
168 |
|
|
|
|
| 92.3% |
Uncovered Elements: 1 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
169 |
6 |
@Override... |
170 |
|
public void setValueAt(Object aValue, int rowIndex, int columnIndex) |
171 |
|
{ |
172 |
6 |
if (columnIndex == UrlLinkDisplay.PRIMARY) |
173 |
|
{ |
174 |
|
|
175 |
1 |
if (rowIndex != primaryRow) |
176 |
|
{ |
177 |
|
|
178 |
|
|
179 |
1 |
data.get(primaryRow).setValue(columnIndex, false); |
180 |
1 |
fireTableRowsUpdated(primaryRow, primaryRow); |
181 |
|
|
182 |
|
|
183 |
1 |
primaryRow = rowIndex; |
184 |
1 |
data.get(rowIndex).setValue(columnIndex, aValue); |
185 |
|
|
186 |
1 |
fireTableRowsUpdated(rowIndex, rowIndex); |
187 |
|
} |
188 |
|
} |
189 |
|
else |
190 |
|
{ |
191 |
5 |
data.get(rowIndex).setValue(columnIndex, aValue); |
192 |
5 |
fireTableRowsUpdated(rowIndex, rowIndex); |
193 |
|
} |
194 |
|
} |
195 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
196 |
5 |
@Override... |
197 |
|
public Class<?> getColumnClass(int columnIndex) |
198 |
|
{ |
199 |
5 |
return getValueAt(0, columnIndex).getClass(); |
200 |
|
} |
201 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
202 |
5 |
@Override... |
203 |
|
public String getColumnName(int columnIndex) |
204 |
|
{ |
205 |
5 |
return displayColumns.get(columnIndex); |
206 |
|
} |
207 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
208 |
1 |
public void removeRow(int rowIndex)... |
209 |
|
{ |
210 |
|
|
211 |
1 |
data.remove(rowIndex); |
212 |
|
|
213 |
|
|
214 |
1 |
if (primaryRow > rowIndex) |
215 |
|
{ |
216 |
1 |
primaryRow--; |
217 |
|
} |
218 |
|
|
219 |
|
|
220 |
1 |
fireTableRowsDeleted(rowIndex, rowIndex); |
221 |
|
} |
222 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
223 |
1 |
public int insertRow(String name, String url)... |
224 |
|
{ |
225 |
|
|
226 |
1 |
UrlLink link = new UrlLink(name, url, name); |
227 |
1 |
UrlLinkDisplay u = new UrlLinkDisplay(name, link, true, false); |
228 |
1 |
int index = data.size(); |
229 |
1 |
data.add(u); |
230 |
|
|
231 |
|
|
232 |
1 |
fireTableRowsInserted(index, index); |
233 |
1 |
return index; |
234 |
|
} |
235 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
236 |
0 |
public int getPrimaryColumn()... |
237 |
|
{ |
238 |
0 |
return UrlLinkDisplay.PRIMARY; |
239 |
|
} |
240 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
241 |
0 |
public int getNameColumn()... |
242 |
|
{ |
243 |
0 |
return UrlLinkDisplay.NAME; |
244 |
|
} |
245 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
246 |
0 |
public int getDatabaseColumn()... |
247 |
|
{ |
248 |
0 |
return UrlLinkDisplay.DATABASE; |
249 |
|
} |
250 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
251 |
0 |
public int getIdColumn()... |
252 |
|
{ |
253 |
0 |
return UrlLinkDisplay.ID; |
254 |
|
} |
255 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
256 |
0 |
public int getUrlColumn()... |
257 |
|
{ |
258 |
0 |
return UrlLinkDisplay.URL; |
259 |
|
} |
260 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
261 |
0 |
public int getSelectedColumn()... |
262 |
|
{ |
263 |
0 |
return UrlLinkDisplay.SELECTED; |
264 |
|
} |
265 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
266 |
0 |
public boolean isUserEntry(... |
267 |
|
Entry<? extends TableModel, ? extends Object> entry) |
268 |
|
{ |
269 |
0 |
return dataProvider |
270 |
|
.isUserEntry(entry.getStringValue(UrlLinkDisplay.ID)); |
271 |
|
} |
272 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
273 |
0 |
public boolean isUniqueName(String name)... |
274 |
|
{ |
275 |
0 |
return !dataProvider.contains(name); |
276 |
|
} |
277 |
|
} |