Autopsy  4.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-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.ArrayList;
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 class PromptDialogManager {
47 
48  private static final Logger LOGGER = Logger.getLogger(PromptDialogManager.class.getName());
49 
50  @NbBundle.Messages("PrompDialogManager.buttonType.showTimeline=Show Timeline")
51  private static final ButtonType SHOW_TIMELINE = 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")
57  private static final ButtonType UPDATE = new ButtonType(Bundle.PrompDialogManager_buttonType_update(), ButtonBar.ButtonData.OK_DONE);
58 
59  private static final Image LOGO;
60 
61  static {
62  Image x = null;
63  try {
64  x = new Image(new URL("nbresloc:/org/netbeans/core/startup/frame.gif").openStream()); //NON-NLS
65  } catch (IOException ex) {
66  LOGGER.log(Level.WARNING, "Failed to load branded icon for progress dialog.", ex); //NON-NLS
67  }
68  LOGO = x;
69  }
70  private Dialog<?> currentDialog;
71 
73 
75  this.controller = controller;
76  }
77 
85  boolean bringCurrentDialogToFront() {
86  if (currentDialog != null && currentDialog.isShowing()) {
87  ((Stage) currentDialog.getDialogPane().getScene().getWindow()).toFront();
88  return true;
89  }
90  return false;
91  }
92 
93  @NbBundle.Messages({"PromptDialogManager.progressDialog.title=Populating Timeline Data"})
94  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
95  void showProgressDialog(CancellationProgressTask<?> task) {
96  currentDialog = new ProgressDialog(task);
97  currentDialog.initModality(Modality.NONE);
98  currentDialog.setTitle(Bundle.PromptDialogManager_progressDialog_title());
99  setDialogIcons(currentDialog);
100  currentDialog.headerTextProperty().bind(task.titleProperty());
101 
102  DialogPane dialogPane = currentDialog.getDialogPane();
103  dialogPane.setPrefSize(400, 200); //override autosizing which fails for some reason
104 
105  //co-ordinate task cancelation and dialog hiding.
106  task.setOnCancelled(cancelled -> currentDialog.close());
107  task.setOnSucceeded(succeeded -> currentDialog.close());
108  task.setOnFailed(failed -> currentDialog.close());
109 
110  dialogPane.getButtonTypes().setAll(ButtonType.CANCEL);
111  final Node cancelButton = dialogPane.lookupButton(ButtonType.CANCEL);
112  cancelButton.disableProperty().bind(task.cancellableProperty().not());
113  currentDialog.setOnCloseRequest(closeRequest -> {
114  if (task.isRunning()) {
115  closeRequest.consume();
116  }
117  if (task.isCancellable() && task.isCancelRequested() == false) {
118  task.requestCancel();
119  }
120  });
121 
122  currentDialog.show();
123  }
124 
125  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
126  static private void setDialogIcons(Dialog<?> dialog) {
127  ((Stage) dialog.getDialogPane().getScene().getWindow()).getIcons().setAll(LOGO);
128  }
129 
136  @NbBundle.Messages({"PromptDialogManager.confirmDuringIngest.headerText=You are trying to show a timeline before ingest has been completed.\nThe timeline may be incomplete.",
137  "PromptDialogManager.confirmDuringIngest.contentText=Do you want to continue?"})
138  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
139  boolean confirmDuringIngest() {
140  currentDialog = new Alert(Alert.AlertType.CONFIRMATION, Bundle.PromptDialogManager_confirmDuringIngest_contentText(), SHOW_TIMELINE, ButtonType.CANCEL);
141  currentDialog.initModality(Modality.APPLICATION_MODAL);
142  currentDialog.setHeaderText(Bundle.PromptDialogManager_confirmDuringIngest_headerText());
143  setDialogIcons(currentDialog);
144  currentDialog.setTitle(Bundle.Timeline_confirmation_dialogs_title());
145 
146  return currentDialog.showAndWait().map(SHOW_TIMELINE::equals).orElse(false);
147  }
148 
149  @NbBundle.Messages({"PromptDialogManager.rebuildPrompt.headerText=The Timeline database is incomplete and/or out of date.\nSome events may be missing or inaccurate and some features may be unavailable.",
150  "PromptDialogManager.rebuildPrompt.details=Details:"})
151  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
152  boolean confirmRebuild(ArrayList<String> rebuildReasons) {
153  currentDialog = new Alert(Alert.AlertType.CONFIRMATION, Bundle.TimeLinecontroller_updateNowQuestion(), UPDATE, CONTINUE_NO_UPDATE);
154  currentDialog.initModality(Modality.APPLICATION_MODAL);
155  currentDialog.setHeaderText(Bundle.PromptDialogManager_rebuildPrompt_headerText());
156  setDialogIcons(currentDialog);
157  currentDialog.setTitle(Bundle.Timeline_confirmation_dialogs_title());
158 
159  DialogPane dialogPane = currentDialog.getDialogPane();
160  ListView<String> listView = new ListView<>(FXCollections.observableArrayList(rebuildReasons));
161  listView.setCellFactory(lstView -> new WrappingListCell());
162  listView.setMaxHeight(75);
163  Node wrappedListView = Borders.wrap(listView).lineBorder().title(Bundle.PromptDialogManager_rebuildPrompt_details()).buildAll();
164  dialogPane.setExpandableContent(wrappedListView);
165 
166  return currentDialog.showAndWait().map(UPDATE::equals).orElse(false);
167  }
168 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:166

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.