Skip to content

Commit

Permalink
PGCK-376 updated saving block journals (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
baslo2 authored Jul 26, 2024
1 parent 90fc619 commit dfa0252
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 21 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ java-приложение для работы с блокировками в С

### Версии

1.9.0

* Добавлен gitHub Actions
* Обновлены библиотеки
* Обновлена лицензия
* Обновлены тесты
* Добавлена возможность группировки баз данных в настройках соединения
* Добавлена настройка для выбора расположения журналов блокировок
* Добавлена кнопка открытия директории в журнале сохраненных блокировок

1.8.0

* Добавлена настройка для ограничения количества блокировок в списке и в файлах журналов
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ru.taximaxim</groupId>
<artifactId>pgsqlblocks</artifactId>
<version>1.8.0</version>
<version>1.9.0</version>
<packaging>jar</packaging>

<name>pgSqlBlocks</name>
Expand Down
71 changes: 59 additions & 12 deletions src/main/java/ru/taximaxim/pgsqlblocks/dialogs/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -45,6 +52,7 @@ public class SettingsDialog extends Dialog {
private Button confirmRequiredButton;
private Button confirmExitButton;
private Combo languageCombo;
private Text journalsPathText;

public SettingsDialog(Settings settings, Shell shell) {
super(shell);
Expand All @@ -64,14 +72,12 @@ protected Control createDialogArea(Composite parent) {
populateGeneralGroup(container);
populateProcessGroup(container);
populateNotificationGroup(container);
populateBlockJournalPathGroup(container);
return container;
}

private void populateGeneralGroup(Composite container) {
Group generalGroup = new Group(container, SWT.SHADOW_IN);
generalGroup.setText(resourceBundle.getString("general"));
generalGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
generalGroup.setLayout(new GridLayout(2, false));
Group generalGroup = createGroup(container, resourceBundle.getString("general"), 2);

Label selectLocale = new Label(generalGroup, SWT.HORIZONTAL);
selectLocale.setText(resourceBundle.getString("select_ui_language"));
Expand All @@ -83,10 +89,7 @@ private void populateGeneralGroup(Composite container) {
}

private void populateProcessGroup(Composite container) {
Group processGroup = new Group(container, SWT.SHADOW_IN);
processGroup.setText(resourceBundle.getString("processes"));
processGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
processGroup.setLayout(new GridLayout(3, false));
Group processGroup = createGroup(container, resourceBundle.getString("processes"), 3);

Label updatePeriodLabel = new Label(processGroup, SWT.HORIZONTAL);
updatePeriodLabel.setText(resourceBundle.getString("auto_update_interval"));
Expand Down Expand Up @@ -130,10 +133,7 @@ private void populateProcessGroup(Composite container) {
}

private void populateNotificationGroup(Composite container) {
Group notificationGroup = new Group(container, SWT.SHADOW_IN);
notificationGroup.setText(resourceBundle.getString("notifications"));
notificationGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
notificationGroup.setLayout(new GridLayout(2, false));
Group notificationGroup = createGroup(container, resourceBundle.getString("notifications"), 2);

Label idleShowToolTip = new Label(notificationGroup, SWT.HORIZONTAL);
idleShowToolTip.setText(resourceBundle.getString("show_tray_notifications"));
Expand All @@ -154,6 +154,52 @@ private void populateNotificationGroup(Composite container) {
confirmExitButton.setSelection(settings.isConfirmExit());
}

private void populateBlockJournalPathGroup(Composite container) {
Group generalGroup = createGroup(container, resourceBundle.getString("path"), 3);

journalsPathText = new Text(generalGroup, SWT.BORDER);
journalsPathText.setText(settings.getBlocksJournalPath());
journalsPathText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

Button btnSetDefaulfDir = new Button(generalGroup, SWT.PUSH);
btnSetDefaulfDir.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, true));
btnSetDefaulfDir.setImage(ImageUtils.getImage(Images.BACK));
btnSetDefaulfDir.setToolTipText(resourceBundle.getString("return_default_directory"));
btnSetDefaulfDir.addSelectionListener(new SelectionAdapter() {

@Override
public void widgetSelected(SelectionEvent e) {
journalsPathText.setText(PathBuilder.getInstance().getDefaultBlocksJournalPath().toString());
}
});

Button btnDir = new Button(generalGroup, SWT.PUSH);
btnDir.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, true));
btnDir.setImage(ImageUtils.getImage(Images.FOLDER));
btnDir.setToolTipText(resourceBundle.getString("choose_dir"));
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 path = dialog.open();
if (path != null) {
journalsPathText.setText(path);
}
}
});
}

private Group createGroup(Composite container, String name, int numColumns) {
Group group = new Group(container, SWT.SHADOW_IN);
group.setText(name);
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
group.setLayout(new GridLayout(numColumns, false));
return group;
}

@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
Expand All @@ -170,6 +216,7 @@ protected void okPressed() {
settings.setConfirmExit(confirmExitButton.getSelection());
settings.setLanguage(languageCombo.getText());
settings.setShowBackendPid(showBackendPidButton.getSelection());
settings.setBlocksJournalsPath(journalsPathText.getText().trim());

super.okPressed();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ protected Object[][] getContents() {
{"columns", "Columns"},
{"general", "General"},
{"select_ui_language", "UI language (requires restart)"},
{"path", "Path to save block journals"},
{"choose_dir", "Choose directory"},
{"return_default_directory", "Return default directory"},

// create database dialog
{"name", "Connection name*"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ protected Object[][] getContents() {
{"columns", "Колонки"},
{"general", "Общие"},
{"select_ui_language", "Язык интерфейса (требует перезапуска)"},
{"path", "Путь хранения журналов блокировок"},
{"choose_dir", "Выберите директорию"},
{"return_default_directory", "Вернуть директорию по умолчанию"},

// create database dialog
{"name", "Имя соединения*"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*******************************************************************************/
package ru.taximaxim.pgsqlblocks.modules.blocksjournal.view;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -36,7 +38,10 @@
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

import ru.taximaxim.pgsqlblocks.common.models.DBBlocksJournal;
import ru.taximaxim.pgsqlblocks.common.models.DBBlocksJournalListener;
Expand All @@ -45,6 +50,8 @@
import ru.taximaxim.pgsqlblocks.common.ui.DBBlocksJournalViewDataSource;
import ru.taximaxim.pgsqlblocks.common.ui.DBProcessInfoView;
import ru.taximaxim.pgsqlblocks.dialogs.DBProcessInfoDialog;
import ru.taximaxim.pgsqlblocks.utils.ImageUtils;
import ru.taximaxim.pgsqlblocks.utils.Images;
import ru.taximaxim.pgsqlblocks.utils.PathBuilder;
import ru.taximaxim.pgsqlblocks.utils.Settings;
import ru.taximaxim.pgsqlblocks.xmlstore.ColumnLayoutsXmlStore;
Expand Down Expand Up @@ -90,10 +97,26 @@ protected Control createContents(Composite parent) {
Composite contentComposite = new Composite(parent, SWT.NONE);
contentComposite.setLayout(new GridLayout());

ToolBar toolBar = new ToolBar(contentComposite, SWT.HORIZONTAL);
ToolItem openDirToolItem = new ToolItem(toolBar, SWT.PUSH);
openDirToolItem.setImage(ImageUtils.getImage(Images.FOLDER));
openDirToolItem.setToolTipText(resourceBundle.getString("open_dir"));
openDirToolItem.addListener(SWT.Selection, event -> {
File file = new File(Settings.getInstance().getBlocksJournalPath());
try {
Desktop.getDesktop().open(file);
} catch (Exception ex) {
MessageBox m = new MessageBox(getShell(), SWT.ICON_ERROR);
m.setMessage(ex.getLocalizedMessage());
m.open();
}
});

SashForm sashForm = new SashForm(contentComposite, SWT.HORIZONTAL);
sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

filesTable = new TableViewer(sashForm, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
filesTable.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
filesTable.getTable().setHeaderVisible(true);
TableViewerColumn column = new TableViewerColumn(filesTable, SWT.NONE);
column.getColumn().setText(resourceBundle.getString("journals"));
Expand All @@ -103,9 +126,9 @@ protected Control createContents(Composite parent) {
filesTable.setInput(journalFiles);
filesTable.addSelectionChangedListener(this::filesTableSelectionChanged);

Composite processesContentContainer = new Composite(sashForm, SWT.NONE);
Composite processesContentContainer = new Composite(sashForm, SWT.BORDER);
processesContentContainer.setLayout(new GridLayout());
processesContentContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
processesContentContainer.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true));

DBBlocksJournalViewDataSource dbBlocksJournalViewDataSource =
new DBBlocksJournalViewDataSource(resourceBundle, false);
Expand All @@ -125,7 +148,7 @@ protected Control createContents(Composite parent) {
processInfoView.hideToolBar();
processInfoView.hide();

sashForm.setWeights(new int[] {20, 80});
sashForm.setWeights(25, 75);
getJournalFilesFromJournalsDir();

return super.createContents(parent);
Expand All @@ -152,7 +175,12 @@ private void getJournalFilesFromJournalsDir() {
Path blocksJournalsDirPath = PathBuilder.getInstance().getBlocksJournalsDir();
File[] files = blocksJournalsDirPath.toFile().listFiles();
if (files != null) {
List<File> filesList = Arrays.asList(files);
List<File> filesList = new ArrayList<>();;
for (File f : files) {
if (f.getName().endsWith(".xml")) {
filesList.add(f);
}
}
filesList.sort(Comparator.comparingLong(File::lastModified));
this.journalFiles.addAll(filesList);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ru/taximaxim/pgsqlblocks/utils/Images.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public enum Images {
HIDE_LOG_PANEL("images/log_hide_16.png"),
BLOCKS_JOURNAL_FOLDER("images/blocks_journal_folder_16.png"),
FOLDER("images/folder_16.png"),
TABLE("images/table_16.png");
TABLE("images/table_16.png"),
BACK("images/back-16.png");

private String location;

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/ru/taximaxim/pgsqlblocks/utils/PathBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public static PathBuilder getInstance() {
}

public Path getBlocksJournalsDir() {
Path blocksJournalsDir = path.resolve("blocksJournals");
if (!blocksJournalsDir.toFile().exists()) {
Path blocksJournalsDir = path.resolve(Settings.getInstance().getBlocksJournalPath());
if (Files.notExists(path)) {
try {
Files.createDirectory(blocksJournalsDir);
} catch (IOException e) {
Expand All @@ -71,6 +71,10 @@ public Path getServersPath() {
return path.resolve("servers.xml");
}

public Path getDefaultBlocksJournalPath() {
return path.resolve("blocksJournals");
}

public Path getColumnsPath() {
return path.resolve("columns");
}
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/ru/taximaxim/pgsqlblocks/utils/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -107,12 +110,13 @@ 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);
}

public static Settings getInstance() {
if(instance == null) {
if (instance == null) {
instance = new Settings();
}
return instance;
Expand Down Expand Up @@ -167,6 +171,7 @@ public void setLimitBlocks(int limitBlocks) {
public int getLimitBlocks() {
return limitBlocks;
}

/**
* Gets the maximum time in seconds that a driver can wait
* when attempting to log in to a database.
Expand All @@ -176,6 +181,7 @@ public int getLimitBlocks() {
public int getLoginTimeout() {
return loginTimeout;
}

/**
* Получаем флаг автообновления
* @return the autoUpdate
Expand Down Expand Up @@ -289,6 +295,25 @@ public ResourceBundle getResourceBundle() {
return resources;
}

public void setBlocksJournalsPath(String path) {
if (path.isEmpty() && blocksJournalPath != null) {
blocksJournalPath = null;
properties.remove(BLOCKS_JOURNAL_PATH);
return;
}
if (!Objects.equals(blocksJournalPath, path)) {
blocksJournalPath = path;
saveProperties(BLOCKS_JOURNAL_PATH, blocksJournalPath);
}
}

public String getBlocksJournalPath() {
if (blocksJournalPath == null || blocksJournalPath.isEmpty()) {
blocksJournalPath = PathBuilder.getInstance().getDefaultBlocksJournalPath().toString();
}
return blocksJournalPath;
}

private void saveProperties(String key, String value) {
try (FileOutputStream saveProp = new FileOutputStream(propFile)) {
properties.setProperty(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected Object[][] getContents() {
{"all-filter-tooltip", "Filter by filters below using \"contains (~)\""},
{"columns", "Columns"},
{"default_action", "Empty"},
{"choose_dir", "Choose directory"},
};
}
}
Loading

0 comments on commit dfa0252

Please sign in to comment.