Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CommonFilesPanel.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.commonfilesearch;
20 
21 import java.io.File;
22 import java.sql.ResultSet;
23 import java.sql.SQLException;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.HashMap;
27 import java.util.Map;
28 import java.util.Map.Entry;
29 import java.util.concurrent.ExecutionException;
30 import java.util.logging.Level;
31 import javax.swing.ComboBoxModel;
32 import javax.swing.SwingUtilities;
33 import javax.swing.SwingWorker;
34 import org.openide.explorer.ExplorerManager;
35 import org.openide.util.NbBundle;
46 import org.sleuthkit.datamodel.SleuthkitCase;
47 import org.sleuthkit.datamodel.SleuthkitCase.CaseDbQuery;
48 import org.sleuthkit.datamodel.TskCoreException;
49 
54 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
55 public final class CommonFilesPanel extends javax.swing.JPanel {
56 
57  private static final long serialVersionUID = 1L;
58 
59  private static final Long NO_DATA_SOURCE_SELECTED = -1L;
60 
61  private ComboBoxModel<String> dataSourcesList = new DataSourceComboBoxModel();
62  private Map<Long, String> dataSourceMap;
63 
64  private static final Logger LOGGER = Logger.getLogger(CommonFilesPanel.class.getName());
65  private boolean singleDataSource = false;
66  private String selectedDataSource = "";
67  private boolean pictureViewCheckboxState;
68  private boolean documentsCheckboxState;
69 
73  @NbBundle.Messages({
74  "CommonFilesPanel.title=Common Files Panel",
75  "CommonFilesPanel.exception=Unexpected Exception loading DataSources."})
76  public CommonFilesPanel() {
77  initComponents();
78 
79  this.setupDataSources();
80 
81  this.errorText.setVisible(false);
82  }
83 
90  @NbBundle.Messages({
91  "CommonFilesPanel.buildDataSourceMap.done.tskCoreException=Unable to run query against DB.",
92  "CommonFilesPanel.buildDataSourceMap.done.noCurrentCaseException=Unable to open case file.",
93  "CommonFilesPanel.buildDataSourceMap.done.exception=Unexpected exception building data sources map.",
94  "CommonFilesPanel.buildDataSourceMap.done.interupted=Something went wrong building the Common Files Search dialog box.",
95  "CommonFilesPanel.buildDataSourceMap.done.sqlException=Unable to query db for data sources.",
96  "CommonFilesPanel.buildDataSourcesMap.updateUi.noDataSources=No data sources were found."})
97  private void setupDataSources() {
98 
99  new SwingWorker<Map<Long, String>, Void>() {
100 
101  private static final String SELECT_DATA_SOURCES_LOGICAL = "select obj_id, name from tsk_files where obj_id in (SELECT obj_id FROM tsk_objects WHERE obj_id in (select obj_id from data_source_info))";
102 
103  private static final String SELECT_DATA_SOURCES_IMAGE = "select obj_id, name from tsk_image_names where obj_id in (SELECT obj_id FROM tsk_objects WHERE obj_id in (select obj_id from data_source_info))";
104 
105  private void updateUi() {
106 
107  String[] dataSourcesNames = new String[CommonFilesPanel.this.dataSourceMap.size()];
108 
109  //only enable all this stuff if we actually have datasources
110  if (dataSourcesNames.length > 0) {
111  dataSourcesNames = CommonFilesPanel.this.dataSourceMap.values().toArray(dataSourcesNames);
112  CommonFilesPanel.this.dataSourcesList = new DataSourceComboBoxModel(dataSourcesNames);
114 
115  boolean multipleDataSources = this.caseHasMultipleSources();
116  CommonFilesPanel.this.allDataSourcesRadioButton.setEnabled(multipleDataSources);
117  CommonFilesPanel.this.allDataSourcesRadioButton.setSelected(multipleDataSources);
118 
119  if (!multipleDataSources) {
120  CommonFilesPanel.this.withinDataSourceRadioButton.setSelected(true);
121  withinDataSourceSelected(true);
122  }
123 
124  CommonFilesPanel.this.searchButton.setEnabled(true);
125  } else {
126  MessageNotifyUtil.Message.info(Bundle.CommonFilesPanel_buildDataSourcesMap_updateUi_noDataSources());
128  }
129  }
130 
131  private boolean caseHasMultipleSources() {
132  return CommonFilesPanel.this.dataSourceMap.size() >= 2;
133  }
134 
135  private void loadLogicalSources(SleuthkitCase tskDb, Map<Long, String> dataSouceMap) throws TskCoreException, SQLException {
136  //try block releases resources - exceptions are handled in done()
137  try (
138  CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_LOGICAL);
139  ResultSet resultSet = query.getResultSet()) {
140  while (resultSet.next()) {
141  Long objectId = resultSet.getLong(1);
142  String dataSourceName = resultSet.getString(2);
143  dataSouceMap.put(objectId, dataSourceName);
144  }
145  }
146  }
147 
148  private void loadImageSources(SleuthkitCase tskDb, Map<Long, String> dataSouceMap) throws SQLException, TskCoreException {
149  //try block releases resources - exceptions are handled in done()
150  try (
151  CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_IMAGE);
152  ResultSet resultSet = query.getResultSet()) {
153 
154  while (resultSet.next()) {
155  Long objectId = resultSet.getLong(1);
156  String dataSourceName = resultSet.getString(2);
157  File image = new File(dataSourceName);
158  String dataSourceNameTrimmed = image.getName();
159  dataSouceMap.put(objectId, dataSourceNameTrimmed);
160  }
161  }
162  }
163 
164  @Override
165  protected Map<Long, String> doInBackground() throws NoCurrentCaseException, TskCoreException, SQLException {
166 
167  Map<Long, String> dataSouceMap = new HashMap<>();
168 
169  Case currentCase = Case.getOpenCase();
170  SleuthkitCase tskDb = currentCase.getSleuthkitCase();
171 
172  loadLogicalSources(tskDb, dataSouceMap);
173 
174  loadImageSources(tskDb, dataSouceMap);
175 
176  return dataSouceMap;
177  }
178 
179  @Override
180  protected void done() {
181 
182  try {
183  CommonFilesPanel.this.dataSourceMap = this.get();
184 
185  updateUi();
186 
187  } catch (InterruptedException ex) {
188  LOGGER.log(Level.SEVERE, "Interrupted while building Common Files Search dialog.", ex);
189  MessageNotifyUtil.Message.error(Bundle.CommonFilesPanel_buildDataSourceMap_done_interupted());
190  } catch (ExecutionException ex) {
191  String errorMessage;
192  Throwable inner = ex.getCause();
193  if (inner instanceof TskCoreException) {
194  LOGGER.log(Level.SEVERE, "Failed to load data sources from database.", ex);
195  errorMessage = Bundle.CommonFilesPanel_buildDataSourceMap_done_tskCoreException();
196  } else if (inner instanceof NoCurrentCaseException) {
197  LOGGER.log(Level.SEVERE, "Current case has been closed.", ex);
198  errorMessage = Bundle.CommonFilesPanel_buildDataSourceMap_done_noCurrentCaseException();
199  } else if (inner instanceof SQLException) {
200  LOGGER.log(Level.SEVERE, "Unable to query db for data sources.", ex);
201  errorMessage = Bundle.CommonFilesPanel_buildDataSourceMap_done_sqlException();
202  } else {
203  LOGGER.log(Level.SEVERE, "Unexpected exception while building Common Files Search dialog panel.", ex);
204  errorMessage = Bundle.CommonFilesPanel_buildDataSourceMap_done_exception();
205  }
206  MessageNotifyUtil.Message.error(errorMessage);
207  }
208  }
209  }.execute();
210  }
211 
212  @NbBundle.Messages({
213  "CommonFilesPanel.search.results.titleAll=Common Files (All Data Sources)",
214  "CommonFilesPanel.search.results.titleSingle=Common Files (Match Within Data Source: %s)",
215  "CommonFilesPanel.search.results.pathText=Common Files Search Results",
216  "CommonFilesPanel.search.done.tskCoreException=Unable to run query against DB.",
217  "CommonFilesPanel.search.done.noCurrentCaseException=Unable to open case file.",
218  "CommonFilesPanel.search.done.exception=Unexpected exception running Common Files Search.",
219  "CommonFilesPanel.search.done.interupted=Something went wrong finding common files.",
220  "CommonFilesPanel.search.done.sqlException=Unable to query db for files or data sources."})
221  private void search() {
222  String pathText = Bundle.CommonFilesPanel_search_results_pathText();
223 
224  new SwingWorker<CommonFilesMetadata, Void>() {
225 
226  private String tabTitle;
227 
228  private void setTitleForAllDataSources() {
229  this.tabTitle = Bundle.CommonFilesPanel_search_results_titleAll();
230  }
231 
232  private void setTitleForSingleSource(Long dataSourceId) {
233  final String CommonFilesPanel_search_results_titleSingle = Bundle.CommonFilesPanel_search_results_titleSingle();
234  final Object[] dataSourceName = new Object[]{dataSourceMap.get(dataSourceId)};
235 
236  this.tabTitle = String.format(CommonFilesPanel_search_results_titleSingle, dataSourceName);
237  }
238 
239  private Long determineDataSourceId() {
240  Long selectedObjId = CommonFilesPanel.NO_DATA_SOURCE_SELECTED;
242  for (Entry<Long, String> dataSource : CommonFilesPanel.this.dataSourceMap.entrySet()) {
243  if (dataSource.getValue().equals(CommonFilesPanel.this.selectedDataSource)) {
244  selectedObjId = dataSource.getKey();
245  break;
246  }
247  }
248  }
249  return selectedObjId;
250  }
251 
252  @Override
253  @SuppressWarnings({"BoxedValueEquality", "NumberEquality"})
254  protected CommonFilesMetadata doInBackground() throws TskCoreException, NoCurrentCaseException, SQLException {
255  Long dataSourceId = determineDataSourceId();
256 
257  CommonFilesMetadataBuilder builder;
258  boolean filterByMedia = false;
259  boolean filterByDocuments = false;
260  if (selectedFileCategoriesButton.isSelected()) {
261  if (pictureVideoCheckbox.isSelected()) {
262  filterByMedia = true;
263  }
264  if (documentsCheckbox.isSelected()) {
265  filterByDocuments = true;
266  }
267  }
268  if (dataSourceId == CommonFilesPanel.NO_DATA_SOURCE_SELECTED) {
269  builder = new AllDataSourcesCommonFilesAlgorithm(CommonFilesPanel.this.dataSourceMap, filterByMedia, filterByDocuments);
270 
271  setTitleForAllDataSources();
272  } else {
273  builder = new SingleDataSource(dataSourceId, CommonFilesPanel.this.dataSourceMap, filterByMedia, filterByDocuments);
274 
275  setTitleForSingleSource(dataSourceId);
276  }
277 
278  this.tabTitle = builder.buildTabTitle();
279 
280  CommonFilesMetadata metadata = builder.findCommonFiles();
281 
282  return metadata;
283  }
284 
285  @Override
286  protected void done() {
287  try {
288  super.done();
289 
290  CommonFilesMetadata metadata = get();
291 
292  CommonFilesNode commonFilesNode = new CommonFilesNode(metadata);
293 
294  DataResultFilterNode dataResultFilterNode = new DataResultFilterNode(commonFilesNode, ExplorerManager.find(CommonFilesPanel.this));
295 
296  TableFilterNode tableFilterWithDescendantsNode = new TableFilterNode(dataResultFilterNode);
297 
299 
300  Collection<DataResultViewer> viewers = new ArrayList<>(1);
301  viewers.add(table);
302 
303  DataResultTopComponent.createInstance(tabTitle, pathText, tableFilterWithDescendantsNode, metadata.size(), viewers);
304 
305  } catch (InterruptedException ex) {
306  LOGGER.log(Level.SEVERE, "Interrupted while loading Common Files", ex);
307  MessageNotifyUtil.Message.error(Bundle.CommonFilesPanel_search_done_interupted());
308  } catch (ExecutionException ex) {
309  String errorMessage;
310  Throwable inner = ex.getCause();
311  if (inner instanceof TskCoreException) {
312  LOGGER.log(Level.SEVERE, "Failed to load files from database.", ex);
313  errorMessage = Bundle.CommonFilesPanel_search_done_tskCoreException();
314  } else if (inner instanceof NoCurrentCaseException) {
315  LOGGER.log(Level.SEVERE, "Current case has been closed.", ex);
316  errorMessage = Bundle.CommonFilesPanel_search_done_noCurrentCaseException();
317  } else if (inner instanceof SQLException) {
318  LOGGER.log(Level.SEVERE, "Unable to query db for files.", ex);
319  errorMessage = Bundle.CommonFilesPanel_search_done_sqlException();
320  } else {
321  LOGGER.log(Level.SEVERE, "Unexpected exception while running Common Files Search.", ex);
322  errorMessage = Bundle.CommonFilesPanel_search_done_exception();
323  }
324  MessageNotifyUtil.Message.error(errorMessage);
325  }
326  }
327  }.execute();
328  }
329 
335  @SuppressWarnings("unchecked")
336  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
337  private void initComponents() {
338 
339  dataSourcesButtonGroup = new javax.swing.ButtonGroup();
340  fileTypeFilterButtonGroup = new javax.swing.ButtonGroup();
341  searchButton = new javax.swing.JButton();
342  allDataSourcesRadioButton = new javax.swing.JRadioButton();
343  withinDataSourceRadioButton = new javax.swing.JRadioButton();
344  selectDataSourceComboBox = new javax.swing.JComboBox<>();
345  commonFilesSearchLabel = new javax.swing.JLabel();
346  cancelButton = new javax.swing.JButton();
347  allFileCategoriesRadioButton = new javax.swing.JRadioButton();
348  selectedFileCategoriesButton = new javax.swing.JRadioButton();
349  pictureVideoCheckbox = new javax.swing.JCheckBox();
350  documentsCheckbox = new javax.swing.JCheckBox();
351  dataSourceLabel = new javax.swing.JLabel();
352  categoriesLabel = new javax.swing.JLabel();
353  errorText = new javax.swing.JLabel();
354 
355  org.openide.awt.Mnemonics.setLocalizedText(searchButton, org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.searchButton.text")); // NOI18N
356  searchButton.setEnabled(false);
357  searchButton.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
358  searchButton.addActionListener(new java.awt.event.ActionListener() {
359  public void actionPerformed(java.awt.event.ActionEvent evt) {
360  searchButtonActionPerformed(evt);
361  }
362  });
363 
364  dataSourcesButtonGroup.add(allDataSourcesRadioButton);
365  allDataSourcesRadioButton.setSelected(true);
366  org.openide.awt.Mnemonics.setLocalizedText(allDataSourcesRadioButton, org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.allDataSourcesRadioButton.text")); // NOI18N
367  allDataSourcesRadioButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
368  allDataSourcesRadioButton.addActionListener(new java.awt.event.ActionListener() {
369  public void actionPerformed(java.awt.event.ActionEvent evt) {
370  allDataSourcesRadioButtonActionPerformed(evt);
371  }
372  });
373 
374  dataSourcesButtonGroup.add(withinDataSourceRadioButton);
375  org.openide.awt.Mnemonics.setLocalizedText(withinDataSourceRadioButton, org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.withinDataSourceRadioButton.text")); // NOI18N
376  withinDataSourceRadioButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
377  withinDataSourceRadioButton.addActionListener(new java.awt.event.ActionListener() {
378  public void actionPerformed(java.awt.event.ActionEvent evt) {
379  withinDataSourceRadioButtonActionPerformed(evt);
380  }
381  });
382 
383  selectDataSourceComboBox.setModel(dataSourcesList);
384  selectDataSourceComboBox.setEnabled(false);
385  selectDataSourceComboBox.addActionListener(new java.awt.event.ActionListener() {
386  public void actionPerformed(java.awt.event.ActionEvent evt) {
387  selectDataSourceComboBoxActionPerformed(evt);
388  }
389  });
390 
391  org.openide.awt.Mnemonics.setLocalizedText(commonFilesSearchLabel, org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.commonFilesSearchLabel.text")); // NOI18N
392  commonFilesSearchLabel.setFocusable(false);
393 
394  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.cancelButton.text")); // NOI18N
395  cancelButton.setActionCommand(org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.cancelButton.actionCommand")); // NOI18N
396  cancelButton.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
397  cancelButton.addActionListener(new java.awt.event.ActionListener() {
398  public void actionPerformed(java.awt.event.ActionEvent evt) {
399  cancelButtonActionPerformed(evt);
400  }
401  });
402 
403  fileTypeFilterButtonGroup.add(allFileCategoriesRadioButton);
404  org.openide.awt.Mnemonics.setLocalizedText(allFileCategoriesRadioButton, org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.allFileCategoriesRadioButton.text")); // NOI18N
405  allFileCategoriesRadioButton.setToolTipText(org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.allFileCategoriesRadioButton.toolTipText")); // NOI18N
406  allFileCategoriesRadioButton.addActionListener(new java.awt.event.ActionListener() {
407  public void actionPerformed(java.awt.event.ActionEvent evt) {
408  allFileCategoriesRadioButtonActionPerformed(evt);
409  }
410  });
411 
412  fileTypeFilterButtonGroup.add(selectedFileCategoriesButton);
413  selectedFileCategoriesButton.setSelected(true);
414  org.openide.awt.Mnemonics.setLocalizedText(selectedFileCategoriesButton, org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.selectedFileCategoriesButton.text")); // NOI18N
415  selectedFileCategoriesButton.setToolTipText(org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.selectedFileCategoriesButton.toolTipText")); // NOI18N
416  selectedFileCategoriesButton.addActionListener(new java.awt.event.ActionListener() {
417  public void actionPerformed(java.awt.event.ActionEvent evt) {
418  selectedFileCategoriesButtonActionPerformed(evt);
419  }
420  });
421 
422  pictureVideoCheckbox.setSelected(true);
423  org.openide.awt.Mnemonics.setLocalizedText(pictureVideoCheckbox, org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.pictureVideoCheckbox.text")); // NOI18N
424  pictureVideoCheckbox.addActionListener(new java.awt.event.ActionListener() {
425  public void actionPerformed(java.awt.event.ActionEvent evt) {
426  pictureVideoCheckboxActionPerformed(evt);
427  }
428  });
429 
430  documentsCheckbox.setSelected(true);
431  org.openide.awt.Mnemonics.setLocalizedText(documentsCheckbox, org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.documentsCheckbox.text")); // NOI18N
432  documentsCheckbox.addActionListener(new java.awt.event.ActionListener() {
433  public void actionPerformed(java.awt.event.ActionEvent evt) {
434  documentsCheckboxActionPerformed(evt);
435  }
436  });
437 
438  org.openide.awt.Mnemonics.setLocalizedText(dataSourceLabel, org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.text")); // NOI18N
439  dataSourceLabel.setName(""); // NOI18N
440 
441  org.openide.awt.Mnemonics.setLocalizedText(categoriesLabel, org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.categoriesLabel.text")); // NOI18N
442  categoriesLabel.setName(""); // NOI18N
443 
444  errorText.setForeground(new java.awt.Color(255, 0, 0));
445  org.openide.awt.Mnemonics.setLocalizedText(errorText, org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.errorText.text")); // NOI18N
446 
447  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
448  this.setLayout(layout);
449  layout.setHorizontalGroup(
450  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
451  .addGroup(layout.createSequentialGroup()
452  .addContainerGap()
453  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
454  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
455  .addComponent(errorText)
456  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
457  .addComponent(searchButton)
458  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
459  .addComponent(cancelButton)
460  .addContainerGap())
461  .addGroup(layout.createSequentialGroup()
462  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
463  .addComponent(categoriesLabel)
464  .addComponent(commonFilesSearchLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
465  .addComponent(dataSourceLabel)
466  .addGroup(layout.createSequentialGroup()
467  .addGap(6, 6, 6)
468  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
469  .addGroup(layout.createSequentialGroup()
470  .addGap(29, 29, 29)
471  .addComponent(selectDataSourceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE))
472  .addComponent(withinDataSourceRadioButton)
473  .addComponent(allDataSourcesRadioButton)
474  .addComponent(allFileCategoriesRadioButton)
475  .addComponent(selectedFileCategoriesButton)
476  .addGroup(layout.createSequentialGroup()
477  .addGap(21, 21, 21)
478  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
479  .addComponent(pictureVideoCheckbox)
480  .addComponent(documentsCheckbox))))))
481  .addGap(19, 19, 19))))
482  );
483  layout.setVerticalGroup(
484  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
485  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
486  .addContainerGap()
487  .addComponent(commonFilesSearchLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
488  .addGap(18, 18, 18)
489  .addComponent(dataSourceLabel)
490  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
491  .addComponent(allDataSourcesRadioButton)
492  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
493  .addComponent(withinDataSourceRadioButton)
494  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
495  .addComponent(selectDataSourceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
496  .addGap(18, 18, 18)
497  .addComponent(categoriesLabel)
498  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
499  .addComponent(selectedFileCategoriesButton)
500  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
501  .addComponent(pictureVideoCheckbox)
502  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
503  .addComponent(documentsCheckbox)
504  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
505  .addComponent(allFileCategoriesRadioButton)
506  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
507  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
508  .addComponent(cancelButton)
509  .addComponent(searchButton)
510  .addComponent(errorText)))
511  );
512  }// </editor-fold>//GEN-END:initComponents
513 
514  private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed
515  search();
516  SwingUtilities.windowForComponent(this).dispose();
517  }//GEN-LAST:event_searchButtonActionPerformed
518 
519  private void allDataSourcesRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allDataSourcesRadioButtonActionPerformed
520  selectDataSourceComboBox.setEnabled(!allDataSourcesRadioButton.isSelected());
521  singleDataSource = false;
522  }//GEN-LAST:event_allDataSourcesRadioButtonActionPerformed
523 
524  private void selectDataSourceComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectDataSourceComboBoxActionPerformed
525  final Object selectedItem = selectDataSourceComboBox.getSelectedItem();
526  if (selectedItem != null) {
527  selectedDataSource = selectedItem.toString();
528  } else {
529  selectedDataSource = "";
530  }
531  }//GEN-LAST:event_selectDataSourceComboBoxActionPerformed
532 
533  private void withinDataSourceRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_withinDataSourceRadioButtonActionPerformed
534  withinDataSourceSelected(withinDataSourceRadioButton.isSelected());
535  }//GEN-LAST:event_withinDataSourceRadioButtonActionPerformed
536 
537  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
538  SwingUtilities.windowForComponent(this).dispose();
539  }//GEN-LAST:event_cancelButtonActionPerformed
540 
541  private void allFileCategoriesRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allFileCategoriesRadioButtonActionPerformed
542  this.manageCheckBoxState();
543  this.toggleErrorTextAndSearchBox();
544  }//GEN-LAST:event_allFileCategoriesRadioButtonActionPerformed
545 
546  private void selectedFileCategoriesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectedFileCategoriesButtonActionPerformed
547  this.manageCheckBoxState();
548  }//GEN-LAST:event_selectedFileCategoriesButtonActionPerformed
549 
550  private void pictureVideoCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pictureVideoCheckboxActionPerformed
551  this.toggleErrorTextAndSearchBox();
552  }//GEN-LAST:event_pictureVideoCheckboxActionPerformed
553 
554  private void documentsCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_documentsCheckboxActionPerformed
555  this.toggleErrorTextAndSearchBox();
556  }//GEN-LAST:event_documentsCheckboxActionPerformed
557 
559  if (!this.pictureVideoCheckbox.isSelected() && !this.documentsCheckbox.isSelected() && !this.allFileCategoriesRadioButton.isSelected()) {
560  this.searchButton.setEnabled(false);
561  this.errorText.setVisible(true);
562  } else {
563  this.searchButton.setEnabled(true);
564  this.errorText.setVisible(false);
565  }
566  }
567 
568  private void withinDataSourceSelected(boolean selected) {
569  selectDataSourceComboBox.setEnabled(selected);
570  if (selectDataSourceComboBox.isEnabled()) {
571  selectDataSourceComboBox.setSelectedIndex(0);
572  singleDataSource = true;
573  }
574  }
575 
576  private void manageCheckBoxState() {
577 
578  if (this.allFileCategoriesRadioButton.isSelected()) {
579 
580  this.pictureViewCheckboxState = this.pictureVideoCheckbox.isSelected();
581  this.documentsCheckboxState = this.documentsCheckbox.isSelected();
582 
583  this.pictureVideoCheckbox.setEnabled(false);
584  this.documentsCheckbox.setEnabled(false);
585  }
586 
587  if (this.selectedFileCategoriesButton.isSelected()) {
588 
589  this.pictureVideoCheckbox.setSelected(this.pictureViewCheckboxState);
590  this.documentsCheckbox.setSelected(this.documentsCheckboxState);
591 
592  this.pictureVideoCheckbox.setEnabled(true);
593  this.documentsCheckbox.setEnabled(true);
594 
595  this.toggleErrorTextAndSearchBox();
596  }
597  }
598 
599  // Variables declaration - do not modify//GEN-BEGIN:variables
600  private javax.swing.JRadioButton allDataSourcesRadioButton;
601  private javax.swing.JRadioButton allFileCategoriesRadioButton;
602  private javax.swing.JButton cancelButton;
603  private javax.swing.JLabel categoriesLabel;
604  private javax.swing.JLabel commonFilesSearchLabel;
605  private javax.swing.JLabel dataSourceLabel;
606  private javax.swing.ButtonGroup dataSourcesButtonGroup;
607  private javax.swing.JCheckBox documentsCheckbox;
608  private javax.swing.JLabel errorText;
609  private javax.swing.ButtonGroup fileTypeFilterButtonGroup;
610  private javax.swing.JCheckBox pictureVideoCheckbox;
611  private javax.swing.JButton searchButton;
612  private javax.swing.JComboBox<String> selectDataSourceComboBox;
613  private javax.swing.JRadioButton selectedFileCategoriesButton;
614  private javax.swing.JRadioButton withinDataSourceRadioButton;
615  // End of variables declaration//GEN-END:variables
616 }
void documentsCheckboxActionPerformed(java.awt.event.ActionEvent evt)
void searchButtonActionPerformed(java.awt.event.ActionEvent evt)
void selectDataSourceComboBoxActionPerformed(java.awt.event.ActionEvent evt)
void withinDataSourceRadioButtonActionPerformed(java.awt.event.ActionEvent evt)
void allDataSourcesRadioButtonActionPerformed(java.awt.event.ActionEvent evt)
static DataResultTopComponent createInstance(String title, String description, Node node, int childNodeCount)
void selectedFileCategoriesButtonActionPerformed(java.awt.event.ActionEvent evt)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
void allFileCategoriesRadioButtonActionPerformed(java.awt.event.ActionEvent evt)
void pictureVideoCheckboxActionPerformed(java.awt.event.ActionEvent evt)
void cancelButtonActionPerformed(java.awt.event.ActionEvent evt)

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.