19 package org.sleuthkit.autopsy.casemodule;
22 import java.util.ArrayList;
23 import java.util.List;
25 import java.util.TreeSet;
26 import javax.swing.JFileChooser;
27 import org.openide.util.NbBundle;
30 import java.util.logging.Level;
31 import javax.swing.JOptionPane;
38 @SuppressWarnings(
"PMD.SingularField")
39 final class LocalFilesPanel extends javax.swing.JPanel {
41 private static final long serialVersionUID = 1L;
43 private final Set<File> currentFiles =
new TreeSet<>();
44 private boolean enableNext =
false;
45 private static final Logger logger = Logger.getLogger(LocalFilesPanel.class.getName());
46 private String displayName =
"";
56 private void customInit() {
57 localFileChooser.setMultiSelectionEnabled(
true);
58 errorLabel.setVisible(
false);
59 selectedPaths.setText(
"");
60 this.displayNameLabel.setText(NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.displayNameLabel.text"));
68 @SuppressWarnings(
"unchecked")
70 private
void initComponents() {
72 localFileChooser =
new javax.swing.JFileChooser();
73 jPanel1 =
new javax.swing.JPanel();
74 selectButton =
new javax.swing.JButton();
75 clearButton =
new javax.swing.JButton();
76 selectedPathsScrollPane =
new javax.swing.JScrollPane();
77 selectedPaths =
new javax.swing.JTextArea();
78 errorLabel =
new javax.swing.JLabel();
79 changeNameButton =
new javax.swing.JButton();
80 displayNameLabel =
new javax.swing.JLabel();
82 localFileChooser.setApproveButtonText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.localFileChooser.approveButtonText"));
83 localFileChooser.setApproveButtonToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.localFileChooser.approveButtonToolTipText"));
84 localFileChooser.setDialogTitle(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.localFileChooser.dialogTitle"));
85 localFileChooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES);
87 org.openide.awt.Mnemonics.setLocalizedText(selectButton,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.selectButton.text"));
88 selectButton.setToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.selectButton.toolTipText"));
89 selectButton.setActionCommand(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.selectButton.actionCommand"));
90 selectButton.setMaximumSize(
new java.awt.Dimension(70, 23));
91 selectButton.setMinimumSize(
new java.awt.Dimension(70, 23));
92 selectButton.setPreferredSize(
new java.awt.Dimension(70, 23));
93 selectButton.addActionListener(
new java.awt.event.ActionListener() {
94 public void actionPerformed(java.awt.event.ActionEvent evt) {
95 selectButtonActionPerformed(evt);
99 org.openide.awt.Mnemonics.setLocalizedText(clearButton,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.clearButton.text"));
100 clearButton.setToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.clearButton.toolTipText"));
101 clearButton.setMaximumSize(
new java.awt.Dimension(70, 23));
102 clearButton.setMinimumSize(
new java.awt.Dimension(70, 23));
103 clearButton.setPreferredSize(
new java.awt.Dimension(70, 23));
104 clearButton.addActionListener(
new java.awt.event.ActionListener() {
105 public void actionPerformed(java.awt.event.ActionEvent evt) {
106 clearButtonActionPerformed(evt);
110 selectedPathsScrollPane.setPreferredSize(
new java.awt.Dimension(379, 96));
112 selectedPaths.setEditable(
false);
113 selectedPaths.setColumns(20);
114 selectedPaths.setRows(5);
115 selectedPaths.setToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.selectedPaths.toolTipText"));
116 selectedPathsScrollPane.setViewportView(selectedPaths);
118 errorLabel.setForeground(
new java.awt.Color(255, 0, 0));
119 org.openide.awt.Mnemonics.setLocalizedText(errorLabel,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.errorLabel.text"));
121 org.openide.awt.Mnemonics.setLocalizedText(changeNameButton,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.changeNameButton.text"));
122 changeNameButton.addActionListener(
new java.awt.event.ActionListener() {
123 public void actionPerformed(java.awt.event.ActionEvent evt) {
124 changeNameButtonActionPerformed(evt);
128 org.openide.awt.Mnemonics.setLocalizedText(displayNameLabel,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.displayNameLabel.text"));
130 javax.swing.GroupLayout jPanel1Layout =
new javax.swing.GroupLayout(jPanel1);
131 jPanel1.setLayout(jPanel1Layout);
132 jPanel1Layout.setHorizontalGroup(
133 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
134 .addGroup(jPanel1Layout.createSequentialGroup()
136 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
137 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
138 .addComponent(selectedPathsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
139 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
140 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
141 .addComponent(selectButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
142 .addComponent(clearButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
144 .addGroup(jPanel1Layout.createSequentialGroup()
145 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
146 .addGroup(jPanel1Layout.createSequentialGroup()
147 .addComponent(displayNameLabel)
148 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
149 .addComponent(changeNameButton))
150 .addComponent(errorLabel))
151 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
154 jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {clearButton, selectButton});
156 jPanel1Layout.setVerticalGroup(
157 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
158 .addGroup(jPanel1Layout.createSequentialGroup()
160 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
161 .addGroup(jPanel1Layout.createSequentialGroup()
162 .addComponent(selectButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
164 .addComponent(clearButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
165 .addComponent(selectedPathsScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
166 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
167 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
168 .addComponent(changeNameButton)
169 .addComponent(displayNameLabel))
171 .addComponent(errorLabel)
175 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
176 this.setLayout(layout);
177 layout.setHorizontalGroup(
178 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
179 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
181 layout.setVerticalGroup(
182 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
183 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
187 private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {
188 int returnVal = localFileChooser.showOpenDialog(
this);
190 if (returnVal == JFileChooser.APPROVE_OPTION) {
191 File[] files = localFileChooser.getSelectedFiles();
192 StringBuilder allPaths =
new StringBuilder();
193 for (File f : files) {
196 for (File f : currentFiles) {
199 allPaths.append(f.getAbsolutePath()).append(
"\n");
201 this.selectedPaths.setText(allPaths.toString());
202 this.selectedPaths.setToolTipText(allPaths.toString());
205 enableNext = !currentFiles.isEmpty();
208 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
209 }
catch (Exception e) {
210 logger.log(Level.SEVERE,
"LocalFilesPanel listener threw exception", e);
211 MessageNotifyUtil.Notify.show(NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.moduleErr"),
212 NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.moduleErr.msg"),
213 MessageNotifyUtil.MessageType.ERROR);
217 private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {
221 private void changeNameButtonActionPerformed(java.awt.event.ActionEvent evt) {
222 final String selectedDisplayName = JOptionPane.showInputDialog(
"New Display Name: ");
223 if (selectedDisplayName != null && !selectedDisplayName.isEmpty()) {
224 this.displayName = selectedDisplayName;
225 this.displayNameLabel.setText(
"Display Name: " + this.displayName);
233 currentFiles.clear();
234 selectedPaths.setText(
"");
236 errorLabel.setVisible(
false);
238 this.displayNameLabel.setText(NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.displayNameLabel.text"));
240 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
241 }
catch (Exception e) {
242 logger.log(Level.SEVERE,
"LocalFilesPanel listener threw exception", e);
243 MessageNotifyUtil.Notify.show(NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.moduleErr"),
244 NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.moduleErr.msg"),
245 MessageNotifyUtil.MessageType.ERROR);
253 List<String> getContentPaths() {
254 List<String> pathsList =
new ArrayList<>();
255 if (currentFiles == null) {
258 for (File f : currentFiles) {
259 pathsList.add(f.getAbsolutePath());
270 boolean validatePanel() {
272 warnIfPathIsInvalid(getContentPaths());
283 "LocalFilesPanel.pathValidation.dataSourceOnCDriveError=Warning: Path to multi-user data source is on \"C:\" drive",
284 "LocalFilesPanel.pathValidation.getOpenCase=WARNING: Exception while gettting open case."
286 private void warnIfPathIsInvalid(
final List<String> pathsList) {
287 errorLabel.setVisible(
false);
290 final Case.CaseType currentCaseType = Case.getCurrentCaseThrows().getCaseType();
292 for (String currentPath : pathsList) {
293 if (!PathValidator.isValidForCaseType(currentPath, currentCaseType)) {
294 errorLabel.setVisible(
true);
295 errorLabel.setText(Bundle.LocalFilesPanel_pathValidation_dataSourceOnCDriveError());
299 }
catch (NoCurrentCaseException ex) {
300 errorLabel.setVisible(
true);
301 errorLabel.setText(Bundle.LocalFilesPanel_pathValidation_getOpenCase());
310 String getFileSetName() {
311 return this.displayName;
315 private javax.swing.JButton changeNameButton;
316 private javax.swing.JButton clearButton;
317 private javax.swing.JLabel displayNameLabel;
318 private javax.swing.JLabel errorLabel;
319 private javax.swing.JPanel jPanel1;
320 private javax.swing.JFileChooser localFileChooser;
321 private javax.swing.JButton selectButton;
322 private javax.swing.JTextArea selectedPaths;
323 private javax.swing.JScrollPane selectedPathsScrollPane;