Search in sources :

Example 1 with GeneralFilter

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());
}
Also used : JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) DoubleClickListener(com.intellij.ui.DoubleClickListener) GeneralFilter(org.jdesktop.swingx.sort.RowFilters.GeneralFilter) JButton(javax.swing.JButton) DocumentAdapter(com.intellij.ui.DocumentAdapter) JBProgressBar(com.intellij.ui.JBProgressBar) JBTextField(com.intellij.ui.components.JBTextField) JBTable(com.intellij.ui.table.JBTable) DocumentEvent(javax.swing.event.DocumentEvent) BorderLayout(java.awt.BorderLayout) CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser) TableModel(javax.swing.table.TableModel) TableRowSorter(javax.swing.table.TableRowSorter) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

CredentialedUser (com.google.cloud.tools.intellij.login.CredentialedUser)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 DocumentAdapter (com.intellij.ui.DocumentAdapter)1 DoubleClickListener (com.intellij.ui.DoubleClickListener)1 JBProgressBar (com.intellij.ui.JBProgressBar)1 JBTextField (com.intellij.ui.components.JBTextField)1 JBTable (com.intellij.ui.table.JBTable)1 BorderLayout (java.awt.BorderLayout)1 MouseEvent (java.awt.event.MouseEvent)1 JButton (javax.swing.JButton)1 JPanel (javax.swing.JPanel)1 DocumentEvent (javax.swing.event.DocumentEvent)1 TableModel (javax.swing.table.TableModel)1 TableRowSorter (javax.swing.table.TableRowSorter)1 GeneralFilter (org.jdesktop.swingx.sort.RowFilters.GeneralFilter)1