use of org.jdesktop.swingx.sort.RowFilters.GeneralFilter in project google-cloud-intellij by GoogleCloudPlatform.
the class ProjectSelectionDialog method createUIComponents.
@VisibleForTesting
void createUIComponents() {
addAccountButton = new JButton();
addAccountButton.addActionListener((event) -> Services.getLoginService().logIn());
// prepare table model and rendering.
projectListTable = new JBTable();
projectListTableModel = new ProjectListTableModel();
projectListTable.setModel(projectListTableModel);
projectListTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
projectListTable.getSelectionModel().addListSelectionListener(e -> validateProjectSelection());
FilteredTextTableCellRenderer filterRenderer = new FilteredTextTableCellRenderer();
projectListTable.setDefaultRenderer(Object.class, filterRenderer);
DoubleClickListener tableDoubleClickListener = new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent event) {
dialogWrapper.clickDefaultButton();
return true;
}
};
tableDoubleClickListener.installOn(projectListTable);
// filter rows based on text field content.
filterTextField = new JBTextField();
TableRowSorter<TableModel> sorter = new TableRowSorter<>(projectListTableModel);
projectListTable.setRowSorter(sorter);
GeneralFilter filter = new GeneralFilter() {
@Override
protected boolean include(Entry value, int index) {
return value.getStringValue(index).toLowerCase().contains(filterTextField.getText().toLowerCase());
}
};
sorter.setRowFilter(filter);
// on filter types, update row filter and renderer.
filterTextField.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
sorter.allRowsChanged();
filterRenderer.setFilterText(filterTextField.getText());
}
});
refreshAction = new RefreshAction();
// prepare account combobox model and rendering.
accountComboBox = new ComboBox<>();
accountComboBox.setRenderer(new AccountComboBoxRenderer());
accountComboBox.addActionListener((event) -> refreshProjectListUi((CredentialedUser) accountComboBox.getSelectedItem()));
progressBar = new JBProgressBar();
progressBar.setIndeterminate(true);
progressBar.setVisible(false);
// wrapper for center panel that holds either project selection or sign in screen.
centerPanelWrapper = new JPanel(new BorderLayout());
}
Aggregations