mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-15 01:57:39 -05:00
1723 Adds database folder as a user directory preference.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* *****************************************************************************
|
* *****************************************************************************
|
||||||
* Copyright (C) 2014-2023 Dennis Sheirer
|
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -157,7 +157,8 @@ public class SDRTrunk
|
|||||||
boolean headless = GraphicsEnvironment.isHeadless();
|
boolean headless = GraphicsEnvironment.isHeadless();
|
||||||
|
|
||||||
//Set the user's preferred location for the database prior to starting the application
|
//Set the user's preferred location for the database prior to starting the application
|
||||||
String dbpath = new UserPreferences().getDirectoryPreference().getDirectoryApplicationRoot().toString();
|
// String dbpath = new UserPreferences().getDirectoryPreference().getDirectoryApplicationRoot().toString();
|
||||||
|
String dbpath = new UserPreferences().getDirectoryPreference().getDirectoryDatabase().getParent().toString();
|
||||||
System.setProperty("derby.system.home", dbpath);
|
System.setProperty("derby.system.home", dbpath);
|
||||||
|
|
||||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(SDRTrunk.class)
|
ConfigurableApplicationContext context = new SpringApplicationBuilder(SDRTrunk.class)
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import javafx.event.ActionEvent;
|
|||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Orientation;
|
import javafx.geometry.Orientation;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.Separator;
|
import javafx.scene.control.Separator;
|
||||||
@@ -74,6 +75,11 @@ public class DirectoryPreferenceEditor extends PreferenceEditor implements IPref
|
|||||||
private Button mResetConfigurationButton;
|
private Button mResetConfigurationButton;
|
||||||
private Label mConfigurationPathLabel;
|
private Label mConfigurationPathLabel;
|
||||||
|
|
||||||
|
private Label mDatabaseLabel;
|
||||||
|
private Button mChangeDatabaseButton;
|
||||||
|
private Button mResetDatabaseButton;
|
||||||
|
private Label mDatabasePathLabel;
|
||||||
|
|
||||||
private Label mEventLogsLabel;
|
private Label mEventLogsLabel;
|
||||||
private Button mChangeEventLogsButton;
|
private Button mChangeEventLogsButton;
|
||||||
private Button mResetEventLogsButton;
|
private Button mResetEventLogsButton;
|
||||||
@@ -203,6 +209,19 @@ public class DirectoryPreferenceEditor extends PreferenceEditor implements IPref
|
|||||||
mEditorPane.add(getResetConfigurationButton(), 3, row++);
|
mEditorPane.add(getResetConfigurationButton(), 3, row++);
|
||||||
|
|
||||||
|
|
||||||
|
GridPane.setMargin(getDatabaseLabel(), new Insets(0, 10, 0, 0));
|
||||||
|
mEditorPane.add(getDatabaseLabel(), 0, row);
|
||||||
|
|
||||||
|
GridPane.setMargin(getDatabasePathLabel(), new Insets(0, 10, 0, 0));
|
||||||
|
mEditorPane.add(getDatabasePathLabel(), 1, row);
|
||||||
|
|
||||||
|
GridPane.setMargin(getChangeDatabaseButton(), new Insets(2, 10, 2, 0));
|
||||||
|
mEditorPane.add(getChangeDatabaseButton(), 2, row);
|
||||||
|
|
||||||
|
GridPane.setMargin(getResetDatabaseButton(), new Insets(2, 0, 2, 0));
|
||||||
|
mEditorPane.add(getResetDatabaseButton(), 3, row++);
|
||||||
|
|
||||||
|
|
||||||
GridPane.setMargin(getEventLogsLabel(), new Insets(0, 10, 0, 0));
|
GridPane.setMargin(getEventLogsLabel(), new Insets(0, 10, 0, 0));
|
||||||
mEditorPane.add(getEventLogsLabel(), 0, row);
|
mEditorPane.add(getEventLogsLabel(), 0, row);
|
||||||
|
|
||||||
@@ -590,6 +609,66 @@ public class DirectoryPreferenceEditor extends PreferenceEditor implements IPref
|
|||||||
return mConfigurationPathLabel;
|
return mConfigurationPathLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Label getDatabaseLabel()
|
||||||
|
{
|
||||||
|
if(mDatabaseLabel == null)
|
||||||
|
{
|
||||||
|
mDatabaseLabel = new Label("Database");
|
||||||
|
}
|
||||||
|
|
||||||
|
return mDatabaseLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Button getChangeDatabaseButton()
|
||||||
|
{
|
||||||
|
if(mChangeDatabaseButton == null)
|
||||||
|
{
|
||||||
|
mChangeDatabaseButton = new Button("Change...");
|
||||||
|
mChangeDatabaseButton.setOnAction(event -> {
|
||||||
|
DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||||
|
directoryChooser.setTitle("Select Database Folder");
|
||||||
|
directoryChooser.setInitialDirectory(mDirectoryPreference.getDirectoryDatabase().toFile());
|
||||||
|
Stage stage = (Stage)getChangeCallButton().getScene().getWindow();
|
||||||
|
File selected = directoryChooser.showDialog(stage);
|
||||||
|
|
||||||
|
if(selected != null)
|
||||||
|
{
|
||||||
|
mDirectoryPreference.setDirectoryDatabase(selected.toPath());
|
||||||
|
|
||||||
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||||
|
alert.setTitle("Directory Updated");
|
||||||
|
alert.setHeaderText("Database Directory Updated");
|
||||||
|
alert.setContentText("Please restart the application for the change to take effect.");
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return mChangeDatabaseButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Button getResetDatabaseButton()
|
||||||
|
{
|
||||||
|
if(mResetDatabaseButton == null)
|
||||||
|
{
|
||||||
|
mResetDatabaseButton = new Button("Reset");
|
||||||
|
mResetDatabaseButton.setOnAction(event -> mDirectoryPreference.resetDirectoryDatabase());
|
||||||
|
}
|
||||||
|
|
||||||
|
return mResetDatabaseButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Label getDatabasePathLabel()
|
||||||
|
{
|
||||||
|
if(mDatabasePathLabel == null)
|
||||||
|
{
|
||||||
|
mDatabasePathLabel = new Label(mDirectoryPreference.getDirectoryDatabase().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return mDatabasePathLabel;
|
||||||
|
}
|
||||||
|
|
||||||
private Label getEventLogsLabel()
|
private Label getEventLogsLabel()
|
||||||
{
|
{
|
||||||
if(mEventLogsLabel == null)
|
if(mEventLogsLabel == null)
|
||||||
@@ -988,6 +1067,7 @@ public class DirectoryPreferenceEditor extends PreferenceEditor implements IPref
|
|||||||
getApplicationRootPathLabel().setText(mDirectoryPreference.getDirectoryApplicationRoot().toString());
|
getApplicationRootPathLabel().setText(mDirectoryPreference.getDirectoryApplicationRoot().toString());
|
||||||
getApplicationLogsPathLabel().setText(mDirectoryPreference.getDirectoryApplicationLog().toString());
|
getApplicationLogsPathLabel().setText(mDirectoryPreference.getDirectoryApplicationLog().toString());
|
||||||
getCallPathLabel().setText(mDirectoryPreference.getDirectoryCalls().toString());
|
getCallPathLabel().setText(mDirectoryPreference.getDirectoryCalls().toString());
|
||||||
|
getDatabasePathLabel().setText(mDirectoryPreference.getDirectoryDatabase().toString());
|
||||||
getEventLogsPathLabel().setText(mDirectoryPreference.getDirectoryEventLog().toString());
|
getEventLogsPathLabel().setText(mDirectoryPreference.getDirectoryEventLog().toString());
|
||||||
getPlaylistPathLabel().setText(mDirectoryPreference.getDirectoryPlaylist().toString());
|
getPlaylistPathLabel().setText(mDirectoryPreference.getDirectoryPlaylist().toString());
|
||||||
getRecordingPathLabel().setText(mDirectoryPreference.getDirectoryRecording().toString());
|
getRecordingPathLabel().setText(mDirectoryPreference.getDirectoryRecording().toString());
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ public class DirectoryPreference extends Preference
|
|||||||
private static final String DIRECTORY_APPLICATION_LOG = "logs";
|
private static final String DIRECTORY_APPLICATION_LOG = "logs";
|
||||||
private static final String DIRECTORY_CALL = "calls";
|
private static final String DIRECTORY_CALL = "calls";
|
||||||
private static final String DIRECTORY_CONFIGURATION = "configuration";
|
private static final String DIRECTORY_CONFIGURATION = "configuration";
|
||||||
|
private static final String DIRECTORY_DATABASE = "database";
|
||||||
private static final String DIRECTORY_EVENT_LOG = "event_logs";
|
private static final String DIRECTORY_EVENT_LOG = "event_logs";
|
||||||
private static final String DIRECTORY_JMBE = "jmbe";
|
private static final String DIRECTORY_JMBE = "jmbe";
|
||||||
private static final String DIRECTORY_PLAYLIST = "playlist";
|
private static final String DIRECTORY_PLAYLIST = "playlist";
|
||||||
@@ -53,8 +54,9 @@ public class DirectoryPreference extends Preference
|
|||||||
|
|
||||||
private static final String PREFERENCE_KEY_DIRECTORY_APPLICATION_ROOT = "directory.application.root";
|
private static final String PREFERENCE_KEY_DIRECTORY_APPLICATION_ROOT = "directory.application.root";
|
||||||
private static final String PREFERENCE_KEY_DIRECTORY_APPLICATION_LOGS = "directory.application.logs";
|
private static final String PREFERENCE_KEY_DIRECTORY_APPLICATION_LOGS = "directory.application.logs";
|
||||||
private static final String PREFERENCE_KEY_DIRECTORY_CALLS = "directory.event.calls";
|
private static final String PREFERENCE_KEY_DIRECTORY_CALLS = "directory.calls";
|
||||||
private static final String PREFERENCE_KEY_DIRECTORY_CONFIGURATION = "directory.configuration";
|
private static final String PREFERENCE_KEY_DIRECTORY_CONFIGURATION = "directory.configuration";
|
||||||
|
private static final String PREFERENCE_KEY_DIRECTORY_DATABASE = "directory.database";
|
||||||
private static final String PREFERENCE_KEY_DIRECTORY_EVENT_LOGS = "directory.event.logs";
|
private static final String PREFERENCE_KEY_DIRECTORY_EVENT_LOGS = "directory.event.logs";
|
||||||
private static final String PREFERENCE_KEY_DIRECTORY_JMBE = "directory.jmbe";
|
private static final String PREFERENCE_KEY_DIRECTORY_JMBE = "directory.jmbe";
|
||||||
private static final String PREFERENCE_KEY_DIRECTORY_PLAYLIST = "directory.playlist";
|
private static final String PREFERENCE_KEY_DIRECTORY_PLAYLIST = "directory.playlist";
|
||||||
@@ -68,6 +70,7 @@ public class DirectoryPreference extends Preference
|
|||||||
private Path mDirectoryApplicationLogs;
|
private Path mDirectoryApplicationLogs;
|
||||||
private Path mDirectoryCalls;
|
private Path mDirectoryCalls;
|
||||||
private Path mDirectoryConfiguration;
|
private Path mDirectoryConfiguration;
|
||||||
|
private Path mDirectoryDatabase;
|
||||||
private Path mDirectoryEventLogs;
|
private Path mDirectoryEventLogs;
|
||||||
private Path mDirectoryJmbe;
|
private Path mDirectoryJmbe;
|
||||||
private Path mDirectoryPlaylist;
|
private Path mDirectoryPlaylist;
|
||||||
@@ -129,6 +132,7 @@ public class DirectoryPreference extends Preference
|
|||||||
{
|
{
|
||||||
mDirectoryApplicationLogs = null;
|
mDirectoryApplicationLogs = null;
|
||||||
mDirectoryCalls = null;
|
mDirectoryCalls = null;
|
||||||
|
mDirectoryDatabase = null;
|
||||||
mDirectoryEventLogs = null;
|
mDirectoryEventLogs = null;
|
||||||
mDirectoryJmbe = null;
|
mDirectoryJmbe = null;
|
||||||
mDirectoryPlaylist = null;
|
mDirectoryPlaylist = null;
|
||||||
@@ -306,6 +310,41 @@ public class DirectoryPreference extends Preference
|
|||||||
notifyPreferenceUpdated();
|
notifyPreferenceUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path to the folder for the database
|
||||||
|
*/
|
||||||
|
public Path getDirectoryDatabase()
|
||||||
|
{
|
||||||
|
if(mDirectoryDatabase == null)
|
||||||
|
{
|
||||||
|
mDirectoryDatabase = getPath(PREFERENCE_KEY_DIRECTORY_DATABASE, getDefaultDatabaseDirectory());
|
||||||
|
//Don't autocreate this directory ... spring will fail to initialize and start the database if the
|
||||||
|
//directory already exists but doesn't contain any database files.
|
||||||
|
}
|
||||||
|
|
||||||
|
return mDirectoryDatabase;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the path to the database folder
|
||||||
|
*/
|
||||||
|
public void setDirectoryDatabase(Path path)
|
||||||
|
{
|
||||||
|
mDirectoryDatabase = path;
|
||||||
|
mPreferences.put(PREFERENCE_KEY_DIRECTORY_DATABASE, path.toString());
|
||||||
|
notifyPreferenceUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a stored database directory preference so that the default path can be used again
|
||||||
|
*/
|
||||||
|
public void resetDirectoryDatabase()
|
||||||
|
{
|
||||||
|
mPreferences.remove(PREFERENCE_KEY_DIRECTORY_DATABASE);
|
||||||
|
mDirectoryDatabase = null;
|
||||||
|
notifyPreferenceUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Path to the folder for storing event logs
|
* Path to the folder for storing event logs
|
||||||
*/
|
*/
|
||||||
@@ -542,6 +581,14 @@ public class DirectoryPreference extends Preference
|
|||||||
return getDirectoryApplicationRoot().resolve(DIRECTORY_CONFIGURATION);
|
return getDirectoryApplicationRoot().resolve(DIRECTORY_CONFIGURATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default database directory
|
||||||
|
*/
|
||||||
|
public Path getDefaultDatabaseDirectory()
|
||||||
|
{
|
||||||
|
return getDirectoryApplicationRoot().resolve(DIRECTORY_DATABASE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default event logs directory
|
* Default event logs directory
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user