3779: Updates according the comments.

This commit is contained in:
U-BASIS\zhaohui 2018-05-08 18:02:54 -04:00
parent 76f26b90da
commit 9f78d8bb35
4 changed files with 66 additions and 72 deletions

View File

@ -57,5 +57,5 @@ HashSearchPanel.emptyHashMsg.text=Must enter something for hash search.
FileSearchPanel.errorLabel.text=\
DataSourcePanel.dataSourceCheckBox.label=Data Source:
DataSourcePanel.dataSourceCheckBox.actionCommand=Data Source:
DataSourcePanel.jLabel.text=*Note: Multiple data sources can be selected
DataSourcePanel.dataSourceCheckBox.text=Data Source:
DataSourcePanel.dataSourceNoteLable.text=*Note: Multiple data sources can be selected

View File

@ -26,10 +26,17 @@ import org.openide.util.NbBundle.Messages;
*/
class DataSourceFilter extends AbstractFileSearchFilter<DataSourcePanel> {
/**
* Construct DataSourceFilter with the DataSourcePanel
* @param component A DataSourcePanel
*/
public DataSourceFilter(DataSourcePanel component) {
super(component);
}
/**
* Default constructor to construct a new DataSourceFilter with a new DataSourcePanel
*/
public DataSourceFilter() {
this(new DataSourcePanel());
}
@ -43,16 +50,16 @@ class DataSourceFilter extends AbstractFileSearchFilter<DataSourcePanel> {
public String getPredicate() throws FilterValidationException {
String predicate = "";
for (Long dataSourceObjId : this.getComponent().getDataSourcesSelected()) {
predicate += "data_source_obj_id = '" + dataSourceObjId + "' OR ";
}
if (predicate.length() > 3) {
predicate = predicate.substring(0, predicate.length() - 3);
if (!predicate.isEmpty()) {
predicate += " OR ";
}
predicate += "data_source_obj_id = '" + dataSourceObjId + "'";
}
return predicate;
}
@Override
public void addActionListener(ActionListener l) {
public void addActionListener(ActionListener lis) {
}
@Override

View File

@ -33,7 +33,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" pref="0" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel" min="-2" max="-2" attributes="0"/>
<Component id="dataSourceNoteLable" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
@ -48,7 +48,7 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="95" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel" min="-2" max="-2" attributes="0"/>
<Component id="dataSourceNoteLable" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
@ -65,7 +65,7 @@
<Component class="javax.swing.JList" name="dataSourceList">
<Properties>
<Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="new javax.swing.AbstractListModel&lt;String&gt;() {&#xa; List&lt;String&gt; strings = getDataSourceArray();&#xa; public int getSize() { return strings.size(); }&#xa; public String getElementAt(int i) { return strings.get(i); }&#xa;}" type="code"/>
<Connection code="new javax.swing.AbstractListModel&lt;String&gt;() {&#xa; List&lt;String&gt; strings = getDataSourceArray();&#xa; public int getSize() { return strings.size(); }&#xa; public String getElementAt(int idx) { return strings.get(idx); }&#xa;}" type="code"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 200]"/>
@ -91,13 +91,13 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="dataSourceCheckBoxActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel">
<Component class="javax.swing.JLabel" name="dataSourceNoteLable">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="10" style="0"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/sleuthkit/autopsy/filesearch/Bundle.properties" key="DataSourcePanel.jLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
<ResourceString bundle="org/sleuthkit/autopsy/filesearch/Bundle.properties" key="DataSourcePanel.dataSourceNoteLable.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>

View File

@ -21,8 +21,6 @@ package org.sleuthkit.autopsy.filesearch;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.io.File;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@ -36,15 +34,19 @@ import javax.swing.event.ListSelectionEvent;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.DataSource;
import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException;
/**
* Subpanel with controls for data source filtering.
*/
public class DataSourcePanel extends javax.swing.JPanel {
private static final Logger logger = Logger.getLogger(DataSourcePanel.class.getName());
private static final long serialVersionUID = 1L;
private final Map<Long, String> dataSourceMap = new HashMap<>();
private List<String> toolTipList = new ArrayList<>();
private final List<String> toolTipList = new ArrayList<>();
/**
* Creates new form DataSourcePanel
@ -52,19 +54,19 @@ public class DataSourcePanel extends javax.swing.JPanel {
public DataSourcePanel() {
initComponents();
setComponentsEnabled();
this.dataSourceList.addListSelectionListener((ListSelectionEvent e) -> {
this.dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> {
firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
});
this.dataSourceList.addMouseMotionListener(new MouseMotionListener() {
@Override
public void mouseDragged(MouseEvent e) {
public void mouseDragged(MouseEvent evt) {
}
@Override
public void mouseMoved(MouseEvent e) {
JList<String> DsList = (JList<String>) e.getSource();
int index = DsList.locationToIndex(e.getPoint());
public void mouseMoved(MouseEvent evt) {
JList<String> DsList = (JList<String>) evt.getSource();
int index = DsList.locationToIndex(evt.getPoint());
if (index > -1) {
DsList.setToolTipText(toolTipList.get(index));
}
@ -72,29 +74,38 @@ public class DataSourcePanel extends javax.swing.JPanel {
});
}
/**
* Get dataSourceMap with object id and data source display name. Add the data source full name to toolTipList
*
* @return The list of data source name
*/
private List<String> getDataSourceArray() {
List<String> dataSourceList = new ArrayList<>();
try {
Case currentCase = Case.getOpenCase();
Case currentCase = Case.getCurrentCaseThrows();
SleuthkitCase tskDb = currentCase.getSleuthkitCase();
getLoadLogicalSources(tskDb);
getLoadImageSources(tskDb);
List<DataSource> dataSources = tskDb.getDataSources();
Collections.sort(dataSources, (DataSource ds1, DataSource ds2) -> ds1.getName().compareTo(ds2.getName()));
for (DataSource ds : dataSources) {
String dsName = ds.getName();
File dataSourceFullName = new File(dsName);
String displayName = dataSourceFullName.getName();
dataSourceMap.put(ds.getId(), displayName);
toolTipList.add(dsName);
dataSourceList.add(displayName);
}
} catch (NoCurrentCaseException ex) {
logger.log(Level.SEVERE, "Unable to get current open case.", ex);
} catch (TskCoreException | SQLException ex) {
} catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Failed to get data source info from database.", ex);
}
List<String> dataSourcesList = new ArrayList<>(dataSourceMap.values());
Collections.sort(dataSourcesList, (String dsName1, String dsName2) -> dsName1.compareTo(dsName2));
List<String> dataSourceDisplayNames = new ArrayList<>();
for (String dataSource : dataSourcesList) {
File dataSourceFullName = new File(dataSource);
dataSourceDisplayNames.add(dataSourceFullName.getName());
toolTipList.add(dataSourceFullName.getParent());
}
return dataSourceDisplayNames;
return dataSourceList;
}
/**
* Get a set of data source object ids that are selected.
* @return A set of selected object ids.
*/
Set<Long> getDataSourcesSelected() {
Set<Long> dataSourceObjIdSet = new HashSet<>();
for (Long key : dataSourceMap.keySet()) {
@ -108,14 +119,21 @@ public class DataSourcePanel extends javax.swing.JPanel {
return dataSourceObjIdSet;
}
/**
* Is dataSourceCheckBox selected
* @return true if the dataSoureCheckBox is selected
*/
boolean isSelected() {
return this.dataSourceCheckBox.isSelected();
}
/**
* Enable the dataSourceList and dataSourceNoteLable if the dataSourceCheckBox is checked.
*/
void setComponentsEnabled() {
boolean enabled = this.isSelected();
this.dataSourceList.setEnabled(enabled);
this.jLabel.setEnabled(enabled);
this.dataSourceNoteLable.setEnabled(enabled);
}
/**
@ -130,7 +148,7 @@ public class DataSourcePanel extends javax.swing.JPanel {
jScrollPane1 = new javax.swing.JScrollPane();
dataSourceList = new javax.swing.JList<>();
dataSourceCheckBox = new javax.swing.JCheckBox();
jLabel = new javax.swing.JLabel();
dataSourceNoteLable = new javax.swing.JLabel();
setMinimumSize(new java.awt.Dimension(150, 150));
setPreferredSize(new java.awt.Dimension(100, 100));
@ -138,7 +156,7 @@ public class DataSourcePanel extends javax.swing.JPanel {
dataSourceList.setModel(new javax.swing.AbstractListModel<String>() {
List<String> strings = getDataSourceArray();
public int getSize() { return strings.size(); }
public String getElementAt(int i) { return strings.get(i); }
public String getElementAt(int idx) { return strings.get(idx); }
});
dataSourceList.setMinimumSize(new java.awt.Dimension(0, 200));
jScrollPane1.setViewportView(dataSourceList);
@ -150,8 +168,8 @@ public class DataSourcePanel extends javax.swing.JPanel {
}
});
jLabel.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(jLabel, org.openide.util.NbBundle.getMessage(DataSourcePanel.class, "DataSourcePanel.jLabel.text")); // NOI18N
dataSourceNoteLable.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(dataSourceNoteLable, org.openide.util.NbBundle.getMessage(DataSourcePanel.class, "DataSourcePanel.dataSourceNoteLable.text")); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
@ -165,7 +183,7 @@ public class DataSourcePanel extends javax.swing.JPanel {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel)
.addComponent(dataSourceNoteLable)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
@ -176,7 +194,7 @@ public class DataSourcePanel extends javax.swing.JPanel {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel)
.addComponent(dataSourceNoteLable)
.addContainerGap())
);
@ -189,41 +207,10 @@ public class DataSourcePanel extends javax.swing.JPanel {
this.dataSourceList.setSelectedIndices(new int[0]);
}//GEN-LAST:event_dataSourceCheckBoxActionPerformed
private void getLoadLogicalSources(SleuthkitCase tskDb) throws TskCoreException, SQLException {
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)) order by name";
try (
SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_LOGICAL);
ResultSet resultSet = query.getResultSet()) {
while (resultSet.next()) {
Long objectId = resultSet.getLong("obj_id");
String dataSourceName = resultSet.getString("name");
dataSourceMap.put(objectId, dataSourceName);
toolTipList.add(dataSourceName);
}
}
}
private void getLoadImageSources(SleuthkitCase tskDb) throws SQLException, TskCoreException {
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)) order by name";
try (
SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_IMAGE);
ResultSet resultSet = query.getResultSet()) {
while (resultSet.next()) {
Long objectId = resultSet.getLong("obj_id");
String dataSourceName = resultSet.getString("name");
File image = new File(dataSourceName);
dataSourceMap.put(objectId, image.getName());
toolTipList.add(dataSourceName);
}
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JCheckBox dataSourceCheckBox;
private javax.swing.JList<String> dataSourceList;
private javax.swing.JLabel jLabel;
private javax.swing.JLabel dataSourceNoteLable;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration//GEN-END:variables
}