use of nl.andrewl.emaildatasetbrowser.view.PathSelectField 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.PathSelectField in project EmailDatasetBrowser by ArchitecturalKnowledgeAnalysis.
the class GenerateDatasetAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
JDialog dialog = new JDialog(browser, "Generate Dataset", true);
JPanel p = new JPanel(new BorderLayout());
JPanel inputPanel = new JPanel();
inputPanel.setLayout(new BoxLayout(inputPanel, BoxLayout.PAGE_AXIS));
var items = buildMBoxDirsPanel(dialog);
inputPanel.add(items.getKey());
JList<Path> mboxDirsList = items.getValue();
PathSelectField datasetDirField = PathSelectField.directorySelectField();
inputPanel.add(datasetDirField);
p.add(inputPanel, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(event -> dialog.dispose());
JButton generateButton = new JButton("Generate");
generateButton.addActionListener(event -> {
if (!validateDialog(dialog, mboxDirsList, datasetDirField))
return;
Collection<Path> paths = new ArrayList<>();
for (int i = 0; i < mboxDirsList.getModel().getSize(); i++) {
paths.add(mboxDirsList.getModel().getElementAt(i));
}
Path dsDir = datasetDirField.getSelectedPath();
dialog.dispose();
ProgressDialog progressDialog = new ProgressDialog(browser, "Generating...", "Generating the dataset.");
progressDialog.activate();
Status status = new Status().withMessageConsumer(progressDialog);
new EmailDatasetGenerator(status).generate(paths, dsDir).handle((unused, throwable) -> {
progressDialog.done();
if (throwable != null) {
throwable.printStackTrace();
progressDialog.accept("An exception occurred: " + throwable.getMessage());
}
return null;
});
});
buttonPanel.add(generateButton);
buttonPanel.add(cancelButton);
p.add(buttonPanel, BorderLayout.SOUTH);
dialog.setContentPane(p);
dialog.pack();
dialog.setLocationRelativeTo(browser);
dialog.setVisible(true);
}
use of nl.andrewl.emaildatasetbrowser.view.PathSelectField 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