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 final class LocalFilesPanel
extends javax.swing.JPanel {
40 private static final long serialVersionUID = 1L;
42 private final Set<File> currentFiles =
new TreeSet<>();
43 private boolean enableNext =
false;
44 private static final Logger logger = Logger.getLogger(LocalFilesPanel.class.getName());
45 private String displayName =
"";
55 private void customInit() {
56 localFileChooser.setMultiSelectionEnabled(
true);
57 errorLabel.setVisible(
false);
58 selectedPaths.setText(
"");
59 this.displayNameLabel.setText(NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.displayNameLabel.text"));
67 @SuppressWarnings(
"unchecked")
69 private
void initComponents() {
71 localFileChooser =
new javax.swing.JFileChooser();
72 jPanel1 =
new javax.swing.JPanel();
73 selectButton =
new javax.swing.JButton();
74 clearButton =
new javax.swing.JButton();
75 selectedPathsScrollPane =
new javax.swing.JScrollPane();
76 selectedPaths =
new javax.swing.JTextArea();
77 errorLabel =
new javax.swing.JLabel();
78 changeNameButton =
new javax.swing.JButton();
79 displayNameLabel =
new javax.swing.JLabel();
81 localFileChooser.setApproveButtonText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.localFileChooser.approveButtonText"));
82 localFileChooser.setApproveButtonToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.localFileChooser.approveButtonToolTipText"));
83 localFileChooser.setDialogTitle(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.localFileChooser.dialogTitle"));
84 localFileChooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES);
86 org.openide.awt.Mnemonics.setLocalizedText(selectButton,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.selectButton.text"));
87 selectButton.setToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.selectButton.toolTipText"));
88 selectButton.setActionCommand(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.selectButton.actionCommand"));
89 selectButton.setMaximumSize(
new java.awt.Dimension(70, 23));
90 selectButton.setMinimumSize(
new java.awt.Dimension(70, 23));
91 selectButton.setPreferredSize(
new java.awt.Dimension(70, 23));
92 selectButton.addActionListener(
new java.awt.event.ActionListener() {
93 public void actionPerformed(java.awt.event.ActionEvent evt) {
94 selectButtonActionPerformed(evt);
98 org.openide.awt.Mnemonics.setLocalizedText(clearButton,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.clearButton.text"));
99 clearButton.setToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.clearButton.toolTipText"));
100 clearButton.setMaximumSize(
new java.awt.Dimension(70, 23));
101 clearButton.setMinimumSize(
new java.awt.Dimension(70, 23));
102 clearButton.setPreferredSize(
new java.awt.Dimension(70, 23));
103 clearButton.addActionListener(
new java.awt.event.ActionListener() {
104 public void actionPerformed(java.awt.event.ActionEvent evt) {
105 clearButtonActionPerformed(evt);
109 selectedPathsScrollPane.setPreferredSize(
new java.awt.Dimension(379, 96));
111 selectedPaths.setEditable(
false);
112 selectedPaths.setColumns(20);
113 selectedPaths.setRows(5);
114 selectedPaths.setToolTipText(
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.selectedPaths.toolTipText"));
115 selectedPathsScrollPane.setViewportView(selectedPaths);
117 errorLabel.setForeground(
new java.awt.Color(255, 0, 0));
118 org.openide.awt.Mnemonics.setLocalizedText(errorLabel,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.errorLabel.text"));
120 org.openide.awt.Mnemonics.setLocalizedText(changeNameButton,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.changeNameButton.text"));
121 changeNameButton.addActionListener(
new java.awt.event.ActionListener() {
122 public void actionPerformed(java.awt.event.ActionEvent evt) {
123 changeNameButtonActionPerformed(evt);
127 org.openide.awt.Mnemonics.setLocalizedText(displayNameLabel,
org.openide.util.NbBundle.getMessage(LocalFilesPanel.class,
"LocalFilesPanel.displayNameLabel.text"));
129 javax.swing.GroupLayout jPanel1Layout =
new javax.swing.GroupLayout(jPanel1);
130 jPanel1.setLayout(jPanel1Layout);
131 jPanel1Layout.setHorizontalGroup(
132 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
133 .addGroup(jPanel1Layout.createSequentialGroup()
135 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
136 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
137 .addComponent(selectedPathsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
138 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
139 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
140 .addComponent(selectButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
141 .addComponent(clearButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
143 .addGroup(jPanel1Layout.createSequentialGroup()
144 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
145 .addGroup(jPanel1Layout.createSequentialGroup()
146 .addComponent(displayNameLabel)
147 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
148 .addComponent(changeNameButton))
149 .addComponent(errorLabel))
150 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
153 jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {clearButton, selectButton});
155 jPanel1Layout.setVerticalGroup(
156 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
157 .addGroup(jPanel1Layout.createSequentialGroup()
159 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
160 .addGroup(jPanel1Layout.createSequentialGroup()
161 .addComponent(selectButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
163 .addComponent(clearButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
164 .addComponent(selectedPathsScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
165 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
166 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
167 .addComponent(changeNameButton)
168 .addComponent(displayNameLabel))
170 .addComponent(errorLabel)
174 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
175 this.setLayout(layout);
176 layout.setHorizontalGroup(
177 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
178 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
180 layout.setVerticalGroup(
181 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
182 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
186 private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {
187 int returnVal = localFileChooser.showOpenDialog(
this);
189 if (returnVal == JFileChooser.APPROVE_OPTION) {
190 File[] files = localFileChooser.getSelectedFiles();
191 StringBuilder allPaths =
new StringBuilder();
192 for (File f : files) {
195 for (File f : currentFiles) {
198 allPaths.append(f.getAbsolutePath()).append(
"\n");
200 this.selectedPaths.setText(allPaths.toString());
201 this.selectedPaths.setToolTipText(allPaths.toString());
204 enableNext = !currentFiles.isEmpty();
207 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
208 }
catch (Exception e) {
209 logger.log(Level.SEVERE,
"LocalFilesPanel listener threw exception", e);
210 MessageNotifyUtil.Notify.show(NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.moduleErr"),
211 NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.moduleErr.msg"),
212 MessageNotifyUtil.MessageType.ERROR);
216 private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {
220 private void changeNameButtonActionPerformed(java.awt.event.ActionEvent evt) {
221 final String selectedDisplayName = JOptionPane.showInputDialog(
"New Display Name: ");
222 if (selectedDisplayName != null && !selectedDisplayName.isEmpty()) {
223 this.displayName = selectedDisplayName;
224 this.displayNameLabel.setText(
"Display Name: " + this.displayName);
232 currentFiles.clear();
233 selectedPaths.setText(
"");
235 errorLabel.setVisible(
false);
237 this.displayNameLabel.setText(NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.displayNameLabel.text"));
239 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
240 }
catch (Exception e) {
241 logger.log(Level.SEVERE,
"LocalFilesPanel listener threw exception", e);
242 MessageNotifyUtil.Notify.show(NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.moduleErr"),
243 NbBundle.getMessage(
this.getClass(),
"LocalFilesPanel.moduleErr.msg"),
244 MessageNotifyUtil.MessageType.ERROR);
252 List<String> getContentPaths() {
253 List<String> pathsList =
new ArrayList<>();
254 if (currentFiles == null) {
257 for (File f : currentFiles) {
258 pathsList.add(f.getAbsolutePath());
269 boolean validatePanel() {
271 warnIfPathIsInvalid(getContentPaths());
281 @NbBundle.Messages(
"LocalFilesPanel.pathValidation.error=WARNING: Exception while gettting opon case.")
282 private void warnIfPathIsInvalid(
final List<String> pathsList) {
283 errorLabel.setVisible(
false);
286 final Case.CaseType currentCaseType = Case.getOpenCase().getCaseType();
288 for (String currentPath : pathsList) {
289 if (!PathValidator.isValid(currentPath, currentCaseType)) {
290 errorLabel.setVisible(
true);
291 errorLabel.setText(NbBundle.getMessage(
this.getClass(),
"DataSourceOnCDriveError.text"));
295 }
catch (NoCurrentCaseException ex) {
296 errorLabel.setVisible(
true);
297 errorLabel.setText(Bundle.LocalFilesPanel_pathValidation_error());
306 String getFileSetName() {
307 return this.displayName;
311 private javax.swing.JButton changeNameButton;
312 private javax.swing.JButton clearButton;
313 private javax.swing.JLabel displayNameLabel;
314 private javax.swing.JLabel errorLabel;
315 private javax.swing.JPanel jPanel1;
316 private javax.swing.JFileChooser localFileChooser;
317 private javax.swing.JButton selectButton;
318 private javax.swing.JTextArea selectedPaths;
319 private javax.swing.JScrollPane selectedPathsScrollPane;