Search in sources :

Example 1 with ApacheMailingListFetcher

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);
}
Also used : Path(java.nio.file.Path) ApacheMailingListFetcher(nl.andrewl.emaildownloader.ApacheMailingListFetcher) TimePickerSettings(com.github.lgooddatepicker.components.TimePickerSettings) DateTimePicker(com.github.lgooddatepicker.components.DateTimePicker) ProgressDialog(nl.andrewl.emaildatasetbrowser.view.ProgressDialog) DatePickerSettings(com.github.lgooddatepicker.components.DatePickerSettings) PathSelectField(nl.andrewl.emaildatasetbrowser.view.PathSelectField) LabelledField(nl.andrewl.emaildatasetbrowser.view.LabelledField)

Aggregations

DatePickerSettings (com.github.lgooddatepicker.components.DatePickerSettings)1 DateTimePicker (com.github.lgooddatepicker.components.DateTimePicker)1 TimePickerSettings (com.github.lgooddatepicker.components.TimePickerSettings)1 Path (java.nio.file.Path)1 LabelledField (nl.andrewl.emaildatasetbrowser.view.LabelledField)1 PathSelectField (nl.andrewl.emaildatasetbrowser.view.PathSelectField)1 ProgressDialog (nl.andrewl.emaildatasetbrowser.view.ProgressDialog)1 ApacheMailingListFetcher (nl.andrewl.emaildownloader.ApacheMailingListFetcher)1