Autopsy  3.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 
20 package org.sleuthkit.autopsy.casemodule;
21 
22 import java.awt.Component;
23 import java.awt.Dialog;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.util.logging.Level;
27 import javax.swing.Action;
28 import javax.swing.ImageIcon;
29 import javax.swing.JButton;
30 import javax.swing.JOptionPane;
31 import javax.swing.SwingUtilities;
32 import javax.swing.event.ChangeEvent;
33 import javax.swing.event.ChangeListener;
34 import org.openide.DialogDisplayer;
35 import org.openide.WizardDescriptor;
36 import org.openide.util.ChangeSupport;
37 import org.openide.util.HelpCtx;
38 import org.openide.util.NbBundle;
39 import org.openide.util.actions.CallableSystemAction;
40 import org.openide.util.actions.Presenter;
41 import org.openide.util.lookup.ServiceProvider;
45 
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 
77  static final Logger logger = Logger.getLogger(AddImageAction.class.getName());
78 
79  private WizardDescriptor wizardDescriptor;
80  private WizardDescriptor.Iterator<WizardDescriptor> iterator;
81  private Dialog dialog;
82  private JButton toolbarButton = new JButton();
83 
87  public AddImageAction() {
88  putValue(Action.NAME, NbBundle.getMessage(AddImageAction.class, "CTL_AddImage")); // set the action Name
89 
90  // set the action for the toolbar button
91  toolbarButton.addActionListener(new ActionListener() {
92 
93  @Override
94  public void actionPerformed(ActionEvent e) {
96  }
97  });
98 
99  this.setEnabled(false); // disable this action class
100  }
101 
107  @Override
108  public void actionPerformed(ActionEvent e) {
110  final String msg = NbBundle.getMessage(this.getClass(), "AddImageAction.ingestConfig.ongoingIngest.msg");
111  if (JOptionPane.showConfirmDialog(null, msg,
112  NbBundle.getMessage(this.getClass(),
113  "AddImageAction.ingestConfig.ongoingIngest.title"),
114  JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) {
115  return;
116  }
117  }
118 
119  iterator = new AddImageWizardIterator(this);
120  wizardDescriptor = new WizardDescriptor(iterator);
121  wizardDescriptor.setTitle(NbBundle.getMessage(this.getClass(), "AddImageAction.wizard.title"));
122  wizardDescriptor.putProperty(NAME, e);
123 
124  if (dialog != null) {
125  dialog.setVisible(false); // hide the old one
126  }
127  dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
128  dialog.setVisible(true);
129  dialog.toFront();
130 
131  // Do any cleanup that needs to happen (potentially: stopping the
132  //add-image process, reverting an image)
133  runCleanupTasks();
134  }
135 
140  void restart() {
141  // Simulate clicking finish for the current dialog
142  wizardDescriptor.setValue(WizardDescriptor.FINISH_OPTION);
143  dialog.setVisible(false);
144 
145  // let the previous call to AddImageAction.actionPerformed() finish up
146  // after the wizard, this will run when its it's done
147  final Runnable r = new Runnable() {
148  @Override
149  public void run() {
150  actionPerformed(null);
151  }
152  };
153 
154  SwingUtilities.invokeLater(r);
155  }
156 
157  public interface IndexImageTask {
158  void runTask(Image newImage);
159  }
160 
164  @Override
165  public void performAction() {
166  }
167 
173  @Override
174  public String getName() {
175  return NbBundle.getMessage(AddImageAction.class, "CTL_AddImageButton");
176  }
177 
183  @Override
184  public HelpCtx getHelpCtx() {
185  return HelpCtx.DEFAULT_HELP;
186  }
187 
193  @Override
194  public Component getToolbarPresenter() {
195  ImageIcon icon = new ImageIcon(getClass().getResource("btn_icon_add_image.png")); //NON-NLS
196  toolbarButton.setIcon(icon);
197  toolbarButton.setText(this.getName());
198  return toolbarButton;
199  }
200 
206  @Override
207  public void setEnabled(boolean value) {
208  super.setEnabled(value);
209  toolbarButton.setEnabled(value);
210  }
211 
221  public void requestFocusButton(String buttonText) {
222  // get all buttons on this wizard panel
223  Object[] wizardButtons = wizardDescriptor.getOptions();
224  for (int i = 0; i < wizardButtons.length; i++) {
225  JButton tempButton = (JButton) wizardButtons[i];
226  if (tempButton.getText().equals(buttonText)) {
227  tempButton.setDefaultCapable(true);
228  tempButton.requestFocus();
229  }
230  }
231  }
232 
238  private void runCleanupTasks() {
239  cleanupSupport.fireChange();
240  }
241 
242  ChangeSupport cleanupSupport = new ChangeSupport(this);
243 
253  abstract class CleanupTask implements ChangeListener {
254 
255  @Override
256  public void stateChanged(ChangeEvent e) {
257  // fired by AddImageAction.runCleanupTasks() after the wizard closes
258  try {
259  cleanup();
260  } catch (Exception ex) {
261  Logger logger = Logger.getLogger(this.getClass().getName());
262  logger.log(Level.WARNING, "Error cleaning up from wizard.", ex); //NON-NLS
263  } finally {
264  disable(); // cleanup tasks should only run once.
265  }
266  }
267 
271  public void enable() {
272  cleanupSupport.addChangeListener(this);
273  }
274 
279  abstract void cleanup() throws Exception;
280 
284  public void disable() {
285  cleanupSupport.removeChangeListener(this);
286  }
287  }
288 }
static synchronized IngestManager getInstance()
WizardDescriptor.Iterator< WizardDescriptor > iterator
static Logger getLogger(String name)
Definition: Logger.java:131

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