Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
DropdownListSearchPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.keywordsearch;
20 
21 import java.awt.Component;
22 import java.awt.Cursor;
23 import java.awt.EventQueue;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.beans.PropertyChangeEvent;
27 import java.beans.PropertyChangeListener;
28 import java.util.ArrayList;
29 import java.util.HashSet;
30 import java.util.Iterator;
31 import java.util.List;
32 import java.util.Set;
33 import java.util.logging.Level;
34 import javax.swing.JCheckBox;
35 import javax.swing.JTable;
36 import javax.swing.ListSelectionModel;
37 import javax.swing.event.ListSelectionEvent;
38 import javax.swing.event.ListSelectionListener;
39 import javax.swing.table.AbstractTableModel;
40 import javax.swing.table.TableCellRenderer;
41 import javax.swing.table.TableColumn;
42 import org.openide.util.NbBundle;
43 import org.openide.util.actions.SystemAction;
46 
51 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
52 class DropdownListSearchPanel extends AdHocSearchPanel {
53 
54  private static final Logger logger = Logger.getLogger(DropdownListSearchPanel.class.getName());
55  private static DropdownListSearchPanel instance;
56  private XmlKeywordSearchList loader;
57  private final KeywordListsTableModel listsTableModel;
58  private final KeywordsTableModel keywordsTableModel;
59  private ActionListener searchAddListener;
60  private boolean ingestRunning;
61 
65  private DropdownListSearchPanel() {
66  listsTableModel = new KeywordListsTableModel();
67  keywordsTableModel = new KeywordsTableModel();
68  initComponents();
69  customizeComponents();
70  dataSourceList.setModel(getDataSourceListModel());
71 
72  dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> {
73  firePropertyChange(Bundle.DropdownSingleTermSearchPanel_selected(), null, null);
74  });
75  }
76 
77  static synchronized DropdownListSearchPanel getDefault() {
78  if (instance == null) {
79  instance = new DropdownListSearchPanel();
80  }
81  return instance;
82  }
83 
84  private void customizeComponents() {
85  listsTable.setTableHeader(null);
86  listsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
87  //customize column witdhs
88  final int leftWidth = leftPane.getPreferredSize().width;
89  TableColumn column;
90  for (int i = 0; i < listsTable.getColumnCount(); i++) {
91  column = listsTable.getColumnModel().getColumn(i);
92  if (i == 0) {
93  column.setPreferredWidth(((int) (leftWidth * 0.10)));
94  column.setCellRenderer(new LeftCheckBoxRenderer());
95  } else {
96  column.setPreferredWidth(((int) (leftWidth * 0.89)));
97  }
98  }
99  final int rightWidth = rightPane.getPreferredSize().width;
100  for (int i = 0; i < keywordsTable.getColumnCount(); i++) {
101  column = keywordsTable.getColumnModel().getColumn(i);
102  if (i == 0) {
103  column.setPreferredWidth(((int) (rightWidth * 0.60)));
104  } else {
105  column.setPreferredWidth(((int) (rightWidth * 0.38)));
106  }
107  }
108 
109  loader = XmlKeywordSearchList.getCurrent();
110  listsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
111  @Override
112  public void valueChanged(ListSelectionEvent e) {
113  ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource();
114  if (!listSelectionModel.isSelectionEmpty()) {
115  int index = listSelectionModel.getMinSelectionIndex();
116  KeywordList list = listsTableModel.getListAt(index);
117  keywordsTableModel.resync(list);
118  } else {
119  keywordsTableModel.deleteAll();
120  }
121  }
122  });
123 
124  ingestRunning = IngestManager.getInstance().isIngestRunning();
125  updateComponents();
126 
127  IngestManager.getInstance().addIngestJobEventListener(new PropertyChangeListener() {
128  @Override
129  public void propertyChange(PropertyChangeEvent evt) {
130  Object source = evt.getSource();
131  if (source instanceof String && ((String) source).equals("LOCAL")) { //NON-NLS
132  EventQueue.invokeLater(() -> {
133  ingestRunning = IngestManager.getInstance().isIngestRunning();
134  updateComponents();
135  });
136  }
137  }
138  });
139 
140  searchAddListener = new ActionListener() {
141  @Override
142  public void actionPerformed(ActionEvent e) {
143  if (ingestRunning) {
144  IngestSearchRunner.getInstance().addKeywordListsToAllJobs(listsTableModel.getSelectedLists());
145  logger.log(Level.INFO, "Submitted enqueued lists to ingest"); //NON-NLS
146  } else {
147  searchAction(e);
148  }
149  }
150  };
151 
152  searchAddButton.addActionListener(searchAddListener);
153  }
154 
155  private void updateComponents() {
156  ingestRunning = IngestManager.getInstance().isIngestRunning();
157  if (ingestRunning) {
158  searchAddButton.setText(NbBundle.getMessage(this.getClass(), "KeywordSearchListsViewerPanel.initIngest.addIngestTitle"));
159  searchAddButton.setToolTipText(NbBundle.getMessage(this.getClass(), "KeywordSearchListsViewerPanel.initIngest.addIngestMsg"));
160 
161  } else {
162  searchAddButton.setText(NbBundle.getMessage(this.getClass(), "KeywordSearchListsViewerPanel.initIngest.searchIngestTitle"));
163  searchAddButton.setToolTipText(NbBundle.getMessage(this.getClass(), "KeywordSearchListsViewerPanel.initIngest.addIdxSearchMsg"));
164  }
165  listsTableModel.resync();
166  updateIngestIndexLabel();
167 
168  jSaveSearchResults.setSelected(true);
169  }
170 
171  private void updateIngestIndexLabel() {
172  if (ingestRunning) {
173  ingestIndexLabel.setText(NbBundle.getMessage(this.getClass(), "KeywordSearchListsViewerPanel.initIngest.ongoingIngestMsg", filesIndexed));
174  } else {
175  ingestIndexLabel.setText(NbBundle.getMessage(this.getClass(), "KeywordSearchListsViewerPanel.initIngest.fileIndexCtMsg", filesIndexed));
176  }
177  }
178 
179  @Override
180  protected void postFilesIndexedChange() {
181  updateIngestIndexLabel();
182  }
183 
187  void resync() {
188  listsTableModel.resync();
189  }
190 
196  @SuppressWarnings("unchecked")
197  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
198  private void initComponents() {
199 
200  jSplitPane1 = new javax.swing.JSplitPane();
201  leftPane = new javax.swing.JScrollPane();
202  listsTable = new javax.swing.JTable();
203  rightPane = new javax.swing.JScrollPane();
204  keywordsTable = new javax.swing.JTable();
205  manageListsButton = new javax.swing.JButton();
206  searchAddButton = new javax.swing.JButton();
207  ingestIndexLabel = new javax.swing.JLabel();
208  dataSourceCheckBox = new javax.swing.JCheckBox();
209  jScrollPane1 = new javax.swing.JScrollPane();
210  dataSourceList = new javax.swing.JList<>();
211  jSaveSearchResults = new javax.swing.JCheckBox();
212 
213  setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD, 11));
214 
215  jSplitPane1.setFont(leftPane.getFont());
216 
217  leftPane.setFont(leftPane.getFont().deriveFont(leftPane.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
218  leftPane.setMinimumSize(new java.awt.Dimension(150, 23));
219  leftPane.setOpaque(false);
220 
221  listsTable.setBackground(new java.awt.Color(240, 240, 240));
222  listsTable.setFont(listsTable.getFont().deriveFont(listsTable.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
223  listsTable.setModel(listsTableModel);
224  listsTable.setShowHorizontalLines(false);
225  listsTable.setShowVerticalLines(false);
226  listsTable.getTableHeader().setReorderingAllowed(false);
227  leftPane.setViewportView(listsTable);
228 
229  jSplitPane1.setLeftComponent(leftPane);
230 
231  rightPane.setFont(rightPane.getFont().deriveFont(rightPane.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
232  rightPane.setOpaque(false);
233 
234  keywordsTable.setBackground(new java.awt.Color(240, 240, 240));
235  keywordsTable.setFont(keywordsTable.getFont().deriveFont(keywordsTable.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
236  keywordsTable.setModel(keywordsTableModel);
237  keywordsTable.setGridColor(new java.awt.Color(153, 153, 153));
238  rightPane.setViewportView(keywordsTable);
239 
240  jSplitPane1.setRightComponent(rightPane);
241 
242  manageListsButton.setFont(manageListsButton.getFont().deriveFont(manageListsButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
243  manageListsButton.setText(org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, "KeywordSearchListsViewerPanel.manageListsButton.text")); // NOI18N
244  manageListsButton.setToolTipText(org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, "KeywordSearchListsViewerPanel.manageListsButton.toolTipText")); // NOI18N
245  manageListsButton.addActionListener(new java.awt.event.ActionListener() {
246  public void actionPerformed(java.awt.event.ActionEvent evt) {
247  manageListsButtonActionPerformed(evt);
248  }
249  });
250 
251  searchAddButton.setFont(searchAddButton.getFont().deriveFont(searchAddButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
252  searchAddButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/search-icon.png"))); // NOI18N
253  searchAddButton.setText(org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, "KeywordSearchListsViewerPanel.searchAddButton.text")); // NOI18N
254  searchAddButton.addActionListener(new java.awt.event.ActionListener() {
255  public void actionPerformed(java.awt.event.ActionEvent evt) {
256  searchAddButtonActionPerformed(evt);
257  }
258  });
259 
260  ingestIndexLabel.setFont(ingestIndexLabel.getFont().deriveFont(ingestIndexLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 10));
261  ingestIndexLabel.setText(org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, "KeywordSearchListsViewerPanel.ingestIndexLabel.text")); // NOI18N
262 
263  dataSourceCheckBox.setText(org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, "DropdownListSearchPanel.dataSourceCheckBox.text")); // NOI18N
264  dataSourceCheckBox.addActionListener(new java.awt.event.ActionListener() {
265  public void actionPerformed(java.awt.event.ActionEvent evt) {
266  dataSourceCheckBoxActionPerformed(evt);
267  }
268  });
269 
270  dataSourceList.setMinimumSize(new java.awt.Dimension(0, 200));
271  jScrollPane1.setViewportView(dataSourceList);
272 
273  jSaveSearchResults.setText(org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, "DropdownListSearchPanel.jSaveSearchResults.text")); // NOI18N
274  jSaveSearchResults.setToolTipText(org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, "DropdownListSearchPanel.jSaveSearchResults.toolTipText")); // NOI18N
275 
276  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
277  this.setLayout(layout);
278  layout.setHorizontalGroup(
279  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
280  .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
281  .addComponent(jScrollPane1)
282  .addGroup(layout.createSequentialGroup()
283  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
284  .addComponent(dataSourceCheckBox)
285  .addComponent(jSaveSearchResults)
286  .addGroup(layout.createSequentialGroup()
287  .addComponent(searchAddButton)
288  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
289  .addComponent(manageListsButton)
290  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
291  .addComponent(ingestIndexLabel)))
292  .addGap(0, 120, Short.MAX_VALUE))
293  );
294 
295  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {manageListsButton, searchAddButton});
296 
297  layout.setVerticalGroup(
298  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
299  .addGroup(layout.createSequentialGroup()
300  .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
301  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
302  .addComponent(dataSourceCheckBox)
303  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
304  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
305  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
306  .addComponent(jSaveSearchResults)
307  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
308  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
309  .addComponent(manageListsButton)
310  .addComponent(searchAddButton)
311  .addComponent(ingestIndexLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE))
312  .addGap(23, 23, 23))
313  );
314  }// </editor-fold>//GEN-END:initComponents
315 
316  private void manageListsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manageListsButtonActionPerformed
317  SystemAction.get(KeywordSearchConfigurationAction.class).performAction();
318  }//GEN-LAST:event_manageListsButtonActionPerformed
319 
320  private void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataSourceCheckBoxActionPerformed
321  updateDataSourceListModel();
322  }//GEN-LAST:event_dataSourceCheckBoxActionPerformed
323 
324  private void searchAddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchAddButtonActionPerformed
325  // TODO add your handling code here:
326  }//GEN-LAST:event_searchAddButtonActionPerformed
327 
328  // Variables declaration - do not modify//GEN-BEGIN:variables
329  private javax.swing.JCheckBox dataSourceCheckBox;
330  private javax.swing.JList<String> dataSourceList;
331  private javax.swing.JLabel ingestIndexLabel;
332  private javax.swing.JCheckBox jSaveSearchResults;
333  private javax.swing.JScrollPane jScrollPane1;
334  private javax.swing.JSplitPane jSplitPane1;
335  private javax.swing.JTable keywordsTable;
336  private javax.swing.JScrollPane leftPane;
337  private javax.swing.JTable listsTable;
338  private javax.swing.JButton manageListsButton;
339  private javax.swing.JScrollPane rightPane;
340  private javax.swing.JButton searchAddButton;
341  // End of variables declaration//GEN-END:variables
342 
343  private void searchAction(ActionEvent e) {
344  setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
345 
346  try {
347  search(jSaveSearchResults.isSelected());
348  } finally {
349  setCursor(null);
350  }
351  }
352 
353  @Override
354  List<KeywordList> getKeywordLists() {
355  return listsTableModel.getSelectedListsL();
356  }
357 
358  void addSearchButtonActionListener(ActionListener al) {
359  searchAddButton.addActionListener(al);
360  }
361 
366  @Override
367  Set<Long> getDataSourcesSelected() {
368  Set<Long> dataSourceObjIdSet = new HashSet<>();
369  for (Long key : getDataSourceMap().keySet()) {
370  String value = getDataSourceMap().get(key);
371  for (String dataSource : this.dataSourceList.getSelectedValuesList()) {
372  if (value.equals(dataSource)) {
373  dataSourceObjIdSet.add(key);
374  }
375  }
376  }
377  return dataSourceObjIdSet;
378  }
379 
380  private class KeywordListsTableModel extends AbstractTableModel {
381  //data
382 
383  private final XmlKeywordSearchList listsHandle = XmlKeywordSearchList.getCurrent();
384  private final List<ListTableEntry> listData = new ArrayList<>();
385 
386  @Override
387  public int getColumnCount() {
388  return 2;
389  }
390 
391  @Override
392  public int getRowCount() {
393  return listData.size();
394  }
395 
396  @Override
397  public String getColumnName(int column) {
398  String ret = null;
399  switch (column) {
400  case 0:
401  ret = NbBundle.getMessage(this.getClass(), "KeywordSearch.selectedColLbl");
402  break;
403  case 1:
404  ret = NbBundle.getMessage(this.getClass(), "KeywordSearch.nameColLbl");
405  break;
406  default:
407  break;
408  }
409  return ret;
410  }
411 
412  @Override
413  public Object getValueAt(int rowIndex, int columnIndex) {
414  Object ret = null;
415  ListTableEntry entry = null;
416  //iterate until row
417  Iterator<ListTableEntry> it = listData.iterator();
418  for (int i = 0; i <= rowIndex; ++i) {
419  entry = it.next();
420  }
421  if (null != entry) {
422  switch (columnIndex) {
423  case 0:
424  ret = (Object) entry.selected;
425  break;
426  case 1:
427  ret = (Object) entry.name;
428  break;
429  default:
430  break;
431  }
432  }
433  return ret;
434  }
435 
436  @Override
437  public boolean isCellEditable(int rowIndex, int columnIndex) {
438  return (columnIndex == 0 && !ingestRunning);
439  }
440 
441  @Override
442  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
443  if (columnIndex == 0) {
444  ListTableEntry entry = null;
445  Iterator<ListTableEntry> it = listData.iterator();
446  for (int i = 0; i <= rowIndex; i++) {
447  entry = it.next();
448  }
449  if (entry != null) {
450  entry.selected = (Boolean) aValue;
451  if (ingestRunning) {
452  //updateUseForIngest(getListAt(rowIndex), (Boolean) aValue);
453  }
454  }
455 
456  }
457  }
458 
459  @Override
460  public Class<?> getColumnClass(int c) {
461  return getValueAt(0, c).getClass();
462  }
463 
464  List<String> getAllLists() {
465  List<String> ret = new ArrayList<>();
466  for (ListTableEntry e : listData) {
467  ret.add(e.name);
468  }
469  return ret;
470  }
471 
472  KeywordList getListAt(int rowIndex) {
473  return listsHandle.getList((String) getValueAt(rowIndex, 1));
474  }
475 
476  List<String> getSelectedLists() {
477  List<String> ret = new ArrayList<>();
478  for (ListTableEntry e : listData) {
479  if (e.selected) {
480  ret.add(e.name);
481  }
482  }
483  return ret;
484  }
485 
486  List<KeywordList> getSelectedListsL() {
487  List<KeywordList> ret = new ArrayList<>();
488  for (String s : getSelectedLists()) {
489  ret.add(listsHandle.getList(s));
490  }
491  return ret;
492  }
493 
494  boolean listExists(String list) {
495  List<String> all = getAllLists();
496  return all.contains(list);
497  }
498 
499  //resync model from handle, then update table
500  void resync() {
501  listData.clear();
502  addLists(listsHandle.getListsL());
503  fireTableDataChanged();
504  }
505 
506  //add lists to the model
507  private void addLists(List<KeywordList> lists) {
508  for (KeywordList list : lists) {
509  if (!listExists(list.getName())) {
510  listData.add(new ListTableEntry(list, ingestRunning));
511  }
512  }
513  }
514 
515  //single model entry
516  private class ListTableEntry implements Comparable<ListTableEntry> {
517 
518  String name;
519  Boolean selected;
520 
521  ListTableEntry(KeywordList list, boolean ingestRunning) {
522  this.name = list.getName();
523  if (ingestRunning) {
524  this.selected = list.getUseForIngest();
525  } else {
526  this.selected = false;
527  }
528  }
529 
530  @Override
531  public int compareTo(ListTableEntry e) {
532  return this.name.compareTo(e.name);
533  }
534  }
535  }
536 
537  private class KeywordsTableModel extends AbstractTableModel {
538 
539  List<KeywordTableEntry> listData = new ArrayList<>();
540 
541  @Override
542  public int getRowCount() {
543  return listData.size();
544  }
545 
546  @Override
547  public int getColumnCount() {
548  return 2;
549  }
550 
551  @Override
552  public String getColumnName(int column) {
553  String ret = null;
554  switch (column) {
555  case 0:
556  ret = NbBundle.getMessage(this.getClass(), "KeywordSearch.nameColLbl");
557  break;
558  case 1:
559  ret = NbBundle.getMessage(this.getClass(), "KeywordSearch.typeColLbl");
560  break;
561  default:
562  break;
563  }
564  return ret;
565  }
566 
567  @Override
568  public Object getValueAt(int rowIndex, int columnIndex) {
569  Object ret = null;
570  KeywordTableEntry entry = null;
571  //iterate until row
572  Iterator<KeywordTableEntry> it = listData.iterator();
573  for (int i = 0; i <= rowIndex; ++i) {
574  entry = it.next();
575  }
576  if (null != entry) {
577  switch (columnIndex) {
578  case 0:
579  ret = (Object) entry.name;
580  break;
581  case 1:
582  ret = (Object) entry.keywordType;
583  break;
584  default:
585  break;
586  }
587  }
588  return ret;
589  }
590 
591  @Override
592  public boolean isCellEditable(int rowIndex, int columnIndex) {
593  return false;
594  }
595 
596  @Override
597  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
598  }
599 
600  @Override
601  public Class<?> getColumnClass(int c) {
602  return getValueAt(0, c).getClass();
603  }
604 
605  void resync(KeywordList list) {
606  listData.clear();
607  for (Keyword k : list.getKeywords()) {
608  listData.add(new KeywordTableEntry(k));
609  }
610  fireTableDataChanged();
611  }
612 
613  void deleteAll() {
614  listData.clear();
615  fireTableDataChanged();
616  }
617 
618  //single model entry
619  private class KeywordTableEntry implements Comparable<KeywordTableEntry> {
620 
621  String name;
622  String keywordType;
623 
624  KeywordTableEntry(Keyword keyword) {
625  this.name = keyword.getSearchTerm();
626  this.keywordType = keyword.getSearchTermType();
627  }
628 
629  @Override
630  public int compareTo(KeywordTableEntry e) {
631  return this.name.compareTo(e.name);
632  }
633  }
634  }
635 
636  private class LeftCheckBoxRenderer extends JCheckBox implements TableCellRenderer {
637 
638  @Override
640  JTable table, Object value,
641  boolean isSelected, boolean hasFocus,
642  int row, int column) {
643 
644  this.setHorizontalAlignment(JCheckBox.CENTER);
645  this.setVerticalAlignment(JCheckBox.CENTER);
646 
647  setEnabled(!ingestRunning);
648 
649  boolean selected = (Boolean) table.getModel().getValueAt(row, 0);
650  setSelected(selected);
651 
652  if (isSelected) {
653  setBackground(listsTable.getSelectionBackground());
654  } else {
655  setBackground(listsTable.getBackground());
656  }
657 
658  return this;
659  }
660  }
661 
665  @NbBundle.Messages({"DropdownListSearchPanel.selected=Ad Hoc Search data source filter is selected"})
666  void updateDataSourceListModel() {
667  getDataSourceListModel().removeAllElements();
668  for (String dsName : getDataSourceArray()) {
669  getDataSourceListModel().addElement(dsName);
670  }
671  setComponentsEnabled();
672  firePropertyChange(Bundle.DropdownListSearchPanel_selected(), null, null);
673 
674  }
675 
679  private void setComponentsEnabled() {
680 
681  if (getDataSourceListModel().size() > 1) {
682  this.dataSourceCheckBox.setEnabled(true);
683 
684  boolean enabled = this.dataSourceCheckBox.isSelected();
685  this.dataSourceList.setEnabled(enabled);
686  if (enabled) {
687  this.dataSourceList.setSelectionInterval(0, this.dataSourceList.getModel().getSize()-1);
688  } else {
689  this.dataSourceList.setSelectedIndices(new int[0]);
690  }
691  } else {
692  this.dataSourceCheckBox.setEnabled(false);
693  this.dataSourceCheckBox.setSelected(false);
694  this.dataSourceList.setEnabled(false);
695  this.dataSourceList.setSelectedIndices(new int[0]);
696  }
697  }
698 
699 }
Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.