Autopsy  4.6.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-17 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 
62  private static final Image AUTOPSY_ICON;
63 
64  static {
65  Image tempImg = null;
66  try {
67  tempImg = new Image(new URL("nbresloc:/org/netbeans/core/startup/frame.gif").openStream()); //NON-NLS
68  } catch (IOException ex) {
69  logger.log(Level.WARNING, "Failed to load branded icon for progress dialog.", ex); //NON-NLS
70  }
71  AUTOPSY_ICON = tempImg;
72  }
73 
75  private Dialog<?> currentDialog;
76 
78 
85  this.controller = controller;
86  }
87 
95  boolean bringCurrentDialogToFront() {
96  if (currentDialog != null && currentDialog.isShowing()) {
97  ((Stage) currentDialog.getDialogPane().getScene().getWindow()).toFront();
98  return true;
99  }
100  return false;
101  }
102 
108  @NbBundle.Messages({"PromptDialogManager.progressDialog.title=Populating Timeline Data"})
109  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
110  void showDBPopulationProgressDialog(CancellationProgressTask<?> task) {
111  currentDialog = new ProgressDialog(task);
112  currentDialog.initModality(Modality.NONE);
113  currentDialog.setTitle(Bundle.PromptDialogManager_progressDialog_title());
115  currentDialog.headerTextProperty().bind(task.titleProperty());
116 
117  DialogPane dialogPane = currentDialog.getDialogPane();
118  dialogPane.setPrefSize(400, 200); //override autosizing which fails for some reason
119 
120  //co-ordinate task cancelation and dialog hiding.
121  task.setOnCancelled(cancelled -> currentDialog.close());
122  task.setOnSucceeded(succeeded -> currentDialog.close());
123  task.setOnFailed(failed -> currentDialog.close());
124 
125  dialogPane.getButtonTypes().setAll(ButtonType.CANCEL);
126  final Node cancelButton = dialogPane.lookupButton(ButtonType.CANCEL);
127  cancelButton.disableProperty().bind(task.cancellableProperty().not());
128  currentDialog.setOnCloseRequest(closeRequest -> {
129  if (task.isRunning()) {
130  closeRequest.consume();
131  }
132  if (task.isCancellable() && task.isCancelRequested() == false) {
133  task.requestCancel();
134  }
135  });
136 
137  currentDialog.show();
138  }
139 
145  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
146  public static void setDialogIcons(Dialog<?> dialog) {
147  ((Stage) dialog.getDialogPane().getScene().getWindow()).getIcons().setAll(AUTOPSY_ICON);
148  }
149 
156  @NbBundle.Messages({
157  "PromptDialogManager.confirmDuringIngest.headerText=You are trying to update the Timeline DB before ingest has been completed. The Timeline DB may be incomplete.",
158  "PromptDialogManager.confirmDuringIngest.contentText=Do you want to continue?"})
159  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
160  boolean confirmDuringIngest() {
161  currentDialog = new Alert(Alert.AlertType.CONFIRMATION, Bundle.PromptDialogManager_confirmDuringIngest_contentText(), CONTINUE, ButtonType.CANCEL);
162  currentDialog.initModality(Modality.APPLICATION_MODAL);
163  currentDialog.setTitle(Bundle.Timeline_dialogs_title());
165  currentDialog.setHeaderText(Bundle.PromptDialogManager_confirmDuringIngest_headerText());
166 
167  //show dialog and map all results except "continue" to false.
168  return currentDialog.showAndWait().map(CONTINUE::equals).orElse(false);
169  }
170 
179  @NbBundle.Messages({
180  "PromptDialogManager.rebuildPrompt.headerText=The Timeline DB is incomplete and/or out of date."
181  + " Some events may be missing or inaccurate and some features may be unavailable.",
182  "PromptDialogManager.rebuildPrompt.details=Details"})
183  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
184  boolean confirmRebuild(List<String> rebuildReasons) {
185  currentDialog = new Alert(Alert.AlertType.CONFIRMATION, Bundle.TimeLinecontroller_updateNowQuestion(), UPDATE, CONTINUE_NO_UPDATE);
186  currentDialog.initModality(Modality.APPLICATION_MODAL);
187  currentDialog.setTitle(Bundle.Timeline_dialogs_title());
189 
190  currentDialog.setHeaderText(Bundle.PromptDialogManager_rebuildPrompt_headerText());
191 
192  //set up listview of reasons to rebuild
193  ListView<String> listView = new ListView<>(FXCollections.observableArrayList(rebuildReasons));
194  listView.setCellFactory(lstView -> new WrappingListCell());
195  listView.setMaxHeight(75);
196 
197  //wrap listview in title border.
198  Node wrappedListView = Borders.wrap(listView)
199  .lineBorder()
200  .title(Bundle.PromptDialogManager_rebuildPrompt_details())
201  .buildAll();
202 
203  DialogPane dialogPane = currentDialog.getDialogPane();
204  dialogPane.setExpandableContent(wrappedListView);
205  dialogPane.setMaxWidth(500);
206 
207  //show dialog and map all results except "update" to false.
208  return currentDialog.showAndWait().map(UPDATE::equals).orElse(false);
209  }
210 
211  @NbBundle.Messages({
212  "PromptDialogManager.showTooManyFiles.contentText="
213  + "There are too many files in the DB to ensure reasonable performance."
214  + " Timeline will be disabled. ",
215  "PromptDialogManager.showTooManyFiles.headerText="})
216  static void showTooManyFiles() {
217  Alert dialog = new Alert(Alert.AlertType.INFORMATION,
218  Bundle.PromptDialogManager_showTooManyFiles_contentText(), ButtonType.OK);
219  dialog.initModality(Modality.APPLICATION_MODAL);
220  dialog.setTitle(Bundle.Timeline_dialogs_title());
221  setDialogIcons(dialog);
222  dialog.setHeaderText(Bundle.PromptDialogManager_showTooManyFiles_headerText());
223  dialog.showAndWait();
224  }
225 
226  @NbBundle.Messages({
227  "PromptDialogManager.showTimeLineDisabledMessage.contentText="
228  + "Timeline functionality is not available yet."
229  + " Timeline will be disabled. ",
230  "PromptDialogManager.showTimeLineDisabledMessage.headerText="})
231  static void showTimeLineDisabledMessage() {
232  Alert dialog = new Alert(Alert.AlertType.INFORMATION,
233  Bundle.PromptDialogManager_showTimeLineDisabledMessage_contentText(), ButtonType.OK);
234  dialog.initModality(Modality.APPLICATION_MODAL);
235  dialog.setTitle(Bundle.Timeline_dialogs_title());
236  setDialogIcons(dialog);
237  dialog.setHeaderText(Bundle.PromptDialogManager_showTimeLineDisabledMessage_headerText());
238  dialog.showAndWait();
239  }
240 
241 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.