Skip to content

Commit

Permalink
Fix Find Loading Rows Function
Browse files Browse the repository at this point in the history
The recursive function attempted to get a jobID that didn't exist within the loading rows hashtable.
  • Loading branch information
AvocadoMoon committed Oct 4, 2024
1 parent 7bc1c0f commit fac12ae
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ public void initialize(ControlButtonsPanel controlButtonsPanel, ExportDetailsPan
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
int actualRow = loadingRowsJobID.containsKey(row) ? findLoadingRow(row) : -1;
int actualRow = loadingRowsJobID.containsKey(row) ? findLoadingRow(row, row) : -1;
if (actualRow != -1){
if (actualRow != row){
loadingRowsJobID.put(actualRow, loadingRowsJobID.get(row));
loadingRowsJobID.remove(row);
}
cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, actualRow, column);
cell.setForeground(Color.decode("#228B22"));
} else {
Expand Down Expand Up @@ -163,6 +159,7 @@ private void automaticRefresh(){
if(isUpdated){
n5ExportTableModel.fireTableDataChanged();
this.updateUI();
exportListTable.repaint();
}
}
Thread.sleep(TimeUnit.SECONDS.toMillis(2));
Expand Down Expand Up @@ -194,15 +191,20 @@ public void copySelectedRowLink(){
}

// The table may have changed by refreshing it, so if past idea of affected row no longer align correct it
private int findLoadingRow(int row){
if (row < 0 || row == n5ExportTableModel.getRowCount()){
private int findLoadingRow(int currentRow, int initialRow){
String expectedJobID = loadingRowsJobID.get(initialRow);
if (currentRow < 0 || currentRow == n5ExportTableModel.getRowCount()){
return -1;
}
else if (n5ExportTableModel.getRowData(row).jobID.equals(loadingRowsJobID.get(row)) &&
row < n5ExportTableModel.getRowCount()){
return row;
else if (n5ExportTableModel.getRowData(currentRow).jobID.equals(expectedJobID) &&
currentRow < n5ExportTableModel.getRowCount()){
if (currentRow != initialRow){
loadingRowsJobID.put(currentRow, expectedJobID);
loadingRowsJobID.remove(initialRow);
}
return currentRow;
} else {
return findLoadingRow(row + 1);
return findLoadingRow(currentRow + 1, initialRow);
}
}

Expand All @@ -219,7 +221,7 @@ public void valueChanged(ListSelectionEvent e) {
ExportDataRepresentation.SimulationExportDataRepresentation rowData = n5ExportTableModel.getRowData(row);
exportDetailsPanel.addExportDetailEntries("Variables: " + rowData.variables, rowData.differentParameterValues);

int loadingRow = loadingRowsJobID.containsKey(row) ? findLoadingRow(row) : -1;
int loadingRow = loadingRowsJobID.containsKey(row) ? findLoadingRow(row, row) : -1;
controlPanel.allowCancel(loadingRow != -1);
}

Expand Down

0 comments on commit fac12ae

Please sign in to comment.