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") |
|
|
| 0% |
Uncovered Elements: 59 (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 |
|
|
|
|
| 0% |
Uncovered Elements: 54 (54) |
Complexity: 10 |
Complexity Density: 0.2 |
|
74 |
0 |
public FTSDataColumnPreferences(PreferenceSource source,... |
75 |
|
FTSRestClientI ftsRestClient) |
76 |
|
{ |
77 |
0 |
this.ftsRestClient = ftsRestClient; |
78 |
0 |
if (source.equals(PreferenceSource.STRUCTURE_CHOOSER) |
79 |
|
|| source.equals(PreferenceSource.PREFERENCES)) |
80 |
|
{ |
81 |
0 |
structSummaryColumns = ((StructureFTSRestClientI) ftsRestClient) |
82 |
|
.getAllDefaultDisplayedStructureDataColumns(); |
83 |
|
} |
84 |
0 |
allFTSDataColumns.addAll(ftsRestClient.getAllFTSDataColumns()); |
85 |
|
|
86 |
0 |
tbl_FTSDataColumnPrefs.setAutoCreateRowSorter(true); |
87 |
0 |
this.getViewport().add(tbl_FTSDataColumnPrefs); |
88 |
0 |
this.currentSource = source; |
89 |
|
|
90 |
0 |
String[] columnNames = ftsRestClient.getPreferencesColumnsFor(source); |
91 |
|
|
92 |
0 |
Object[][] data = new Object[allFTSDataColumns.size()][3]; |
93 |
|
|
94 |
0 |
int x = 0; |
95 |
0 |
for (FTSDataColumnI field : allFTSDataColumns) |
96 |
|
{ |
97 |
|
|
98 |
|
|
99 |
0 |
if (field.getName().equalsIgnoreCase("all")) |
100 |
|
{ |
101 |
0 |
continue; |
102 |
|
} |
103 |
|
|
104 |
0 |
switch (source) |
105 |
|
{ |
106 |
0 |
case SEARCH_SUMMARY: |
107 |
0 |
data[x++] = new Object[] { ftsRestClient |
108 |
|
.getAllDefaultDisplayedFTSDataColumns().contains(field), |
109 |
|
field.getName(), field.getGroup() }; |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
0 |
break; |
114 |
0 |
case STRUCTURE_CHOOSER: |
115 |
0 |
data[x++] = new Object[] { structSummaryColumns.contains(field), |
116 |
|
field.getName(), field.getGroup() }; |
117 |
0 |
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 |
0 |
map.put(field.getName(), field); |
128 |
|
} |
129 |
|
|
130 |
0 |
FTSDataColumnPrefsTableModel model = new FTSDataColumnPrefsTableModel( |
131 |
|
columnNames, data); |
132 |
0 |
tbl_FTSDataColumnPrefs.setModel(model); |
133 |
|
|
134 |
0 |
switch (source) |
135 |
|
{ |
136 |
0 |
case SEARCH_SUMMARY: |
137 |
0 |
case STRUCTURE_CHOOSER: |
138 |
0 |
tbl_FTSDataColumnPrefs.getColumnModel().getColumn(0) |
139 |
|
.setPreferredWidth(30); |
140 |
0 |
tbl_FTSDataColumnPrefs.getColumnModel().getColumn(0).setMinWidth(20); |
141 |
0 |
tbl_FTSDataColumnPrefs.getColumnModel().getColumn(0).setMaxWidth(40); |
142 |
0 |
tbl_FTSDataColumnPrefs.getColumnModel().getColumn(1) |
143 |
|
.setPreferredWidth(150); |
144 |
0 |
tbl_FTSDataColumnPrefs.getColumnModel().getColumn(1).setMinWidth(150); |
145 |
0 |
tbl_FTSDataColumnPrefs.getColumnModel().getColumn(2) |
146 |
|
.setPreferredWidth(150); |
147 |
0 |
tbl_FTSDataColumnPrefs.getColumnModel().getColumn(2).setMinWidth(150); |
148 |
|
|
149 |
0 |
TableRowSorter<TableModel> sorter = new TableRowSorter<>( |
150 |
|
tbl_FTSDataColumnPrefs.getModel()); |
151 |
0 |
tbl_FTSDataColumnPrefs.setRowSorter(sorter); |
152 |
0 |
List<RowSorter.SortKey> sortKeys = new ArrayList<>(); |
153 |
0 |
int columnIndexToSort = 2; |
154 |
0 |
sortKeys.add(new RowSorter.SortKey(columnIndexToSort, |
155 |
|
SortOrder.ASCENDING)); |
156 |
0 |
sorter.setComparator(columnIndexToSort, |
157 |
|
new Comparator<FTSDataColumnGroupI>() |
158 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
159 |
0 |
@Override... |
160 |
|
public int compare(FTSDataColumnGroupI o1, |
161 |
|
FTSDataColumnGroupI o2) |
162 |
|
{ |
163 |
0 |
return o1.getSortOrder() - o2.getSortOrder(); |
164 |
|
} |
165 |
|
}); |
166 |
0 |
sorter.setSortKeys(sortKeys); |
167 |
|
|
168 |
|
|
169 |
0 |
tbl_FTSDataColumnPrefs |
170 |
|
.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); |
171 |
0 |
break; |
172 |
0 |
case PREFERENCES: |
173 |
0 |
default: |
174 |
0 |
break; |
175 |
|
} |
176 |
|
|
177 |
|
} |
178 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
179 |
0 |
public Collection<FTSDataColumnI> getStructureSummaryFields()... |
180 |
|
{ |
181 |
0 |
return structSummaryColumns; |
182 |
|
} |
183 |
|
|
|
|
| 0% |
Uncovered Elements: 70 (70) |
Complexity: 25 |
Complexity Density: 0.54 |
|
184 |
|
class FTSDataColumnPrefsTableModel extends AbstractTableModel |
185 |
|
{ |
186 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
187 |
0 |
public FTSDataColumnPrefsTableModel(String[] columnNames,... |
188 |
|
Object[][] data) |
189 |
|
{ |
190 |
0 |
this.data = data; |
191 |
0 |
this.columnNames = columnNames; |
192 |
|
} |
193 |
|
|
194 |
|
private Object[][] data; |
195 |
|
|
196 |
|
private String[] columnNames; |
197 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
198 |
0 |
@Override... |
199 |
|
public int getColumnCount() |
200 |
|
{ |
201 |
0 |
return columnNames.length; |
202 |
|
} |
203 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
204 |
0 |
@Override... |
205 |
|
public int getRowCount() |
206 |
|
{ |
207 |
0 |
return data.length; |
208 |
|
} |
209 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
210 |
0 |
@Override... |
211 |
|
public String getColumnName(int col) |
212 |
|
{ |
213 |
0 |
return columnNames[col]; |
214 |
|
} |
215 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
216 |
0 |
@Override... |
217 |
|
public Object getValueAt(int row, int col) |
218 |
|
{ |
219 |
0 |
return data[row][col]; |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
227 |
0 |
@Override... |
228 |
|
public Class getColumnClass(int c) |
229 |
|
{ |
230 |
0 |
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 |
|
} |