mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-06 21:00:22 +00:00
update for loading
This commit is contained in:
parent
c82bb93ce7
commit
14cb87e4fb
@ -49,6 +49,8 @@ final class AddImageWizardDataSourceSettingsVisual extends JPanel {
|
|||||||
private JPanel currentPanel;
|
private JPanel currentPanel;
|
||||||
|
|
||||||
private final Map<String, DataSourceProcessor> datasourceProcessorsMap = new HashMap<>();
|
private final Map<String, DataSourceProcessor> datasourceProcessorsMap = new HashMap<>();
|
||||||
|
|
||||||
|
private final PanelUpdateListener panelUpdateListener;
|
||||||
|
|
||||||
private String currentDsp;
|
private String currentDsp;
|
||||||
|
|
||||||
@ -60,6 +62,7 @@ final class AddImageWizardDataSourceSettingsVisual extends JPanel {
|
|||||||
AddImageWizardDataSourceSettingsVisual(AddImageWizardDataSourceSettingsPanel wizPanel) {
|
AddImageWizardDataSourceSettingsVisual(AddImageWizardDataSourceSettingsPanel wizPanel) {
|
||||||
initComponents();
|
initComponents();
|
||||||
this.wizPanel = wizPanel;
|
this.wizPanel = wizPanel;
|
||||||
|
this.panelUpdateListener = new PanelUpdateListener();
|
||||||
typePanel.setLayout(new BorderLayout());
|
typePanel.setLayout(new BorderLayout());
|
||||||
discoverDataSourceProcessors();
|
discoverDataSourceProcessors();
|
||||||
currentDsp = ImageDSProcessor.getType(); //default value to the ImageDSProcessor
|
currentDsp = ImageDSProcessor.getType(); //default value to the ImageDSProcessor
|
||||||
@ -107,24 +110,37 @@ final class AddImageWizardDataSourceSettingsVisual extends JPanel {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private void updateCurrentPanel(JPanel panel) {
|
private void updateCurrentPanel(JPanel panel) {
|
||||||
|
cleanupUpdateListener(currentPanel);
|
||||||
currentPanel = panel;
|
currentPanel = panel;
|
||||||
typePanel.removeAll();
|
typePanel.removeAll();
|
||||||
typePanel.add(currentPanel, BorderLayout.CENTER);
|
typePanel.add(currentPanel, BorderLayout.CENTER);
|
||||||
typePanel.validate();
|
typePanel.validate();
|
||||||
typePanel.repaint();
|
typePanel.repaint();
|
||||||
currentPanel.addPropertyChangeListener(new PropertyChangeListener() {
|
cleanupUpdateListener(currentPanel);
|
||||||
@Override
|
currentPanel.addPropertyChangeListener(panelUpdateListener);
|
||||||
public void propertyChange(PropertyChangeEvent evt) {
|
|
||||||
if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString())) {
|
|
||||||
wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
|
|
||||||
}
|
|
||||||
if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.FOCUS_NEXT.toString())) {
|
|
||||||
wizPanel.moveFocusToNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
|
this.wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes PanelUpdateListener from panel if found.
|
||||||
|
* @param panel The panel from which to remove the listener.
|
||||||
|
*/
|
||||||
|
private void cleanupUpdateListener(JPanel panel) {
|
||||||
|
if (panel == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PropertyChangeListener[] listeners = panel.getPropertyChangeListeners();
|
||||||
|
if (listeners == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (PropertyChangeListener listener: listeners) {
|
||||||
|
if (listener instanceof PanelUpdateListener) {
|
||||||
|
panel.removePropertyChangeListener(listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the currently selected DS Processor
|
* Returns the currently selected DS Processor
|
||||||
@ -221,4 +237,20 @@ final class AddImageWizardDataSourceSettingsVisual extends JPanel {
|
|||||||
|
|
||||||
protected abstract boolean addSeparatorAfter(JList list, Object value, int index);
|
protected abstract boolean addSeparatorAfter(JList list, Object value, int index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A property change listener that responds to update events.
|
||||||
|
*/
|
||||||
|
private class PanelUpdateListener implements PropertyChangeListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void propertyChange(PropertyChangeEvent evt) {
|
||||||
|
if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString())) {
|
||||||
|
wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
|
||||||
|
}
|
||||||
|
if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.FOCUS_NEXT.toString())) {
|
||||||
|
wizPanel.moveFocusToNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,9 @@ public class ImageDSProcessor implements DataSourceProcessor, AutoIngestDataSour
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isPanelValid() {
|
public boolean isPanelValid() {
|
||||||
return configPanel.validatePanel();
|
// before attempting to validate the panel (a potentially long running operation),
|
||||||
|
// check if the validation is loading or on delay.
|
||||||
|
return !configPanel.isValidationLoading() && configPanel.validatePanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,7 +67,9 @@ public class ImageFilePanel extends JPanel {
|
|||||||
private static int VALIDATE_TIMEOUT_MILLIS = 1200;
|
private static int VALIDATE_TIMEOUT_MILLIS = 1200;
|
||||||
static ScheduledThreadPoolExecutor delayedValidationService = new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat("ImageFilePanel delayed validation").build());
|
static ScheduledThreadPoolExecutor delayedValidationService = new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat("ImageFilePanel delayed validation").build());
|
||||||
|
|
||||||
private Future<Void> validateAction = null;
|
private final Object validateActionLock = new Object();
|
||||||
|
private Runnable validateAction = null;
|
||||||
|
private Future<?> validateFuture = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new form ImageFilePanel
|
* Creates new form ImageFilePanel
|
||||||
@ -632,10 +634,6 @@ public class ImageFilePanel extends JPanel {
|
|||||||
showError(Bundle.ImageFilePanel_validatePanel_invalidSHA256());
|
showError(Bundle.ImageFilePanel_validatePanel_invalidSHA256());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PathValidator.isValidForCaseType(path, Case.getCurrentCase().getCaseType())) {
|
|
||||||
showError(Bundle.ImageFilePanel_validatePanel_dataSourceOnCDriveError());
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String password = this.getPassword();
|
String password = this.getPassword();
|
||||||
@ -652,8 +650,12 @@ public class ImageFilePanel extends JPanel {
|
|||||||
showError(Bundle.ImageFilePanel_validatePanel_unknownError());
|
showError(Bundle.ImageFilePanel_validatePanel_unknownError());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
showError(null);
|
if (!PathValidator.isValidForCaseType(path, Case.getCurrentCase().getCaseType())) {
|
||||||
|
showError(Bundle.ImageFilePanel_validatePanel_dataSourceOnCDriveError());
|
||||||
|
} else {
|
||||||
|
showError(null);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -683,6 +685,16 @@ public class ImageFilePanel extends JPanel {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return True if the panel is on a delay for validating (i.e. typing a
|
||||||
|
* password for bitlocker).
|
||||||
|
*/
|
||||||
|
public boolean isValidationLoading() {
|
||||||
|
synchronized (this.validateActionLock) {
|
||||||
|
return this.validateAction != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void storeSettings() {
|
public void storeSettings() {
|
||||||
String imagePathName = getContentPaths();
|
String imagePathName = getContentPaths();
|
||||||
@ -746,23 +758,64 @@ public class ImageFilePanel extends JPanel {
|
|||||||
delayValidate();
|
delayValidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void delayValidate() {
|
/**
|
||||||
if (ImageFilePanel.this.validateAction != null) {
|
* Run validation on a delay to avoid password checking too many times
|
||||||
ImageFilePanel.this.validateAction.cancel(true);
|
* while typing.
|
||||||
|
*/
|
||||||
|
private void delayValidate() {
|
||||||
|
boolean triggerUpdate = false;
|
||||||
|
synchronized (ImageFilePanel.this.validateActionLock) {
|
||||||
|
if (ImageFilePanel.this.validateFuture != null &&
|
||||||
|
!ImageFilePanel.this.validateFuture.isCancelled() &&
|
||||||
|
!ImageFilePanel.this.validateFuture.isDone()) {
|
||||||
|
ImageFilePanel.this.validateFuture.cancel(true);
|
||||||
|
triggerUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageFilePanel.this.validateAction = new ValidationRunnable();
|
||||||
|
|
||||||
|
ImageFilePanel.this.validateFuture = ImageFilePanel.this.delayedValidationService.schedule(
|
||||||
|
ImageFilePanel.this.validateAction,
|
||||||
|
VALIDATE_TIMEOUT_MILLIS,
|
||||||
|
TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// trigger invalidation after setting up new runnable if not already triggered
|
||||||
|
if (triggerUpdate) {
|
||||||
|
firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
|
||||||
|
}
|
||||||
|
|
||||||
errorLabel.setVisible(false);
|
errorLabel.setVisible(false);
|
||||||
if (!ImageFilePanel.this.loadingLabel.isVisible()) {
|
if (!ImageFilePanel.this.loadingLabel.isVisible()) {
|
||||||
ImageFilePanel.this.loadingLabel.setVisible(true);
|
ImageFilePanel.this.loadingLabel.setVisible(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runnable to run the updateHelper if the validation action remains
|
||||||
|
* this runnable.
|
||||||
|
*/
|
||||||
|
private class ValidationRunnable implements Runnable {
|
||||||
|
|
||||||
ImageFilePanel.this.validateAction = ImageFilePanel.this.delayedValidationService.schedule(
|
@Override
|
||||||
() -> {
|
public void run() {
|
||||||
ImageFilePanel.this.updateHelper();
|
if (Thread.interrupted()) {
|
||||||
return null;
|
return;
|
||||||
},
|
}
|
||||||
VALIDATE_TIMEOUT_MILLIS,
|
|
||||||
TimeUnit.MILLISECONDS);
|
synchronized (ImageFilePanel.this.validateActionLock) {
|
||||||
|
if (ImageFilePanel.this.validateAction != this) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the validation action to null to indicate that this is done running and can be validated.
|
||||||
|
ImageFilePanel.this.validateAction = null;
|
||||||
|
ImageFilePanel.this.validateFuture = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageFilePanel.this.updateHelper();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user