From c45ad1b88c7a9461812142471905dbd9dc526cb9 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Mon, 12 Sep 2022 16:54:23 +0300 Subject: [PATCH] show reindex preview --- .../muwire/gui/LibrarySyncController.groovy | 10 +++ gui/griffon-app/i18n/messages.properties | 8 ++ .../com/muwire/gui/LibrarySyncView.groovy | 87 +++++++++++++++++-- 3 files changed, 99 insertions(+), 6 deletions(-) diff --git a/gui/griffon-app/controllers/com/muwire/gui/LibrarySyncController.groovy b/gui/griffon-app/controllers/com/muwire/gui/LibrarySyncController.groovy index dc7891d4..46f0484a 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/LibrarySyncController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/LibrarySyncController.groovy @@ -21,4 +21,14 @@ class LibrarySyncController { model.cancelScan() view.scanCancelled() } + + @ControllerAction + void cancel() { + view.previewCancelled() + } + + @ControllerAction + void reindex() { + + } } diff --git a/gui/griffon-app/i18n/messages.properties b/gui/griffon-app/i18n/messages.properties index 6b2bbe0b..e3edb58f 100644 --- a/gui/griffon-app/i18n/messages.properties +++ b/gui/griffon-app/i18n/messages.properties @@ -772,6 +772,14 @@ EXPORT_CONNECTIONS_SUCCESS={0} connections exporte to {1} LIBRARY_SCAN_TITLE=Scanning Library LIBRARY_SCAN_BODY=Scanning library for files that may be out of sync LIBRARY_SCAN_NO_STALE=There are no files out of sync +LIBRARY_SCAN_PREVIEW_TITLE=Out of sync files found +LIBRARY_SCAN_PREVIEW_FILES_BODY=The following shared files may be out of sync +LIBRARY_SCAN_PREVIEW_COLUMN_FILE=File +LIBRARY_SCAN_PREVIEW_COLUMN_SHARED=Shared +LIBRARY_SCAN_PREVIEW_COLUMN_MODIFIED=Modified +LIBRARY_SCAN_PREVIEW_COLLECTIONS_BODY=The following collections may be affected +LIBRARY_SCAN_PREVIEW_REINDEX=Re-Index + ## Tooltips TOOLTIP_FILE_FEED_DISABLED=Your file feed is disabled diff --git a/gui/griffon-app/views/com/muwire/gui/LibrarySyncView.groovy b/gui/griffon-app/views/com/muwire/gui/LibrarySyncView.groovy index 4adbca96..6e01e441 100644 --- a/gui/griffon-app/views/com/muwire/gui/LibrarySyncView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/LibrarySyncView.groovy @@ -1,5 +1,6 @@ package com.muwire.gui +import com.google.common.collect.Sets import griffon.core.GriffonApplication import griffon.core.artifact.GriffonView import griffon.inject.MVCMember @@ -12,7 +13,10 @@ import javax.swing.JFrame import javax.swing.JOptionPane import javax.swing.JPanel import javax.swing.JProgressBar +import javax.swing.JTable import java.awt.BorderLayout +import java.awt.Dimension + import static com.muwire.gui.Translator.trans @ArtifactProviderFor(GriffonView) @@ -28,16 +32,20 @@ class LibrarySyncView { LibrarySyncController controller private JFrame mainFrame + private int rowHeight - JDialog scanDialog - JDialog previewDialog - JDialog reindexDialog + private JDialog scanDialog + private JDialog previewDialog + private JDialog reindexDialog + + private JDialog nextDialog private JProgressBar scanProgressBar JProgressBar reindexProgressBar void initUI() { mainFrame = (JFrame) application.windowManager.findWindow("main-frame") + rowHeight = (int)application.context.get("row-height") scanDialog = new JDialog(mainFrame, trans("LIBRARY_SCAN_TITLE"), true) @@ -62,7 +70,9 @@ class LibrarySyncView { void mvcGroupInit(Map args) { model.startScan() - scanDialog.setVisible(true) + nextDialog = scanDialog + while(nextDialog != null) + nextDialog.setVisible(true) } void updateScanProgressBar(int percent) { @@ -70,16 +80,81 @@ class LibrarySyncView { } void scanCancelled() { + nextDialog = null scanDialog.setVisible(false) } void scanFinished() { + scanDialog.setVisible(false) + if (model.staleFiles.isEmpty()) { - JOptionPane.showMessageDialog(scanDialog, trans("LIBRARY_SCAN_NO_STALE"), + JOptionPane.showMessageDialog(mainFrame, trans("LIBRARY_SCAN_NO_STALE"), trans("LIBRARY_SCAN_NO_STALE"), JOptionPane.INFORMATION_MESSAGE) - scanDialog.setVisible(false) + nextDialog = null return } + + previewDialog = new JDialog(mainFrame, trans("LIBRARY_SCAN_PREVIEW_TITLE"), true) + nextDialog = previewDialog + + JTable staleFilesTable + JPanel previewPanel = builder.panel { + borderLayout() + panel(constraints: BorderLayout.CENTER) { + int rows = model.staleCollections.isEmpty() ? 1 : 2 + gridLayout(rows: rows, cols: 1) + panel { + borderLayout() + panel (constraints: BorderLayout.NORTH) { + label(text: trans("LIBRARY_SCAN_PREVIEW_FILES_BODY")) + } + scrollPane(constraints: BorderLayout.CENTER) { + staleFilesTable = table(autoCreateRowSorter: true, rowHeight: rowHeight) { + tableModel(list: model.staleFiles) { + closureColumn(header : trans("LIBRARY_SCAN_PREVIEW_COLUMN_FILE"), + type: String, read: {it.getCachedPath()}) + closureColumn(header : trans("LIBRARY_SCAN_PREVIEW_COLUMN_SHARED"), + type: Long, read: {it.getSharedTime()}) + closureColumn(header: trans("LIBRARY_SCAN_PREVIEW_COLUMN_MODIFIED"), + type: Long, read: {it.getFile().lastModified()}) + } + } + } + } + if (rows > 1) { + panel { + borderLayout() + panel(constraints: BorderLayout.NORTH) { + label(text: trans("LIBRARY_SCAN_PREVIEW_COLLECTIONS_BODY")) + } + scrollPane(constraints: BorderLayout.CENTER) { + list(items: model.staleCollections.collect {it.getName()}) + } + } + } + } + panel(constraints: BorderLayout.SOUTH) { + button(text: trans("LIBRARY_SCAN_PREVIEW_REINDEX"), reindexAction) + button(text: trans("CANCEL"), cancelAction) + } + } + + TableUtil.dateColumn(staleFilesTable, 1) + TableUtil.dateColumn(staleFilesTable, 2) + staleFilesTable.setDefaultRenderer(Long.class, new DateRenderer()) + + Dimension dimension = mainFrame.getSize() + previewDialog.with { + getContentPane().add(previewPanel) + setSize((int)(dimension.getWidth() - 100), (int)(dimension.getHeight() - 100)) + setLocationRelativeTo(mainFrame) + setDefaultCloseOperation(DISPOSE_ON_CLOSE) + } + } + + void previewCancelled() { + nextDialog = null + previewDialog.setVisible(false) } }