19 package org.sleuthkit.autopsy.filequery;
21 import com.google.common.eventbus.Subscribe;
22 import java.util.List;
24 import javax.swing.DefaultListCellRenderer;
25 import javax.swing.DefaultListModel;
26 import javax.swing.JList;
27 import javax.swing.JOptionPane;
28 import org.openide.util.NbBundle.Messages;
35 class GroupListPanel
extends javax.swing.JPanel {
37 private static final long serialVersionUID = 1L;
38 private FileType resultType = null;
39 private Map<GroupKey, Integer> groupMap = null;
40 private List<FileSearchFiltering.FileFilter> searchfilters;
41 private FileSearch.AttributeType groupingAttribute;
42 private FileGroup.GroupSortingAlgorithm groupSort;
43 private FileSorter.SortingMethod fileSortMethod;
44 private GroupKey selectedGroupKey;
59 void handleSearchStartedEvent(DiscoveryEventUtils.SearchStartedEvent searchStartedEvent) {
60 resultType = searchStartedEvent.getType();
61 groupKeyList.setListData(
new GroupKey[0]);
64 @Messages({
"GroupsListPanel.noResults.message.text=No results were found for the selected filters.",
65 "GroupsListPanel.noResults.title.text=No results found"})
73 void handleSearchCompleteEvent(DiscoveryEventUtils.SearchCompleteEvent searchCompleteEvent) {
74 groupMap = searchCompleteEvent.getGroupMap();
75 searchfilters = searchCompleteEvent.getFilters();
76 groupingAttribute = searchCompleteEvent.getGroupingAttr();
77 groupSort = searchCompleteEvent.getGroupSort();
78 fileSortMethod = searchCompleteEvent.getFileSort();
79 groupKeyList.setListData(groupMap.keySet().toArray(
new GroupKey[groupMap.keySet().size()]));
80 if (groupKeyList.getModel().getSize() > 0) {
81 groupKeyList.setSelectedIndex(0);
83 JOptionPane.showMessageDialog(DiscoveryTopComponent.getTopComponent(),
84 Bundle.GroupsListPanel_noResults_message_text(),
85 Bundle.GroupsListPanel_noResults_title_text(),
86 JOptionPane.INFORMATION_MESSAGE);
95 @SuppressWarnings(
"unchecked")
97 private
void initComponents() {
99 javax.swing.JScrollPane groupListScrollPane =
new javax.swing.JScrollPane();
100 groupKeyList =
new javax.swing.JList<>();
102 groupKeyList.setBorder(javax.swing.BorderFactory.createTitledBorder(
org.openide.util.NbBundle.getMessage(GroupListPanel.class,
"GroupListPanel.groupKeyList.border.title")));
103 groupKeyList.setModel(
new DefaultListModel<GroupKey>());
104 groupKeyList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
105 groupKeyList.setCellRenderer(
new GroupListRenderer());
106 groupKeyList.addListSelectionListener(
new javax.swing.event.ListSelectionListener() {
107 public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
111 groupListScrollPane.setViewportView(groupKeyList);
113 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
114 this.setLayout(layout);
115 layout.setHorizontalGroup(
116 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
117 .addGap(0, 144, Short.MAX_VALUE)
118 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
119 .addComponent(groupListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE))
121 layout.setVerticalGroup(
122 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
123 .addGap(0, 300, Short.MAX_VALUE)
124 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
125 .addComponent(groupListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE))
132 void resetGroupList() {
133 groupKeyList.setListData(
new GroupKey[0]);
141 private void groupSelected(javax.swing.event.ListSelectionEvent evt) {
142 if (!evt.getValueIsAdjusting()) {
143 if (groupKeyList.getSelectedValue() != null) {
144 GroupKey selectedGroup = groupKeyList.getSelectedValue();
145 for (GroupKey groupKey : groupMap.keySet()) {
146 if (selectedGroup.equals(groupKey)) {
147 selectedGroupKey = groupKey;
148 DiscoveryEventUtils.getDiscoveryEventBus().post(
new DiscoveryEventUtils.GroupSelectedEvent(
149 searchfilters, groupingAttribute, groupSort, fileSortMethod, selectedGroupKey, groupMap.get(selectedGroupKey), resultType));
154 DiscoveryEventUtils.getDiscoveryEventBus().post(
new DiscoveryEventUtils.NoResultsEvent());
160 private javax.swing.JList<GroupKey> groupKeyList;
169 private static final long serialVersionUID = 1L;
177 boolean cellHasFocus) {
178 Object newValue = value;
179 if (newValue instanceof GroupKey) {
180 String valueString = newValue.toString();
181 setToolTipText(valueString);
183 if (groupingAttribute instanceof FileSearch.ParentPathAttribute && valueString.length() > 37) {
184 valueString = valueString.substring(0, 16) +
" ... " + valueString.substring(valueString.length() - 16);
186 newValue = valueString +
" (" + groupMap.get(newValue) +
")";
188 super.getListCellRendererComponent(list, newValue, index, isSelected, cellHasFocus);
java.awt.Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus)