mirror of
https://github.com/elisspace/autopsy.git
synced 2026-10-01 23:09:56 +00:00
add property change listener
This commit is contained in:
+25
-1
@@ -18,6 +18,8 @@
|
||||
*/
|
||||
package org.sleuthkit.autopsy.centralrepository.datamodel;
|
||||
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
@@ -38,17 +40,39 @@ public class CentralRepoDbManager {
|
||||
|
||||
|
||||
private static volatile CentralRepoDbChoice savedChoice = null;
|
||||
|
||||
|
||||
private static final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(CentralRepoDbManager.class);
|
||||
|
||||
/**
|
||||
* Save the selected platform to the config file.
|
||||
*/
|
||||
public static synchronized CentralRepoDbChoice saveDbChoice(CentralRepoDbChoice choice) {
|
||||
CentralRepoDbChoice newChoice = (choice == null) ? CentralRepoDbChoice.DISABLED : choice;
|
||||
CentralRepoDbChoice oldChoice = savedChoice;
|
||||
savedChoice = newChoice;
|
||||
ModuleSettings.setConfigSetting("CentralRepository", "db.selectedPlatform", newChoice.getSettingKey());
|
||||
propertyChangeSupport.firePropertyChange("savedChoice", oldChoice, 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.
|
||||
*/
|
||||
|
||||
+3
-26
@@ -50,25 +50,6 @@ import java.util.logging.Level;
|
||||
*/
|
||||
@SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
|
||||
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 Logger logger = Logger.getLogger(GlobalSettingsPanel.class.getName());
|
||||
@@ -83,8 +64,8 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i
|
||||
public GlobalSettingsPanel() {
|
||||
ingestJobEventListener = new IngestJobEventPropertyChangeListener();
|
||||
|
||||
// most recently created panel will receive update events
|
||||
GlobalSettingsPanel.setSettingsChangeListener(() -> ingestStateUpdated(Case.isCaseOpen()));
|
||||
// listen for change events in currently saved choice
|
||||
CentralRepoDbManager.addPropertyChangeListener((PropertyChangeEvent evt) -> ingestStateUpdated(Case.isCaseOpen()));
|
||||
initComponents();
|
||||
customizeComponents();
|
||||
addIngestJobEventsListener();
|
||||
@@ -222,8 +203,6 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i
|
||||
else if (JOptionPane.NO_OPTION == result) {
|
||||
invokeCrChoice(parent, CentralRepoDbChoice.POSTGRESQL_CUSTOM);
|
||||
}
|
||||
|
||||
GlobalSettingsPanel.onSettingsChange();
|
||||
}
|
||||
|
||||
|
||||
@@ -231,14 +210,12 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
boolean successful = EamDbSettingsDialog.testStatusAndCreate(parent, new CentralRepoDbManager());
|
||||
if (successful) {
|
||||
updateDatabase(parent);
|
||||
onSettingsChange();
|
||||
updateDatabase(parent);
|
||||
}
|
||||
else {
|
||||
// disable central repository
|
||||
CentralRepoDbUtil.setUseCentralRepo(false);
|
||||
CentralRepoDbManager.saveDbChoice(CentralRepoDbChoice.DISABLED);
|
||||
GlobalSettingsPanel.onSettingsChange();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user