Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 09:52 Go to next message
Luca Ferrari is currently offline 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 09:58]

Report message to a moderator

Re: problem with virtual table [message #513881 is a reply to message #513872] Thu, 11 February 2010 10:00 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5294
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 02:47 Go to previous messageGo to next message
Catalin Gerea is currently offline Catalin Gerea
Messages: 89
Registered: July 2009
Location: Bucharest, Romania
Member

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 03:54 Go to previous messageGo to next message
Luca Ferrari is currently offline 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 03:55]

Report message to a moderator

Re: problem with virtual table [message #514062 is a reply to message #514022] Fri, 12 February 2010 05:45 Go to previous messageGo to next message
Catalin Gerea is currently offline Catalin Gerea
Messages: 89
Registered: July 2009
Location: Bucharest, Romania
Member

Hello Luca

1. http://java.sun.com/docs/books/tutorial/java/nutsandbolts/sw itch.html -->
Quote:
The break statements are necessary because without them, case statements fall through; that is, without an explicit break, control will flow sequentially through subsequent case statements.
. But this is just for code clearance; as you said the switch statement is never reached.

2. How do you set the input to your table?

3. See http://wiki.eclipse.org/index.php/JFaceSnippets for some examples of lazy content providers, including one for the tableviewer.

4. Regarding the crash I suspect that it is a Linux specific problem (a google search about 'pango_layout_new+0x2a' revealed a lot of bugs); maybe this one https://bugzilla.redhat.com/show_bug.cgi?id=522187) will help you more: it says something about updating your eclipse but since I am not an linux expert I cannot help you with this.


Time is what you make of it.
Re: problem with virtual table [message #514078 is a reply to message #514062] Fri, 12 February 2010 06:29 Go to previous messageGo to next message
Luca Ferrari is currently offline Luca Ferrari
Messages: 159
Registered: November 2009
Senior Member
Hi,
the table viewer receives its input as follows:

	    this.tableViewer.setInput(this.tableContentProvider.getWritableListDataModel(true));
	    
	    if (this.tableContentProvider instanceof BaseLazyLoadingTableContentProvider) {
		this.tableViewer.setContentProvider( this.tableContentProvider );
		this.tableViewer.getTable().setItemCount( this.getTableContentProvider().getDao().countAll());
	    }



where getWritableListDataModel provides the model (a writablelist) with the first chunk of data loaded.

According to this example http:// dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.snippets /Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewe rs/Snippet030VirtualLazyTableViewer.java?view=markup the only difference is that my model is embedded in the content provider as a writable list.

Unluckily, I've already installed the latest packages 355a for swt-gtk, so the workaround proposed in the bug report is not working. Moreover, I'm using kubuntu and don't know how to disable "assistive technology". Hope someone can give me an hint.

Re: problem with virtual table [message #514779 is a reply to message #514078] Tue, 16 February 2010 10:52 Go to previous messageGo to next message
Luca Ferrari is currently offline Luca Ferrari
Messages: 159
Registered: November 2009
Senior Member
I have tried the same application on a Windows (win32) machine and it works pretty fine, I can see the query made against the database as the table rows become visible, and I can see all the elements of the table.
The same code, on my linux (kubuntu 64 bit) box does not show any table entry, that is every row is blank (even if the model has the data in it).
Re: problem with virtual table [message #515052 is a reply to message #514779] Wed, 17 February 2010 10:09 Go to previous message
Luca Ferrari is currently offline Luca Ferrari
Messages: 159
Registered: November 2009
Senior Member
No way, I did an error evaluation the windows version: the data is loaded lazily but the table shows a set of empty rows. So I guess I'm doing something wrong in my code, in the following there is the definition of the table viewer and the association with the content provider:

this.tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.VIRTUAL | SWT.FULL_SELECTION);

this.tableViewer.setContentProvider( this.tableContentProvider );
		this.tableViewer.getTable().setItemCount( this.getTableContentProvider().getDao().countAll());


and the content provider is an ILazyContentProvider with the following definition:

 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);
    }



I cannot see anything wrong here, does anybody has another hint?
Previous Topic:radio button group with no default selection
Next Topic:VerifyListener, statemask
Goto Forum:
  


Current Time: Thu Aug 28 19:25:06 EDT 2014

Powered by FUDForum. Page generated in 0.01853 seconds