Autopsy  4.8.0
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 
220  listsTable.setBackground(new java.awt.Color(240, 240, 240));
221  listsTable.setFont(listsTable.getFont().deriveFont(listsTable.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
222  listsTable.setModel(listsTableModel);
223  listsTable.setShowHorizontalLines(false);
224  listsTable.setShowVerticalLines(false);
225  listsTable.getTableHeader().setReorderingAllowed(false);
226  leftPane.setViewportView(listsTable);
227 
228  jSplitPane1.setLeftComponent(leftPane);
229 
230  rightPane.setFont(rightPane.getFont().deriveFont(rightPane.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
231 
232  keywordsTable.setBackground(new java.awt.Color(240, 240, 240));
233  keywordsTable.setFont(keywordsTable.getFont().deriveFont(keywordsTable.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
234  keywordsTable.setModel(keywordsTableModel);
235  keywordsTable.setGridColor(new java.awt.Color(153, 153, 153));
236  rightPane.setViewportView(keywordsTable);
237 
238  jSplitPane1.setRightComponent(rightPane);
239 
240  manageListsButton.setFont(manageListsButton.getFont().deriveFont(manageListsButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
241  manageListsButton.setText(org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, "KeywordSearchListsViewerPanel.manageListsButton.text")); // NOI18N
242  manageListsButton.setToolTipText(org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, "KeywordSearchListsViewerPanel.manageListsButton.toolTipText")); // NOI18N
243  manageListsButton.addActionListener(new java.awt.event.ActionListener() {
244  public void actionPerformed(java.awt.event.ActionEvent evt) {
245  manageListsButtonActionPerformed(evt);
246  }
247  });
248 
249  searchAddButton.setFont(searchAddButton.getFont().deriveFont(searchAddButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
250  searchAddButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/search-icon.png"))); // NOI18N
251  searchAddButton.setText(org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, "KeywordSearchListsViewerPanel.searchAddButton.text")); // NOI18N
252  searchAddButton.addActionListener(new java.awt.event.ActionListener() {
253  public void actionPerformed(java.awt.event.ActionEvent evt) {
254  searchAddButtonActionPerformed(evt);
255  }
256  });
257 
258  ingestIndexLabel.setFont(ingestIndexLabel.getFont().deriveFont(ingestIndexLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 10));
259  ingestIndexLabel.setText(org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, "KeywordSearchListsViewerPanel.ingestIndexLabel.text")); // NOI18N
260 
261  dataSourceCheckBox.setText(org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, "DropdownListSearchPanel.dataSourceCheckBox.text")); // NOI18N
262  dataSourceCheckBox.addActionListener(new java.awt.event.ActionListener() {
263  public void actionPerformed(java.awt.event.ActionEvent evt) {
264  dataSourceCheckBoxActionPerformed(evt);
265  }
266  });
267 
268  dataSourceList.setMinimumSize(new java.awt.Dimension(0, 200));
269  jScrollPane1.setViewportView(dataSourceList);
270 
271  jSaveSearchResults.setText(org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, "DropdownListSearchPanel.jSaveSearchResults.text")); // NOI18N
272  jSaveSearchResults.setToolTipText(org.openide.util.NbBundle.getMessage(DropdownListSearchPanel.class, "DropdownListSearchPanel.jSaveSearchResults.toolTipText")); // NOI18N
273 
274  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
275  this.setLayout(layout);
276  layout.setHorizontalGroup(
277  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
278  .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
279  .addComponent(jScrollPane1)
280  .addGroup(layout.createSequentialGroup()
281  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
282  .addComponent(dataSourceCheckBox)
283  .addComponent(jSaveSearchResults)
284  .addGroup(layout.createSequentialGroup()
285  .addComponent(searchAddButton)
286  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
287  .addComponent(manageListsButton)
288  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
289  .addComponent(ingestIndexLabel)))
290  .addGap(0, 120, Short.MAX_VALUE))
291  );
292 
293  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {manageListsButton, searchAddButton});
294 
295  layout.setVerticalGroup(
296  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
297  .addGroup(layout.createSequentialGroup()
298  .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
299  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
300  .addComponent(dataSourceCheckBox)
301  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
302  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
303  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
304  .addComponent(jSaveSearchResults)
305  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
306  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
307  .addComponent(manageListsButton)
308  .addComponent(searchAddButton)
309  .addComponent(ingestIndexLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE))
310  .addGap(23, 23, 23))
311  );
312  }// </editor-fold>//GEN-END:initComponents
313 
314  private void manageListsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manageListsButtonActionPerformed
315  SystemAction.get(KeywordSearchConfigurationAction.class).performAction();
316  }//GEN-LAST:event_manageListsButtonActionPerformed
317 
318  private void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataSourceCheckBoxActionPerformed
319  updateDataSourceListModel();
320  }//GEN-LAST:event_dataSourceCheckBoxActionPerformed
321 
322  private void searchAddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchAddButtonActionPerformed
323  // TODO add your handling code here:
324  }//GEN-LAST:event_searchAddButtonActionPerformed
325 
326  // Variables declaration - do not modify//GEN-BEGIN:variables
327  private javax.swing.JCheckBox dataSourceCheckBox;
328  private javax.swing.JList<String> dataSourceList;
329  private javax.swing.JLabel ingestIndexLabel;
330  private javax.swing.JCheckBox jSaveSearchResults;
331  private javax.swing.JScrollPane jScrollPane1;
332  private javax.swing.JSplitPane jSplitPane1;
333  private javax.swing.JTable keywordsTable;
334  private javax.swing.JScrollPane leftPane;
335  private javax.swing.JTable listsTable;
336  private javax.swing.JButton manageListsButton;
337  private javax.swing.JScrollPane rightPane;
338  private javax.swing.JButton searchAddButton;
339  // End of variables declaration//GEN-END:variables
340 
341  private void searchAction(ActionEvent e) {
342  setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
343 
344  try {
345  search(jSaveSearchResults.isSelected());
346  } finally {
347  setCursor(null);
348  }
349  }
350 
351  @Override
352  List<KeywordList> getKeywordLists() {
353  return listsTableModel.getSelectedListsL();
354  }
355 
356  void addSearchButtonActionListener(ActionListener al) {
357  searchAddButton.addActionListener(al);
358  }
359 
364  @Override
365  Set<Long> getDataSourcesSelected() {
366  Set<Long> dataSourceObjIdSet = new HashSet<>();
367  for (Long key : getDataSourceMap().keySet()) {
368  String value = getDataSourceMap().get(key);
369  for (String dataSource : this.dataSourceList.getSelectedValuesList()) {
370  if (value.equals(dataSource)) {
371  dataSourceObjIdSet.add(key);
372  }
373  }
374  }
375  return dataSourceObjIdSet;
376  }
377 
378  private class KeywordListsTableModel extends AbstractTableModel {
379  //data
380 
381  private final XmlKeywordSearchList listsHandle = XmlKeywordSearchList.getCurrent();
382  private final List<ListTableEntry> listData = new ArrayList<>();
383 
384  @Override
385  public int getColumnCount() {
386  return 2;
387  }
388 
389  @Override
390  public int getRowCount() {
391  return listData.size();
392  }
393 
394  @Override
395  public String getColumnName(int column) {
396  String ret = null;
397  switch (column) {
398  case 0:
399  ret = NbBundle.getMessage(this.getClass(), "KeywordSearch.selectedColLbl");
400  break;
401  case 1:
402  ret = NbBundle.getMessage(this.getClass(), "KeywordSearch.nameColLbl");
403  break;
404  default:
405  break;
406  }
407  return ret;
408  }
409 
410  @Override
411  public Object getValueAt(int rowIndex, int columnIndex) {
412  Object ret = null;
413  ListTableEntry entry = null;
414  //iterate until row
415  Iterator<ListTableEntry> it = listData.iterator();
416  for (int i = 0; i <= rowIndex; ++i) {
417  entry = it.next();
418  }
419  if (null != entry) {
420  switch (columnIndex) {
421  case 0:
422  ret = (Object) entry.selected;
423  break;
424  case 1:
425  ret = (Object) entry.name;
426  break;
427  default:
428  break;
429  }
430  }
431  return ret;
432  }
433 
434  @Override
435  public boolean isCellEditable(int rowIndex, int columnIndex) {
436  return (columnIndex == 0 && !ingestRunning);
437  }
438 
439  @Override
440  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
441  if (columnIndex == 0) {
442  ListTableEntry entry = null;
443  Iterator<ListTableEntry> it = listData.iterator();
444  for (int i = 0; i <= rowIndex; i++) {
445  entry = it.next();
446  }
447  if (entry != null) {
448  entry.selected = (Boolean) aValue;
449  if (ingestRunning) {
450  //updateUseForIngest(getListAt(rowIndex), (Boolean) aValue);
451  }
452  }
453 
454  }
455  }
456 
457  @Override
458  public Class<?> getColumnClass(int c) {
459  return getValueAt(0, c).getClass();
460  }
461 
462  List<String> getAllLists() {
463  List<String> ret = new ArrayList<>();
464  for (ListTableEntry e : listData) {
465  ret.add(e.name);
466  }
467  return ret;
468  }
469 
470  KeywordList getListAt(int rowIndex) {
471  return listsHandle.getList((String) getValueAt(rowIndex, 1));
472  }
473 
474  List<String> getSelectedLists() {
475  List<String> ret = new ArrayList<>();
476  for (ListTableEntry e : listData) {
477  if (e.selected) {
478  ret.add(e.name);
479  }
480  }
481  return ret;
482  }
483 
484  List<KeywordList> getSelectedListsL() {
485  List<KeywordList> ret = new ArrayList<>();
486  for (String s : getSelectedLists()) {
487  ret.add(listsHandle.getList(s));
488  }
489  return ret;
490  }
491 
492  boolean listExists(String list) {
493  List<String> all = getAllLists();
494  return all.contains(list);
495  }
496 
497  //resync model from handle, then update table
498  void resync() {
499  listData.clear();
500  addLists(listsHandle.getListsL());
501  fireTableDataChanged();
502  }
503 
504  //add lists to the model
505  private void addLists(List<KeywordList> lists) {
506  for (KeywordList list : lists) {
507  if (!listExists(list.getName())) {
508  listData.add(new ListTableEntry(list, ingestRunning));
509  }
510  }
511  }
512 
513  //single model entry
514  private class ListTableEntry implements Comparable<ListTableEntry> {
515 
516  String name;
517  Boolean selected;
518 
519  ListTableEntry(KeywordList list, boolean ingestRunning) {
520  this.name = list.getName();
521  if (ingestRunning) {
522  this.selected = list.getUseForIngest();
523  } else {
524  this.selected = false;
525  }
526  }
527 
528  @Override
529  public int compareTo(ListTableEntry e) {
530  return this.name.compareTo(e.name);
531  }
532  }
533  }
534 
535  private class KeywordsTableModel extends AbstractTableModel {
536 
537  List<KeywordTableEntry> listData = new ArrayList<>();
538 
539  @Override
540  public int getRowCount() {
541  return listData.size();
542  }
543 
544  @Override
545  public int getColumnCount() {
546  return 2;
547  }
548 
549  @Override
550  public String getColumnName(int column) {
551  String ret = null;
552  switch (column) {
553  case 0:
554  ret = NbBundle.getMessage(this.getClass(), "KeywordSearch.nameColLbl");
555  break;
556  case 1:
557  ret = NbBundle.getMessage(this.getClass(), "KeywordSearch.typeColLbl");
558  break;
559  default:
560  break;
561  }
562  return ret;
563  }
564 
565  @Override
566  public Object getValueAt(int rowIndex, int columnIndex) {
567  Object ret = null;
568  KeywordTableEntry entry = null;
569  //iterate until row
570  Iterator<KeywordTableEntry> it = listData.iterator();
571  for (int i = 0; i <= rowIndex; ++i) {
572  entry = it.next();
573  }
574  if (null != entry) {
575  switch (columnIndex) {
576  case 0:
577  ret = (Object) entry.name;
578  break;
579  case 1:
580  ret = (Object) entry.keywordType;
581  break;
582  default:
583  break;
584  }
585  }
586  return ret;
587  }
588 
589  @Override
590  public boolean isCellEditable(int rowIndex, int columnIndex) {
591  return false;
592  }
593 
594  @Override
595  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
596  }
597 
598  @Override
599  public Class<?> getColumnClass(int c) {
600  return getValueAt(0, c).getClass();
601  }
602 
603  void resync(KeywordList list) {
604  listData.clear();
605  for (Keyword k : list.getKeywords()) {
606  listData.add(new KeywordTableEntry(k));
607  }
608  fireTableDataChanged();
609  }
610 
611  void deleteAll() {
612  listData.clear();
613  fireTableDataChanged();
614  }
615 
616  //single model entry
617  private class KeywordTableEntry implements Comparable<KeywordTableEntry> {
618 
619  String name;
620  String keywordType;
621 
622  KeywordTableEntry(Keyword keyword) {
623  this.name = keyword.getSearchTerm();
624  this.keywordType = keyword.getSearchTermType();
625  }
626 
627  @Override
628  public int compareTo(KeywordTableEntry e) {
629  return this.name.compareTo(e.name);
630  }
631  }
632  }
633 
634  private class LeftCheckBoxRenderer extends JCheckBox implements TableCellRenderer {
635 
636  @Override
638  JTable table, Object value,
639  boolean isSelected, boolean hasFocus,
640  int row, int column) {
641 
642  this.setHorizontalAlignment(JCheckBox.CENTER);
643  this.setVerticalAlignment(JCheckBox.CENTER);
644 
645  setEnabled(!ingestRunning);
646 
647  boolean selected = (Boolean) table.getModel().getValueAt(row, 0);
648  setSelected(selected);
649 
650  if (isSelected) {
651  setBackground(listsTable.getSelectionBackground());
652  } else {
653  setBackground(listsTable.getBackground());
654  }
655 
656  return this;
657  }
658  }
659 
663  @NbBundle.Messages({"DropdownListSearchPanel.selected=Ad Hoc Search data source filter is selected"})
664  void updateDataSourceListModel() {
665  getDataSourceListModel().removeAllElements();
666  for (String dsName : getDataSourceArray()) {
667  getDataSourceListModel().addElement(dsName);
668  }
669  setComponentsEnabled();
670  firePropertyChange(Bundle.DropdownListSearchPanel_selected(), null, null);
671 
672  }
673 
677  private void setComponentsEnabled() {
678 
679  if (getDataSourceListModel().size() > 1) {
680  this.dataSourceCheckBox.setEnabled(true);
681 
682  boolean enabled = this.dataSourceCheckBox.isSelected();
683  this.dataSourceList.setEnabled(enabled);
684  if (enabled) {
685  this.dataSourceList.setSelectionInterval(0, this.dataSourceList.getModel().getSize()-1);
686  } else {
687  this.dataSourceList.setSelectedIndices(new int[0]);
688  }
689  } else {
690  this.dataSourceCheckBox.setEnabled(false);
691  this.dataSourceCheckBox.setSelected(false);
692  this.dataSourceList.setEnabled(false);
693  this.dataSourceList.setSelectedIndices(new int[0]);
694  }
695  }
696 
697 }
Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)

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