Autopsy  4.1
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-16 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 static final 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. Some events may be missing or inaccurate and some features may be unavailable.",
181  "PromptDialogManager.rebuildPrompt.details=Details"})
182  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
183  boolean confirmRebuild(List<String> rebuildReasons) {
184  currentDialog = new Alert(Alert.AlertType.CONFIRMATION, Bundle.TimeLinecontroller_updateNowQuestion(), UPDATE, CONTINUE_NO_UPDATE);
185  currentDialog.initModality(Modality.APPLICATION_MODAL);
186  currentDialog.setTitle(Bundle.Timeline_dialogs_title());
188 
189  currentDialog.setHeaderText(Bundle.PromptDialogManager_rebuildPrompt_headerText());
190 
191  //set up listview of reasons to rebuild
192  ListView<String> listView = new ListView<>(FXCollections.observableArrayList(rebuildReasons));
193  listView.setCellFactory(lstView -> new WrappingListCell());
194  listView.setMaxHeight(75);
195 
196  //wrap listview in title border.
197  Node wrappedListView = Borders.wrap(listView)
198  .lineBorder()
199  .title(Bundle.PromptDialogManager_rebuildPrompt_details())
200  .buildAll();
201 
202  DialogPane dialogPane = currentDialog.getDialogPane();
203  dialogPane.setExpandableContent(wrappedListView);
204  dialogPane.setMaxWidth(500);
205 
206  //show dialog and map all results except "update" to false.
207  return currentDialog.showAndWait().map(UPDATE::equals).orElse(false);
208  }
209 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Tue Oct 25 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.