Example usage for javax.swing RowFilter RowFilter

List of usage examples for javax.swing RowFilter RowFilter

Introduction

In this page you can find the example usage for javax.swing RowFilter RowFilter.

Prototype

RowFilter

Source Link

Usage

From source file:org.omegat.gui.issues.IssuesPanelController.java

void updateFilter() {
    int selection = panel.typeList.getSelectedIndex();
    if (selection < 0) {
        return;/*from  w  w  w. j  a  v a 2s.  com*/
    }
    TypeListModel model = ((TypeListModel) panel.typeList.getModel());
    String type = model.getTypeAt(selection);
    @SuppressWarnings("unchecked")
    TableRowSorter<IssuesTableModel> sorter = (TableRowSorter<IssuesTableModel>) panel.table.getRowSorter();
    sorter.setRowFilter(new RowFilter<IssuesTableModel, Integer>() {
        @Override
        public boolean include(RowFilter.Entry<? extends IssuesTableModel, ? extends Integer> entry) {
            return type == ALL_TYPES || entry.getStringValue(IssueColumn.TYPE.index).equals(type);
        }
    });
    int totalItems = panel.table.getModel().getRowCount();
    if (type == ALL_TYPES) {
        updateTitle(totalItems);
    } else {
        updateTitle((int) model.getCountAt(selection), totalItems);
    }
    panel.table.changeSelection(0, 0, false, false);
}

From source file:org.yccheok.jstock.gui.StockDatabaseJDialog.java

@SuppressWarnings("unchecked")
private void newFilter() {
    final String text = jTextField1.getText();

    // I really have no idea what the second parameter is.
    final RowFilter<StockInfoTableModel, Integer> rf;

    // If current expression doesn't parse, don't update.
    try {//w  w  w  .j  a  v a2  s  . co  m
        // (?i) is for case insensitive.
        rf = RowFilter.regexFilter("^(?i)" + Pattern.quote(text));
    } catch (java.util.regex.PatternSyntaxException e) {
        return;
    }

    if (org.yccheok.jstock.engine.Utils.isPinyinTSTSearchEngineRequiredForSymbol() == false) {
        ((TableRowSorter<StockInfoTableModel>) jTable1.getRowSorter()).setRowFilter(rf);
    } else {
        ((TableRowSorter<StockInfoTableModel>) jTable1.getRowSorter())
                .setRowFilter(new RowFilter<StockInfoTableModel, Integer>() {

                    @Override
                    public boolean include(Entry<? extends StockInfoTableModel, ? extends Integer> entry) {
                        // Try regexFilter first.
                        if (rf.include(entry)) {
                            return true;
                        }
                        // Fail. Further try with pinyin. Pinyin is in lower case.
                        final String lower_text = text.toLowerCase();
                        final StockInfoTableModel model = entry.getModel();
                        final Symbol symbol = model.getStockInfos().get(entry.getIdentifier()).symbol;
                        List<String> pinyins = org.yccheok.jstock.gui.Utils.toHanyuPinyin(symbol.toString());
                        for (String pinyin : pinyins) {
                            if (pinyin.startsWith(lower_text)) {
                                return true;
                            }
                        }
                        return false;
                    }

                });
    }
}

From source file:put.semantic.fcanew.ui.MainWindow.java

private void applyFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyFilterActionPerformed
    try {/*  w ww  .  j av  a2  s  . c  om*/
        final Pattern p = Pattern.compile(filterText.getText(), Pattern.CASE_INSENSITIVE);
        RowFilter<ContextDataModel, Object> rf = new RowFilter<ContextDataModel, Object>() {

            @Override
            public boolean include(RowFilter.Entry<? extends ContextDataModel, ? extends Object> entry) {
                Object id = entry.getValue(0);
                if (!(id instanceof OWLNamedIndividual)) {
                    return true;
                }
                for (String s : getPossibleLabels((OWLNamedIndividual) id)) {
                    if (p.matcher(s).find()) {
                        return true;
                    }
                }
                return false;
            }
        };
        ((TableRowSorter) contextTable.getRowSorter()).setRowFilter(rf);
    } catch (java.util.regex.PatternSyntaxException e) {
        return;
    }
}