Replaced javafx dialogs with modal swing JOptionPane

This commit is contained in:
Kelly Kelly 2019-10-02 10:58:24 -04:00
parent 5ede580ee0
commit 150632df74
2 changed files with 74 additions and 65 deletions

View File

@ -32,12 +32,15 @@ SaveSnapShotAsReport.ErrorWritingReport=Error writing report to disk at {0}.
SaveSnapShotAsReport.FailedToAddReport=Failed to add snaphot to case as a report. SaveSnapShotAsReport.FailedToAddReport=Failed to add snaphot to case as a report.
SaveSnapShotAsReport.reportName.header=Enter a report name for the Timeline Snapshot Report. SaveSnapShotAsReport.reportName.header=Enter a report name for the Timeline Snapshot Report.
# {0} - generated default report name # {0} - generated default report name
SaveSnapShotAsReport.reportName.prompt=leave empty for default report name: {0}. SaveSnapShotAsReport.reportName.prompt=Leave empty for default report name:\n{0}.
# {0} - report file path # {0} - report file path
SaveSnapShotAsReport.ReportSavedAt=Report saved at [{0}] SaveSnapShotAsReport.ReportSavedAt=Report saved at [{0}]
SaveSnapShotAsReport.Success=Success SaveSnapShotAsReport.Success=Success
SaveSnapShotAsReport_OK_Button=OK
SaveSnapShotAsReport_Open_Button=Open Report
SaveSnapShotAsReport_Path_Failure_Report=Failed to create report. Supplied report name has invalid characters: {0} SaveSnapShotAsReport_Path_Failure_Report=Failed to create report. Supplied report name has invalid characters: {0}
SaveSnapShotAsReport_Report_Failed=Report failed SaveSnapShotAsReport_Report_Failed=Report failed
SaveSnapShotAsReport_success_message=Snapshot report successfully created at location: \n\n {0}
Timeline.ModuleName=Timeline Timeline.ModuleName=Timeline
ViewArtifactInTimelineAction.displayName=View Result in Timeline... ViewArtifactInTimelineAction.displayName=View Result in Timeline...
ViewFileInTimelineAction.viewFile.displayName=View File in Timeline... ViewFileInTimelineAction.viewFile.displayName=View File in Timeline...

View File

@ -37,6 +37,7 @@ import javafx.scene.control.TextInputDialog;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.controlsfx.control.HyperlinkLabel; import org.controlsfx.control.HyperlinkLabel;
import org.controlsfx.control.action.Action; import org.controlsfx.control.action.Action;
@ -50,6 +51,8 @@ import org.sleuthkit.autopsy.timeline.PromptDialogManager;
import org.sleuthkit.autopsy.timeline.TimeLineController; import org.sleuthkit.autopsy.timeline.TimeLineController;
import org.sleuthkit.autopsy.timeline.snapshot.SnapShotReportWriter; import org.sleuthkit.autopsy.timeline.snapshot.SnapShotReportWriter;
import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskCoreException;
import javafx.application.Platform;
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
/** /**
* Action that saves a snapshot of the given node as an autopsy report. * Action that saves a snapshot of the given node as an autopsy report.
@ -82,11 +85,14 @@ public class SaveSnapshotAsReport extends Action {
"# {0} - report path", "# {0} - report path",
"SaveSnapShotAsReport.ErrorWritingReport=Error writing report to disk at {0}.", "SaveSnapShotAsReport.ErrorWritingReport=Error writing report to disk at {0}.",
"# {0} - generated default report name", "# {0} - generated default report name",
"SaveSnapShotAsReport.reportName.prompt=leave empty for default report name: {0}.", "SaveSnapShotAsReport.reportName.prompt=Leave empty for default report name:\n{0}.",
"SaveSnapShotAsReport.reportName.header=Enter a report name for the Timeline Snapshot Report.", "SaveSnapShotAsReport.reportName.header=Enter a report name for the Timeline Snapshot Report.",
"SaveSnapShotAsReport.duplicateReportNameError.text=A report with that name already exists.", "SaveSnapShotAsReport.duplicateReportNameError.text=A report with that name already exists.",
"SaveSnapShotAsReport_Report_Failed=Report failed", "SaveSnapShotAsReport_Report_Failed=Report failed",
"SaveSnapShotAsReport_Path_Failure_Report=Failed to create report. Supplied report name has invalid characters: {0}" "SaveSnapShotAsReport_Path_Failure_Report=Failed to create report. Supplied report name has invalid characters: {0}",
"SaveSnapShotAsReport_success_message=Snapshot report successfully created at location: \n\n {0}",
"SaveSnapShotAsReport_Open_Button=Open Report",
"SaveSnapShotAsReport_OK_Button=OK"
}) })
public SaveSnapshotAsReport(TimeLineController controller, Supplier<Node> nodeSupplier) { public SaveSnapshotAsReport(TimeLineController controller, Supplier<Node> nodeSupplier) {
super(Bundle.SaveSnapShotAsReport_action_name_text()); super(Bundle.SaveSnapShotAsReport_action_name_text());
@ -101,24 +107,25 @@ public class SaveSnapshotAsReport extends Action {
final String defaultReportName = FileUtil.escapeFileName(currentCase.getDisplayName() + " " + new SimpleDateFormat("MM-dd-yyyy-HH-mm-ss").format(generationDate)); //NON_NLS final String defaultReportName = FileUtil.escapeFileName(currentCase.getDisplayName() + " " + new SimpleDateFormat("MM-dd-yyyy-HH-mm-ss").format(generationDate)); //NON_NLS
BufferedImage snapshot = SwingFXUtils.fromFXImage(nodeSupplier.get().snapshot(null, null), null); BufferedImage snapshot = SwingFXUtils.fromFXImage(nodeSupplier.get().snapshot(null, null), null);
//prompt user to pick report name SwingUtilities.invokeLater(() ->{
TextInputDialog textInputDialog = new TextInputDialog(); String message = String.format("%s\n\n%s", Bundle.SaveSnapShotAsReport_reportName_header(), Bundle.SaveSnapShotAsReport_reportName_prompt(defaultReportName));
PromptDialogManager.setDialogIcons(textInputDialog);
textInputDialog.setTitle(Bundle.SaveSnapShotAsReport_action_dialogs_title());
textInputDialog.getEditor().setPromptText(Bundle.SaveSnapShotAsReport_reportName_prompt(defaultReportName));
textInputDialog.setHeaderText(Bundle.SaveSnapShotAsReport_reportName_header());
//keep prompt even if text field has focus, until user starts typing. String reportName = JOptionPane.showInputDialog(SwingUtilities.windowForComponent(controller.getTopComponent()), message,
textInputDialog.getEditor().setStyle("-fx-prompt-text-fill: derive(-fx-control-inner-background, -30%);");//NON_NLS Bundle.SaveSnapShotAsReport_action_dialogs_title(), JOptionPane.QUESTION_MESSAGE);
//show dialog and handle result reportName = StringUtils.defaultIfBlank(reportName, defaultReportName);
textInputDialog.showAndWait().ifPresent(enteredReportName -> {
//reportName defaults to case name + timestamp if left blank createReport(controller, reportName, generationDate, snapshot);
String reportName = StringUtils.defaultIfBlank(enteredReportName, defaultReportName); });
});
}
private void createReport(TimeLineController controller, String reportName, Date generationDate, BufferedImage snapshot) {
Path reportFolderPath; Path reportFolderPath;
try{ try {
reportFolderPath = Paths.get(currentCase.getReportDirectory(), reportName, "Timeline Snapshot"); reportFolderPath = Paths.get(currentCase.getReportDirectory(), reportName, "Timeline Snapshot");
} catch(InvalidPathException ex) { } catch (InvalidPathException ex) {
//notify user of report location //notify user of report location
final Alert alert = new Alert(Alert.AlertType.ERROR, null, OK); final Alert alert = new Alert(Alert.AlertType.ERROR, null, OK);
alert.setTitle(Bundle.SaveSnapShotAsReport_Report_Failed()); alert.setTitle(Bundle.SaveSnapShotAsReport_Report_Failed());
@ -137,7 +144,7 @@ public class SaveSnapshotAsReport extends Action {
generationDate, snapshot).writeReport(); generationDate, snapshot).writeReport();
} catch (IOException ex) { } catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Error writing report to disk at " + reportFolderPath, ex); //NON_NLS LOGGER.log(Level.SEVERE, "Error writing report to disk at " + reportFolderPath, ex); //NON_NLS
new Alert(Alert.AlertType.ERROR, Bundle.SaveSnapShotAsReport_ErrorWritingReport(reportFolderPath)).show(); MessageNotifyUtil.Message.error( Bundle.SaveSnapShotAsReport_ErrorWritingReport(reportFolderPath));
return; return;
} }
@ -146,24 +153,23 @@ public class SaveSnapshotAsReport extends Action {
Case.getCurrentCaseThrows().addReport(reportMainFilePath.toString(), Bundle.Timeline_ModuleName(), reportName); Case.getCurrentCaseThrows().addReport(reportMainFilePath.toString(), Bundle.Timeline_ModuleName(), reportName);
} catch (TskCoreException | NoCurrentCaseException ex) { } catch (TskCoreException | NoCurrentCaseException ex) {
LOGGER.log(Level.WARNING, "Failed to add " + reportMainFilePath.toString() + " to case as a report", ex); //NON_NLS LOGGER.log(Level.WARNING, "Failed to add " + reportMainFilePath.toString() + " to case as a report", ex); //NON_NLS
new Alert(Alert.AlertType.ERROR, Bundle.SaveSnapShotAsReport_FailedToAddReport()).show(); MessageNotifyUtil.Message.error(Bundle.SaveSnapShotAsReport_FailedToAddReport());
return; return;
} }
//notify user of report location Object[] options = { Bundle.SaveSnapShotAsReport_Open_Button(),
final Alert alert = new Alert(Alert.AlertType.INFORMATION, null, OPEN, OK); Bundle.SaveSnapShotAsReport_OK_Button()};
alert.setTitle(Bundle.SaveSnapShotAsReport_action_dialogs_title());
alert.setHeaderText(Bundle.SaveSnapShotAsReport_Success());
//make action to open report, and hyperlinklable to invoke action int result = JOptionPane.showOptionDialog(SwingUtilities.windowForComponent(controller.getTopComponent()),
Bundle.SaveSnapShotAsReport_success_message(reportMainFilePath),
Bundle.SaveSnapShotAsReport_action_dialogs_title(),
JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null,
options, options[0]);
if(result == 0) {
final OpenReportAction openReportAction = new OpenReportAction(reportMainFilePath); final OpenReportAction openReportAction = new OpenReportAction(reportMainFilePath);
HyperlinkLabel hyperlinkLabel = new HyperlinkLabel(Bundle.SaveSnapShotAsReport_ReportSavedAt(reportMainFilePath.toString())); openReportAction.handle(null);
hyperlinkLabel.setOnAction(openReportAction); }
alert.getDialogPane().setContent(hyperlinkLabel);
alert.showAndWait().filter(OPEN::equals).ifPresent(buttonType -> openReportAction.handle(null));
});
});
} }
/** /**