Search in sources :

Example 1 with ProgressDialog

use of nl.andrewl.emaildatasetbrowser.view.ProgressDialog in project EmailDatasetBrowser by ArchitecturalKnowledgeAnalysis.

the class UpgradeDatasetAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    JDialog upgradeDialog = new JDialog(browser, "Upgrade Dataset", true);
    PathSelectField ds1Select = PathSelectField.directorySelectField();
    PathSelectField ds2Select = PathSelectField.directorySelectField();
    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel bodyPanel = new JPanel();
    bodyPanel.setLayout(new BoxLayout(bodyPanel, BoxLayout.PAGE_AXIS));
    bodyPanel.add(new LabelledField("Old Dataset Directory", ds1Select));
    bodyPanel.add(new LabelledField("New Dataset Directory", ds2Select));
    mainPanel.add(bodyPanel, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(e1 -> upgradeDialog.dispose());
    buttonPanel.add(cancelButton);
    JButton okayButton = new JButton("Upgrade");
    okayButton.addActionListener(e1 -> {
        var ds1 = EmailDataset.open(ds1Select.getSelectedPath()).join();
        try {
            if (ds1.getVersion() != 1) {
                JOptionPane.showMessageDialog(upgradeDialog, "Can only upgrade from version 1 datasets.", "Invalid Version", JOptionPane.WARNING_MESSAGE);
                return;
            }
            ProgressDialog progress = ProgressDialog.minimalText(upgradeDialog, "Upgrading...");
            Async.run(() -> {
                new Version1Upgrader().upgrade(ds1Select.getSelectedPath(), ds2Select.getSelectedPath(), new Status().withMessageConsumer(progress));
                progress.done();
                upgradeDialog.dispose();
            });
        } catch (Exception e2) {
            e2.printStackTrace();
            upgradeDialog.dispose();
        }
    });
    buttonPanel.add(okayButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    upgradeDialog.setContentPane(mainPanel);
    upgradeDialog.setPreferredSize(new Dimension(500, 300));
    upgradeDialog.pack();
    upgradeDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    upgradeDialog.setLocationRelativeTo(browser);
    upgradeDialog.setVisible(true);
}
Also used : Status(nl.andrewl.email_indexer.util.Status) ProgressDialog(nl.andrewl.emaildatasetbrowser.view.ProgressDialog) PathSelectField(nl.andrewl.emaildatasetbrowser.view.PathSelectField) Version1Upgrader(nl.andrewl.email_indexer.data.upgrade.Version1Upgrader) LabelledField(nl.andrewl.emaildatasetbrowser.view.LabelledField)

Example 2 with ProgressDialog

use of nl.andrewl.emaildatasetbrowser.view.ProgressDialog in project EmailDatasetBrowser by ArchitecturalKnowledgeAnalysis.

the class DeleteHiddenAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (emailViewPanel.getCurrentDataset() == null)
        return;
    int result = JOptionPane.showConfirmDialog(emailViewPanel, "Are you sure you want to delete all hidden emails? This cannot be undone.", "Confirm Deletion", JOptionPane.YES_NO_OPTION);
    if (result == JOptionPane.YES_OPTION) {
        ProgressDialog progress = ProgressDialog.minimal(emailViewPanel, "Deleting Hidden Emails", "Deleting all hidden emails permanently...");
        ForkJoinPool.commonPool().submit(() -> {
            new EmailRepository(emailViewPanel.getCurrentDataset()).deleteAllHidden();
            progress.append("All emails have been deleted.");
            progress.done();
        });
    }
}
Also used : ProgressDialog(nl.andrewl.emaildatasetbrowser.view.ProgressDialog) EmailRepository(nl.andrewl.email_indexer.data.EmailRepository)

Example 3 with ProgressDialog

use of nl.andrewl.emaildatasetbrowser.view.ProgressDialog in project EmailDatasetBrowser by ArchitecturalKnowledgeAnalysis.

the class HideAllByAuthorAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    var email = emailViewPanel.getEmail();
    String emailAddress = email.sentFrom().substring(email.sentFrom().lastIndexOf('<') + 1, email.sentFrom().length() - 1);
    ProgressDialog progress = ProgressDialog.minimalText(emailViewPanel, "Hiding Emails by Author");
    progress.append("Hiding all emails sent by \"%s\".".formatted(emailAddress));
    ForkJoinPool.commonPool().submit(() -> {
        long count = new EmailRepository(emailViewPanel.getCurrentDataset()).hideAllEmailsBySentFrom('%' + emailAddress + '%');
        progress.append("Hid %d emails.".formatted(count));
        progress.done();
    });
}
Also used : ProgressDialog(nl.andrewl.emaildatasetbrowser.view.ProgressDialog) EmailRepository(nl.andrewl.email_indexer.data.EmailRepository)

Example 4 with ProgressDialog

use of nl.andrewl.emaildatasetbrowser.view.ProgressDialog in project EmailDatasetBrowser by ArchitecturalKnowledgeAnalysis.

the class ExportLuceneSearchAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    String query = searchPanel.getQuery();
    if (query == null || searchPanel.getDataset() == null)
        return;
    JFileChooser fc = new JFileChooser(".");
    fc.setFileFilter(new FileNameExtensionFilter("Text files", ".txt"));
    fc.setAcceptAllFileFilterUsed(false);
    int result = fc.showSaveDialog(searchPanel);
    if (result != JFileChooser.APPROVE_OPTION)
        return;
    Path file = fc.getSelectedFile().toPath();
    ProgressDialog progress = ProgressDialog.minimalText(searchPanel, "Exporting Query Results");
    progress.append("Generating export for query: \"%s\"".formatted(query));
    var repo = new EmailRepository(searchPanel.getDataset());
    var tagRepo = new TagRepository(searchPanel.getDataset());
    new EmailIndexSearcher().searchAsync(searchPanel.getDataset(), query, searchPanel.getResultCount()).handleAsync((emailIds, throwable) -> {
        if (throwable != null) {
            progress.append("An error occurred while searching: " + throwable.getMessage());
        } else {
            progress.append("Found %d emails.".formatted(emailIds.size()));
            progress.appendF("Exporting the top %d emails.", searchPanel.getResultCount());
            try {
                List<EmailEntryPreview> emails = emailIds.parallelStream().map(id -> repo.findPreviewById(id).orElse(null)).filter(Objects::nonNull).limit(searchPanel.getResultCount()).toList();
                writeExport(emails, repo, tagRepo, query, file, progress);
            } catch (IOException ex) {
                progress.append("An error occurred while exporting: " + ex.getMessage());
                ex.printStackTrace();
            }
        }
        progress.done();
        return null;
    });
}
Also used : Path(java.nio.file.Path) ProgressDialog(nl.andrewl.emaildatasetbrowser.view.ProgressDialog) PrintWriter(java.io.PrintWriter) EmailRepository(nl.andrewl.email_indexer.data.EmailRepository) ActionListener(java.awt.event.ActionListener) EmailEntryPreview(nl.andrewl.email_indexer.data.EmailEntryPreview) TagRepository(nl.andrewl.email_indexer.data.TagRepository) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) ZonedDateTime(java.time.ZonedDateTime) FileWriter(java.io.FileWriter) IOException(java.io.IOException) LuceneSearchPanel(nl.andrewl.emaildatasetbrowser.view.search.LuceneSearchPanel) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Tag(nl.andrewl.email_indexer.data.Tag) EmailIndexSearcher(nl.andrewl.email_indexer.data.search.EmailIndexSearcher) Path(java.nio.file.Path) javax.swing(javax.swing) EmailIndexSearcher(nl.andrewl.email_indexer.data.search.EmailIndexSearcher) IOException(java.io.IOException) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) ProgressDialog(nl.andrewl.emaildatasetbrowser.view.ProgressDialog) EmailRepository(nl.andrewl.email_indexer.data.EmailRepository) TagRepository(nl.andrewl.email_indexer.data.TagRepository) EmailEntryPreview(nl.andrewl.email_indexer.data.EmailEntryPreview) Objects(java.util.Objects)

Example 5 with ProgressDialog

use of nl.andrewl.emaildatasetbrowser.view.ProgressDialog in project EmailDatasetBrowser by ArchitecturalKnowledgeAnalysis.

the class EmailDatasetBrowser method closeDataset.

private CompletableFuture<Void> closeDataset() {
    if (currentDataset == null)
        return CompletableFuture.completedFuture(null);
    ProgressDialog dialog = new ProgressDialog(this, "Closing Dataset", "Closing the current dataset.", true, false, false);
    dialog.appendF("Closing the currently open dataset at %s", currentDataset.getOpenDir());
    dialog.activate();
    return currentDataset.close().handle((unused, throwable) -> {
        if (throwable != null) {
            throwable.printStackTrace();
            JOptionPane.showMessageDialog(emailViewPanel, "An error occurred while closing the database:\n" + throwable.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        } else {
            dialog.append("Dataset closed successfully.");
        }
        dialog.done();
        currentDataset = null;
        return null;
    });
}
Also used : ProgressDialog(nl.andrewl.emaildatasetbrowser.view.ProgressDialog)

Aggregations

ProgressDialog (nl.andrewl.emaildatasetbrowser.view.ProgressDialog)12 Path (java.nio.file.Path)5 EmailRepository (nl.andrewl.email_indexer.data.EmailRepository)5 Status (nl.andrewl.email_indexer.util.Status)3 PathSelectField (nl.andrewl.emaildatasetbrowser.view.PathSelectField)3 IOException (java.io.IOException)2 TagRepository (nl.andrewl.email_indexer.data.TagRepository)2 EmailIndexSearcher (nl.andrewl.email_indexer.data.search.EmailIndexSearcher)2 LabelledField (nl.andrewl.emaildatasetbrowser.view.LabelledField)2 DatePickerSettings (com.github.lgooddatepicker.components.DatePickerSettings)1 DateTimePicker (com.github.lgooddatepicker.components.DateTimePicker)1 TimePickerSettings (com.github.lgooddatepicker.components.TimePickerSettings)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 Instant (java.time.Instant)1 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1