From aaf94ab5e9afefe69a1ec8fb16424edd8ec5544c Mon Sep 17 00:00:00 2001 From: Elmir Shamsutdinov Date: Fri, 26 Jul 2024 11:50:36 +0300 Subject: [PATCH] updated by feedback --- .../blocksjournal/view/BlocksJournalView.java | 38 ++++++++++++------- .../modules/db/controller/DBController.java | 27 ++++++++----- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/main/java/ru/taximaxim/pgsqlblocks/modules/blocksjournal/view/BlocksJournalView.java b/src/main/java/ru/taximaxim/pgsqlblocks/modules/blocksjournal/view/BlocksJournalView.java index 4b63f0e..6b38098 100644 --- a/src/main/java/ru/taximaxim/pgsqlblocks/modules/blocksjournal/view/BlocksJournalView.java +++ b/src/main/java/ru/taximaxim/pgsqlblocks/modules/blocksjournal/view/BlocksJournalView.java @@ -32,11 +32,13 @@ import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.jface.window.ApplicationWindow; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; 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; @@ -93,25 +95,27 @@ protected Point getInitialSize() { @Override protected Control createContents(Composite parent) { Composite contentComposite = new Composite(parent, SWT.NONE); - contentComposite.setLayout(new GridLayout(2, false)); + contentComposite.setLayout(new GridLayout()); - Composite journalsComposite = new Composite(contentComposite, SWT.NONE); - journalsComposite.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true)); - journalsComposite.setLayout(new GridLayout()); - - ToolItem b = new ToolItem(new ToolBar(journalsComposite, SWT.HORIZONTAL), SWT.PUSH); - b.setImage(ImageUtils.getImage(Images.FOLDER)); - b.setToolTipText(resourceBundle.getString("open_dir")); - b.addListener(SWT.Selection, event -> { + 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 (IOException ex) { - ex.printStackTrace(); + } catch (Exception ex) { + MessageBox m = new MessageBox(getShell(), SWT.ICON_ERROR); + m.setMessage(ex.getLocalizedMessage()); + m.open(); } }); - filesTable = new TableViewer(journalsComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + 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); @@ -122,7 +126,7 @@ protected Control createContents(Composite parent) { filesTable.setInput(journalFiles); filesTable.addSelectionChangedListener(this::filesTableSelectionChanged); - Composite processesContentContainer = new Composite(contentComposite, SWT.NONE); + Composite processesContentContainer = new Composite(sashForm, SWT.BORDER); processesContentContainer.setLayout(new GridLayout()); processesContentContainer.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true)); @@ -144,6 +148,7 @@ protected Control createContents(Composite parent) { processInfoView.hideToolBar(); processInfoView.hide(); + sashForm.setWeights(25, 75); getJournalFilesFromJournalsDir(); return super.createContents(parent); @@ -170,7 +175,12 @@ private void getJournalFilesFromJournalsDir() { Path blocksJournalsDirPath = PathBuilder.getInstance().getBlocksJournalsDir(); File[] files = blocksJournalsDirPath.toFile().listFiles(); if (files != null) { - List filesList = Arrays.asList(files); + List 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); } diff --git a/src/main/java/ru/taximaxim/pgsqlblocks/modules/db/controller/DBController.java b/src/main/java/ru/taximaxim/pgsqlblocks/modules/db/controller/DBController.java index 943d156..8eb54e5 100644 --- a/src/main/java/ru/taximaxim/pgsqlblocks/modules/db/controller/DBController.java +++ b/src/main/java/ru/taximaxim/pgsqlblocks/modules/db/controller/DBController.java @@ -473,26 +473,35 @@ public void dbBlocksJournalDidCloseProcesses(List proces } private void saveBlockedProcessesToFile(List processes, boolean isOpenProcess) { + DBBlocksXmlStore store = getXmlStore(); List oldProcesses = store.readObjects(); + // FIXME doesn't work with procLimit != 0 + List result = new ArrayList<>(); if (isOpenProcess) { - processes = processes.stream() - .filter(e -> !oldProcesses.contains(e)) - .collect(Collectors.toList()); - if(processes.isEmpty()) { - return; + result.addAll(oldProcesses); + for (DBBlocksJournalProcess p : processes) { + if (!oldProcesses.contains(p)) { + result.add(p); + } } - } - oldProcesses.addAll(processes); + } else { + for (DBBlocksJournalProcess p : oldProcesses) { + if (!processes.contains(p)) { + result.add(p); + } + } + result.addAll(processes); + } if (procLimit != 0) { - for (List subList : chopped(oldProcesses, procLimit)) { + for (List subList : chopped(result, procLimit)) { getXmlStore().writeObjects(subList); part++; } part--; } else { - store.writeObjects(oldProcesses); + store.writeObjects(result); } }