1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.fts.core; |
22 |
|
|
23 |
|
import jalview.fts.api.FTSDataColumnI; |
24 |
|
import jalview.fts.api.FTSDataColumnI.FTSDataColumnGroupI; |
25 |
|
import jalview.fts.api.FTSRestClientI; |
26 |
|
import jalview.fts.api.StructureFTSRestClientI; |
27 |
|
import jalview.fts.service.pdb.PDBFTSRestClient; |
28 |
|
|
29 |
|
import java.util.ArrayList; |
30 |
|
import java.util.Collection; |
31 |
|
import java.util.Comparator; |
32 |
|
import java.util.HashMap; |
33 |
|
import java.util.LinkedHashSet; |
34 |
|
import java.util.List; |
35 |
|
|
36 |
|
import javax.swing.JScrollPane; |
37 |
|
import javax.swing.JTable; |
38 |
|
import javax.swing.RowSorter; |
39 |
|
import javax.swing.SortOrder; |
40 |
|
import javax.swing.table.AbstractTableModel; |
41 |
|
import javax.swing.table.TableModel; |
42 |
|
import javax.swing.table.TableRowSorter; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@author |
49 |
|
|
50 |
|
|
51 |
|
@SuppressWarnings("serial") |
|
|
| 86.4% |
Uncovered Elements: 8 (59) |
Complexity: 12 |
Complexity Density: 0.23 |
|
52 |
|
public class FTSDataColumnPreferences extends JScrollPane |
53 |
|
{ |
54 |
|
protected JTable tbl_FTSDataColumnPrefs = new JTable(); |
55 |
|
|
56 |
|
protected JScrollPane scrl_pdbDocFieldConfig = new JScrollPane( |
57 |
|
tbl_FTSDataColumnPrefs); |
58 |
|
|
59 |
|
private HashMap<String, FTSDataColumnI> map = new HashMap<String, FTSDataColumnI>(); |
60 |
|
|
61 |
|
private Collection<FTSDataColumnI> structSummaryColumns = new LinkedHashSet<FTSDataColumnI>(); |
62 |
|
|
63 |
|
private Collection<FTSDataColumnI> allFTSDataColumns = new LinkedHashSet<FTSDataColumnI>(); |
64 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
65 |
|
public enum PreferenceSource |
66 |
|
{ |
67 |
|
SEARCH_SUMMARY, STRUCTURE_CHOOSER, PREFERENCES; |
68 |
|
} |
69 |
|
|
70 |
|
private PreferenceSource currentSource; |
71 |
|
|
72 |
|
private FTSRestClientI ftsRestClient; |
73 |
|
|
|
|
| 85.2% |
Uncovered Elements: 8 (54) |
Complexity: 10 |
Complexity Density: 0.2 |
|
74 |
140 |
public FTSDataColumnPreferences(PreferenceSource source,... |
75 |
|
FTSRestClientI ftsRestClient) |
76 |
|
{ |
77 |
140 |
this.ftsRestClient = ftsRestClient; |
78 |
140 |
if (source.equals(PreferenceSource.STRUCTURE_CHOOSER) |
79 |
|
|| source.equals(PreferenceSource.PREFERENCES)) |
80 |
|
{ |
81 |
138 |
structSummaryColumns = ((StructureFTSRestClientI) ftsRestClient) |
82 |
|
.getAllDefaultDisplayedStructureDataColumns(); |
83 |
|
} |
84 |
140 |
allFTSDataColumns.addAll(ftsRestClient.getAllFTSDataColumns()); |
85 |
|
|
86 |
140 |
tbl_FTSDataColumnPrefs.setAutoCreateRowSorter(true); |
87 |
140 |
this.getViewport().add(tbl_FTSDataColumnPrefs); |
88 |
140 |
this.currentSource = source; |
89 |
|
|
90 |
140 |
String[] columnNames = ftsRestClient.getPreferencesColumnsFor(source); |
91 |
|
|
92 |
140 |
Object[][] data = new Object[allFTSDataColumns.size()][3]; |
93 |
|
|
94 |
140 |
int x = 0; |
95 |
140 |
for (FTSDataColumnI field : allFTSDataColumns) |
96 |
|
{ |
97 |
|
|
98 |
|
|
99 |
7147 |
if (field.getName().equalsIgnoreCase("all")) |
100 |
|
{ |
101 |
69 |
continue; |
102 |
|
} |
103 |
|
|
104 |
7078 |
switch (source) |
105 |
|
{ |
106 |
102 |
case SEARCH_SUMMARY: |
107 |
102 |
data[x++] = new Object[] { ftsRestClient |
108 |
|
.getAllDefaultDisplayedFTSDataColumns().contains(field), |
109 |
|
field.getName(), field.getGroup() }; |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
102 |
break; |
114 |
6976 |
case STRUCTURE_CHOOSER: |
115 |
6976 |
data[x++] = new Object[] { structSummaryColumns.contains(field), |
116 |
|
field.getName(), field.getGroup() }; |
117 |
6976 |
break; |
118 |
0 |
case PREFERENCES: |
119 |
0 |
data[x++] = new Object[] { |
120 |
|
field.getName(), ftsRestClient |
121 |
|
.getAllDefaultDisplayedFTSDataColumns().contains(field), |
122 |
|
structSummaryColumns.contains(field) }; |
123 |
0 |
break; |
124 |
0 |
default: |
125 |
0 |
break; |
126 |
|
} |
127 |
7078 |
map.put(field.getName(), field); |
128 |
|
} |
129 |
|
|
130 |
140 |
FTSDataColumnPrefsTableModel model = new FTSDataColumnPrefsTableModel( |
131 |
|
columnNames, data); |
132 |
140 |
tbl_FTSDataColumnPrefs.setModel(model); |
133 |
|
|
134 |
140 |
switch (source) |
135 |
|
{ |
136 |
2 |
case SEARCH_SUMMARY: |
137 |
138 |
case STRUCTURE_CHOOSER: |
138 |
140 |
tbl_FTSDataColumnPrefs.getColumnModel().getColumn(0) |
139 |
|
.setPreferredWidth(30); |
140 |
140 |
tbl_FTSDataColumnPrefs.getColumnModel().getColumn(0).setMinWidth(20); |
141 |
140 |
tbl_FTSDataColumnPrefs.getColumnModel().getColumn(0).setMaxWidth(40); |
142 |
140 |
tbl_FTSDataColumnPrefs.getColumnModel().getColumn(1) |
143 |
|
.setPreferredWidth(150); |
144 |
140 |
tbl_FTSDataColumnPrefs.getColumnModel().getColumn(1).setMinWidth(150); |
145 |
140 |
tbl_FTSDataColumnPrefs.getColumnModel().getColumn(2) |
146 |
|
.setPreferredWidth(150); |
147 |
140 |
tbl_FTSDataColumnPrefs.getColumnModel().getColumn(2).setMinWidth(150); |
148 |
|
|
149 |
140 |
TableRowSorter<TableModel> sorter = new TableRowSorter<>( |
150 |
|
tbl_FTSDataColumnPrefs.getModel()); |
151 |
140 |
tbl_FTSDataColumnPrefs.setRowSorter(sorter); |
152 |
140 |
List<RowSorter.SortKey> sortKeys = new ArrayList<>(); |
153 |
140 |
int columnIndexToSort = 2; |
154 |
140 |
sortKeys.add(new RowSorter.SortKey(columnIndexToSort, |
155 |
|
SortOrder.ASCENDING)); |
156 |
140 |
sorter.setComparator(columnIndexToSort, |
157 |
|
new Comparator<FTSDataColumnGroupI>() |
158 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
159 |
30338 |
@Override... |
160 |
|
public int compare(FTSDataColumnGroupI o1, |
161 |
|
FTSDataColumnGroupI o2) |
162 |
|
{ |
163 |
30338 |
return o1.getSortOrder() - o2.getSortOrder(); |
164 |
|
} |
165 |
|
}); |
166 |
140 |
sorter.setSortKeys(sortKeys); |
167 |
|
|
168 |
|
|
169 |
140 |
tbl_FTSDataColumnPrefs |
170 |
|
.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); |
171 |
140 |
break; |
172 |
0 |
case PREFERENCES: |
173 |
0 |
default: |
174 |
0 |
break; |
175 |
|
} |
176 |
|
|
177 |
|
} |
178 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
179 |
52 |
public Collection<FTSDataColumnI> getStructureSummaryFields()... |
180 |
|
{ |
181 |
52 |
return structSummaryColumns; |
182 |
|
} |
183 |
|
|
|
|
| 18.6% |
Uncovered Elements: 57 (70) |
Complexity: 25 |
Complexity Density: 0.54 |
|
184 |
|
class FTSDataColumnPrefsTableModel extends AbstractTableModel |
185 |
|
{ |
186 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
187 |
140 |
public FTSDataColumnPrefsTableModel(String[] columnNames,... |
188 |
|
Object[][] data) |
189 |
|
{ |
190 |
140 |
this.data = data; |
191 |
140 |
this.columnNames = columnNames; |
192 |
|
} |
193 |
|
|
194 |
|
private Object[][] data; |
195 |
|
|
196 |
|
private String[] columnNames; |
197 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
198 |
1680 |
@Override... |
199 |
|
public int getColumnCount() |
200 |
|
{ |
201 |
1680 |
return columnNames.length; |
202 |
|
} |
203 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
204 |
700 |
@Override... |
205 |
|
public int getRowCount() |
206 |
|
{ |
207 |
700 |
return data.length; |
208 |
|
} |
209 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
210 |
420 |
@Override... |
211 |
|
public String getColumnName(int col) |
212 |
|
{ |
213 |
420 |
return columnNames[col]; |
214 |
|
} |
215 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
216 |
61922 |
@Override... |
217 |
|
public Object getValueAt(int row, int col) |
218 |
|
{ |
219 |
61922 |
return data[row][col]; |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
227 |
280 |
@Override... |
228 |
|
public Class getColumnClass(int c) |
229 |
|
{ |
230 |
280 |
return getValueAt(0, c).getClass(); |
231 |
|
} |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 4 |
Complexity Density: 0.5 |
|
236 |
0 |
@Override... |
237 |
|
public boolean isCellEditable(int row, int col) |
238 |
|
{ |
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
0 |
switch (currentSource) |
245 |
|
{ |
246 |
0 |
case SEARCH_SUMMARY: |
247 |
0 |
case STRUCTURE_CHOOSER: |
248 |
0 |
return (col == 0) && !isPrimaryKeyCell(row, 1); |
249 |
0 |
case PREFERENCES: |
250 |
0 |
return (col == 1 || col == 2) && !isPrimaryKeyCell(row, 0); |
251 |
0 |
default: |
252 |
0 |
return false; |
253 |
|
} |
254 |
|
|
255 |
|
} |
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
@param |
261 |
|
@param |
262 |
|
@return |
263 |
|
|
264 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
265 |
0 |
public boolean isPrimaryKeyCell(int row, int col)... |
266 |
|
{ |
267 |
0 |
String name = getValueAt(row, col).toString(); |
268 |
0 |
FTSDataColumnI pdbField = map.get(name); |
269 |
0 |
return pdbField.isPrimaryKeyColumn(); |
270 |
|
} |
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
|
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 9 |
Complexity Density: 0.38 |
|
275 |
0 |
@Override... |
276 |
|
public void setValueAt(Object value, int row, int col) |
277 |
|
{ |
278 |
0 |
data[row][col] = value; |
279 |
0 |
fireTableCellUpdated(row, col); |
280 |
|
|
281 |
0 |
String name = null; |
282 |
0 |
switch (currentSource) |
283 |
|
{ |
284 |
0 |
case SEARCH_SUMMARY: |
285 |
0 |
case STRUCTURE_CHOOSER: |
286 |
0 |
name = getValueAt(row, 1).toString(); |
287 |
0 |
break; |
288 |
0 |
case PREFERENCES: |
289 |
0 |
name = getValueAt(row, 0).toString(); |
290 |
0 |
break; |
291 |
0 |
default: |
292 |
0 |
break; |
293 |
|
} |
294 |
0 |
boolean selected = ((Boolean) value).booleanValue(); |
295 |
|
|
296 |
0 |
FTSDataColumnI ftsDataColumn = map.get(name); |
297 |
|
|
298 |
0 |
if (currentSource == PreferenceSource.SEARCH_SUMMARY) |
299 |
|
{ |
300 |
0 |
updatePrefs(ftsRestClient.getAllDefaultDisplayedFTSDataColumns(), |
301 |
|
ftsDataColumn, selected); |
302 |
|
} |
303 |
0 |
else if (currentSource == PreferenceSource.STRUCTURE_CHOOSER) |
304 |
|
{ |
305 |
0 |
updatePrefs(structSummaryColumns, ftsDataColumn, selected); |
306 |
|
} |
307 |
0 |
else if (currentSource == PreferenceSource.PREFERENCES) |
308 |
|
{ |
309 |
0 |
if (col == 1) |
310 |
|
{ |
311 |
0 |
updatePrefs(ftsRestClient.getAllDefaultDisplayedFTSDataColumns(), |
312 |
|
ftsDataColumn, selected); |
313 |
|
} |
314 |
0 |
else if (col == 2) |
315 |
|
{ |
316 |
0 |
updatePrefs(structSummaryColumns, ftsDataColumn, selected); |
317 |
|
} |
318 |
|
} |
319 |
|
} |
320 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 5 |
Complexity Density: 1.25 |
|
321 |
0 |
private void updatePrefs(Collection<FTSDataColumnI> prefConfig,... |
322 |
|
FTSDataColumnI dataColumn, boolean selected) |
323 |
|
{ |
324 |
0 |
if (prefConfig.contains(dataColumn) && !selected) |
325 |
|
{ |
326 |
0 |
prefConfig.remove(dataColumn); |
327 |
|
} |
328 |
|
|
329 |
0 |
if (!prefConfig.contains(dataColumn) && selected) |
330 |
|
{ |
331 |
0 |
prefConfig.add(dataColumn); |
332 |
|
} |
333 |
|
} |
334 |
|
|
335 |
|
} |
336 |
|
} |