ColumnChooserDialog not working with hidden columns

This forum is used by users to request and discuss new product features. Please do not use this forum for technical support including bug reports.

Moderator: JIDE Support

Forum rules
Product suggestions only. Please do not use this forum for technical support including bug reports.

ColumnChooserDialog not working with hidden columns

Postby ricci » Fri Aug 27, 2010 8:43 am

Hello,

I noticed some strange behavior while using the TableColumnChooserDialog. I have a table where I want to remove some columns. So the table itself has for example 20 columns. I want to show 10 of them at application start. 5 can be added with the right click menu on the table header. The last 5 shouldn't be shown at all. The reason for this is, that we want one table for different workflows and want to be able to configure which columns the user can show/hide for each workflow.

The TableColumnChooserDialog is displayed correctly with correct columns selected/fixed. It also doesn't show the columns that the user isn't allowed to see. But when I select one of the columns that aren't selected yet, I get all the columns added that the user shouldn't be able to add.

This behavior only only comes up in the Dialog while die right-click menu on the table works fine.

Is there a way to work around this issue?
ricci
 
Posts: 2
Joined: Fri Aug 27, 2010 8:29 am

Re: ColumnChooserDialog not working with hidden columns

Postby JIDE Support » Fri Aug 27, 2010 9:18 am

Thanks for bug report. Will fix it in 2.10.0. For now, please use the following code for work around.
Code: Select all
        TableColumnChooserPopupMenuCustomizer menuCustomizer = new TableColumnChooserPopupMenuCustomizer() {
            @Override
            protected TableColumnChooserDialog createTableColumnChooserDialog(Window owner, String title, JTable table) {
                if (owner instanceof Frame) {
                    return new TableColumnChooserDialog((Frame) owner, title, table) {
                        @Override
                        public ButtonPanel createButtonPanel() {
                            ButtonPanel buttonPanel = super.createButtonPanel();
                            if (buttonPanel.getComponent(0) instanceof JButton) {
                                Object value = ((JButton) buttonPanel.getComponent(0)).getAction().getValue(Action.NAME);
                                ((JButton) buttonPanel.getComponent(0)).setAction(new AbstractAction("" + value) {
                                    @Override
                                    public void actionPerformed(ActionEvent e) {
                                        showOrHideColumns(getSelectedModelIndices(getSelectedColumns()));
                                        setDialogResult(RESULT_AFFIRMED);
                                        setVisible(false);

                                    }
                                    private int[] getSelectedModelIndices(int[] selectedViewIndices) {
                                        Set<Integer> modelIndexList = new HashSet<Integer>();
                                        if (getHiddenColumns() != null) {
                                            for (int column : getHiddenColumns()) {
                                                if (TableColumnChooser.isVisibleColumn(_table, column)) {
                                                    modelIndexList.add(column);
                                                }
                                            }
                                        }
                                        for (int viewIndex : selectedViewIndices) {
                                            modelIndexList.add(getActualModelIndex(viewIndex));
                                        }
                                        Integer[] indexArray = modelIndexList.toArray(new Integer[modelIndexList.size()]);
                                        Arrays.sort(indexArray);
                                        int[] modelIndices = new int[modelIndexList.size()];
                                        for (int i = 0; i < modelIndexList.size(); i++) {
                                            modelIndices[i] = indexArray[i];
                                        }
                                        return modelIndices;
                                    }

                                    private int getActualModelIndex(int viewListIndex) {
                                        List<Integer> hiddenColumns = getHiddenColumns();
                                        if (hiddenColumns == null || hiddenColumns.size() == 0) {
                                            return viewListIndex;
                                        }

                                        for (int modelIndex = 0, currentIndex = 0; modelIndex < _table.getModel().getColumnCount(); modelIndex++) {
                                            if (!hiddenColumns.contains(modelIndex)) {
                                                if (currentIndex == viewListIndex) {
                                                    return modelIndex;
                                                }
                                                currentIndex++;
                                            }
                                        }
                                        System.err.println("View index should not be larger than column count in the model.");
                                        return -1;
                                    }
                                });
                            }
                            return buttonPanel;
                        }
                    };
                }
                else if (owner instanceof Dialog) {
                    return new TableColumnChooserDialog((Dialog) owner, title, table) {
                        @Override
                        public ButtonPanel createButtonPanel() {
                            ButtonPanel buttonPanel = super.createButtonPanel();
                            return buttonPanel;
                        }
                    };
                }
                return null;
            }
        };

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 33508
Joined: Sun Sep 14, 2003 10:49 am

Re: ColumnChooserDialog not working with hidden columns

Postby ricci » Mon Aug 30, 2010 12:08 am

Thanks for the quick reply.

Your workaround is working as expected.
ricci
 
Posts: 2
Joined: Fri Aug 27, 2010 8:29 am

Re: ColumnChooserDialog not working with hidden columns

Postby JIDE Support » Mon Oct 04, 2010 2:58 pm

Just so you know, this is fixed in 2.10.0 just released.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 33508
Joined: Sun Sep 14, 2003 10:49 am


Return to Product Suggestions

Who is online

Users browsing this forum: No registered users and 2 guests