Autopsy  4.15.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
LocalFilesPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018 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.io.File;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.Set;
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;
34 
38 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
39 final class LocalFilesPanel extends javax.swing.JPanel {
40 
41  private static final long serialVersionUID = 1L;
42 
43  private final Set<File> currentFiles = new TreeSet<>(); //keep currents in a set to disallow duplicates per add
44  private boolean enableNext = false;
45  private static final Logger logger = Logger.getLogger(LocalFilesPanel.class.getName());
46  private String displayName = "";
47 
51  LocalFilesPanel() {
52  initComponents();
53  customInit();
54  }
55 
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"));
61  }
62 
68  @SuppressWarnings("unchecked")
69  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
70  private void initComponents() {
71 
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();
81 
82  localFileChooser.setApproveButtonText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.localFileChooser.approveButtonText")); // NOI18N
83  localFileChooser.setApproveButtonToolTipText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.localFileChooser.approveButtonToolTipText")); // NOI18N
84  localFileChooser.setDialogTitle(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.localFileChooser.dialogTitle")); // NOI18N
85  localFileChooser.setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES);
86 
87  org.openide.awt.Mnemonics.setLocalizedText(selectButton, org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.selectButton.text")); // NOI18N
88  selectButton.setToolTipText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.selectButton.toolTipText")); // NOI18N
89  selectButton.setActionCommand(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.selectButton.actionCommand")); // NOI18N
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);
96  }
97  });
98 
99  org.openide.awt.Mnemonics.setLocalizedText(clearButton, org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.clearButton.text")); // NOI18N
100  clearButton.setToolTipText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.clearButton.toolTipText")); // NOI18N
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);
107  }
108  });
109 
110  selectedPathsScrollPane.setPreferredSize(new java.awt.Dimension(379, 96));
111 
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")); // NOI18N
116  selectedPathsScrollPane.setViewportView(selectedPaths);
117 
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")); // NOI18N
120 
121  org.openide.awt.Mnemonics.setLocalizedText(changeNameButton, org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.changeNameButton.text")); // NOI18N
122  changeNameButton.addActionListener(new java.awt.event.ActionListener() {
123  public void actionPerformed(java.awt.event.ActionEvent evt) {
124  changeNameButtonActionPerformed(evt);
125  }
126  });
127 
128  org.openide.awt.Mnemonics.setLocalizedText(displayNameLabel, org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.displayNameLabel.text")); // NOI18N
129 
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()
135  .addContainerGap()
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))
143  .addGap(2, 2, 2))
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))))
152  );
153 
154  jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {clearButton, selectButton});
155 
156  jPanel1Layout.setVerticalGroup(
157  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
158  .addGroup(jPanel1Layout.createSequentialGroup()
159  .addGap(0, 0, 0)
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)
163  .addGap(36, 36, 36)
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))
170  .addGap(13, 13, 13)
171  .addComponent(errorLabel)
172  .addContainerGap())
173  );
174 
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)
180  );
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)
184  );
185  }// </editor-fold>//GEN-END:initComponents
186 
187  private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectButtonActionPerformed
188  int returnVal = localFileChooser.showOpenDialog(this);
189 
190  if (returnVal == JFileChooser.APPROVE_OPTION) {
191  File[] files = localFileChooser.getSelectedFiles();
192  StringBuilder allPaths = new StringBuilder();
193  for (File f : files) {
194  currentFiles.add(f);
195  }
196  for (File f : currentFiles) {
197  //loop over set of all files to ensure list is accurate
198  //update label
199  allPaths.append(f.getAbsolutePath()).append("\n");
200  }
201  this.selectedPaths.setText(allPaths.toString());
202  this.selectedPaths.setToolTipText(allPaths.toString());
203  }
204 
205  enableNext = !currentFiles.isEmpty();
206 
207  try {
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); //NON-NLS
211  MessageNotifyUtil.Notify.show(NbBundle.getMessage(this.getClass(), "LocalFilesPanel.moduleErr"),
212  NbBundle.getMessage(this.getClass(), "LocalFilesPanel.moduleErr.msg"),
213  MessageNotifyUtil.MessageType.ERROR);
214  }
215  }//GEN-LAST:event_selectButtonActionPerformed
216 
217  private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed
218  reset();
219  }//GEN-LAST:event_clearButtonActionPerformed
220 
221  private void changeNameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeNameButtonActionPerformed
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);
226  }
227  }//GEN-LAST:event_changeNameButtonActionPerformed
228 
232  void reset() {
233  currentFiles.clear();
234  selectedPaths.setText("");
235  enableNext = false;
236  errorLabel.setVisible(false);
237  displayName = "";
238  this.displayNameLabel.setText(NbBundle.getMessage(this.getClass(), "LocalFilesPanel.displayNameLabel.text"));
239  try {
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); //NON-NLS
243  MessageNotifyUtil.Notify.show(NbBundle.getMessage(this.getClass(), "LocalFilesPanel.moduleErr"),
244  NbBundle.getMessage(this.getClass(), "LocalFilesPanel.moduleErr.msg"),
245  MessageNotifyUtil.MessageType.ERROR);
246  }
247  }
253  List<String> getContentPaths() {
254  List<String> pathsList = new ArrayList<>();
255  if (currentFiles == null) {
256  return pathsList;
257  }
258  for (File f : currentFiles) {
259  pathsList.add(f.getAbsolutePath());
260  }
261  return pathsList;
262  }
263 
270  boolean validatePanel() {
271  // display warning if there is one (but don't disable "next" button)
272  warnIfPathIsInvalid(getContentPaths());
273  return enableNext;
274  }
275 
282  @NbBundle.Messages({
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."
285  })
286  private void warnIfPathIsInvalid(final List<String> pathsList) {
287  errorLabel.setVisible(false);
288 
289  try {
290  final Case.CaseType currentCaseType = Case.getCurrentCaseThrows().getCaseType();
291 
292  for (String currentPath : pathsList) {
293  if (!PathValidator.isValidForMultiUserCase(currentPath, currentCaseType)) {
294  errorLabel.setVisible(true);
295  errorLabel.setText(Bundle.LocalFilesPanel_pathValidation_dataSourceOnCDriveError());
296  return;
297  }
298  }
299  } catch (NoCurrentCaseException ex) {
300  errorLabel.setVisible(true);
301  errorLabel.setText(Bundle.LocalFilesPanel_pathValidation_getOpenCase());
302  }
303  }
304 
310  String getFileSetName() {
311  return this.displayName;
312  }
313 
314  // Variables declaration - do not modify//GEN-BEGIN:variables
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;
324  // End of variables declaration//GEN-END:variables
325 }

Copyright © 2012-2020 Basis Technology. Generated on: Mon Jul 6 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.