简体   繁体   English

如何将两个级别的过滤器添加到同一GlazedList表?

[英]How to add two filters in different level to the same GlazedList table?

I have created a table which i want to filter it in two different level. 我创建了一个表,希望将其过滤为两个不同级别。 first filter it with radio button on the file extension like(.jpg, .doc, the rest). 首先使用文件扩展名(如.jpg,.doc等)上的单选按钮对其进行过滤。 Second filter it with textField to search something inside the first filtered. 第二个过滤器使用textField对其进行过滤,以在第一个过滤器中搜索某些内容。 As below you can see in demo i can filter the table with radio button but i don't know how to apply the second level filter (JTextField) on the table. 如下所示,您可以在演示中看到我可以使用单选按钮过滤表格,但是我不知道如何在表格上应用第二级过滤器(JTextField)。

Does any body know how to do it? 有没有人知道该怎么做?

在此处输入图片说明

public class TwoLevelFilterTablePanel extends OeVubPanel {
private static final File DirectoryEngine = new File("C:\\Users\\Public\\Pictures\\Sample Pictures");
private JRadioButton jpg,doc,others;
private ButtonGroup radioSet;
private JTextField txtFilter;
private JTable glazedTable;
private BasicEventList<MyCode> eventList;
private JPanel filterPanel,radioSetPanel;

public TwoLevelFilterTablePanel(BasicEventList<MyCode> eventList) {
    this.eventList=eventList;
    createComponents();
    layoutComponents();
}

public void createComponents() {
    jpg = new JRadioButton("jpg");
    doc= new JRadioButton("doc");
    others= new JRadioButton("other");
    radioSet = new ButtonGroup();
    radioSet.add(jpg);
    radioSet.add(doc);
    radioSet.add(others);
    txtFilter = new JTextField();

    radioSetPanel = new JPanel();
    radioSetPanel.setLayout(new BoxLayout(radioSetPanel, BoxLayout.X_AXIS));
    radioSetPanel.add(jpg);
    radioSetPanel.add(doc);
    radioSetPanel.add(others);
    filterPanel=new JPanel();
    filterPanel.setLayout(new BoxLayout(filterPanel, BoxLayout.Y_AXIS));
    filterPanel.add(radioSetPanel);
    filterPanel.add(txtFilter);

    final BarcodeMatcherEditor barcodeMatcherEditor = new BarcodeMatcherEditor(jpg,doc,others);
    final FilterList filteredRadioSet = new FilterList(eventList, barcodeMatcherEditor);

    // build a JTable
    String[] propertyNames = new String[] {"name", "size","date"};
    String[] columnLabels = new String[] {"Name", "Size","Date"};
    TableFormat tf = GlazedLists.tableFormat(MyCode.class, propertyNames, columnLabels);
    glazedTable = new JTable(new EventTableModel(filteredRadioSet, tf));
}

public void layoutComponents() {
    setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
    add(filterPanel);
    add(new WebScrollPane(glazedTable));
}

public static void main(String[] args) {
    BasicEventList<MyCode> eventList  = new BasicEventList<MyCode>();
    for(File file : DirectoryEngine.listFiles()){
        eventList.add(new MyCode(file.getName(),file.length(),new Date(file.lastModified())));
    }
    TwoLevelFilterTablePanel demo = new TwoLevelFilterTablePanel(eventList );
    JFrame frame = new JFrame();
    Container cp = frame.getContentPane();
    cp.add(demo);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500, 500);
    frame.setLocation(500, 500);
    frame.setVisible(true);
}
} 

MatcherEditor class: MatcherEditor类:

public class BarcodeMatcherEditor extends AbstractMatcherEditor implements ActionListener {
    private JRadioButton jpg,doc,others;
    public BarcodeMatcherEditor(JRadioButton jpg, JRadioButton doc, JRadioButton others) {
        this.jpg = jpg;
        this.doc=doc;
        this.others =others;
        this.jpg.addActionListener(this);
        this.doc.addActionListener(this);
        this.others.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e) {
        final String filter = ((JRadioButton)e.getSource()).getText();
        if (filter == null)
            this.fireMatchAll();
        else
            this.fireChanged(new BarcodeFilterMatcher(filter));
    }

    private static class BarcodeFilterMatcher implements Matcher {
        private final String filter;
        public BarcodeFilterMatcher(String filter) {
            this.filter = filter;
        }
        public boolean matches(Object item) {
            final MyCode code = (MyCode) item;
            return return filter.equals("other") || code.getName().endsWith(this.filter);
        }
    }
}

You simply chain two FilterList s together: 您只需将两个FilterList在一起:

EventList<Person> personLists = ...
...
FilterList<Person> filterListByGender = new FilterList<Person>(personList, genderMatchEditor);
FilterList<Person> filterListBySurname = new FilterList<Person>(filterByGender, textSurnameMatchEditor);
// Continue using the filterListBySurname as you usually would
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式对第二列的glazedList表进行排序? - How programmatically sort glazedList table ascendant acording second column? Glazedlist表的第一行中的IndexOutOfBoundsException? - IndexOutOfBoundsException in the first row of Glazedlist table? 为什么GlazedList表产生IllegalStateException? - Why GlazedList table produce IllegalStateException? 如何在流中使用两个过滤器进行不同的转换 - How to use two filters in stream for different transformations 如何在Java中使用DOM在XML文档中的相同层次结构级别上添加两个或多个相同名称的元素 - How to add two or more elements of the same name at the same hierarchical level in an XML document using DOM in Java GlazedList-仅基于1列的过滤表 - GlazedList - Filter table based on 1 column only 如何将相同的记录插入到java中的两个不同的表中? - How to insert the same record into two different table in java? 如何在两个不同的类中使用相同的add()方法 - How to use the same add() method in two different classes JSP页面如何在同一表中列出两个不同的bean? - How can a JSP page list two different beans in the same table? 如何在JUNG中添加具有相同标签(但不同端点)的两条边? - How to add two edges having the same label (but different endpoints) in JUNG?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM