Skip to content

Commit

Permalink
Add possibility to switch columns in result, make sure collection nr …
Browse files Browse the repository at this point in the history
…is sorted as numbers
  • Loading branch information
GenieTim committed Sep 28, 2024
1 parent 8e8bf7f commit 32b9ab8
Show file tree
Hide file tree
Showing 3 changed files with 400 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import edu.harvard.mcz.imagecapture.ui.CopyRowButtonEditor;
import edu.harvard.mcz.imagecapture.ui.frame.SpecimenDetailsViewPane;
import edu.harvard.mcz.imagecapture.ui.tablemodel.SpecimenListTableModel;
import edu.harvard.mcz.imagecapture.ui.tablemodel.TableColumnManager;
import org.hibernate.SessionException;
import org.hibernate.TransactionException;
import org.slf4j.Logger;
Expand Down Expand Up @@ -133,6 +134,7 @@ private JTable getJTable() {
model = new SpecimenListTableModel(s.findAll());
}
jTable.setModel(model);
new TableColumnManager(jTable);
sorter = new TableRowSorter<>(model);
sorter.toggleSortOrder(SpecimenListTableModel.COL_BARCODE - 1);
jTable.setRowSorter(sorter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@ public Object getValueAt(int rowIndex, int columnIndex) {
result = s.getCollection();
break;
case COL_COLLECTION_NR:
result = s.getFirstNumberWithType("Collection Number");
String collectionNr = s.getFirstNumberWithType("Collection Number");
if (collectionNr != null) {
try {
result = Double.parseDouble(collectionNr);
} catch (NumberFormatException e) {
result = collectionNr;
}
}
break;
}
}
Expand All @@ -157,6 +164,9 @@ public Class getColumnClass(int c) {
// needs to return Long for ID column that is to contain button
// and ** Must Not ** return Long for any other column).
Class result = String.class; // Default value to return when table is empty.
if (c == COL_COLLECTION_NR) {
return Double.class;
}
try {
result = getValueAt(0, c).getClass();
} catch (NullPointerException e) {
Expand Down
Loading

0 comments on commit 32b9ab8

Please sign in to comment.