23 package org.sleuthkit.autopsy.report.infrastructure;
27 import java.awt.Component;
28 import java.awt.Cursor;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.beans.PropertyChangeEvent;
32 import java.text.MessageFormat;
33 import java.util.EnumSet;
35 import java.util.concurrent.ExecutionException;
36 import java.util.logging.Level;
37 import javax.swing.ImageIcon;
38 import javax.swing.JButton;
39 import javax.swing.SwingWorker;
40 import org.openide.DialogDisplayer;
41 import org.openide.NotifyDescriptor;
42 import org.openide.WizardDescriptor;
43 import org.openide.awt.ActionID;
44 import org.openide.awt.ActionReference;
45 import org.openide.awt.ActionReferences;
46 import org.openide.awt.ActionRegistration;
47 import org.openide.util.HelpCtx;
48 import org.openide.util.NbBundle;
49 import org.openide.util.actions.CallableSystemAction;
50 import org.openide.util.actions.Presenter;
51 import org.openide.windows.WindowManager;
56 @ActionID(category =
"Tools",
id =
"org.sleuthkit.autopsy.report.infrastructure.ReportWizardAction")
57 @ActionRegistration(displayName =
"#CTL_ReportWizardAction", lazy =
false)
58 @ActionReferences(value = {
59 @ActionReference(path =
"Menu/Tools", position = 301, separatorAfter = 399)
61 @ActionReference(path =
"Toolbars/Case", position = 106)})
62 public final class ReportWizardAction extends CallableSystemAction implements Presenter.Toolbar, ActionListener {
65 private static final String REPORTING_CONFIGURATION_NAME =
"ReportAction";
66 private static final boolean DISPLAY_CASE_SPECIFIC_DATA =
true;
67 private static final boolean RUN_REPORTS =
true;
68 private final JButton toolbarButton =
new JButton();
69 private static final String ACTION_NAME = NbBundle.getMessage(
ReportWizardAction.class,
"ReportWizardAction.actionName.text");
70 private static ReportGenerationPanel
panel;
83 @SuppressWarnings(
"unchecked")
84 public static
void doReportWizard(String configName,
boolean displayCaseSpecificData,
boolean runReports) {
85 WizardDescriptor wiz =
new WizardDescriptor(
new ReportWizardIterator(configName, displayCaseSpecificData));
86 wiz.setTitleFormat(
new MessageFormat(
"{0} {1}"));
87 wiz.setTitle(NbBundle.getMessage(
ReportWizardAction.class,
"ReportWizardAction.reportWiz.title"));
88 if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) {
92 saveReportingConfiguration(configName, wiz);
93 }
catch (ReportConfigException ex) {
94 logger.log(Level.SEVERE,
"Failed to save reporting configuration " + configName, ex);
95 NotifyDescriptor descriptor =
new NotifyDescriptor.Message(
96 NbBundle.getMessage(
ReportWizardAction.class,
"ReportWizardAction.unableToSaveConfig.errorLabel.text"),
97 NotifyDescriptor.ERROR_MESSAGE);
98 DialogDisplayer.getDefault().notify(descriptor);
103 panel =
new ReportGenerationPanel();
109 generator.displayProgressPanel();
114 @SuppressWarnings(value =
"unchecked")
115 private static
void saveReportingConfiguration(String configName, WizardDescriptor wiz) throws ReportConfigException {
117 ReportingConfig reportingConfig =
new ReportingConfig(configName);
118 reportingConfig.setFileReportSettings((FileReportSettings) wiz.getProperty(
"fileReportSettings"));
119 reportingConfig.setTableReportSettings((TableReportSettings) wiz.getProperty(
"tableReportSettings"));
121 Map<String, ReportModuleConfig> moduleConfigs = (Map<String, ReportModuleConfig>) wiz.getProperty(
"moduleConfigs");
126 if (portableCaseReportSettings != null) {
127 config.setModuleSettings(portableCaseReportSettings);
132 reportingConfig.setModuleConfigs(moduleConfigs);
135 ReportingConfigLoader.saveConfig(reportingConfig);
142 Case newCase = (
Case) evt.getNewValue();
152 @SuppressWarnings(
"unchecked")
153 public
void actionPerformed(ActionEvent e) {
154 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
155 doReportWizard(REPORTING_CONFIGURATION_NAME, DISPLAY_CASE_SPECIFIC_DATA, RUN_REPORTS);
156 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
170 return HelpCtx.DEFAULT_HELP;
180 ImageIcon icon =
new ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/report/images/btn_icon_generate_report.png"));
181 toolbarButton.setIcon(icon);
182 toolbarButton.setText(NbBundle.getMessage(
this.getClass(),
"ReportWizardAction.toolBarButton.text"));
183 return toolbarButton;
193 super.setEnabled(value);
194 toolbarButton.setEnabled(value);
202 this.doInBackground = doInBackground;
207 doInBackground.run();
215 }
catch (InterruptedException | ExecutionException ex) {
216 panel.getProgressPanel().updateStatusLabel(NbBundle.getMessage(
this.getClass(),
"ReportGenerator.errors.reportErrorText") + ex.getLocalizedMessage());
217 logger.log(Level.SEVERE,
"failed to generate reports", ex);
219 catch (java.util.concurrent.CancellationException ex) {
Component getToolbarPresenter()
static boolean runningWithGUI
static ReportGenerationPanel panel
ReportWorker(Runnable doInBackground)
void setEnabled(boolean value)
synchronized static Logger getLogger(String name)
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
final Runnable doInBackground