I'm trying to dispose of columns and add new ones to a Nebula Grid, the data in the table won't change I just want to be able to change the columns used.
I am getting a bug where the Grid is throwing index out of bounds exceptions as it's iterating through a list of existing columns but using a value "endColumnIndex" to stop the loop, but the endColumnIndex value is bigger than the list of new columns.
I believe this is due to using Visual Range Support, and the value for the current on screen columns is not being updated as I am removing them.
I have written a class to reproduce this bug here, and am hoping someone has a workaround for this issue:
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();
}
}