Autopsy  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-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.Dimension;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.text.MessageFormat;
27 import java.util.logging.Level;
28 import javax.swing.Action;
29 import javax.swing.ImageIcon;
30 import javax.swing.JButton;
31 import javax.swing.JOptionPane;
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;
49 import org.sleuthkit.datamodel.Image;
50 
58 // TODO: need annotation because there's a "Lookup.getDefault().lookup(AddImageAction.class)"
59 // used in AddImageWizardPanel1 (among other places). It really shouldn't be done like that.
60 @ActionID(category = "Tools", id = "org.sleuthkit.autopsy.casemodule.AddImageAction")
61 @ActionRegistration(displayName = "#CTL_AddImage", lazy = false)
62 @ActionReferences(value = {
63  @ActionReference(path = "Toolbars/Case", position = 100)})
64 @ServiceProvider(service = AddImageAction.class)
65 public final class AddImageAction extends CallableSystemAction implements Presenter.Toolbar {
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  static final Dimension SIZE = new Dimension(875, 550);
88 
89  private WizardDescriptor wizardDescriptor;
90  private WizardDescriptor.Iterator<WizardDescriptor> iterator;
91  private Dialog dialog;
92  private JButton toolbarButton = new JButton();
93 
97  public AddImageAction() {
98  putValue(Action.NAME, NbBundle.getMessage(AddImageAction.class, "CTL_AddImage")); // set the action Name
99 
100  // set the action for the toolbar button
101  toolbarButton.addActionListener(new ActionListener() {
102 
103  @Override
104  public void actionPerformed(ActionEvent e) {
106  }
107  });
108 
109  this.setEnabled(false); // disable this action class
110  }
111 
117  @Override
118  public void actionPerformed(ActionEvent e) {
120  final String msg = NbBundle.getMessage(this.getClass(), "AddImageAction.ingestConfig.ongoingIngest.msg");
121  if (JOptionPane.showConfirmDialog(null, msg,
122  NbBundle.getMessage(this.getClass(),
123  "AddImageAction.ingestConfig.ongoingIngest.title"),
124  JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) {
125  return;
126  }
127  }
128 
129  iterator = new AddImageWizardIterator(this);
130  wizardDescriptor = new WizardDescriptor(iterator);
131  wizardDescriptor.setTitle(NbBundle.getMessage(this.getClass(), "AddImageAction.wizard.title"));
132  wizardDescriptor.putProperty(NAME, e);
133  wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));
134 
135  if (dialog != null) {
136  dialog.setVisible(false); // hide the old one
137  }
138  dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
139  Dimension d = dialog.getSize();
140  dialog.setSize(SIZE);
141  dialog.setVisible(true);
142  dialog.toFront();
143 
144  // Do any cleanup that needs to happen (potentially: stopping the
145  //add-image process, reverting an image)
146  runCleanupTasks();
147  }
148 
153  void restart() {
154  // Simulate clicking finish for the current dialog
155  wizardDescriptor.setValue(WizardDescriptor.FINISH_OPTION);
156  dialog.setVisible(false);
157 
158  // let the previous call to AddImageAction.actionPerformed() finish up
159  // after the wizard, this will run when its it's done
160  final Runnable r = new Runnable() {
161  @Override
162  public void run() {
163  actionPerformed(null);
164  }
165  };
166 
167  SwingUtilities.invokeLater(r);
168  }
169 
170  public interface IndexImageTask {
171 
172  void runTask(Image newImage);
173  }
174 
179  @Override
180  public void performAction() {
181  }
182 
188  @Override
189  public String getName() {
190  return NbBundle.getMessage(AddImageAction.class, "CTL_AddImageButton");
191  }
192 
198  @Override
199  public HelpCtx getHelpCtx() {
200  return HelpCtx.DEFAULT_HELP;
201  }
202 
208  @Override
209  public Component getToolbarPresenter() {
210  ImageIcon icon = new ImageIcon(getClass().getResource("btn_icon_add_image.png")); //NON-NLS
211  toolbarButton.setIcon(icon);
212  toolbarButton.setText(this.getName());
213  return toolbarButton;
214  }
215 
221  @Override
222  public void setEnabled(boolean value) {
223  super.setEnabled(value);
224  toolbarButton.setEnabled(value);
225  }
226 
236  public void requestFocusButton(String buttonText) {
237  // get all buttons on this wizard panel
238  Object[] wizardButtons = wizardDescriptor.getOptions();
239  for (int i = 0; i < wizardButtons.length; i++) {
240  JButton tempButton = (JButton) wizardButtons[i];
241  if (tempButton.getText().equals(buttonText)) {
242  tempButton.setDefaultCapable(true);
243  tempButton.requestFocus();
244  }
245  }
246  }
247 
253  private void runCleanupTasks() {
254  cleanupSupport.fireChange();
255  }
256 
257  ChangeSupport cleanupSupport = new ChangeSupport(this);
258 
268  abstract class CleanupTask implements ChangeListener {
269 
270  @Override
271  public void stateChanged(ChangeEvent e) {
272  // fired by AddImageAction.runCleanupTasks() after the wizard closes
273  try {
274  cleanup();
275  } catch (Exception ex) {
276  Logger logger = Logger.getLogger(this.getClass().getName());
277  logger.log(Level.WARNING, "Error cleaning up from wizard.", ex); //NON-NLS
278  } finally {
279  disable(); // cleanup tasks should only run once.
280  }
281  }
282 
286  public void enable() {
287  cleanupSupport.addChangeListener(this);
288  }
289 
295  abstract void cleanup() throws Exception;
296 
300  public void disable() {
301  cleanupSupport.removeChangeListener(this);
302  }
303  }
304 }
static synchronized IngestManager getInstance()
synchronized static Logger getLogger(String name)
Definition: Logger.java:161
WizardDescriptor.Iterator< WizardDescriptor > iterator

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.