Error deleting columns from nebula grid using Visual Range support

I am trying to remove columns and add new ones to the fog grid, the data in the table will not change. I just want to change the columns used.

I get an error when the Grid throws an exception from the exception limits, iterating through the list of existing columns, but using the endColumnIndex value to stop the loop, but the endColumnIndex value is larger than the list of new columns.

I believe this is due to the use of Visual Range support, and the value for the current columns of the screen is not updated as I delete them.

I wrote a class to reproduce this error here, and I hope someone has a workaround for this problem:

import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
import org.eclipse.nebula.jface.gridviewer.GridViewerColumn;
import org.eclipse.nebula.widgets.grid.GridColumn;
import org.eclipse.nebula.widgets.grid.GridItem;
import org.eclipse.nebula.widgets.grid.GridVisibleRangeSupport;
import org.eclipse.nebula.widgets.grid.GridVisibleRangeSupport.RangeChangedEvent;
import org.eclipse.nebula.widgets.grid.GridVisibleRangeSupport.VisibleRangeChangedListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class GridRangeChangeBug {


    public static void main(String[] args) {
        Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setSize(800, 800);

        shell.setLayout(new GridLayout(1, true));

        Button go = new Button(shell, SWT.PUSH);
        go.setText("Reproduce Bug");

        final GridTableViewer viewer = new GridTableViewer(shell, SWT.H_SCROLL
                | SWT.V_SCROLL | SWT.BORDER);
        viewer.getGrid().setLayoutData(
                new GridData(SWT.FILL, SWT.FILL, true, true));
        viewer.getGrid().setHeaderVisible(true);

        GridVisibleRangeSupport rangeSupport = GridVisibleRangeSupport.createFor(viewer.getGrid());
        rangeSupport.addRangeChangeListener(new VisibleRangeChangedListener() {

            @Override
            public void rangeChanged(RangeChangedEvent event) {


            }
        });


        for (int i = 0; i < 100; i++) {
            GridViewerColumn col = new GridViewerColumn(viewer, SWT.NONE);
            col.getColumn().setWidth(30);
            col.getColumn().setText("" + i);
        }

        go.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                for (GridColumn c : viewer.getGrid().getColumns()) {
                    c.dispose();
                }
                for (int i = 0; i < 10; i++) {
                    GridViewerColumn col = new GridViewerColumn(viewer,
                            SWT.NONE);
                    col.getColumn().setWidth(30);
                    col.getColumn().setText("" + i);
                }
            }

        });

        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }

}
+4
source share

All Articles