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);
}
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();
});
}
}
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();
});
}
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;
});
}
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;
});
}
Aggregations