Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter pop up not updating #11

Closed
chrisjones2004 opened this issue Jul 20, 2012 · 10 comments
Closed

Filter pop up not updating #11

chrisjones2004 opened this issue Jul 20, 2012 · 10 comments
Assignees
Labels

Comments

@chrisjones2004
Copy link

  1. Filter the column "Ints" for value 1 only.
  2. Click "New data" which changes some of the values in the column
  3. Clear the filter

The filter popup does not show the correct values which are now in the column

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;

import org.oxbow.swingbits.table.filter.IFilterChangeListener;
import org.oxbow.swingbits.table.filter.ITableFilter;
import org.oxbow.swingbits.table.filter.JTableFilter;
import org.oxbow.swingbits.table.filter.TableRowFilterSupport;

import java.awt.event.*;

public class TableFilter {
final JTable table;
JTableFilter tableFilter;

public TableFilter() {

    final String[] cols = { "Checkbox", "Ints", "Strings", "Bools", "test" };
    Object[][] data = { { false, 1, "A", false, "hide" },
            { false, 1, "B", false, "hide" },
            { false, 1, "C", false, "hide" } ,{false, 3, "C", false, "hide" }};

    final DefaultTableModel model = newModel(cols, data);
    table = new JTable(model) {
        @Override
        public boolean isCellEditable(int row, int col) {
                return true;
        }

    };
    table.getTableHeader().setReorderingAllowed(false);

    tableFilter = new JTableFilter(table);
    tableFilter.addChangeListener(new IFilterChangeListener(){

        @Override
        public void filterChanged(ITableFilter<?> arg0) {
            System.out.println("Fitler Event");

        }

    });
    TableRowFilterSupport.forFilter(tableFilter).searchable(true).apply();

    JButton newDataButton = new JButton("New Data");
    newDataButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            for(int i = 0;i<table.getRowCount();i++){
                table.setValueAt(i+5, i, 1);
            }
        }

    });


    JPanel buttonPanel = new JPanel();
    buttonPanel.add(newDataButton);

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(new JScrollPane(table), BorderLayout.CENTER);
    panel.add(buttonPanel, BorderLayout.SOUTH);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
}

public void updateNewFilter(){
    tableFilter = new JTableFilter(table);
}

private DefaultTableModel newModel(final String[] cols, Object[][] data) {
    return new DefaultTableModel(data, cols) {
        @Override
        public Class<?> getColumnClass(int column) {
            Class returnValue;
            if ((column >= 0) && (column < getColumnCount())
                    && getRowCount() > 0 && getValueAt(0, column) != null) {
                returnValue = getValueAt(0, column).getClass();
            } else {
                returnValue = Object.class;
            }
            return returnValue;
        }
    };
}




public static void main(String[] args) {
    new TableFilter();
}

}

@chrisjones2004
Copy link
Author

Thanks for fixing this. This now works. However what would be really helpfull is the option of being able to decide whether new data is included in the filter or not. Take these two scenarios for example:

  1. I want to filter out all non-zero values in a column. i.e all distinctcolumnitems are checked apart from 0
    • If a cell in the filtered colum changes from 3 -> 4, it should still be shown in the column
  2. I want to only show zero values in a column. i.e only zero is checked
    • If a cell values changes from 0 -> 1, it should be not be shown in the column any more (current implementatio)

Therefore could you add some method to the filter for example
tableFilter.setVisiblityForNewDistinctColumnItem(boolean b)

@eugener
Copy link
Owner

eugener commented Jul 23, 2012

This requirement would probably be satisfied by the ability to add custom actions. See issue #8.

@chrisjones2004
Copy link
Author

OK thanks, do you know when you are likely to implement this new feature?

@eugener
Copy link
Owner

eugener commented Jul 24, 2012

Working on it. It is one of the few issues left for planned v1.0 release. Would probably estimate 1-2 weeks

@chrisjones2004
Copy link
Author

Thats great, thanks very much.

@chrisjones2004
Copy link
Author

Hows the release coming along? Any updates? The new custom actions will be very useful for me

@eugener
Copy link
Owner

eugener commented Aug 22, 2012

Working on it :) Besides number filtering, do you have anything else in mind?

@chrisjones2004
Copy link
Author

Great :). If possible I suppose I would like the filters to be as close to excel as possible i.e

Numbers: greater than, less than, not equal too, equal too, above/below average
Strings: starts with, ends with, contains, equals, not equal too

The way I would probably do it, is create the most standard filters as concrete custom actions that programmers can simply add, without having to worry about the inner workings.

Then if we want to create more advanced filters there should be an interface we can extend/implement to create our own.

Thanks!

@eugener
Copy link
Owner

eugener commented Jan 11, 2016

Was experimental change at the time :) I added it to the master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants