mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-13 16:36:15 +00:00
add property change listener
This commit is contained in:
parent
50c7ddb1a6
commit
c63bfaf72e
@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.centralrepository.datamodel;
|
package org.sleuthkit.autopsy.centralrepository.datamodel;
|
||||||
|
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.beans.PropertyChangeSupport;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -39,16 +41,38 @@ public class CentralRepoDbManager {
|
|||||||
|
|
||||||
private static volatile CentralRepoDbChoice savedChoice = null;
|
private static volatile CentralRepoDbChoice savedChoice = null;
|
||||||
|
|
||||||
|
private static final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(CentralRepoDbManager.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the selected platform to the config file.
|
* Save the selected platform to the config file.
|
||||||
*/
|
*/
|
||||||
public static synchronized CentralRepoDbChoice saveDbChoice(CentralRepoDbChoice choice) {
|
public static synchronized CentralRepoDbChoice saveDbChoice(CentralRepoDbChoice choice) {
|
||||||
CentralRepoDbChoice newChoice = (choice == null) ? CentralRepoDbChoice.DISABLED : choice;
|
CentralRepoDbChoice newChoice = (choice == null) ? CentralRepoDbChoice.DISABLED : choice;
|
||||||
|
CentralRepoDbChoice oldChoice = savedChoice;
|
||||||
savedChoice = newChoice;
|
savedChoice = newChoice;
|
||||||
ModuleSettings.setConfigSetting("CentralRepository", "db.selectedPlatform", newChoice.getSettingKey());
|
ModuleSettings.setConfigSetting("CentralRepository", "db.selectedPlatform", newChoice.getSettingKey());
|
||||||
|
propertyChangeSupport.firePropertyChange("savedChoice", oldChoice, newChoice);
|
||||||
return newChoice;
|
return newChoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* adds a property change listener
|
||||||
|
* NOTE: currently only listening for changes in currently saved db choice
|
||||||
|
*
|
||||||
|
* @param listener the listener for the event
|
||||||
|
*/
|
||||||
|
public static void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||||
|
propertyChangeSupport.addPropertyChangeListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* removes a propert change listener
|
||||||
|
* @param listener the listener to remove
|
||||||
|
*/
|
||||||
|
public static void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||||
|
propertyChangeSupport.removePropertyChangeListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the selectedPlatform boolean from the config file, if it is set.
|
* Load the selectedPlatform boolean from the config file, if it is set.
|
||||||
*/
|
*/
|
||||||
|
@ -51,25 +51,6 @@ import java.util.logging.Level;
|
|||||||
@SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
|
@SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
|
||||||
public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel implements OptionsPanel {
|
public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel implements OptionsPanel {
|
||||||
|
|
||||||
/**
|
|
||||||
* listener to handle when settings change and an instance of this class needs to be notified.
|
|
||||||
*/
|
|
||||||
private interface OnSettingsChangeListener {
|
|
||||||
void onSettingsChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static OnSettingsChangeListener listener = null;
|
|
||||||
|
|
||||||
private static void onSettingsChange() {
|
|
||||||
if (listener != null)
|
|
||||||
listener.onSettingsChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setSettingsChangeListener(OnSettingsChangeListener newListener) {
|
|
||||||
listener = newListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static final Logger logger = Logger.getLogger(GlobalSettingsPanel.class.getName());
|
private static final Logger logger = Logger.getLogger(GlobalSettingsPanel.class.getName());
|
||||||
private static final Set<IngestManager.IngestJobEvent> INGEST_JOB_EVENTS_OF_INTEREST = EnumSet.of(IngestManager.IngestJobEvent.STARTED, IngestManager.IngestJobEvent.CANCELLED, IngestManager.IngestJobEvent.COMPLETED);
|
private static final Set<IngestManager.IngestJobEvent> INGEST_JOB_EVENTS_OF_INTEREST = EnumSet.of(IngestManager.IngestJobEvent.STARTED, IngestManager.IngestJobEvent.CANCELLED, IngestManager.IngestJobEvent.COMPLETED);
|
||||||
@ -83,8 +64,8 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i
|
|||||||
public GlobalSettingsPanel() {
|
public GlobalSettingsPanel() {
|
||||||
ingestJobEventListener = new IngestJobEventPropertyChangeListener();
|
ingestJobEventListener = new IngestJobEventPropertyChangeListener();
|
||||||
|
|
||||||
// most recently created panel will receive update events
|
// listen for change events in currently saved choice
|
||||||
GlobalSettingsPanel.setSettingsChangeListener(() -> ingestStateUpdated(Case.isCaseOpen()));
|
CentralRepoDbManager.addPropertyChangeListener((PropertyChangeEvent evt) -> ingestStateUpdated(Case.isCaseOpen()));
|
||||||
initComponents();
|
initComponents();
|
||||||
customizeComponents();
|
customizeComponents();
|
||||||
addIngestJobEventsListener();
|
addIngestJobEventsListener();
|
||||||
@ -222,8 +203,6 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i
|
|||||||
else if (JOptionPane.NO_OPTION == result) {
|
else if (JOptionPane.NO_OPTION == result) {
|
||||||
invokeCrChoice(parent, CentralRepoDbChoice.POSTGRESQL_CUSTOM);
|
invokeCrChoice(parent, CentralRepoDbChoice.POSTGRESQL_CUSTOM);
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalSettingsPanel.onSettingsChange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -232,13 +211,11 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i
|
|||||||
boolean successful = EamDbSettingsDialog.testStatusAndCreate(parent, new CentralRepoDbManager());
|
boolean successful = EamDbSettingsDialog.testStatusAndCreate(parent, new CentralRepoDbManager());
|
||||||
if (successful) {
|
if (successful) {
|
||||||
updateDatabase(parent);
|
updateDatabase(parent);
|
||||||
onSettingsChange();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// disable central repository
|
// disable central repository
|
||||||
CentralRepoDbUtil.setUseCentralRepo(false);
|
CentralRepoDbUtil.setUseCentralRepo(false);
|
||||||
CentralRepoDbManager.saveDbChoice(CentralRepoDbChoice.DISABLED);
|
CentralRepoDbManager.saveDbChoice(CentralRepoDbChoice.DISABLED);
|
||||||
GlobalSettingsPanel.onSettingsChange();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user