Skip to content

Commit

Permalink
code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
baslo2 committed Jul 15, 2024
1 parent 55cc819 commit 1c63a00
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 54 deletions.
80 changes: 38 additions & 42 deletions src/main/java/ru/taximaxim/pgsqlblocks/dialogs/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class SettingsDialog extends Dialog {
private Button confirmRequiredButton;
private Button confirmExitButton;
private Combo languageCombo;
private Text path;
private Text textPath;

public SettingsDialog(Settings settings, Shell shell) {
super(shell);
Expand All @@ -76,39 +76,8 @@ protected Control createDialogArea(Composite parent) {
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"));
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 @@ -120,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 @@ -167,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 @@ -191,6 +154,39 @@ private void populateNotificationGroup(Composite container) {
confirmExitButton.setSelection(settings.isConfirmExit());
}

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

textPath = new Text(generalGroup, SWT.BORDER);
textPath.setText(settings.getBlocksJournalPath());
textPath.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 path = dialog.open();
if (path != null) {
textPath.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 @@ -207,7 +203,7 @@ protected void okPressed() {
settings.setConfirmExit(confirmExitButton.getSelection());
settings.setLanguage(languageCombo.getText());
settings.setShowBackendPid(showBackendPidButton.getSelection());
settings.setBlocksJournalsPath(path.getText());
settings.setBlocksJournalsPath(textPath.getText());

super.okPressed();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ protected Control createContents(Composite parent) {
ImageDescriptor.createFromImage(ImageUtils.getImage(Images.FOLDER))) {
@Override
public void run() {
String s = journalFiles.get(0).getAbsolutePath();
File file = (File) filesTable.getStructuredSelection().getFirstElement();
try {
Desktop.getDesktop().open(new File(s).getParentFile());
Desktop.getDesktop().open(file.getParentFile());
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/ru/taximaxim/pgsqlblocks/utils/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ public ResourceBundle getResourceBundle() {
}

public void setBlocksJournalsPath(String path) {
if (path.isEmpty() || isBlank(path)) {
path = path.trim();
if (path.isEmpty()) {
if (blocksJournalPath != null) {
blocksJournalPath = null;
properties.remove(BLOCKS_JOURNAL_PATH);
Expand All @@ -310,15 +311,6 @@ public void setBlocksJournalsPath(String path) {
}
}

private boolean isBlank(String o) {
for (char c : o.toCharArray()) {
if (!Objects.equals(c, ' ')) {
return false;
}
}
return true;
}

public String getBlocksJournalPath() {
if (blocksJournalPath == null) {
blocksJournalPath = PathBuilder.getInstance().getBlocksJournalPath().toString();
Expand Down

0 comments on commit 1c63a00

Please sign in to comment.