Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
PromptDialogManager.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2015-18 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.timeline;
20 
21 import java.io.IOException;
22 import java.net.URL;
23 import java.util.List;
24 import java.util.logging.Level;
25 import javafx.collections.FXCollections;
26 import javafx.scene.Node;
27 import javafx.scene.control.Alert;
28 import javafx.scene.control.ButtonBar;
29 import javafx.scene.control.ButtonType;
30 import javafx.scene.control.Dialog;
31 import javafx.scene.control.DialogPane;
32 import javafx.scene.control.ListView;
33 import javafx.scene.image.Image;
34 import javafx.stage.Modality;
35 import javafx.stage.Stage;
36 import org.controlsfx.dialog.ProgressDialog;
37 import org.controlsfx.tools.Borders;
38 import org.openide.util.NbBundle;
41 
46 public final class PromptDialogManager {
47 
48  private final static Logger logger = Logger.getLogger(PromptDialogManager.class.getName());
49 
50  @NbBundle.Messages("PrompDialogManager.buttonType.showTimeline=Continue")
51  private static final ButtonType CONTINUE = new ButtonType(Bundle.PrompDialogManager_buttonType_showTimeline(), ButtonBar.ButtonData.OK_DONE);
52 
53  @NbBundle.Messages("PrompDialogManager.buttonType.continueNoUpdate=Continue Without Updating")
54  private static final ButtonType CONTINUE_NO_UPDATE = new ButtonType(Bundle.PrompDialogManager_buttonType_continueNoUpdate(), ButtonBar.ButtonData.CANCEL_CLOSE);
55 
56  @NbBundle.Messages("PrompDialogManager.buttonType.update=Update DB")
57  private static final ButtonType UPDATE = new ButtonType(Bundle.PrompDialogManager_buttonType_update(), ButtonBar.ButtonData.OK_DONE);
58 
60  private static final Image AUTOPSY_ICON;
61 
62  static {
63  Image tempImg = null;
64  try {
65  tempImg = new Image(new URL("nbresloc:/org/netbeans/core/startup/frame.gif").openStream()); //NON-NLS
66  } catch (IOException ex) {
67  logger.log(Level.WARNING, "Failed to load branded icon for progress dialog.", ex); //NON-NLS
68  }
69  AUTOPSY_ICON = tempImg;
70  }
71 
73  private Dialog<?> currentDialog;
74 
76 
83  this.controller = controller;
84  }
85 
93  boolean bringCurrentDialogToFront() {
94  if (currentDialog != null && currentDialog.isShowing()) {
95  ((Stage) currentDialog.getDialogPane().getScene().getWindow()).toFront();
96  return true;
97  }
98  return false;
99  }
100 
106  @NbBundle.Messages({"PromptDialogManager.progressDialog.title=Populating Timeline Data"})
107  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
108  void showDBPopulationProgressDialog(CancellationProgressTask<?> task) {
109  currentDialog = new ProgressDialog(task);
110  currentDialog.initModality(Modality.NONE);
111  currentDialog.setTitle(Bundle.PromptDialogManager_progressDialog_title());
113  currentDialog.headerTextProperty().bind(task.titleProperty());
114 
115  DialogPane dialogPane = currentDialog.getDialogPane();
116  dialogPane.setPrefSize(400, 200); //override autosizing which fails for some reason
117 
118  //co-ordinate task cancelation and dialog hiding.
119  task.setOnCancelled(cancelled -> currentDialog.close());
120  task.setOnSucceeded(succeeded -> currentDialog.close());
121  task.setOnFailed(failed -> currentDialog.close());
122 
123  dialogPane.getButtonTypes().setAll(ButtonType.CANCEL);
124  final Node cancelButton = dialogPane.lookupButton(ButtonType.CANCEL);
125  cancelButton.disableProperty().bind(task.cancellableProperty().not());
126  currentDialog.setOnCloseRequest(closeRequest -> {
127  if (task.isRunning()) {
128  closeRequest.consume();
129  }
130  if (task.isCancellable() && task.isCancelRequested() == false) {
131  task.requestCancel();
132  }
133  });
134 
135  currentDialog.show();
136  }
137 
143  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
144  public static void setDialogIcons(Dialog<?> dialog) {
145  ((Stage) dialog.getDialogPane().getScene().getWindow()).getIcons().setAll(AUTOPSY_ICON);
146  }
147 
154  @NbBundle.Messages({
155  "PromptDialogManager.confirmDuringIngest.headerText=Ingest is still going, and the Timeline may be incomplete.",
156  "PromptDialogManager.confirmDuringIngest.contentText=Do you want to continue?"})
157  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
158  boolean confirmDuringIngest() {
159  currentDialog = new Alert(Alert.AlertType.CONFIRMATION, Bundle.PromptDialogManager_confirmDuringIngest_contentText(), CONTINUE, ButtonType.CANCEL);
160  currentDialog.initModality(Modality.APPLICATION_MODAL);
161  currentDialog.setTitle(Bundle.Timeline_dialogs_title());
163  currentDialog.setHeaderText(Bundle.PromptDialogManager_confirmDuringIngest_headerText());
164 
165  //show dialog and map all results except "continue" to false.
166  return currentDialog.showAndWait().map(CONTINUE::equals).orElse(false);
167  }
168 
177  @NbBundle.Messages({
178  "PromptDialogManager.rebuildPrompt.headerText=The Timeline DB is incomplete and/or out of date."
179  + " Some events may be missing or inaccurate and some features may be unavailable.",
180  "PromptDialogManager.rebuildPrompt.details=Details"})
181  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
182  boolean confirmRebuild(List<String> rebuildReasons) {
183  currentDialog = new Alert(Alert.AlertType.CONFIRMATION, Bundle.TimeLinecontroller_updateNowQuestion(), UPDATE, CONTINUE_NO_UPDATE);
184  currentDialog.initModality(Modality.APPLICATION_MODAL);
185  currentDialog.setTitle(Bundle.Timeline_dialogs_title());
187 
188  currentDialog.setHeaderText(Bundle.PromptDialogManager_rebuildPrompt_headerText());
189 
190  //set up listview of reasons to rebuild
191  ListView<String> listView = new ListView<>(FXCollections.observableArrayList(rebuildReasons));
192  listView.setCellFactory(lstView -> new WrappingListCell());
193  listView.setMaxHeight(75);
194 
195  //wrap listview in title border.
196  Node wrappedListView = Borders.wrap(listView)
197  .lineBorder()
198  .title(Bundle.PromptDialogManager_rebuildPrompt_details())
199  .buildAll();
200 
201  DialogPane dialogPane = currentDialog.getDialogPane();
202  dialogPane.setExpandableContent(wrappedListView);
203  dialogPane.setMaxWidth(500);
204 
205  //show dialog and map all results except "update" to false.
206  return currentDialog.showAndWait().map(UPDATE::equals).orElse(false);
207  }
208 
209  @NbBundle.Messages({
210  "PromptDialogManager.showTooManyFiles.contentText="
211  + "There are too many files in the DB to ensure reasonable performance."
212  + " Timeline will be disabled. ",
213  "PromptDialogManager.showTooManyFiles.headerText="})
214  static void showTooManyFiles() {
215  Alert dialog = new Alert(Alert.AlertType.INFORMATION,
216  Bundle.PromptDialogManager_showTooManyFiles_contentText(), ButtonType.OK);
217  dialog.initModality(Modality.APPLICATION_MODAL);
218  dialog.setTitle(Bundle.Timeline_dialogs_title());
219  setDialogIcons(dialog);
220  dialog.setHeaderText(Bundle.PromptDialogManager_showTooManyFiles_headerText());
221  dialog.showAndWait();
222  }
223 
224  @NbBundle.Messages({
225  "PromptDialogManager.showTimeLineDisabledMessage.contentText="
226  + "Timeline functionality is not available yet."
227  + " Timeline will be disabled. ",
228  "PromptDialogManager.showTimeLineDisabledMessage.headerText="})
229  static void showTimeLineDisabledMessage() {
230  Alert dialog = new Alert(Alert.AlertType.INFORMATION,
231  Bundle.PromptDialogManager_showTimeLineDisabledMessage_contentText(), ButtonType.OK);
232  dialog.initModality(Modality.APPLICATION_MODAL);
233  dialog.setTitle(Bundle.Timeline_dialogs_title());
234  setDialogIcons(dialog);
235  dialog.setHeaderText(Bundle.PromptDialogManager_showTimeLineDisabledMessage_headerText());
236  dialog.showAndWait();
237  }
238 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.