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 |
|
|
|
|
| 0% |
Uncovered Elements: 83 (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 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
71 |
0 |
public UrlLinkTableModel(UrlProviderI baseData)... |
72 |
|
{ |
73 |
0 |
dataProvider = baseData; |
74 |
0 |
data = baseData.getLinksForTable(); |
75 |
0 |
displayColumns = UrlLinkDisplay.getDisplayColumnNames(); |
76 |
|
|
77 |
|
|
78 |
0 |
primaryRow = 0; |
79 |
0 |
Iterator<UrlLinkDisplay> it = data.iterator(); |
80 |
0 |
while (it.hasNext()) |
81 |
|
{ |
82 |
0 |
if (it.next().getIsPrimary()) |
83 |
|
{ |
84 |
0 |
break; |
85 |
|
} |
86 |
|
else |
87 |
|
{ |
88 |
0 |
primaryRow++; |
89 |
|
} |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
0 |
this.addTableModelListener(new TableModelListener() |
94 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
95 |
0 |
@Override... |
96 |
|
public void tableChanged(TableModelEvent e) |
97 |
|
{ |
98 |
0 |
try |
99 |
|
{ |
100 |
|
|
101 |
0 |
dataProvider.setUrlData(data); |
102 |
|
} catch (IllegalArgumentException ex) |
103 |
|
{ |
104 |
0 |
Console.error(ex.getMessage()); |
105 |
|
} |
106 |
|
} |
107 |
|
}); |
108 |
|
|
109 |
|
} |
110 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
111 |
0 |
@Override... |
112 |
|
public int getRowCount() |
113 |
|
{ |
114 |
0 |
if (data == null) |
115 |
|
{ |
116 |
0 |
return 0; |
117 |
|
} |
118 |
|
else |
119 |
|
{ |
120 |
0 |
return data.size(); |
121 |
|
} |
122 |
|
} |
123 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
124 |
0 |
@Override... |
125 |
|
public int getColumnCount() |
126 |
|
{ |
127 |
0 |
return displayColumns.size(); |
128 |
|
} |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
0 |
@Override... |
131 |
|
public Object getValueAt(int rowIndex, int columnIndex) |
132 |
|
{ |
133 |
0 |
return data.get(rowIndex).getValue(columnIndex); |
134 |
|
} |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
0 |
@Override... |
137 |
|
public boolean isCellEditable(int rowIndex, int columnIndex) |
138 |
|
{ |
139 |
0 |
return data.get(rowIndex).isEditable(columnIndex); |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
@param |
147 |
|
@return |
148 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
149 |
0 |
public boolean isRowEditable(int rowIndex)... |
150 |
|
{ |
151 |
|
|
152 |
0 |
return (dataProvider.isUserEntry(data.get(rowIndex).getId())); |
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
@param |
159 |
|
|
160 |
|
@return |
161 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
162 |
0 |
public boolean isRowDeletable(int rowIndex)... |
163 |
|
{ |
164 |
|
|
165 |
0 |
return (dataProvider.isUserEntry(data.get(rowIndex).getId()) |
166 |
|
&& !data.get(rowIndex).getIsPrimary()); |
167 |
|
} |
168 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
169 |
0 |
@Override... |
170 |
|
public void setValueAt(Object aValue, int rowIndex, int columnIndex) |
171 |
|
{ |
172 |
0 |
if (columnIndex == UrlLinkDisplay.PRIMARY) |
173 |
|
{ |
174 |
|
|
175 |
0 |
if (rowIndex != primaryRow) |
176 |
|
{ |
177 |
|
|
178 |
|
|
179 |
0 |
data.get(primaryRow).setValue(columnIndex, false); |
180 |
0 |
fireTableRowsUpdated(primaryRow, primaryRow); |
181 |
|
|
182 |
|
|
183 |
0 |
primaryRow = rowIndex; |
184 |
0 |
data.get(rowIndex).setValue(columnIndex, aValue); |
185 |
|
|
186 |
0 |
fireTableRowsUpdated(rowIndex, rowIndex); |
187 |
|
} |
188 |
|
} |
189 |
|
else |
190 |
|
{ |
191 |
0 |
data.get(rowIndex).setValue(columnIndex, aValue); |
192 |
0 |
fireTableRowsUpdated(rowIndex, rowIndex); |
193 |
|
} |
194 |
|
} |
195 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
196 |
0 |
@Override... |
197 |
|
public Class<?> getColumnClass(int columnIndex) |
198 |
|
{ |
199 |
0 |
return getValueAt(0, columnIndex).getClass(); |
200 |
|
} |
201 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
202 |
0 |
@Override... |
203 |
|
public String getColumnName(int columnIndex) |
204 |
|
{ |
205 |
0 |
return displayColumns.get(columnIndex); |
206 |
|
} |
207 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
208 |
0 |
public void removeRow(int rowIndex)... |
209 |
|
{ |
210 |
|
|
211 |
0 |
data.remove(rowIndex); |
212 |
|
|
213 |
|
|
214 |
0 |
if (primaryRow > rowIndex) |
215 |
|
{ |
216 |
0 |
primaryRow--; |
217 |
|
} |
218 |
|
|
219 |
|
|
220 |
0 |
fireTableRowsDeleted(rowIndex, rowIndex); |
221 |
|
} |
222 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
223 |
0 |
public int insertRow(String name, String url)... |
224 |
|
{ |
225 |
|
|
226 |
0 |
UrlLink link = new UrlLink(name, url, name); |
227 |
0 |
UrlLinkDisplay u = new UrlLinkDisplay(name, link, true, false); |
228 |
0 |
int index = data.size(); |
229 |
0 |
data.add(u); |
230 |
|
|
231 |
|
|
232 |
0 |
fireTableRowsInserted(index, index); |
233 |
0 |
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 |
|
} |