diff --git a/src/main/java/ru/taximaxim/pgsqlblocks/dialogs/SettingsDialog.java b/src/main/java/ru/taximaxim/pgsqlblocks/dialogs/SettingsDialog.java index 40d863d..e812a3d 100644 --- a/src/main/java/ru/taximaxim/pgsqlblocks/dialogs/SettingsDialog.java +++ b/src/main/java/ru/taximaxim/pgsqlblocks/dialogs/SettingsDialog.java @@ -19,17 +19,24 @@ import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.DirectoryDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Spinner; +import org.eclipse.swt.widgets.Text; +import ru.taximaxim.pgsqlblocks.utils.ImageUtils; +import ru.taximaxim.pgsqlblocks.utils.Images; +import ru.taximaxim.pgsqlblocks.utils.PathBuilder; import ru.taximaxim.pgsqlblocks.utils.Settings; public class SettingsDialog extends Dialog { @@ -45,6 +52,7 @@ public class SettingsDialog extends Dialog { private Button confirmRequiredButton; private Button confirmExitButton; private Combo languageCombo; + private Text path; public SettingsDialog(Settings settings, Shell shell) { super(shell); @@ -64,9 +72,38 @@ protected Control createDialogArea(Composite parent) { populateGeneralGroup(container); populateProcessGroup(container); populateNotificationGroup(container); + populateBlockJournalPathGroup(container); return container; } + private void populateBlockJournalPathGroup(Composite container) { + Group generalGroup = new Group(container, SWT.SHADOW_IN); + generalGroup.setText(resourceBundle.getString("path")); + generalGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); + generalGroup.setLayout(new GridLayout(2, false)); + + path = new Text(generalGroup, SWT.BORDER); + path.setText(settings.getBlocksJournalPath()); + path.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true)); + + Button btnDir = new Button(generalGroup, SWT.PUSH); + btnDir.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, true, true)); + btnDir.setImage(ImageUtils.getImage(Images.FOLDER)); + btnDir.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + DirectoryDialog dialog = new DirectoryDialog(getShell()); + dialog.setText(resourceBundle.getString("choose_dir")); + dialog.setFilterPath(PathBuilder.getInstance().getBlocksJournalsDir().toString()); + String p = dialog.open(); + if (p != null) { + path.setText(p); + } + } + }); + } + private void populateGeneralGroup(Composite container) { Group generalGroup = new Group(container, SWT.SHADOW_IN); generalGroup.setText(resourceBundle.getString("general")); @@ -170,6 +207,7 @@ protected void okPressed() { settings.setConfirmExit(confirmExitButton.getSelection()); settings.setLanguage(languageCombo.getText()); settings.setShowBackendPid(showBackendPidButton.getSelection()); + settings.setBlocksJournalsPath(path.getText()); super.okPressed(); } diff --git a/src/main/java/ru/taximaxim/pgsqlblocks/l10n/PgSqlBlocks_en.java b/src/main/java/ru/taximaxim/pgsqlblocks/l10n/PgSqlBlocks_en.java index 43a40d2..8598cda 100644 --- a/src/main/java/ru/taximaxim/pgsqlblocks/l10n/PgSqlBlocks_en.java +++ b/src/main/java/ru/taximaxim/pgsqlblocks/l10n/PgSqlBlocks_en.java @@ -124,6 +124,8 @@ protected Object[][] getContents() { {"columns", "Columns"}, {"general", "General"}, {"select_ui_language", "UI language (requires restart)"}, + {"path", "Path to save block journals"}, + {"choose_dir", "Choose directory"}, // create database dialog {"name", "Connection name*"}, diff --git a/src/main/java/ru/taximaxim/pgsqlblocks/l10n/PgSqlBlocks_ru.java b/src/main/java/ru/taximaxim/pgsqlblocks/l10n/PgSqlBlocks_ru.java index 2f6c578..fbd722c 100644 --- a/src/main/java/ru/taximaxim/pgsqlblocks/l10n/PgSqlBlocks_ru.java +++ b/src/main/java/ru/taximaxim/pgsqlblocks/l10n/PgSqlBlocks_ru.java @@ -124,6 +124,8 @@ protected Object[][] getContents() { {"columns", "Колонки"}, {"general", "Общие"}, {"select_ui_language", "Язык интерфейса (требует перезапуска)"}, + {"path", "Путь хранения журналов блокировок"}, + {"choose_dir", "Выберите директорию"}, // create database dialog {"name", "Имя соединения*"}, diff --git a/src/main/java/ru/taximaxim/pgsqlblocks/utils/PathBuilder.java b/src/main/java/ru/taximaxim/pgsqlblocks/utils/PathBuilder.java index 2b89ebb..a5227aa 100644 --- a/src/main/java/ru/taximaxim/pgsqlblocks/utils/PathBuilder.java +++ b/src/main/java/ru/taximaxim/pgsqlblocks/utils/PathBuilder.java @@ -56,7 +56,7 @@ public static PathBuilder getInstance() { } public Path getBlocksJournalsDir() { - Path blocksJournalsDir = path.resolve("blocksJournals"); + Path blocksJournalsDir = path.resolve(Settings.getInstance().getBlocksJournalPath()); if (!blocksJournalsDir.toFile().exists()) { try { Files.createDirectory(blocksJournalsDir); diff --git a/src/main/java/ru/taximaxim/pgsqlblocks/utils/Settings.java b/src/main/java/ru/taximaxim/pgsqlblocks/utils/Settings.java index 03eaad3..2a79cbb 100644 --- a/src/main/java/ru/taximaxim/pgsqlblocks/utils/Settings.java +++ b/src/main/java/ru/taximaxim/pgsqlblocks/utils/Settings.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.Properties; import java.util.ResourceBundle; @@ -52,6 +53,7 @@ public final class Settings { private static final String CONFIRM_EXIT = "confirm_exit"; private static final String SHOW_LOG_MESSAGES = "show_log_messages"; private static final String CURRENT_LOCALE = "current_locale"; + private static final String BLOCKS_JOURNAL_PATH = "blocks_journal_path"; private int updatePeriodSeconds; private int limitBlocks; @@ -64,6 +66,7 @@ public final class Settings { private boolean confirmRequired; private boolean showBackendPid; private boolean confirmExit; + private String blocksJournalPath; private final Properties properties; private final File propFile; @@ -107,6 +110,7 @@ private Settings() { this.confirmRequired = Boolean.parseBoolean(properties.getProperty(CONFIRM_REQUIRED)); this.confirmExit = Boolean.parseBoolean(properties.getProperty(CONFIRM_EXIT)); this.locale = new Locale.Builder().setLanguageTag(properties.getProperty(CURRENT_LOCALE)).build(); + this.blocksJournalPath = properties.getProperty(BLOCKS_JOURNAL_PATH); resources = ResourceBundle.getBundle(ru.taximaxim.pgsqlblocks.l10n.PgSqlBlocks.class.getName(), locale); } @@ -289,6 +293,30 @@ public ResourceBundle getResourceBundle() { return resources; } + public void setBlocksJournalsPath(String path) { + if (path.isEmpty() || path.isBlank()) { + if (blocksJournalPath != null) { + blocksJournalPath = null; + properties.remove(BLOCKS_JOURNAL_PATH); + return; + } + if (path.equals(PathBuilder.getInstance().getBlocksJournalsDir().toString())) { + return; + } + } + if (!Objects.equals(blocksJournalPath, path)) { + blocksJournalPath = path; + saveProperties(BLOCKS_JOURNAL_PATH, blocksJournalPath); + } + } + + public String getBlocksJournalPath() { + if (blocksJournalPath != null) { + return blocksJournalPath; + } + return PathBuilder.getInstance().getBlocksJournalsDir().toString(); + } + private void saveProperties(String key, String value) { try (FileOutputStream saveProp = new FileOutputStream(propFile)) { properties.setProperty(key, value);