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;
57 @ActionID(category =
"Tools",
id =
"org.sleuthkit.autopsy.report.infrastructure.ReportWizardAction")
58 @ActionRegistration(displayName =
"#CTL_ReportWizardAction", lazy =
false)
59 @ActionReferences(value = {
60 @ActionReference(path =
"Menu/Tools", position = 301, separatorAfter = 399)
62 @ActionReference(path =
"Toolbars/Case", position = 106)})
63 public final class ReportWizardAction extends CallableSystemAction implements Presenter.Toolbar, ActionListener {
66 private static final String REPORTING_CONFIGURATION_NAME =
"ReportAction";
67 private static final boolean DISPLAY_CASE_SPECIFIC_DATA =
true;
68 private static final boolean RUN_REPORTS =
true;
69 private final JButton toolbarButton =
new JButton();
70 private static final String ACTION_NAME = NbBundle.getMessage(
ReportWizardAction.class,
"ReportWizardAction.actionName.text");
71 private static ReportGenerationPanel
panel;
84 @SuppressWarnings(
"unchecked")
85 public static
void doReportWizard(String configName,
boolean displayCaseSpecificData,
boolean runReports) {
86 WizardDescriptor wiz =
new WizardDescriptor(
new ReportWizardIterator(configName, displayCaseSpecificData));
87 wiz.setTitleFormat(
new MessageFormat(
"{0} {1}"));
88 wiz.setTitle(NbBundle.getMessage(
ReportWizardAction.class,
"ReportWizardAction.reportWiz.title"));
89 if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) {
93 saveReportingConfiguration(configName, wiz);
94 }
catch (ReportConfigException ex) {
95 logger.log(Level.SEVERE,
"Failed to save reporting configuration " + configName, ex);
96 NotifyDescriptor descriptor =
new NotifyDescriptor.Message(
97 NbBundle.getMessage(
ReportWizardAction.class,
"ReportWizardAction.unableToSaveConfig.errorLabel.text"),
98 NotifyDescriptor.ERROR_MESSAGE);
99 DialogDisplayer.getDefault().notify(descriptor);
104 panel =
new ReportGenerationPanel();
105 Map<String, ReportModule> modules = (Map<String, ReportModule>) wiz.getProperty(
"modules");
111 generator.displayProgressPanel();
116 @SuppressWarnings(value =
"unchecked")
117 private static
void saveReportingConfiguration(String configName, WizardDescriptor wiz) throws ReportConfigException {
119 ReportingConfig reportingConfig =
new ReportingConfig(configName);
120 reportingConfig.setFileReportSettings((FileReportSettings) wiz.getProperty(
"fileReportSettings"));
121 reportingConfig.setTableReportSettings((TableReportSettings) wiz.getProperty(
"tableReportSettings"));
123 Map<String, ReportModuleConfig> moduleConfigs = (Map<String, ReportModuleConfig>) wiz.getProperty(
"moduleConfigs");
128 if (portableCaseReportSettings != null) {
129 config.setModuleSettings(portableCaseReportSettings);
134 reportingConfig.setModuleConfigs(moduleConfigs);
137 ReportingConfigLoader.saveConfig(reportingConfig);
144 Case newCase = (
Case) evt.getNewValue();
154 @SuppressWarnings(
"unchecked")
155 public
void actionPerformed(ActionEvent e) {
156 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
157 doReportWizard(REPORTING_CONFIGURATION_NAME, DISPLAY_CASE_SPECIFIC_DATA, RUN_REPORTS);
158 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
172 return HelpCtx.DEFAULT_HELP;
182 ImageIcon icon =
new ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/report/images/btn_icon_generate_report.png"));
183 toolbarButton.setIcon(icon);
184 toolbarButton.setText(NbBundle.getMessage(
this.getClass(),
"ReportWizardAction.toolBarButton.text"));
185 return toolbarButton;
195 super.setEnabled(value);
196 toolbarButton.setEnabled(value);
204 this.doInBackground = doInBackground;
209 doInBackground.run();
217 }
catch (InterruptedException | ExecutionException ex) {
218 panel.getProgressPanel().updateStatusLabel(NbBundle.getMessage(
this.getClass(),
"ReportGenerator.errors.reportErrorText") + ex.getLocalizedMessage());
219 logger.log(Level.SEVERE,
"failed to generate reports", ex);
221 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