Problem with suggestions list when deleting and adding columns

27 views
Skip to first unread message

Łukasz Sieńko

unread,
Jul 4, 2016, 11:11:58 AM7/4/16
to tablefilter-swing
Hello all,
I have a problem and I hope you could help me. I am adding and deleting  table columns on demand, using pasted code, but on filter panel suggestion values are not refreshed, I have an empty list for every filter (this feature is probably called Auto Choices).
I have read that it should be done automatically so, as far as I understood properly, using event handling generated by methods: getColumnModel().removeColumn(columnToDelete) and getColumnModel().addColumn((columnToAdd) o).
Do you have any suggestions what to do to refresh list of distinct values in every filter column?

public class MyTable extends JXTable {

    public static final int DEFAULT_ROW_HEIGHT = 18;
    private Map hiddenColumns;

    public MyTable(TableModel dm) {
        super(dm);
        initComponents(); // this does some work a calls inside
initFilters() method
        hiddenColumns = new HashMap();
    }
   
    public void hideColumn(String columnName) {
        int index;
        try {
            index = getColumnModel().getColumnIndex(columnName);
        }
        catch (IllegalArgumentException exp) {
            //column is not present - can be already hidden
            return;
        }
        TableColumn columnToHide = getColumnModel().getColumn(index);
        hiddenColumns.put(columnName, columnToHide);
        hiddenColumns.put(":" + columnName, new Integer(index));
        getColumnModel().removeColumn(columnToHide);
    }

    public void showColumn(String columnName) {
        Object o = hiddenColumns.remove(columnName);
        if (o == null) {
            return;
        }
       
        getColumnModel().addColumn((TableColumn) o);
        o = hiddenColumns.remove(":" + columnName);
        if (o == null) {
            return;
        }
        int column = ((Integer) o).intValue();
        int lastColumn = getColumnModel().getColumnCount() - 1;
        if (column < lastColumn) {
            getColumnModel().moveColumn(lastColumn, column);
        }
    }

    private void initFilters() {
        TableFilterHeader filterHeader = new TableFilterHeader(this);
        IFilterEditor filter;
        for (TableColumn col : TableColumn.values()){
            filter = filterHeader.getFilterEditor(col.ordinal());
            if (col.isFiltered()==1)
                filter.setAutoChoices(AutoChoices.ENABLED);
            else filter.setUserInteractionEnabled(false);
        }
    }

coderazzi

unread,
Jul 4, 2016, 2:00:26 PM7/4/16
to tablefilter-swing
Hi, Poczta,

the other columns do have list of choices? That is, for the other
columns, the table filter shows suggestions?

Best,

Luis
> --
> You received this message because you are subscribed to the Google Groups
> "tablefilter-swing" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to tablefilter-sw...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Łukasz Sieńko

unread,
Jul 8, 2016, 3:51:30 AM7/8/16
to tablefilter-swing, l...@coderazzi.net
Hi Luis,
The problem is that there are empty list of choices for every column, for all.
I solved problem, but in a strange way. I will share with you the solution.
Reason why it happens is this:
1) I call this part of code during table initialization:
    private void initFilters() {
        TableFilterHeader filterHeader = new TableFilterHeader(this);
        IFilterEditor filter;
        for (TableColumn col : TableColumn.values()){
            filter = filterHeader.getFilterEditor(col.ordinal());
            if (col.isFiltered()==1)
                filter.setAutoChoices(AutoChoices.ENABLED);
            else filter.setUserInteractionEnabled(false);
        }
    }
2) After I am hiding all columns using above methods hideColumn(String columnName) and then I am showing only columns that should be visible by default (program parameters) using method: showColumn(String columnName).
3) When I after this I load data, problem does not happen.

To solve the problem I changed order of 2) and 3), so first I load data (I do not modify view) an then I hide and show all necessary columns) and I do it every time I load data.
Moreover, when I show column again, I call method from class IFilterEditor, method is: setAutoChoices(AutoChoices.ENABLED). This helped.
I think the problem happens when I initialize your component and manipulate column model before loading data.
Anyway, thanks for interest.
Cheers
!

coderazzi

unread,
Jul 10, 2016, 10:46:00 AM7/10/16
to tablefilter-swing
Hi, Poczta,

than can be very well the issue. The filter header delays performing
some actions, and you are updating the model just after the
initialization.

One question: why don't you update the table / table model, to hide
the columns before creating the table filter header? If you execute
the example supplied with the library, you can see that hiding /
enabling columns, updating attributes separately for each column works
without issues.

Thanks for the feedback, and best regards,

Luis
Reply all
Reply to author
Forward
0 new messages