Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Problems with checked elements in CheckboxTableViewer based on virtual table
Problems with checked elements in CheckboxTableViewer based on virtual table [message #546255] Mon, 12 July 2010 10:05 Go to next message
Ilya  is currently offline Ilya Friend
Messages: 1
Registered: July 2010
Junior Member
Recently I switched on using virtual table (with flag SWT.VIRTUAL) to speed up creating, updating, etc. rows. Content provider implements IStructuredContentProvider.

I noticed two bugs (well, probably, bugs) which I would like to discuss and find workaround. You can reproduce these bugs very easily using posted snippet. It was taken from JFace snippets and modified.

1. If you programmatically select rows in CheckboxTableViewer (using its method setAllChecked) and try to scroll down, rows are displayed as empty. Click "Select/Deselect All" and scroll down table.

2. If again programmatically select rows using its method setAllChecked, then try to get selected data objects using getCheckedElements, some of data objects are nulls, but shouldn`t be as it corrupts method contract. Click "Select/Deselect All", click "Null Rows" and message with number of rows with null data objects will be displayed.

Did anybody met same problems? How did you solve it?

P.S. In my project I need to have table component which works fast with huge number of rows, supports rows sorting and filtering and has checkboxes in rows. Probably, there are any third-party table components with listed properties?

package org.eclipse.jface.snippets.viewers;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;

 * A simple TableViewer to demonstrate the usage of a standard content provider
 * with a virtual table
 * @author Tom Schindl <>
public class Snippet029VirtualTableViewer {
	private class MyContentProvider implements IStructuredContentProvider {
		private MyModel[] elements;

		 * (non-Javadoc)
		 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
		public Object[] getElements(Object inputElement) {
			return elements;

		 * (non-Javadoc)
		 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
		public void dispose() {


		 * (non-Javadoc)
		 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
		 *      java.lang.Object, java.lang.Object)
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
			this.elements = (MyModel[]) newInput;

	public class MyModel {
		public int counter;

		public MyModel(int counter) {
			this.counter = counter;

		public String toString() {
			return "Item " + this.counter;

	public Snippet029VirtualTableViewer(final Shell shell) {
		Table table = new Table(shell, SWT.CHECK | SWT.FULL_SELECTION | SWT.VIRTUAL);
		final CheckboxTableViewer v = new CheckboxTableViewer(table);
		v.setLabelProvider(new LabelProvider());
		v.setContentProvider(new MyContentProvider());
		MyModel[] model = createModel();

		Button b = new Button(shell, SWT.PUSH);
		b.setText("Select/Deselect All");
		b.addSelectionListener(new SelectionAdapter() {
			private boolean selectionState = true;
			public void widgetSelected(SelectionEvent e) {
				selectionState = !selectionState;
		Button b2 = new Button(shell, SWT.PUSH);
		b2.setText("Null Rows");
		b2.addSelectionListener(new SelectionAdapter() {

			public void widgetSelected(SelectionEvent e) {
				Object[] checked = v.getCheckedElements();
				int nullRows = 0;
				for (int i = 0; i < checked.length; i++) {
					if (null == checked[i]) {
				if (nullRows > 0)
					MessageDialog.openError(shell, "Rows data objects", "Number of rows with null data: " + nullRows);
					MessageDialog.openInformation(shell, "Rows data objects", "No null data");

	private MyModel[] createModel() {
		MyModel[] elements = new MyModel[10000];

		for (int i = 0; i < 10000; i++) {
			elements[i] = new MyModel(i);

		return elements;

	 * @param args
	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());
		new Snippet029VirtualTableViewer(shell);;

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())



Re: Problems with checked elements in CheckboxTableViewer based on virtual table [message #1429956 is a reply to message #546255] Tue, 23 September 2014 23:35 Go to previous messageGo to next message
Xihui Chen is currently offline Xihui ChenFriend
Messages: 8
Registered: December 2013
Junior Member
This can be worked around by revealing the item first before checking it:
tableViewer.setSelection(new StructuredSelection(element), true);
Re: Problems with checked elements in CheckboxTableViewer based on virtual table [message #1786872 is a reply to message #1429956] Mon, 14 May 2018 14:45 Go to previous message
Abhishek Chakraborty is currently offline Abhishek ChakrabortyFriend
Messages: 82
Registered: July 2009
Location: Cologne, Germany

The above solution helped

Abhishek Chakraborty
Previous Topic:Downloading Jface separately
Next Topic:The performance optimization of updateChildren() in org.eclipse.jface.viewers.AbstractTreeViewer
Goto Forum:

Current Time: Tue Apr 20 08:20:53 GMT 2021

Powered by FUDForum. Page generated in 0.01430 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top