Community
Participate
Working Groups
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()); } } }
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(); } }
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.
I have a hack of this working. Need to determine with SSQ and VI the correct behavior.
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.
This is not required for my current implementation so no need to supply this.
I'm going to fix this. Hope the fix doesn't break you.
Fixed > 20041001