Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 76391 - SWt.Virtual tables do not callback on getItems
Summary: SWt.Virtual tables do not callback on getItems
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Steve Northover CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 72358
  Show dependency tree
 
Reported: 2004-10-15 16:31 EDT by Tod Creasey CLA
Modified: 2004-11-01 13:59 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tod Creasey CLA 2004-10-15 16:31:18 EDT
20041013

When I call getItems[] the TableItems are created but the SetData callback 
does not occur.

Here is a code snippet to show the issue

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;

/*
 * Created on Oct 15, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author tod
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class VirtualTableTest {

	public static void main(String[] args) {
		
		final Display display = new Display ();
		Shell shell = new Shell (display);
		shell.setLayout(new FillLayout());
		final Table table = new Table(shell, SWT.BORDER | SWT.VIRTUAL);
		table.addListener(SWT.SetData, new Listener() {
			public void handleEvent(Event e) {
				TableItem item = (TableItem)e.item;
				int index = table.indexOf(item);
				item.setText("item "+ String.valueOf(index));
			}
		});
		
		table.setItemCount(20);
		TableItem[] items = table.getItems();
		for (int i = 0; i < items.length; i++) {
			TableItem item = items[i];
			System.out.println(items[i].getText());
		}


	}
}
Comment 1 Steve Northover CLA 2004-10-15 18:39:23 EDT
This is working as designed (obviously not as you wanted).  Here is some code 
that shows that you get the SWT.SetData event after calling getItems().

import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class PR_76391 {
public static void main(String[] args) {
	final Display display = new Display ();
	Shell shell = new Shell (display);
	shell.setLayout(new FillLayout());
	final Table table = new Table(shell, SWT.BORDER | SWT.VIRTUAL);
	table.addListener(SWT.SetData, new Listener() {
		public void handleEvent(Event e) {
			TableItem item = (TableItem)e.item;
			int index = table.indexOf(item);
			item.setText("item "+ String.valueOf(index));
			System.out.println ("ITEM=\"" + item.getText () 
+ "\"");
		}
	});
	table.setItemCount(5);
	TableItem[] items = table.getItems();
	for (int i = 0; i < items.length; i++) {
		TableItem item = items[i];
		System.out.println ("NOTHING=\"" + items[i].getText() + "\"");
	}
	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) display.sleep();
	}
	display.dispose();
}
}
Comment 2 Steve Northover CLA 2004-10-15 18:47:30 EDT
It would be possible for us to send SWT.SetData when item state is queried 
from a virtual item that has not yet been asked for by the operating system.  
I hadn't planned on doing this because it defeats the purpose of being lazy.  
Please reopen if you want this behavior and I'll discuss it with SSQ when I 
get back.  Thanks.
Comment 3 Steve Northover CLA 2004-10-15 19:19:43 EDT
I have a hack of this working.  Need to determine with SSQ and VI the correct 
behavior.
Comment 4 Tod Creasey CLA 2004-10-18 07:51:34 EDT
Actually all I want is a callback when you create a TableItem - if an item is 
not created that is no problem. The problem I was having was that I was 
getting a series of items some of which had data and some didn't.

I would be happy with a way to query the items that were populated - using the 
visible region is not the most effecient way of doing this. I can keep track 
of this myself if you don't think it is a good idea but I wanted to raise the 
issue.
Comment 5 Tod Creasey CLA 2004-10-18 11:45:57 EDT
This is not required for my current implementation so no need to supply this.
Comment 6 Steve Northover CLA 2004-11-01 12:44:45 EST
I'm going to fix this.  Hope the fix doesn't break you.
Comment 7 Steve Northover CLA 2004-11-01 13:59:19 EST
Fixed > 20041001