Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » TableViewer and adding rows
TableViewer and adding rows [message #436953] Wed, 26 May 2004 16:10 Go to next message
Thomas Tolborg is currently offline Thomas TolborgFriend
Messages: 20
Registered: July 2009
Junior Member
Hello

I am wondering about the best-practice method to implement a way to add
single rows to a tableviewer.

The javadoc for the TableViewer.add method says that it should be called
by the contentprovider.

So .. what should I do. The contentprovider should know the viewer then?
I would then do:
....
TableViewer tableViewer = new TableViewer(parent);
MyContentProvider contentProvider = new MyContentProvider();
contentProvider.setTableViewer(tableViewer);
tableViewer.setContentProvider(contentProvider);
....

and then I would let my model call an add() method on my contentprovider
which in turn would call add() on the tableViewer??

Is that correct, or am I misunderstanding something?

regards,
Thomas Tolborg
Re: TableViewer and adding rows [message #436959 is a reply to message #436953] Wed, 26 May 2004 20:27 Go to previous messageGo to next message
Martin Klinke is currently offline Martin KlinkeFriend
Messages: 80
Registered: July 2009
Member
You won't need the setTableViewer method in your ContentProvider since there
is the argument viewer in the method inputChanged that is invoked each time
when the input is set for the viewer. That's where you get the reference to
the viewer and then can invoke it's methods.

"Thomas Tolborg" <news@tolborg.dk> schrieb im Newsbeitrag
news:c92f48$nmn$1@eclipse.org...
> Hello
>
> I am wondering about the best-practice method to implement a way to add
> single rows to a tableviewer.
>
> The javadoc for the TableViewer.add method says that it should be called
> by the contentprovider.
>
> So .. what should I do. The contentprovider should know the viewer then?
> I would then do:
> ...
> TableViewer tableViewer = new TableViewer(parent);
> MyContentProvider contentProvider = new MyContentProvider();
> contentProvider.setTableViewer(tableViewer);
> tableViewer.setContentProvider(contentProvider);
> ...
>
> and then I would let my model call an add() method on my contentprovider
> which in turn would call add() on the tableViewer??
>
> Is that correct, or am I misunderstanding something?
>
> regards,
> Thomas Tolborg
Re: TableViewer and adding rows [message #436966 is a reply to message #436959] Thu, 27 May 2004 05:20 Go to previous messageGo to next message
Thomas Tolborg is currently offline Thomas TolborgFriend
Messages: 20
Registered: July 2009
Junior Member
Martin Klinke wrote:
> You won't need the setTableViewer method in your ContentProvider since there
> is the argument viewer in the method inputChanged that is invoked each time
> when the input is set for the viewer. That's where you get the reference to
> the viewer and then can invoke it's methods.
>

I don't get it. What if its a different thread that will do the
processing that adds rows to the table.
As far as I can see, the inputChanged method is not called. Its only
called if I use the setInput() method on the tableviewer, but I don't
want to use that since the table does not have any initial input.

/Thomas
Re: TableViewer and adding rows [message #436969 is a reply to message #436959] Thu, 27 May 2004 05:50 Go to previous messageGo to next message
Thomas Tolborg is currently offline Thomas TolborgFriend
Messages: 20
Registered: July 2009
Junior Member
If you look in this example application:
http://www-106.ibm.com/developerworks/library/os-ecjfw/ they add new row
through a static method on the main class... Is that a "correct" way of
doing things?? I would have thought that adding and removing should be
taken care of through the tableviewer.

regards,
Thomas
Re: TableViewer and adding rows [message #436972 is a reply to message #436969] Thu, 27 May 2004 07:55 Go to previous messageGo to next message
Martin Klinke is currently offline Martin KlinkeFriend
Messages: 80
Registered: July 2009
Member
Well, I have just looked at the main class...
This example does not make use of the advantages of a TableViewer at all, it
simply creates one...
There is no content provider, label provider, sorter, filter i.e. the higher
level jface api is not used here.
Actually when using a TableViewer, you implement at least two of the classes
above. Like that you get away from manipulating the table on your own while
describing how the table looks by describing the data you have.

Watch this example and leave away the editor stuff if you don't need it:
http://www.eclipse.org/articles/Article-Table-viewer/table_v iewer.html

Hope this helps.

"Thomas Tolborg" <news@tolborg.dk> schrieb im Newsbeitrag
news:c93v51$dv5$1@eclipse.org...
> If you look in this example application:
> http://www-106.ibm.com/developerworks/library/os-ecjfw/ they add new row
> through a static method on the main class... Is that a "correct" way of
> doing things?? I would have thought that adding and removing should be
> taken care of through the tableviewer.
>
> regards,
> Thomas
Re: TableViewer and adding rows [message #437000 is a reply to message #436972] Thu, 27 May 2004 20:08 Go to previous message
Thomas Tolborg is currently offline Thomas TolborgFriend
Messages: 20
Registered: July 2009
Junior Member
Martin Klinke wrote:
> Well, I have just looked at the main class...
> This example does not make use of the advantages of a TableViewer at all, it
> simply creates one...
> There is no content provider, label provider, sorter, filter i.e. the higher
> level jface api is not used here.
> Actually when using a TableViewer, you implement at least two of the classes
> above. Like that you get away from manipulating the table on your own while
> describing how the table looks by describing the data you have.
>
> Watch this example and leave away the editor stuff if you don't need it:
> http://www.eclipse.org/articles/Article-Table-viewer/table_v iewer.html
>
> Hope this helps.
>

Thanks,
It helped.
Previous Topic:Problem running modified snippet standalone
Next Topic:TableViewer question.
Goto Forum:
  


Current Time: Thu Sep 19 04:26:18 GMT 2024

Powered by FUDForum. Page generated in 0.04410 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top