7811 check table model row count instead of table

This commit is contained in:
William Schaefer 2021-07-13 12:57:51 -04:00
parent 5db2cd89fb
commit 7923e582da

View File

@ -85,7 +85,7 @@ public final class OtherOccurrencesPanel extends javax.swing.JPanel {
private AbstractFile file = null; private AbstractFile file = null;
private SwingWorker<?, ?> worker; private SwingWorker<?, ?> worker;
// Initializing the JFileChooser in a thread to prevent a block on the EDT // Initializing the JFileChooser in a thread to prevent a block on the EDT
// see https://stackoverflow.com/questions/49792375/jfilechooser-is-very-slow-when-using-windows-look-and-feel // see https://stackoverflow.com/questions/49792375/jfilechooser-is-very-slow-when-using-windows-look-and-feel
private final FutureTask<JFileChooser> futureFileChooser = new FutureTask<>(JFileChooser::new); private final FutureTask<JFileChooser> futureFileChooser = new FutureTask<>(JFileChooser::new);
@ -101,7 +101,7 @@ public final class OtherOccurrencesPanel extends javax.swing.JPanel {
this.correlationAttributes = new ArrayList<>(); this.correlationAttributes = new ArrayList<>();
initComponents(); initComponents();
customizeComponents(); customizeComponents();
ExecutorService executor = Executors.newSingleThreadExecutor(); ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(futureFileChooser); executor.execute(futureFileChooser);
} }
@ -253,9 +253,9 @@ public final class OtherOccurrencesPanel extends javax.swing.JPanel {
private void saveToCSV() throws NoCurrentCaseException { private void saveToCSV() throws NoCurrentCaseException {
if (casesTableModel.getRowCount() > 0) { if (casesTableModel.getRowCount() > 0) {
if(CSVFileChooser == null) { if (CSVFileChooser == null) {
try{ try {
CSVFileChooser = futureFileChooser.get(); CSVFileChooser = futureFileChooser.get();
} catch (InterruptedException | ExecutionException ex) { } catch (InterruptedException | ExecutionException ex) {
// If something happened with the thread try and // If something happened with the thread try and
@ -264,7 +264,7 @@ public final class OtherOccurrencesPanel extends javax.swing.JPanel {
CSVFileChooser = new JFileChooser(); CSVFileChooser = new JFileChooser();
} }
} }
Calendar now = Calendar.getInstance(); Calendar now = Calendar.getInstance();
String fileName = String.format("%1$tY%1$tm%1$te%1$tI%1$tM%1$tS_other_data_sources.csv", now); String fileName = String.format("%1$tY%1$tm%1$te%1$tI%1$tM%1$tS_other_data_sources.csv", now);
CSVFileChooser.setCurrentDirectory(new File(Case.getCurrentCaseThrows().getExportDirectory())); CSVFileChooser.setCurrentDirectory(new File(Case.getCurrentCaseThrows().getExportDirectory()));
@ -339,12 +339,13 @@ public final class OtherOccurrencesPanel extends javax.swing.JPanel {
casesTableModel.addCorrelationCase(NO_ARTIFACTS_CASE); casesTableModel.addCorrelationCase(NO_ARTIFACTS_CASE);
} else if (caseCount == 0) { } else if (caseCount == 0) {
casesTableModel.addCorrelationCase(NO_RESULTS_CASE); casesTableModel.addCorrelationCase(NO_RESULTS_CASE);
} } else {
String earliestDate = data.getEarliestCaseDate(); String earliestDate = data.getEarliestCaseDate();
earliestCaseDate.setText(earliestDate.isEmpty() ? Bundle.OtherOccurrencesPanel_earliestCaseNotAvailable() : earliestDate); earliestCaseDate.setText(earliestDate.isEmpty() ? Bundle.OtherOccurrencesPanel_earliestCaseNotAvailable() : earliestDate);
foundInLabel.setText(String.format(Bundle.OtherOccurrencesPanel_foundIn_text(), data.getTotalCount(), caseCount, data.getDataSourceCount())); foundInLabel.setText(String.format(Bundle.OtherOccurrencesPanel_foundIn_text(), data.getTotalCount(), caseCount, data.getDataSourceCount()));
if (caseCount > 0) { if (caseCount > 0) {
casesTable.setRowSelectionInterval(0, 0); casesTable.setRowSelectionInterval(0, 0);
}
} }
} catch (InterruptedException | ExecutionException ex) { } catch (InterruptedException | ExecutionException ex) {
@ -389,12 +390,13 @@ public final class OtherOccurrencesPanel extends javax.swing.JPanel {
casesTableModel.addCorrelationCase(NO_ARTIFACTS_CASE); casesTableModel.addCorrelationCase(NO_ARTIFACTS_CASE);
} else if (caseCount == 0) { } else if (caseCount == 0) {
casesTableModel.addCorrelationCase(NO_RESULTS_CASE); casesTableModel.addCorrelationCase(NO_RESULTS_CASE);
} } else {
String earliestDate = data.getEarliestCaseDate(); String earliestDate = data.getEarliestCaseDate();
earliestCaseDate.setText(earliestDate.isEmpty() ? Bundle.OtherOccurrencesPanel_earliestCaseNotAvailable() : earliestDate); earliestCaseDate.setText(earliestDate.isEmpty() ? Bundle.OtherOccurrencesPanel_earliestCaseNotAvailable() : earliestDate);
foundInLabel.setText(String.format(Bundle.OtherOccurrencesPanel_foundIn_text(), data.getInstanceDataCount(), caseCount, data.getDataSourceCount())); foundInLabel.setText(String.format(Bundle.OtherOccurrencesPanel_foundIn_text(), data.getInstanceDataCount(), caseCount, data.getDataSourceCount()));
if (caseCount > 0) { if (caseCount > 0) {
casesTable.setRowSelectionInterval(0, 0); casesTable.setRowSelectionInterval(0, 0);
}
} }
} }
@ -420,7 +422,7 @@ public final class OtherOccurrencesPanel extends javax.swing.JPanel {
return; return;
} }
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
worker = new SelectionWorker(correlationAttributes, file, deviceId, dataSourceName) { worker = new SelectionWorker(correlationAttributes, file, deviceId, dataSourceName) {
@ -457,14 +459,14 @@ public final class OtherOccurrencesPanel extends javax.swing.JPanel {
} }
} }
} }
if (dataSourcesTable.getRowCount() > 0) { if (dataSourcesTableModel.getRowCount() > 0) {
dataSourcesTable.setRowSelectionInterval(0, 0); dataSourcesTable.setRowSelectionInterval(0, 0);
} }
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
} catch (InterruptedException | ExecutionException ex) { } catch (InterruptedException | ExecutionException ex) {
logger.log(Level.SEVERE, "Failed to update OtherOccurrencesPanel on data source selection", ex); logger.log(Level.SEVERE, "Failed to update OtherOccurrencesPanel on data source selection", ex);
} }
} }
}; };
@ -514,7 +516,7 @@ public final class OtherOccurrencesPanel extends javax.swing.JPanel {
} }
} }
} }
if (filesTable.getRowCount() > 0) { if (filesTableModel.getRowCount() > 0) {
filesTable.setRowSelectionInterval(0, 0); filesTable.setRowSelectionInterval(0, 0);
} }
} catch (InterruptedException | ExecutionException ex) { } catch (InterruptedException | ExecutionException ex) {
@ -614,11 +616,11 @@ public final class OtherOccurrencesPanel extends javax.swing.JPanel {
/** /**
* Construct a new SelectionWorker. * Construct a new SelectionWorker.
* *
* @param coAtInstances * @param coAtInstances
* @param abstractFile * @param abstractFile
* @param deviceIdStr * @param deviceIdStr
* @param dataSourceNameStr * @param dataSourceNameStr
*/ */
SelectionWorker(Collection<CorrelationAttributeInstance> coAtInstances, AbstractFile abstractFile, String deviceIdStr, String dataSourceNameStr) { SelectionWorker(Collection<CorrelationAttributeInstance> coAtInstances, AbstractFile abstractFile, String deviceIdStr, String dataSourceNameStr) {
this.coAtInstances = coAtInstances; this.coAtInstances = coAtInstances;
@ -632,12 +634,12 @@ public final class OtherOccurrencesPanel extends javax.swing.JPanel {
Map<UniquePathKey, NodeData> correlatedNodeDataMap = new HashMap<>(); Map<UniquePathKey, NodeData> correlatedNodeDataMap = new HashMap<>();
for (CorrelationAttributeInstance corAttr : coAtInstances) { for (CorrelationAttributeInstance corAttr : coAtInstances) {
correlatedNodeDataMap.putAll(OtherOccurrences.getCorrelatedInstances(abstractFile, deviceIdStr, dataSourceNameStr, corAttr)); correlatedNodeDataMap.putAll(OtherOccurrences.getCorrelatedInstances(abstractFile, deviceIdStr, dataSourceNameStr, corAttr));
if(isCancelled()) { if (isCancelled()) {
return new HashMap<>(); return new HashMap<>();
} }
} }
return correlatedNodeDataMap; return correlatedNodeDataMap;
} }
} }