Autopsy  4.4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddImageAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 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.casemodule;
20 
21 import java.awt.Component;
22 import java.awt.Cursor;
23 import java.awt.Dialog;
24 import java.awt.Dimension;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.text.MessageFormat;
28 import java.util.logging.Level;
29 import javax.swing.Action;
30 import javax.swing.ImageIcon;
31 import javax.swing.JButton;
32 import javax.swing.SwingUtilities;
33 import javax.swing.event.ChangeEvent;
34 import javax.swing.event.ChangeListener;
35 import org.openide.DialogDisplayer;
36 import org.openide.WizardDescriptor;
37 import org.openide.awt.ActionID;
38 import org.openide.awt.ActionReference;
39 import org.openide.awt.ActionReferences;
40 import org.openide.awt.ActionRegistration;
41 import org.openide.util.ChangeSupport;
42 import org.openide.util.HelpCtx;
43 import org.openide.util.NbBundle;
44 import org.openide.util.actions.CallableSystemAction;
45 import org.openide.util.actions.Presenter;
46 import org.openide.util.lookup.ServiceProvider;
47 import org.openide.windows.WindowManager;
50 import org.sleuthkit.datamodel.Image;
51 
57 @ActionID(category = "Tools", id = "org.sleuthkit.autopsy.casemodule.AddImageAction")
58 @ActionRegistration(displayName = "#CTL_AddImage", lazy = false)
59 @ActionReferences(value = {@ActionReference(path = "Toolbars/Case", position = 100)})
60 @ServiceProvider(service = AddImageAction.class)
61 public final class AddImageAction extends CallableSystemAction implements Presenter.Toolbar {
62 
63  private static final long serialVersionUID = 1L;
64  private static final Dimension SIZE = new Dimension(875, 550);
65  private final ChangeSupport cleanupSupport = new ChangeSupport(this);
66 
67  // Keys into the WizardDescriptor properties that pass information between stages of the wizard
68  // <TYPE>: <DESCRIPTION>
69  // String: time zone that the image is from
70  static final String TIMEZONE_PROP = "timeZone"; //NON-NLS
71  // String[]: array of paths to each data source selected
72  static final String DATASOURCEPATH_PROP = "dataSrcPath"; //NON-NLS
73  // String data source type selected
74  static final String DATASOURCETYPE_PROP = "dataSrcType"; //NON-NLS
75  // CleanupTask: task to clean up the database file if wizard errors/is cancelled after it is created
76  static final String IMAGECLEANUPTASK_PROP = "finalFileCleanup"; //NON-NLS
77  // int: the next availble id for a new image
78  static final String IMAGEID_PROP = "imageId"; //NON-NLS
79  // AddImageProcess: the next availble id for a new image
80  static final String PROCESS_PROP = "process"; //NON-NLS
81  // boolean: whether or not to lookup files in the hashDB
82  static final String LOOKUPFILES_PROP = "lookupFiles"; //NON-NLS
83  // boolean: whether or not to skip processing orphan files on FAT filesystems
84  static final String NOFATORPHANS_PROP = "nofatorphans"; //NON-NLS
85 
86  static final Logger logger = Logger.getLogger(AddImageAction.class.getName());
87  private WizardDescriptor wizardDescriptor;
88  private WizardDescriptor.Iterator<WizardDescriptor> iterator;
89  private Dialog dialog;
90  private final JButton toolbarButton = new JButton();
91 
95  public AddImageAction() {
96  putValue(Action.NAME, NbBundle.getMessage(AddImageAction.class, "CTL_AddImage")); // set the action Name
97 
98  // set the action for the toolbar button
99  toolbarButton.addActionListener(new ActionListener() {
100 
101  @Override
102  public void actionPerformed(ActionEvent e) {
104  }
105  });
106 
107  /*
108  * Disable this action until a case is opened. Currently, the Case class
109  * enables the action.
110  */
111  this.setEnabled(false);
112  }
113 
114  @Override
115  public void actionPerformed(ActionEvent e) {
116  String optionsDlgTitle = NbBundle.getMessage(this.getClass(), "AddImageAction.ingestConfig.ongoingIngest.title");
117  String optionsDlgMessage = NbBundle.getMessage(this.getClass(), "AddImageAction.ingestConfig.ongoingIngest.msg");
118  if (IngestRunningCheck.checkAndConfirmProceed(optionsDlgTitle, optionsDlgMessage)) {
119  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
120  iterator = new AddImageWizardIterator(this);
121  wizardDescriptor = new WizardDescriptor(iterator);
122  wizardDescriptor.setTitle(NbBundle.getMessage(this.getClass(), "AddImageAction.wizard.title"));
123  wizardDescriptor.putProperty(NAME, e);
124  wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));
125 
126  if (dialog != null) {
127  dialog.setVisible(false); // hide the old one
128  }
129  dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
130  Dimension d = dialog.getSize();
131  dialog.setSize(SIZE);
132  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
133  dialog.setVisible(true);
134  dialog.toFront();
135 
136  // Do any cleanup that needs to happen (potentially: stopping the
137  //add-image process, reverting an image)
138  runCleanupTasks();
139  }
140  }
141 
146  void restart() {
147  // Simulate clicking finish for the current dialog
148  wizardDescriptor.setValue(WizardDescriptor.FINISH_OPTION);
149  dialog.setVisible(false);
150 
151  // let the previous call to AddImageAction.actionPerformed() finish up
152  // after the wizard, this will run when its it's done
153  final Runnable r = new Runnable() {
154  @Override
155  public void run() {
156  actionPerformed(null);
157  }
158  };
159 
160  SwingUtilities.invokeLater(r);
161  }
162 
163  public interface IndexImageTask {
164 
165  void runTask(Image newImage);
166  }
167 
168  @Override
169  public void performAction() {
170  actionPerformed(null);
171  }
172 
178  @Override
179  public String getName() {
180  return NbBundle.getMessage(AddImageAction.class, "CTL_AddImageButton");
181  }
182 
188  @Override
189  public HelpCtx getHelpCtx() {
190  return HelpCtx.DEFAULT_HELP;
191  }
192 
198  @Override
199  public Component getToolbarPresenter() {
200  ImageIcon icon = new ImageIcon(getClass().getResource("btn_icon_add_image.png")); //NON-NLS
201  toolbarButton.setIcon(icon);
202  toolbarButton.setText(this.getName());
203  return toolbarButton;
204  }
205 
211  @Override
212  public void setEnabled(boolean value) {
213  super.setEnabled(value);
214  toolbarButton.setEnabled(value);
215  }
216 
226  public void requestFocusButton(String buttonText) {
227  // get all buttons on this wizard panel
228  Object[] wizardButtons = wizardDescriptor.getOptions();
229  for (Object wizardButton : wizardButtons) {
230  JButton tempButton = (JButton) wizardButton;
231  if (tempButton.getText().equals(buttonText)) {
232  tempButton.setDefaultCapable(true);
233  tempButton.requestFocus();
234  }
235  }
236  }
237 
243  private void runCleanupTasks() {
244  cleanupSupport.fireChange();
245  }
246 
256  abstract class CleanupTask implements ChangeListener {
257 
258  @Override
259  public void stateChanged(ChangeEvent e) {
260  // fired by AddImageAction.runCleanupTasks() after the wizard closes
261  try {
262  cleanup();
263  } catch (Exception ex) {
264  Logger logger = Logger.getLogger(this.getClass().getName());
265  logger.log(Level.WARNING, "Error cleaning up from wizard.", ex); //NON-NLS
266  } finally {
267  disable(); // cleanup tasks should only run once.
268  }
269  }
270 
274  public void enable() {
275  cleanupSupport.addChangeListener(this);
276  }
277 
283  abstract void cleanup() throws Exception;
284 
288  public void disable() {
289  cleanupSupport.removeChangeListener(this);
290  }
291  }
292 }
static boolean checkAndConfirmProceed(String optionsDlgTitle, String optionsDlgMessage)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161
WizardDescriptor.Iterator< WizardDescriptor > iterator

Copyright © 2012-2016 Basis Technology. Generated on: Fri Sep 29 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.