Autopsy  4.19.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.RootPaneContainer;
33 import javax.swing.SwingUtilities;
34 import javax.swing.event.ChangeEvent;
35 import javax.swing.event.ChangeListener;
36 import org.openide.DialogDisplayer;
37 import org.openide.WizardDescriptor;
38 import org.openide.awt.ActionID;
39 import org.openide.awt.ActionReference;
40 import org.openide.awt.ActionReferences;
41 import org.openide.awt.ActionRegistration;
42 import org.openide.util.ChangeSupport;
43 import org.openide.util.HelpCtx;
44 import org.openide.util.NbBundle;
45 import org.openide.util.actions.CallableSystemAction;
46 import org.openide.util.actions.Presenter;
47 import org.openide.util.lookup.ServiceProvider;
48 import org.openide.windows.WindowManager;
51 import org.sleuthkit.datamodel.Image;
52 
58 @ActionID(category = "Tools", id = "org.sleuthkit.autopsy.casemodule.AddImageAction")
59 @ActionRegistration(displayName = "#CTL_AddImage", lazy = false)
60 @ActionReferences(value = {
61  @ActionReference(path = "Toolbars/Case", position = 100)})
62 @ServiceProvider(service = AddImageAction.class)
63 public final class AddImageAction extends CallableSystemAction implements Presenter.Toolbar {
64 
65  private static final long serialVersionUID = 1L;
66  private static final Dimension SIZE = new Dimension(875, 550);
67  private final ChangeSupport cleanupSupport = new ChangeSupport(this);
68  // private final static MouseAdapter mouseDisabler = new MouseAdapter() {};
69 
70  // Keys into the WizardDescriptor properties that pass information between stages of the wizard
71  // <TYPE>: <DESCRIPTION>
72  // String: time zone that the image is from
73  static final String TIMEZONE_PROP = "timeZone"; //NON-NLS
74  // String[]: array of paths to each data source selected
75  static final String DATASOURCEPATH_PROP = "dataSrcPath"; //NON-NLS
76  // String data source type selected
77  static final String DATASOURCETYPE_PROP = "dataSrcType"; //NON-NLS
78  // CleanupTask: task to clean up the database file if wizard errors/is cancelled after it is created
79  static final String IMAGECLEANUPTASK_PROP = "finalFileCleanup"; //NON-NLS
80  // int: the next availble id for a new image
81  static final String IMAGEID_PROP = "imageId"; //NON-NLS
82  // AddImageProcess: the next availble id for a new image
83  static final String PROCESS_PROP = "process"; //NON-NLS
84  // boolean: whether or not to lookup files in the hashDB
85  static final String LOOKUPFILES_PROP = "lookupFiles"; //NON-NLS
86  // boolean: whether or not to skip processing orphan files on FAT filesystems
87  static final String NOFATORPHANS_PROP = "nofatorphans"; //NON-NLS
88 
89  static final Logger logger = Logger.getLogger(AddImageAction.class.getName());
90  private WizardDescriptor wizardDescriptor;
91  private WizardDescriptor.Iterator<WizardDescriptor> iterator;
92  private Dialog dialog;
93  private final JButton toolbarButton = new JButton();
94 
98  public AddImageAction() {
99  putValue(Action.NAME, NbBundle.getMessage(AddImageAction.class, "CTL_AddImage")); // set the action Name
100 
101  // set the action for the toolbar button
102  toolbarButton.addActionListener(new ActionListener() {
103 
104  @Override
105  public void actionPerformed(ActionEvent e) {
107  }
108  });
109 
110  /*
111  * Disable this action until a case is opened. Currently, the Case class
112  * enables the action.
113  */
114  this.setEnabled(false);
115  }
116 
117  @Override
118  public void actionPerformed(ActionEvent e) {
119  String optionsDlgTitle = NbBundle.getMessage(this.getClass(), "AddImageAction.ingestConfig.ongoingIngest.title");
120  String optionsDlgMessage = NbBundle.getMessage(this.getClass(), "AddImageAction.ingestConfig.ongoingIngest.msg");
121  if (IngestRunningCheck.checkAndConfirmProceed(optionsDlgTitle, optionsDlgMessage)) {
122  RootPaneContainer root = (RootPaneContainer) WindowManager.getDefault().getMainWindow();
123  root.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
124  root.getGlassPane().setVisible(true);
125  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
126  iterator = new AddImageWizardIterator(this);
127  wizardDescriptor = new WizardDescriptor(iterator);
128  wizardDescriptor.setTitle(NbBundle.getMessage(this.getClass(), "AddImageAction.wizard.title"));
129  wizardDescriptor.putProperty(NAME, e);
130  wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));
131 
132  if (dialog != null) {
133  dialog.setVisible(false); // hide the old one
134  }
135  dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
136  Dimension d = dialog.getSize();
137  dialog.setSize(SIZE);
138  root.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
139  root.getGlassPane().setVisible(false);
140  dialog.setVisible(true);
141  dialog.toFront();
142 
143  // Do any cleanup that needs to happen (potentially: stopping the
144  //add-image process, reverting an image)
145  runCleanupTasks();
146  }
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 
175  @Override
176  public void performAction() {
177  actionPerformed(null);
178  }
179 
185  @Override
186  public String getName() {
187  return NbBundle.getMessage(AddImageAction.class, "CTL_AddImageButton");
188  }
189 
195  @Override
196  public HelpCtx getHelpCtx() {
197  return HelpCtx.DEFAULT_HELP;
198  }
199 
205  @Override
206  public Component getToolbarPresenter() {
207  ImageIcon icon = new ImageIcon(getClass().getResource("btn_icon_add_image.png")); //NON-NLS
208  toolbarButton.setIcon(icon);
209  toolbarButton.setText(this.getName());
210  return toolbarButton;
211  }
212 
218  @Override
219  public void setEnabled(boolean value) {
220  super.setEnabled(value);
221  toolbarButton.setEnabled(value);
222  }
223 
233  public void requestFocusButton(String buttonText) {
234  // get all buttons on this wizard panel
235  Object[] wizardButtons = wizardDescriptor.getOptions();
236  for (Object wizardButton : wizardButtons) {
237  JButton tempButton = (JButton) wizardButton;
238  if (tempButton.getText().equals(buttonText)) {
239  tempButton.setDefaultCapable(true);
240  tempButton.requestFocus();
241  }
242  }
243  }
244 
250  private void runCleanupTasks() {
251  cleanupSupport.fireChange();
252  }
253 
263  abstract class CleanupTask implements ChangeListener {
264 
265  @Override
266  public void stateChanged(ChangeEvent e) {
267  // fired by AddImageAction.runCleanupTasks() after the wizard closes
268  try {
269  cleanup();
270  } catch (Exception ex) {
271  Logger logger = Logger.getLogger(this.getClass().getName());
272  logger.log(Level.WARNING, "Error cleaning up from wizard.", ex); //NON-NLS
273  } finally {
274  disable(); // cleanup tasks should only run once.
275  }
276  }
277 
281  public void enable() {
282  cleanupSupport.addChangeListener(this);
283  }
284 
290  abstract void cleanup() throws Exception;
291 
295  public void disable() {
296  cleanupSupport.removeChangeListener(this);
297  }
298  }
299 }
static boolean checkAndConfirmProceed(String optionsDlgTitle, String optionsDlgMessage)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
WizardDescriptor.Iterator< WizardDescriptor > iterator

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.