Bug 95811 - [Viewers] Virtual table must call setItemCount explicitly
Summary: [Viewers] Virtual table must call setItemCount explicitly
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Linux-GTK
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: contained
Keywords:
: 100686 (view as bug list)
Depends on:
Blocks: 154755
  Show dependency tree
 
Reported: 2005-05-18 14:07 EDT by Tod Creasey CLA
Modified: 2019-09-06 16:14 EDT (History)
4 users (show)

See Also:


Attachments
Test classes (2.83 KB, application/octet-stream)
2005-05-18 14:09 EDT, Tod Creasey CLA
no flags Details
Patch (615 bytes, patch)
2005-05-18 14:28 EDT, Tod Creasey CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tod Creasey CLA 2005-05-18 14:07:56 EDT
On GTK you do not get a callback for free to set the item count for virtual
tables. We need to set this explictly to make them work.
Comment 1 Tod Creasey CLA 2005-05-18 14:09:09 EDT
Created attachment 21358 [details]
Test classes
Comment 2 Tod Creasey CLA 2005-05-18 14:19:03 EDT
Also the case on Windows. We should do this when we can in the refreshAll.
Comment 3 Tod Creasey CLA 2005-05-18 14:27:35 EDT
That test class had a bug - here is a better example

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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;
import org.eclipse.swt.widgets.Table;

public class SimplePhantomRowsTest {

	static boolean showAll = true;

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		Display display = new Display();
		Shell shell = new Shell(display, SWT.CLOSE);

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

		Button button = new Button(shell, SWT.TOGGLE);
		button.setText("Toggle");

		final TableViewer table = new TableViewer(shell, SWT.VIRTUAL);
		table.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
		table.getTable().setLinesVisible(true);

		table.setContentProvider(new IStructuredContentProvider() {

			public Object[] getElements(Object inputElement) {
				int size = 5;
				if (showAll)
					size = 15;

				String[] result = new String[size];
				for (int i = 0; i < result.length; i++) {
					result[i] = "Element " + String.valueOf(i);
				}
				return result;
			}

			public void dispose() {
				// TODO Auto-generated method stub

			}

			public void inputChanged(Viewer viewer, Object oldInput,
					Object newInput) {
				// TODO Auto-generated method stub

			}

		});

		table.setLabelProvider(new LabelProvider() {
			public String getText(Object element) {
				return (String) element;
			};
		});

		table.setInput(table);

		button.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				showAll = !showAll;
				table.refresh();
			}
		});

		shell.setSize(300, 400);
		shell.open();
		while (!shell.isDisposed()) {
			display.readAndDispatch();
		}

	}

}
Comment 4 Tod Creasey CLA 2005-05-18 14:28:13 EDT
Created attachment 21368 [details]
Patch
Comment 5 Tod Creasey CLA 2005-05-18 14:28:31 EDT
Comment on attachment 21368 [details]
Patch

These examples have bugs
Comment 6 Tod Creasey CLA 2005-06-20 16:59:22 EDT
*** Bug 100686 has been marked as a duplicate of this bug. ***
Comment 7 Andras Varga CLA 2005-09-05 18:47:52 EDT
TableViewer.internalVirtualRefreshAll() has the following lines:

  //Don't cache if the root is null but cache if it is not lazy.
  if(root != null)
     virtualManager.cachedElements = 
	((IStructuredContentProvider) getContentProvider()).getElements(root);

and I think the setItemCount() call should go into the if's body:

  //Don't cache if the root is null but cache if it is not lazy.
  if(root != null) {
     virtualManager.cachedElements = 
	((IStructuredContentProvider) getContentProvider()).getElements(root);
     table.setItemCount(cachedElements.length);
  }

Apart from this bug, virtual TableViewer works beautiful!!!
Comment 8 Boris Bokowski CLA 2009-11-26 09:53:11 EST
Hitesh is now responsible for watching bugs in the [Viewers] component area.
Comment 9 Eclipse Webmaster CLA 2019-09-06 16:14:05 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.