Autopsy  4.0
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-2014 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.Dialog;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.util.logging.Level;
26 import javax.swing.Action;
27 import javax.swing.ImageIcon;
28 import javax.swing.JButton;
29 import javax.swing.JOptionPane;
30 import javax.swing.SwingUtilities;
31 import javax.swing.event.ChangeEvent;
32 import javax.swing.event.ChangeListener;
33 import org.openide.DialogDisplayer;
34 import org.openide.WizardDescriptor;
35 import org.openide.util.ChangeSupport;
36 import org.openide.util.HelpCtx;
37 import org.openide.util.NbBundle;
38 import org.openide.util.actions.CallableSystemAction;
39 import org.openide.util.actions.Presenter;
40 import org.openide.util.lookup.ServiceProvider;
43 import org.sleuthkit.datamodel.Image;
44 
52 // TODO: need annotation because there's a "Lookup.getDefault().lookup(AddImageAction.class)"
53 // used in AddImageWizardPanel1 (among other places). It really shouldn't be done like that.
54 @ServiceProvider(service = AddImageAction.class)
55 public final class AddImageAction extends CallableSystemAction implements Presenter.Toolbar {
56 
57  // Keys into the WizardDescriptor properties that pass information between stages of the wizard
58  // <TYPE>: <DESCRIPTION>
59  // String: time zone that the image is from
60  static final String TIMEZONE_PROP = "timeZone"; //NON-NLS
61  // String[]: array of paths to each data source selected
62  static final String DATASOURCEPATH_PROP = "dataSrcPath"; //NON-NLS
63  // String data source type selected
64  static final String DATASOURCETYPE_PROP = "dataSrcType"; //NON-NLS
65  // CleanupTask: task to clean up the database file if wizard errors/is cancelled after it is created
66  static final String IMAGECLEANUPTASK_PROP = "finalFileCleanup"; //NON-NLS
67  // int: the next availble id for a new image
68  static final String IMAGEID_PROP = "imageId"; //NON-NLS
69  // AddImageProcess: the next availble id for a new image
70  static final String PROCESS_PROP = "process"; //NON-NLS
71  // boolean: whether or not to lookup files in the hashDB
72  static final String LOOKUPFILES_PROP = "lookupFiles"; //NON-NLS
73  // boolean: whether or not to skip processing orphan files on FAT filesystems
74  static final String NOFATORPHANS_PROP = "nofatorphans"; //NON-NLS
75 
76  static final Logger logger = Logger.getLogger(AddImageAction.class.getName());
77 
78  private WizardDescriptor wizardDescriptor;
79  private WizardDescriptor.Iterator<WizardDescriptor> iterator;
80  private Dialog dialog;
81  private JButton toolbarButton = new JButton();
82 
86  public AddImageAction() {
87  putValue(Action.NAME, NbBundle.getMessage(AddImageAction.class, "CTL_AddImage")); // set the action Name
88 
89  // set the action for the toolbar button
90  toolbarButton.addActionListener(new ActionListener() {
91 
92  @Override
93  public void actionPerformed(ActionEvent e) {
95  }
96  });
97 
98  this.setEnabled(false); // disable this action class
99  }
100 
106  @Override
107  public void actionPerformed(ActionEvent e) {
109  final String msg = NbBundle.getMessage(this.getClass(), "AddImageAction.ingestConfig.ongoingIngest.msg");
110  if (JOptionPane.showConfirmDialog(null, msg,
111  NbBundle.getMessage(this.getClass(),
112  "AddImageAction.ingestConfig.ongoingIngest.title"),
113  JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) {
114  return;
115  }
116  }
117 
118  iterator = new AddImageWizardIterator(this);
119  wizardDescriptor = new WizardDescriptor(iterator);
120  wizardDescriptor.setTitle(NbBundle.getMessage(this.getClass(), "AddImageAction.wizard.title"));
121  wizardDescriptor.putProperty(NAME, e);
122 
123  if (dialog != null) {
124  dialog.setVisible(false); // hide the old one
125  }
126  dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
127  dialog.setVisible(true);
128  dialog.toFront();
129 
130  // Do any cleanup that needs to happen (potentially: stopping the
131  //add-image process, reverting an image)
132  runCleanupTasks();
133  }
134 
139  void restart() {
140  // Simulate clicking finish for the current dialog
141  wizardDescriptor.setValue(WizardDescriptor.FINISH_OPTION);
142  dialog.setVisible(false);
143 
144  // let the previous call to AddImageAction.actionPerformed() finish up
145  // after the wizard, this will run when its it's done
146  final Runnable r = new Runnable() {
147  @Override
148  public void run() {
149  actionPerformed(null);
150  }
151  };
152 
153  SwingUtilities.invokeLater(r);
154  }
155 
156  public interface IndexImageTask {
157 
158  void runTask(Image newImage);
159  }
160 
165  @Override
166  public void performAction() {
167  }
168 
174  @Override
175  public String getName() {
176  return NbBundle.getMessage(AddImageAction.class, "CTL_AddImageButton");
177  }
178 
184  @Override
185  public HelpCtx getHelpCtx() {
186  return HelpCtx.DEFAULT_HELP;
187  }
188 
194  @Override
195  public Component getToolbarPresenter() {
196  ImageIcon icon = new ImageIcon(getClass().getResource("btn_icon_add_image.png")); //NON-NLS
197  toolbarButton.setIcon(icon);
198  toolbarButton.setText(this.getName());
199  return toolbarButton;
200  }
201 
207  @Override
208  public void setEnabled(boolean value) {
209  super.setEnabled(value);
210  toolbarButton.setEnabled(value);
211  }
212 
222  public void requestFocusButton(String buttonText) {
223  // get all buttons on this wizard panel
224  Object[] wizardButtons = wizardDescriptor.getOptions();
225  for (int i = 0; i < wizardButtons.length; i++) {
226  JButton tempButton = (JButton) wizardButtons[i];
227  if (tempButton.getText().equals(buttonText)) {
228  tempButton.setDefaultCapable(true);
229  tempButton.requestFocus();
230  }
231  }
232  }
233 
239  private void runCleanupTasks() {
240  cleanupSupport.fireChange();
241  }
242 
243  ChangeSupport cleanupSupport = new ChangeSupport(this);
244 
254  abstract class CleanupTask implements ChangeListener {
255 
256  @Override
257  public void stateChanged(ChangeEvent e) {
258  // fired by AddImageAction.runCleanupTasks() after the wizard closes
259  try {
260  cleanup();
261  } catch (Exception ex) {
262  Logger logger = Logger.getLogger(this.getClass().getName());
263  logger.log(Level.WARNING, "Error cleaning up from wizard.", ex); //NON-NLS
264  } finally {
265  disable(); // cleanup tasks should only run once.
266  }
267  }
268 
272  public void enable() {
273  cleanupSupport.addChangeListener(this);
274  }
275 
281  abstract void cleanup() throws Exception;
282 
286  public void disable() {
287  cleanupSupport.removeChangeListener(this);
288  }
289  }
290 }
static synchronized IngestManager getInstance()
synchronized static Logger getLogger(String name)
Definition: Logger.java:166
WizardDescriptor.Iterator< WizardDescriptor > iterator

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.