19 package org.sleuthkit.autopsy.discovery;
21 import com.google.common.eventbus.Subscribe;
22 import java.awt.Cursor;
23 import java.util.List;
25 import javax.swing.DefaultListCellRenderer;
26 import javax.swing.DefaultListModel;
27 import javax.swing.JList;
28 import javax.swing.JOptionPane;
29 import javax.swing.SwingUtilities;
30 import org.openide.util.NbBundle.Messages;
37 final class GroupListPanel
extends javax.swing.JPanel {
39 private static final long serialVersionUID = 1L;
40 private FileType resultType = null;
41 private Map<GroupKey, Integer> groupMap = null;
42 private List<FileSearchFiltering.FileFilter> searchfilters;
43 private FileSearch.AttributeType groupingAttribute;
44 private FileGroup.GroupSortingAlgorithm groupSort;
45 private FileSorter.SortingMethod fileSortMethod;
46 private GroupKey selectedGroupKey;
61 void handleSearchStartedEvent(DiscoveryEventUtils.SearchStartedEvent searchStartedEvent) {
62 resultType = searchStartedEvent.getType();
63 groupKeyList.setListData(
new GroupKey[0]);
66 @Messages({
"GroupsListPanel.noResults.message.text=No results were found for the selected filters.",
67 "GroupsListPanel.noResults.title.text=No results found"})
75 void handleSearchCompleteEvent(DiscoveryEventUtils.SearchCompleteEvent searchCompleteEvent) {
76 groupMap = searchCompleteEvent.getGroupMap();
77 searchfilters = searchCompleteEvent.getFilters();
78 groupingAttribute = searchCompleteEvent.getGroupingAttr();
79 groupSort = searchCompleteEvent.getGroupSort();
80 fileSortMethod = searchCompleteEvent.getFileSort();
81 groupKeyList.setListData(groupMap.keySet().toArray(
new GroupKey[groupMap.keySet().size()]));
82 SwingUtilities.invokeLater(() -> {
83 if (groupKeyList.getModel().getSize() > 0) {
84 groupKeyList.setSelectedIndex(0);
86 JOptionPane.showMessageDialog(DiscoveryTopComponent.getTopComponent(),
87 Bundle.GroupsListPanel_noResults_message_text(),
88 Bundle.GroupsListPanel_noResults_title_text(),
89 JOptionPane.INFORMATION_MESSAGE);
91 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
101 void handleSearchCancelledEvent(DiscoveryEventUtils.SearchCancelledEvent searchCancelledEvent) {
102 SwingUtilities.invokeLater(() -> {
103 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
112 @SuppressWarnings(
"unchecked")
114 private
void initComponents() {
116 javax.swing.JScrollPane groupListScrollPane =
new javax.swing.JScrollPane();
117 groupKeyList =
new javax.swing.JList<>();
119 groupKeyList.setBorder(javax.swing.BorderFactory.createTitledBorder(
org.openide.util.NbBundle.getMessage(GroupListPanel.class,
"GroupListPanel.groupKeyList.border.title")));
120 groupKeyList.setModel(
new DefaultListModel<GroupKey>());
121 groupKeyList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
122 groupKeyList.setCellRenderer(
new GroupListRenderer());
123 groupKeyList.addListSelectionListener(
new javax.swing.event.ListSelectionListener() {
124 public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
128 groupListScrollPane.setViewportView(groupKeyList);
130 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
131 this.setLayout(layout);
132 layout.setHorizontalGroup(
133 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
134 .addGap(0, 144, Short.MAX_VALUE)
135 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
136 .addComponent(groupListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE))
138 layout.setVerticalGroup(
139 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
140 .addGap(0, 300, Short.MAX_VALUE)
141 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
142 .addComponent(groupListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE))
149 void resetGroupList() {
150 SwingUtilities.invokeLater(() -> {
151 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
153 groupKeyList.setListData(
new GroupKey[0]);
161 private void groupSelected(javax.swing.event.ListSelectionEvent evt) {
162 if (!evt.getValueIsAdjusting()) {
163 if (groupKeyList.getSelectedValue() != null) {
164 GroupKey selectedGroup = groupKeyList.getSelectedValue();
165 for (GroupKey groupKey : groupMap.keySet()) {
166 if (selectedGroup.equals(groupKey)) {
167 selectedGroupKey = groupKey;
168 DiscoveryEventUtils.getDiscoveryEventBus().post(
new DiscoveryEventUtils.GroupSelectedEvent(
169 searchfilters, groupingAttribute, groupSort, fileSortMethod, selectedGroupKey, groupMap.get(selectedGroupKey), resultType));
174 DiscoveryEventUtils.getDiscoveryEventBus().post(
new DiscoveryEventUtils.NoResultsEvent());
181 private javax.swing.JList<GroupKey> groupKeyList;
190 private static final long serialVersionUID = 1L;
198 boolean cellHasFocus) {
199 Object newValue = value;
200 if (newValue instanceof GroupKey) {
201 String valueString = newValue.toString();
202 setToolTipText(valueString);
204 if (groupingAttribute instanceof FileSearch.ParentPathAttribute && valueString.length() > 37) {
205 valueString = valueString.substring(0, 16) +
" ... " + valueString.substring(valueString.length() - 16);
207 newValue = valueString +
" (" + groupMap.get(newValue) +
")";
209 super.getListCellRendererComponent(list, newValue, index, isSelected, cellHasFocus);
java.awt.Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus)