use of nl.andrewl.emaildownloader.ApacheMailingListFetcher in project EmailDatasetBrowser by ArchitecturalKnowledgeAnalysis.
the class DownloadEmailsAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
JDialog dialog = new JDialog(owner, "Download ", Dialog.ModalityType.APPLICATION_MODAL);
JPanel p = new JPanel(new BorderLayout());
JTextField domainField = new JTextField(0);
JTextField listField = new JTextField(0);
var timeSettings = new TimePickerSettings();
timeSettings.setAllowEmptyTimes(false);
timeSettings.setInitialTimeToNow();
var dateSettings = new DatePickerSettings();
dateSettings.setAllowEmptyDates(false);
DateTimePicker startPicker = new DateTimePicker(dateSettings.copySettings(), timeSettings);
startPicker.setDateTimeStrict(LocalDateTime.now().minusYears(10));
DateTimePicker endPicker = new DateTimePicker(dateSettings.copySettings(), timeSettings);
endPicker.setDateTimeStrict(LocalDateTime.now());
PathSelectField dirField = PathSelectField.directorySelectField();
JPanel inputPanel = new JPanel();
inputPanel.setLayout(new BoxLayout(inputPanel, BoxLayout.PAGE_AXIS));
inputPanel.add(new LabelledField("Domain", domainField));
inputPanel.add(new LabelledField("List", listField));
inputPanel.add(new LabelledField("Start", startPicker));
inputPanel.add(new LabelledField("End", endPicker));
inputPanel.add(dirField);
p.add(inputPanel, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(event -> dialog.dispose());
JButton downloadButton = new JButton("Download");
downloadButton.addActionListener(event -> {
ApacheMailingListFetcher fetcher = new ApacheMailingListFetcher();
Path outputDir = dirField.getSelectedPath();
dialog.dispose();
ProgressDialog progressDialog = new ProgressDialog(owner, "Downloading...", "Downloading emails");
progressDialog.activate();
fetcher.download(outputDir, domainField.getText(), listField.getText(), startPicker.getDateTimeStrict().atZone(ZoneId.systemDefault()), endPicker.getDateTimeStrict().atZone(ZoneId.systemDefault()), progressDialog).handle((paths, throwable) -> {
progressDialog.done();
if (throwable == null) {
JOptionPane.showMessageDialog(progressDialog, "MBox files downloaded successfully.", "Done", JOptionPane.INFORMATION_MESSAGE);
} else {
throwable.printStackTrace();
}
return null;
});
});
buttonPanel.add(downloadButton);
buttonPanel.add(cancelButton);
p.add(buttonPanel, BorderLayout.SOUTH);
dialog.setContentPane(p);
dialog.pack();
dialog.setLocationRelativeTo(owner);
dialog.setVisible(true);
}
Aggregations