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();
186 if (IndexFinder.getCurrentSolrVersion().equals(indexInfo.getSolrVersion())) {
192 boolean schemaIsCompatible = indexInfo.isCompatible(IndexFinder.getCurrentSchemaVersion());
193 listsButton.setEnabled(schemaIsCompatible);
194 searchDropButton.setEnabled(
true);
195 dropPanel.setRegexSearchEnabled(schemaIsCompatible);
202 disableSearch =
true;
209 logger.log(Level.SEVERE,
"Error getting text index info", ex);
210 disableSearch =
true;
215 dataSources = getDataSourceList();
216 }
catch (TskCoreException ex) {
217 logger.log(Level.SEVERE,
"Error getting text index info", ex);
218 disableSearch =
true;
220 logger.log(Level.SEVERE,
"Exception while getting current case.", ex);
221 disableSearch =
true;
224 searchDropButton.setEnabled(
false);
225 listsButton.setEnabled(
false);
233 dropPanel.clearSearchBox();
234 searchDropButton.setEnabled(
false);
235 listsButton.setEnabled(
false);
246 logger.log(Level.SEVERE,
"Error executing Solr query", ex);
254 DataSource newDataSource = (DataSource) evt.getNewValue();
255 dataSources.add(newDataSource);
267 private synchronized List<DataSource> getDataSourceList() throws
NoCurrentCaseException, TskCoreException {
276 @SuppressWarnings(
"unchecked")
278 private
void initComponents() {
280 listsMenu =
new javax.swing.JPopupMenu();
281 searchMenu =
new javax.swing.JPopupMenu();
282 listsButton =
new javax.swing.JButton();
283 searchDropButton =
new javax.swing.JButton();
284 jSeparator1 =
new javax.swing.JSeparator();
288 listsButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/watchbutton-icon.png")));
289 listsButton.setText(
org.openide.util.NbBundle.getMessage(DropdownToolbar.class,
"ListBundleName"));
290 listsButton.setBorderPainted(
false);
291 listsButton.setContentAreaFilled(
false);
292 listsButton.setEnabled(
false);
293 listsButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/watchbutton-icon-rollover.png")));
294 listsButton.setRolloverSelectedIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/watchbutton-icon-pressed.png")));
295 listsButton.addMouseListener(
new java.awt.event.MouseAdapter() {
296 public void mousePressed(java.awt.event.MouseEvent evt) {
297 listsButtonMousePressed(evt);
300 listsButton.addActionListener(
new java.awt.event.ActionListener() {
301 public void actionPerformed(java.awt.event.ActionEvent evt) {
302 listsButtonActionPerformed(evt);
306 searchDropButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/searchbutton-icon.png")));
307 searchDropButton.setText(
org.openide.util.NbBundle.getMessage(DropdownToolbar.class,
"KeywordSearchPanel.searchDropButton.text"));
308 searchDropButton.setBorderPainted(
false);
309 searchDropButton.setContentAreaFilled(
false);
310 searchDropButton.setEnabled(
false);
311 searchDropButton.setMaximumSize(
new java.awt.Dimension(146, 27));
312 searchDropButton.setMinimumSize(
new java.awt.Dimension(146, 27));
313 searchDropButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/searchbutton-icon-rollover.png")));
314 searchDropButton.setRolloverSelectedIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/searchbutton-icon-pressed.png")));
315 searchDropButton.addMouseListener(
new java.awt.event.MouseAdapter() {
316 public void mousePressed(java.awt.event.MouseEvent evt) {
317 searchDropButtonMousePressed(evt);
321 jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
323 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
324 this.setLayout(layout);
325 layout.setHorizontalGroup(
326 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
327 .addGroup(layout.createSequentialGroup()
328 .addComponent(listsButton)
329 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
330 .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
332 .addComponent(searchDropButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
335 layout.setVerticalGroup(
336 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
337 .addGroup(layout.createSequentialGroup()
338 .addGap(0, 0, Short.MAX_VALUE)
339 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
340 .addComponent(listsButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
341 .addComponent(searchDropButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
342 .addComponent(jSeparator1)))
346 private void listsButtonMousePressed(java.awt.event.MouseEvent evt) {
347 maybeShowListsPopup(evt);
350 private void listsButtonActionPerformed(java.awt.event.ActionEvent evt) {
354 private void searchDropButtonMousePressed(java.awt.event.MouseEvent evt) {
355 maybeShowSearchPopup(evt);
359 private javax.swing.JSeparator jSeparator1;
360 private javax.swing.JButton listsButton;
361 private javax.swing.JPopupMenu listsMenu;
362 private javax.swing.JButton searchDropButton;
363 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()