Issue Details (XML | Word | Printable)

Key: UBA-7620
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Janak Mulani
Reporter: Janak Mulani
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
ULCBase

ULCTable with hidden columns throws IndexOutOfBounds exception while requesting cell editors.

Created: 21/Nov/08 07:18 AM   Updated: 17/Dec/08 05:22 PM
Component/s: components
Affects Version/s: UltraLightClient '08 Update 1
Fix Version/s: UltraLightClient '08 Update 2

Issue Links:
Cloners
 


 Description  « Hide
ULCTable with different number of columns in model and view throws IndexOutOfBounds exception while requesting editors. The following snippet demonstrates the problem:
import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.IEditorComponent;
import com.ulcjava.base.application.IRendererComponent;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.ULCTable;
import com.ulcjava.base.application.ULCTextField;
import com.ulcjava.base.application.table.DefaultTableCellRenderer;
import com.ulcjava.base.application.table.DefaultTableModel;
import com.ulcjava.base.application.table.ITableCellEditor;
import com.ulcjava.base.application.table.ULCTableColumn;
import com.ulcjava.base.application.util.Color;
import com.ulcjava.base.development.DevelopmentRunner;


public class PR7620 extends AbstractApplication {

    public static void main(String[] args) {

        DevelopmentRunner.setApplicationClass(PR7620.class);
        DevelopmentRunner.run();
    }

    private ULCTable table;

    public void start() {

        ULCFrame frame = new ULCFrame("PR7620");


        DefaultTableModel model = new DefaultTableModel(new Object[][] { { "A", "B" }, { "C", "D" } }, new String[] {
                "col1", "col2" });

        table = new ULCTable();
        // Workaround
        // table = new MyTable();

        table.setAutoCreateColumnsFromModel(false);

        table.setModel(model);

        table.addColumn(new ULCTableColumn(1));

        // table.getColumnModel().getColumn(0).setCellRenderer(new MyRenderer());
        table.getColumnModel().getColumn(0).setCellEditor(new MyEditor());


        frame.add(table);

        frame.setLocation(200, 200);
        frame.setSize(200, 200);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
    }

    private static class MyEditor extends ULCTextField implements ITableCellEditor {

        public IEditorComponent getTableCellEditorComponent(ULCTable table, Object value, int row) {
            this.setBackground(Color.red);
            return this;
        }

    }

    private static class MyRenderer extends DefaultTableCellRenderer {

        @Override
        public IRendererComponent getTableCellRendererComponent(ULCTable table, Object value, boolean isSelected,
                boolean hasFocus, int row) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row);
            this.setBackground(Color.yellow);
            return this;
        }

    }

    public static class MyTable extends ULCTable {

        private boolean flag = false;

        @Override
        protected void requestCellRendererComponents(int[] range, int[] columns) {
            flag = true;
            super.requestCellRendererComponents(range, columns);
            flag = false;
        }

        @Override
        protected void requestCellEditorComponents(int[] range, int[] columns) {
            flag = true;
            super.requestCellEditorComponents(range, columns);
            flag = false;
        }

        @Override
        public Object getValueAt(int row, int column) {
            if (flag) {
                return getModel().getValueAt(convertRowIndexToModel(row), column);
            } else {
                return super.getValueAt(row, column);
            }
        }
    }
}

While fixing http://www.canoo.com/jira/browse/UBA-7572 the mapping between model rows and view rows was fixed but the mapping between model columns and view columns was overlooked. requestCellEditorComponents should use View columns and not model columns.

The above code shows an extension of ULCTable as a workaround. It passes model index of column to getValueAt of model when it is called from requestCellEditorComponents



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
There are no comments yet on this issue.