A text search filtering bar including the title, the text field and a clear button. When text is typed into the field the table contents will be filtered to only those matching the search text.
| 47 | * |
| 48 | */ |
| 49 | public class SearchFilterPanel extends JPanel |
| 50 | implements DisplayableFilter<Object, Object>, DocumentListener, ActionListener |
| 51 | { |
| 52 | |
| 53 | private FilterHandler filterHandler; |
| 54 | private final JTextField searchField = new JTextField(); |
| 55 | private final JButton clearButton = new JButton(Icons.CloseX9.getImageIcon()); |
| 56 | |
| 57 | public SearchFilterPanel() |
| 58 | { |
| 59 | searchField.getDocument().addDocumentListener(this); |
| 60 | clearButton.addActionListener(this); |
| 61 | setLayout(new BorderLayout()); |
| 62 | add(new JLabel(LanguageBundle.getString("in_filterLabel")), BorderLayout.WEST); |
| 63 | add(searchField, BorderLayout.CENTER); |
| 64 | add(clearButton, BorderLayout.EAST); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public void insertUpdate(DocumentEvent e) |
| 69 | { |
| 70 | refreshFilter(); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public void removeUpdate(DocumentEvent e) |
| 75 | { |
| 76 | refreshFilter(); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public void changedUpdate(DocumentEvent e) |
| 81 | { |
| 82 | refreshFilter(); |
| 83 | } |
| 84 | |
| 85 | private void refreshFilter() |
| 86 | { |
| 87 | String text = searchField.getText(); |
| 88 | filterHandler.setSearchEnabled(text != null && !text.isEmpty()); |
| 89 | filterHandler.refilter(); |
| 90 | filterHandler.scrollToTop(); |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public boolean accept(Object context, Object element) |
| 95 | { |
| 96 | String typeStr = ""; //$NON-NLS-1$ |
| 97 | String abbStr = ""; //$NON-NLS-1$ |
| 98 | if (element instanceof InfoFacade) |
| 99 | { |
| 100 | typeStr = ((InfoFacade) element).getType(); |
| 101 | } |
| 102 | else if (element instanceof Campaign) |
| 103 | { |
| 104 | typeStr = ((Campaign) element).getListAsString(ListKey.BOOK_TYPE); |
| 105 | abbStr = ((Campaign) element).get(StringKey.SOURCE_SHORT); |
| 106 | } |
nothing calls this directly
no test coverage detected