Home » Eclipse Projects » Standard Widget Toolkit (SWT) » problem with virtual table(the label provider receives always a null object to display)
problem with virtual table [message #513872] |
Thu, 11 February 2010 14:52 |
Luca Ferrari Messages: 159 Registered: November 2009 |
Senior Member |
|
|
Hi all,
I'm experiencing a strange problem with virtual tables in my application, I don't understand if this is a bug or what. IN short each row of the table is empty, even if debugging I can see that the data set into a table item is correct and the data is not null. It seems that the tableitem is set fine, but the label provider is called with a null object to display.
First of all, the declaration of the table viewer has the followings to make the table virtual and to associate a listener for the virtual table:
this.tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.VIRTUAL);
this.tableViewer.setLabelProvider(this.labelProvider);
this.tableViewer.getTable().addListener(SWT.SetData, (Listener) this.tableContentProvider);
Now the label provider for the object is really simple:
public String getColumnText(Object element, int columnIndex) {
// cast the object to a person
if (!(element instanceof Person))
return null;
Person person = (Person) element;
// switch the column
switch (columnIndex) {
case 0:
return person.getSurname();
case 1:
return person.getName();
case 2:
return person.getPersonID();
case 3:
return person.getHireStatusAsString();
case 4:
return person.getSkillCount() + "";
case 5:
return person.getRoleCount() + "";
case 6:
return person.getKknowledgeLevelCount() + "";
case 7:
return person.getPersonEvaluation() + "";
case 8:
return person.getDeficitList().size() + "";
case 9:
return person.getAddress(AddressType.LIVING) + "";
case 10:
return person.getAddress(AddressType.OFFICE) + "";
case 11:
return person.getAddress(AddressType.BORN) + "";
default:
return null;
}
In the case the object passed to the method is null, the label provider does not return any text to show.
The listener associated to the table is the following:
public final void handleEvent(final Event event) {
// get the current table item
TableItem tableItem = (TableItem) event.item;
// now get the next element from the dao
T nextElement = ((ILazyLoadingDAO<T>) getDao()).next();
// add the element to the list model
WritableList model = getWritableListDataModel(false);
if (!model.contains(nextElement))
model.add(nextElement);
// set the table item in the table
tableItem.setData(nextElement);
// uncommenting this makes all the rows visible!
//tableItem.setText( nextElement.toString() );
}
If I uncomment the last line, I can see the first column of the table filled for every row, while without it the table is totally empty. Please note that I've debugged the application in order to see if the nextElement is null, but it is effectively a valid object.
I cannot understand what the problem could be and how to work around it.
Anybody has an idea?
P.S.
I'm using Kubuntu 9.1 with Eclipse 3.5.1 and the plugins about SWT are the following:
ls -l *swt*
-rw-r--r-- 1 luca root 12863 2009-10-30 13:58 org.eclipse.swt_3.5.1.v3555a.jar
-rw-r--r-- 1 luca root 2078648 2009-10-30 13:58 org.eclipse.swt.gtk.linux.x86_64_3.5.1.v3555a.jar
-rw-r--r-- 1 luca root 1761922 2009-10-30 13:58 org.eclipse.swt.gtk.linux.x86_64.source_3.5.1.v3555a.jar
[Updated on: Thu, 11 February 2010 14:58] Report message to a moderator
|
|
|
Re: problem with virtual table [message #513881 is a reply to message #513872] |
Thu, 11 February 2010 15:00 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
This not making a whole lot of sense because TableViewer automagically
works with virtual tables and if you want to laod the items lazily you
pass an ILazyContentProvider.
So you don't have to setup a call back your own beside that your usage
of item.setText() is incorrect because you need to pass the column index
with it! Your code only setts the value for the first cell in a row as
you describe.
Tom
Am 11.02.10 15:52, schrieb Luca Ferrari:
> Hi all,
> I'm experiencing a strange problem with virtual tables in my
> application, I don't understand if this is a bug or what. IN short each
> row of the table is empty, even if debugging I can see that the data set
> into a table item is correct and the data is not null. It seems that the
> tableitem is set fine, but the label provider is called with a null
> object to display.
>
> First of all, the declaration of the table viewer has the followings to
> make the table virtual and to associate a listener for the virtual table:
>
>
> this.tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL |
> SWT.V_SCROLL | SWT.VIRTUAL);
> this.tableViewer.setLabelProvider(this.labelProvider);
> this.tableViewer.getTable().addListener(SWT.SetData, (Listener)
> this.tableContentProvider);
>
>
>
> Now the label provider for the object is really simple:
>
>
> public String getColumnText(Object element, int columnIndex) {
>
> // cast the object to a person
> if (!(element instanceof Person))
> return null;
>
>
> Person person = (Person) element;
>
> // switch the column
> switch (columnIndex) {
> case 0:
> return person.getSurname();
> case 1:
> return person.getName();
> case 2:
> return person.getPersonID();
> case 3:
> return person.getHireStatusAsString();
> case 4:
> return person.getSkillCount() + "";
> case 5:
> return person.getRoleCount() + "";
> case 6:
> return person.getKknowledgeLevelCount() + "";
> case 7:
> return person.getPersonEvaluation() + "";
> case 8:
> return person.getDeficitList().size() + "";
> case 9:
> return person.getAddress(AddressType.LIVING) + "";
> case 10:
> return person.getAddress(AddressType.OFFICE) + "";
> case 11:
> return person.getAddress(AddressType.BORN) + "";
> default:
> return null;
> }
>
>
>
> In the case the object passed to the method is null, the label provider
> does not return any text to show.
> The listener associated to the table is the following:
>
>
> public final void handleEvent(final Event event) {
>
> // get the current table item
> TableItem tableItem = (TableItem) event.item;
> // now get the next element from the dao
> T nextElement = ((ILazyLoadingDAO<T>) getDao()).next();
> // add the element to the list model
> WritableList model = getWritableListDataModel(false);
> if (!model.contains(nextElement))
> model.add(nextElement);
>
> // set the table item in the table
> tableItem.setData(nextElement);
>
> // uncommenting this makes all the rows visible!
> //tableItem.setText( nextElement.toString() );
> }
>
>
>
>
> If I uncomment the last line, I can see the first column of the table
> filled for every row, while without it the table is totally empty.
> Please note that I've debugged the application in order to see if the
> nextElement is null, but it is effectively a valid object.
> I cannot understand what the problem could be and how to work around it.
> Anybody has an idea?
>
|
|
|
Re: problem with virtual table [message #514018 is a reply to message #513872] |
Fri, 12 February 2010 07:47 |
|
Hello Luca
Correct the switch with the appropriate breaks in the getColumnText() of the label provider.
Your label provider reaches the default statement which returns null --> your table does not display anything.
Time is what you make of it.
|
|
|
Re: problem with virtual table [message #514022 is a reply to message #513881] |
Fri, 12 February 2010 08:54 |
Luca Ferrari Messages: 159 Registered: November 2009 |
Senior Member |
|
|
Tom Schindl wrote on Thu, 11 February 2010 10:00 | This not making a whole lot of sense because TableViewer automagically
works with virtual tables and if you want to laod the items lazily you
pass an ILazyContentProvider.
|
Thanks,
I didn't know I have to use a ILazyContentProvider, however I made it one immediatly with the following logic:
public void updateElement(int index) {
// get the object from the cache
T nextElement = ((ILazyLoadingDAO<T>) this.getDao()).get( index );
// refresh the viewer
this.tableViewer.replace(nextElement, index);
}
The problem is that this does not work! I suspect there is a problem or a bug since I got the following:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007fe278977f7a, pid=6946, tid=140611567683856
#
# JRE version: 6.0_15-b03
# Java VM: Java HotSpot(TM) 64-Bit Server VM (14.1-b02 mixed mode linux-amd64 )
# Problematic frame:
# C [libpango-1.0.so.0+0x24f7a] pango_layout_new+0x2a
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
I'm using Linux (Kubuntu 9.1, KDE 4.4) with Eclipse 3.5.1. I don't have a Windows machine to test it now, but I've noted another thing that is quite interesting: my lazy loading mechanism loads a chunk of data (say 10-20 tuples) from the database and then shows them in the table. If I load 10-20 tuples I got the error above, if I load immediatly 200 tuples I don't have the error and I can see the first entries in the table. When I scroll the table to the 200+ tuples I got the error. This makes me think there is a critical section problem, since it seems the UI thread cannot wait the loading of new data. Could it be?
Quote: |
So you don't have to setup a call back your own beside that your usage
of item.setText() is incorrect because you need to pass the column index
with it! Your code only setts the value for the first cell in a row as
you describe.
|
I'm curious to understand why the tableItem.setData() does not work: it should embed the (business) object into the table item, and such object should be displayed according to the label provider. Why instead the label provider receives a null object?
Quote: |
Your label provider reaches the default statement which returns null --> your table does not display anything.
|
I don't think so, because I debugged it and I can see it never reaches the switch at all, since the object passed as argument is null! Moreover the switch has return statements!
[Updated on: Fri, 12 February 2010 08:55] Report message to a moderator
|
|
| | | | |
Goto Forum:
Current Time: Sat Dec 07 02:33:23 GMT 2024
Powered by FUDForum. Page generated in 0.07816 seconds
|