cleanup PromptDialogManager, EventsRepository and TimeLineController

This commit is contained in:
jmillman 2016-03-24 15:56:14 -04:00
parent 843fefac25
commit 767a169d77
3 changed files with 56 additions and 24 deletions

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2015 Basis Technology Corp.
* Copyright 2015-16 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -61,9 +61,9 @@ public class PromptDialogManager {
static {
Image x = null;
try {
x = new Image(new URL("nbresloc:/org/netbeans/core/startup/frame.gif").openStream()); //NOI18N
x = new Image(new URL("nbresloc:/org/netbeans/core/startup/frame.gif").openStream()); //NON-NLS
} catch (IOException ex) {
LOGGER.log(Level.WARNING, "Failed to load branded icon for progress dialog.", ex); //NOI18N NON-NLS
LOGGER.log(Level.WARNING, "Failed to load branded icon for progress dialog.", ex); //NON-NLS
}
LOGO = x;
}
@ -75,6 +75,12 @@ public class PromptDialogManager {
this.controller = controller;
}
/**
* bring the currently managed dialog (if there is one) to the front
*
* @return true if a dialog was brought to the front, or false of there is
* no currently managed open dialog
*/
@ThreadConfined(type = ThreadConfined.ThreadType.JFX)
boolean bringCurrentDialogToFront() {
if (currentDialog != null && currentDialog.isShowing()) {
@ -86,12 +92,12 @@ public class PromptDialogManager {
@NbBundle.Messages({"PromptDialogManager.progressDialog.title=Populating Timeline Data"})
@ThreadConfined(type = ThreadConfined.ThreadType.JFX)
public void showProgressDialog(CancellationProgressTask<?> task) {
void showProgressDialog(CancellationProgressTask<?> task) {
currentDialog = new ProgressDialog(task);
currentDialog.initModality(Modality.NONE);
currentDialog.headerTextProperty().bind(task.titleProperty());
setDialogIcons(currentDialog);
currentDialog.setTitle(Bundle.PromptDialogManager_progressDialog_title());
setDialogIcons(currentDialog);
currentDialog.headerTextProperty().bind(task.titleProperty());
DialogPane dialogPane = currentDialog.getDialogPane();
dialogPane.setPrefSize(400, 200); //override autosizing which fails for some reason
@ -100,6 +106,7 @@ public class PromptDialogManager {
task.setOnCancelled(cancelled -> currentDialog.close());
task.setOnSucceeded(succeeded -> currentDialog.close());
task.setOnFailed(failed -> currentDialog.close());
dialogPane.getButtonTypes().setAll(ButtonType.CANCEL);
final Node cancelButton = dialogPane.lookupButton(ButtonType.CANCEL);
cancelButton.disableProperty().bind(task.cancellableProperty().not());
@ -117,14 +124,7 @@ public class PromptDialogManager {
@ThreadConfined(type = ThreadConfined.ThreadType.JFX)
static private void setDialogIcons(Dialog<?> dialog) {
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
stage.getIcons().setAll(LOGO);
}
@ThreadConfined(type = ThreadConfined.ThreadType.JFX)
static private void setDialogTitle(Dialog<?> dialog) {
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
stage.setTitle(Bundle.Timeline_confirmation_dialogs_title());
((Stage) dialog.getDialogPane().getScene().getWindow()).getIcons().setAll(LOGO);
}
/**
@ -141,7 +141,7 @@ public class PromptDialogManager {
currentDialog.initModality(Modality.APPLICATION_MODAL);
currentDialog.setHeaderText(Bundle.PromptDialogManager_confirmDuringIngest_headerText());
setDialogIcons(currentDialog);
setDialogTitle(currentDialog);
currentDialog.setTitle(Bundle.Timeline_confirmation_dialogs_title());
return currentDialog.showAndWait().map(SHOW_TIMELINE::equals).orElse(false);
}
@ -154,7 +154,7 @@ public class PromptDialogManager {
currentDialog.initModality(Modality.APPLICATION_MODAL);
currentDialog.setHeaderText(Bundle.PromptDialogManager_rebuildPrompt_headerText());
setDialogIcons(currentDialog);
setDialogTitle(currentDialog);
currentDialog.setTitle(Bundle.Timeline_confirmation_dialogs_title());
DialogPane dialogPane = currentDialog.getDialogPane();
ListView<String> listView = new ListView<>(FXCollections.observableArrayList(rebuildReasons));

View File

@ -290,6 +290,14 @@ public class TimeLineController {
advance(filteredEvents.zoomParametersProperty().get().withTimeRange(boundingEventsInterval));
}
/**
* rebuild the repo using the given repo builder (expected to be a member
* reference to {@link EventsRepository#rebuildRepository(java.util.function.Consumer)
* } or {@link EventsRepository#rebuildTags(java.util.function.Consumer) })
* and display the ui when it is done.
*
* @param repoBuilder
*/
@ThreadConfined(type = ThreadConfined.ThreadType.JFX)
private void rebuildRepoHelper(Function<Consumer<Worker.State>, CancellationProgressTask<?>> repoBuilder) {
SwingUtilities.invokeLater(this::closeTimelineWindow);
@ -314,11 +322,7 @@ public class TimeLineController {
}
/**
* rebuld the repo.
*
* @return False if the repo was not rebuilt because because the user
* aborted after prompt about ingest running. True if the repo was
* rebuilt.
* rebuld the entire repo.
*/
@ThreadConfined(type = ThreadConfined.ThreadType.JFX)
void rebuildRepo() {
@ -329,7 +333,6 @@ public class TimeLineController {
* Since tags might have changed while TimeLine wasn't listening, drop the
* tags table and rebuild it by querying for all the tags and inserting them
* in to the TimeLine DB.
*
*/
@ThreadConfined(type = ThreadConfined.ThreadType.JFX)
void rebuildTagsTable() {

View File

@ -320,19 +320,48 @@ public class EventsRepository {
return dbWorker.isRunning();
}
/**
*
* rebuild the entire repo.
*
* @param onStateChange called when he background task changes state.
* Clients can use this to handle failure, or cleanup
* operations for example.
*
* @return the task that will rebuild the repo in a background thread. The
* task has already been started.
*/
@ThreadConfined(type = ThreadConfined.ThreadType.JFX)
public CancellationProgressTask<Void> rebuildRepository(Consumer<Worker.State> onStateChange) {
return rebuildRepository(DBPopulationMode.FULL, onStateChange);
}
/**
*
* drop and rebuild the tags in the repo.
*
* @param onStateChange called when he background task changes state.
* Clients can use this to handle failure, or cleanup
* operations for example.
*
* @return the task that will rebuild the repo in a background thread. The
* task has already been started.
*/
@ThreadConfined(type = ThreadConfined.ThreadType.JFX)
public CancellationProgressTask<Void> rebuildTags(Consumer<Worker.State> onStateChange) {
return rebuildRepository(DBPopulationMode.TAGS_ONLY, onStateChange);
}
/**
* rebuild the repo.
*
* @param mode the value of mode
* @param mode the rebuild mode to use.
* @param onStateChange called when he background task changes state.
* Clients can use this to handle failure, or cleanup
* operations for example.
*
* @return the task that will rebuild the repo in a background thread. The
* task has already been started.
*/
@ThreadConfined(type = ThreadConfined.ThreadType.JFX)
private CancellationProgressTask<Void> rebuildRepository(final DBPopulationMode mode, Consumer<Worker.State> onStateChange) {
@ -409,7 +438,7 @@ public class EventsRepository {
skCase = autoCase.getSleuthkitCase();
tagsManager = autoCase.getServices().getTagsManager();
this.dbPopulationMode = mode;
this.stateProperty().addListener(observable -> onStateChange.accept(getState()));
this.stateProperty().addListener(stateObservable -> onStateChange.accept(getState()));
}
void restartProgressHandle(String title, String message, Double workDone, double total, Boolean cancellable) {