19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.awt.event.MouseEvent;
24 import java.beans.PropertyChangeEvent;
25 import java.beans.PropertyChangeListener;
26 import java.util.ArrayList;
27 import java.util.EnumSet;
28 import java.util.List;
29 import java.util.logging.Level;
30 import javax.swing.SwingUtilities;
31 import javax.swing.event.PopupMenuEvent;
32 import javax.swing.event.PopupMenuListener;
45 @SuppressWarnings(
"PMD.SingularField")
46 class DropdownToolbar extends javax.swing.JPanel {
48 private static final long serialVersionUID = 1L;
49 private static final Logger logger = Logger.getLogger(DropdownToolbar.class.getName());
50 private static DropdownToolbar instance;
51 private SearchSettingsChangeListener searchSettingsChangeListener;
52 private boolean active =
false;
53 private DropdownSingleTermSearchPanel dropPanel = null;
54 private DropdownListSearchPanel listsPanel = null;
55 private List<DataSource> dataSources =
new ArrayList<>();
63 public synchronized static DropdownToolbar getDefault() {
64 if (instance == null) {
65 instance =
new DropdownToolbar();
75 private DropdownToolbar() {
77 customizeComponents();
84 private void customizeComponents() {
85 searchSettingsChangeListener =
new SearchSettingsChangeListener();
86 KeywordSearch.getServer().addServerActionListener(searchSettingsChangeListener);
87 Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE, Case.Events.DATA_SOURCE_ADDED), searchSettingsChangeListener);
89 listsPanel = DropdownListSearchPanel.getDefault();
90 listsPanel.addSearchButtonActionListener((ActionEvent e) -> {
91 listsMenu.setVisible(
false);
93 listsPanel.addPropertyChangeListener(searchSettingsChangeListener);
95 listsMenu.setSize(listsPanel.getPreferredSize().width + 6, listsPanel.getPreferredSize().height + 6);
96 listsMenu.add(listsPanel);
97 listsMenu.addPopupMenuListener(
new PopupMenuListener() {
99 public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
100 listsButton.setSelected(
true);
104 public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
105 listsButton.setSelected(
false);
109 public void popupMenuCanceled(PopupMenuEvent e) {
110 listsButton.setSelected(
false);
114 dropPanel = DropdownSingleTermSearchPanel.getDefault();
115 dropPanel.addPropertyChangeListener(searchSettingsChangeListener);
116 dropPanel.addSearchButtonActionListener(
new ActionListener() {
118 public void actionPerformed(ActionEvent e) {
119 searchMenu.setVisible(
false);
122 searchMenu.setSize(dropPanel.getPreferredSize().width + 6, dropPanel.getPreferredSize().height + 6);
123 searchMenu.add(dropPanel);
124 searchMenu.addPopupMenuListener(
new PopupMenuListener() {
126 public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
127 searchDropButton.setSelected(
true);
131 public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
132 searchDropButton.setSelected(
false);
136 public void popupMenuCanceled(PopupMenuEvent e) {
137 searchDropButton.setSelected(
false);
143 private void maybeShowListsPopup(MouseEvent evt) {
144 if (!active || !listsButton.isEnabled()) {
147 if (evt != null && !SwingUtilities.isLeftMouseButton(evt)) {
150 listsPanel.setDataSources(dataSources);
151 listsPanel.updateDataSourceListModel();
152 listsMenu.show(listsButton, listsButton.getWidth() - listsMenu.getWidth(), listsButton.getHeight() - 1);
155 private void maybeShowSearchPopup(MouseEvent evt) {
156 if (!active || !searchDropButton.isEnabled()) {
159 if (evt != null && !SwingUtilities.isLeftMouseButton(evt)) {
162 dropPanel.setDataSources(dataSources);
163 dropPanel.updateDataSourceListModel();
164 searchMenu.show(searchDropButton, searchDropButton.getWidth() - searchMenu.getWidth(), searchDropButton.getHeight() - 1);
172 String changed = evt.getPropertyName();
174 if (null != evt.getNewValue()) {
175 boolean disableSearch =
false;
181 if (server.coreIsOpen() ==
false) {
182 disableSearch =
true;
185 Index indexInfo = server.getIndexInfo();
188 boolean schemaIsCompatible = indexInfo.isCompatible(IndexFinder.getCurrentSchemaVersion());
189 if (!schemaIsCompatible) {
190 logger.log(Level.WARNING,
"Text index schema version {0} is not compatible with current schema", indexInfo.getSchemaVersion());
191 disableSearch =
true;
193 listsButton.setEnabled(
true);
194 searchDropButton.setEnabled(
true);
195 dropPanel.setRegexSearchEnabled(
true);
203 logger.log(Level.SEVERE,
"Error getting text index info", ex);
204 disableSearch =
true;
209 dataSources = getDataSourceList();
210 }
catch (TskCoreException ex) {
211 logger.log(Level.SEVERE,
"Error getting text index info", ex);
212 disableSearch =
true;
214 logger.log(Level.SEVERE,
"Exception while getting current case.", ex);
215 disableSearch =
true;
218 searchDropButton.setEnabled(
false);
219 listsButton.setEnabled(
false);
227 dropPanel.clearSearchBox();
228 searchDropButton.setEnabled(
false);
229 listsButton.setEnabled(
false);
240 logger.log(Level.SEVERE,
"Error executing Solr query", ex);
248 DataSource newDataSource = (DataSource) evt.getNewValue();
249 dataSources.add(newDataSource);
261 private synchronized List<DataSource> getDataSourceList() throws
NoCurrentCaseException, TskCoreException {
270 @SuppressWarnings(
"unchecked")
272 private
void initComponents() {
274 listsMenu =
new javax.swing.JPopupMenu();
275 searchMenu =
new javax.swing.JPopupMenu();
276 listsButton =
new javax.swing.JButton();
277 searchDropButton =
new javax.swing.JButton();
278 jSeparator1 =
new javax.swing.JSeparator();
282 listsButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/watchbutton-icon.png")));
283 listsButton.setText(
org.openide.util.NbBundle.getMessage(DropdownToolbar.class,
"ListBundleName"));
284 listsButton.setBorderPainted(
false);
285 listsButton.setContentAreaFilled(
false);
286 listsButton.setEnabled(
false);
287 listsButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/watchbutton-icon-rollover.png")));
288 listsButton.setRolloverSelectedIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/watchbutton-icon-pressed.png")));
289 listsButton.addMouseListener(
new java.awt.event.MouseAdapter() {
290 public void mousePressed(java.awt.event.MouseEvent evt) {
291 listsButtonMousePressed(evt);
294 listsButton.addActionListener(
new java.awt.event.ActionListener() {
295 public void actionPerformed(java.awt.event.ActionEvent evt) {
296 listsButtonActionPerformed(evt);
300 searchDropButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/searchbutton-icon.png")));
301 searchDropButton.setText(
org.openide.util.NbBundle.getMessage(DropdownToolbar.class,
"KeywordSearchPanel.searchDropButton.text"));
302 searchDropButton.setBorderPainted(
false);
303 searchDropButton.setContentAreaFilled(
false);
304 searchDropButton.setEnabled(
false);
305 searchDropButton.setMaximumSize(
new java.awt.Dimension(146, 27));
306 searchDropButton.setMinimumSize(
new java.awt.Dimension(146, 27));
307 searchDropButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/searchbutton-icon-rollover.png")));
308 searchDropButton.setRolloverSelectedIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/searchbutton-icon-pressed.png")));
309 searchDropButton.addMouseListener(
new java.awt.event.MouseAdapter() {
310 public void mousePressed(java.awt.event.MouseEvent evt) {
311 searchDropButtonMousePressed(evt);
315 jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
317 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
318 this.setLayout(layout);
319 layout.setHorizontalGroup(
320 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
321 .addGroup(layout.createSequentialGroup()
322 .addComponent(listsButton)
323 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
324 .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
326 .addComponent(searchDropButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
329 layout.setVerticalGroup(
330 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
331 .addGroup(layout.createSequentialGroup()
332 .addGap(0, 0, Short.MAX_VALUE)
333 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
334 .addComponent(listsButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
335 .addComponent(searchDropButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
336 .addComponent(jSeparator1)))
340 private void listsButtonMousePressed(java.awt.event.MouseEvent evt) {
341 maybeShowListsPopup(evt);
344 private void listsButtonActionPerformed(java.awt.event.ActionEvent evt) {
348 private void searchDropButtonMousePressed(java.awt.event.MouseEvent evt) {
349 maybeShowSearchPopup(evt);
353 private javax.swing.JSeparator jSeparator1;
354 private javax.swing.JButton listsButton;
355 private javax.swing.JPopupMenu listsMenu;
356 private javax.swing.JButton searchDropButton;
357 private javax.swing.JPopupMenu searchMenu;
int queryNumIndexedFiles()
static boolean runningWithGUI
static void fireNumIndexedFilesChange(Integer oldNum, Integer newNum)
static synchronized Server getServer()
static final String CORE_EVT
SleuthkitCase getSleuthkitCase()
static Case getCurrentCaseThrows()