Moved the initalization of the date time filters to updateAndApplyFilters

This commit is contained in:
Kelly Kelly 2019-05-23 15:36:36 -04:00
parent 3658d651b3
commit aa9420ca8c

View File

@ -157,7 +157,6 @@ final public class FiltersPanel extends JPanel {
applyFiltersButton.addActionListener(e -> applyFilters()); applyFiltersButton.addActionListener(e -> applyFilters());
refreshButton.addActionListener(e -> applyFilters()); refreshButton.addActionListener(e -> applyFilters());
initalizeDateTimeFilters();
} }
/** /**
@ -184,6 +183,8 @@ final public class FiltersPanel extends JPanel {
void updateAndApplyFilters(boolean initialState) { void updateAndApplyFilters(boolean initialState) {
updateFilters(initialState); updateFilters(initialState);
applyFilters(); applyFilters();
initalizeDateTimeFilters();
} }
private void updateTimeZone() { private void updateTimeZone() {
@ -206,10 +207,6 @@ final public class FiltersPanel extends JPanel {
//clear the device filter widget when the case changes. //clear the device filter widget when the case changes.
devicesMap.clear(); devicesMap.clear();
devicesPane.removeAll(); devicesPane.removeAll();
if(evt.getNewValue() != null) { // Case was opened
initalizeDateTimeFilters();
}
}); });
} }
@ -709,6 +706,10 @@ final public class FiltersPanel extends JPanel {
map.values().forEach(box -> box.setSelected(selected)); map.values().forEach(box -> box.setSelected(selected));
} }
/**
* initalize the DateTimePickers by grabbing the earliest and latest time
* from the autopsy db.
*/
private void initalizeDateTimeFilters() { private void initalizeDateTimeFilters() {
String queryString = "max(date_time) as max, min(date_time) as min from account_relationships"; // NON-NLS String queryString = "max(date_time) as max, min(date_time) as min from account_relationships"; // NON-NLS
if(Case.isCaseOpen()) { if(Case.isCaseOpen()) {
@ -719,28 +720,37 @@ final public class FiltersPanel extends JPanel {
try { try {
if (rs.next()) { if (rs.next()) {
int startDate = rs.getInt("min"); // NON-NLS int startDate = rs.getInt("min"); // NON-NLS
int endData = rs.getInt("max"); // NON-NLS int endDate = rs.getInt("max"); // NON-NLS
startDatePicker.setDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(startDate), Utils.getUserPreferredZoneId()).toLocalDate()); if(startDate != 0 && endDate != 0) {
endDatePicker.setDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(endData), Utils.getUserPreferredZoneId()).toLocalDate()); startDatePicker.setDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(startDate), Utils.getUserPreferredZoneId()).toLocalDate());
endDatePicker.setDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(endDate), Utils.getUserPreferredZoneId()).toLocalDate());
} else {
setDateTimeFiltersToDefault();
}
} else {
setDateTimeFiltersToDefault();
} }
} catch (SQLException ex) { } catch (SQLException ex) {
setDateTimeFiltersToDefault();
logger.log(Level.WARNING, "Unable to set filter date pickers due to SQL exception", ex); //NON-NLS logger.log(Level.WARNING, "Unable to set filter date pickers due to SQL exception", ex); //NON-NLS
} }
} }
}); });
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
logger.log(Level.WARNING, "Exception thrown while initalizing Date Time filters, using default values from date time", ex); //NON-NLS logger.log(Level.WARNING, "Exception thrown while initalizing Date Time filters, using default values from date time", ex); //NON-NLS
startDatePicker.setDate(LocalDate.now().minusWeeks(3)); setDateTimeFiltersToDefault();
endDatePicker.setDate(LocalDate.now());
} }
} else { } else {
startDatePicker.setDate(LocalDate.now().minusWeeks(3)); setDateTimeFiltersToDefault();
endDatePicker.setDate(LocalDate.now());
} }
} }
private void setDateTimeFiltersToDefault() {
startDatePicker.setDate(LocalDate.now().minusWeeks(3));
endDatePicker.setDate(LocalDate.now());
}
private void unCheckAllAccountTypesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_unCheckAllAccountTypesButtonActionPerformed private void unCheckAllAccountTypesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_unCheckAllAccountTypesButtonActionPerformed
setAllAccountTypesSelected(false); setAllAccountTypesSelected(false);
}//GEN-LAST:event_unCheckAllAccountTypesButtonActionPerformed }//GEN-LAST:event_unCheckAllAccountTypesButtonActionPerformed