Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » problem implementing content provider for a table viewer
problem implementing content provider for a table viewer [message #439233] Wed, 07 July 2004 19:53 Go to next message
Paul Davis is currently offline Paul DavisFriend
Messages: 11
Registered: July 2009
Junior Member
I am getting an assertion exception trying to add a content provider to a
TableViewer with the following code:

TableViewer tv = new TableViewer(new Table(c,SWT.NONE|SWT.SINGLE
SWT.H_SCROLL|SWT.V_SCROLL|SWT.FULL_SELECTION));

tv.setContentProvider(new IContentProvider(){
public void dispose() {}
public void inputChanged(Viewer viewer, Object arg1, Object arg2) {}
});

Also, I am confused about how the IContentProvider is supposed to provide
content.
inputChanged doesn't seem like a method name to get the initial content.

Should I just manipulate the SWT control directly?

thanks
Re: problem implementing content provider for a table viewer [message #439319 is a reply to message #439233] Fri, 09 July 2004 14:03 Go to previous messageGo to next message
Paul E. Keyser is currently offline Paul E. KeyserFriend
Messages: 878
Registered: July 2009
Senior Member
0) Think of the ContentProvider as being rather like the "Subject"
(patterns sense) or "Model" (MVC-sense) of the Viewer.

1) For TableViewer, one must provide not IContentProvider, but
IStructuredContentProvider

2) You will also need to provide a LabelProvider, in particular, one
that implements ITableLabelProvider

3) Whether or not the method-name makes sense is a question I'll evade;
but in fact, within inputChanged() you should take the third parameter,
usually called "newInput", and do something with it -- that is the input
value that you set via Viewer.setInput(); in particular, you should use
it to return something suitable in the method getElements() of the
interface IStructuredContentProvider ...

HTH,
Paul

Paul Davis wrote:
> I am getting an assertion exception trying to add a content provider to a
> TableViewer with the following code:
>
> TableViewer tv = new TableViewer(new Table(c,SWT.NONE|SWT.SINGLE
> SWT.H_SCROLL|SWT.V_SCROLL|SWT.FULL_SELECTION));
>
> tv.setContentProvider(new IContentProvider(){
> public void dispose() {}
> public void inputChanged(Viewer viewer, Object arg1, Object arg2) {}
> });
>
> Also, I am confused about how the IContentProvider is supposed to provide
> content.
> inputChanged doesn't seem like a method name to get the initial content.
>
> Should I just manipulate the SWT control directly?
>
> thanks
Re: problem implementing content provider for a table viewer [message #439323 is a reply to message #439319] Fri, 09 July 2004 17:28 Go to previous messageGo to next message
Paul Davis is currently offline Paul DavisFriend
Messages: 11
Registered: July 2009
Junior Member
Thank you Paul,
Using the other interface works great. It even makes sense, unlike (as I
stated before) the 'required' one didn't.

I think I see the design decision that resulted in having this require a
different interface than the compiler requires. It would be nice if the
javadocs would inform those poor ignorant API consumers like myself.
:)
At any rate, thank you very much. I now have a new entry for my notebook.

Paul Keyser wrote:

> 0) Think of the ContentProvider as being rather like the "Subject"
> (patterns sense) or "Model" (MVC-sense) of the Viewer.
>
> 1) For TableViewer, one must provide not IContentProvider, but
> IStructuredContentProvider
>
> 2) You will also need to provide a LabelProvider, in particular, one
> that implements ITableLabelProvider
>
> 3) Whether or not the method-name makes sense is a question I'll evade;
> but in fact, within inputChanged() you should take the third parameter,
> usually called "newInput", and do something with it -- that is the input
> value that you set via Viewer.setInput(); in particular, you should use
> it to return something suitable in the method getElements() of the
> interface IStructuredContentProvider ...
>
> HTH,
> Paul
>
> Paul Davis wrote:
>> I am getting an assertion exception trying to add a content provider to a
>> TableViewer with the following code:
>>
>> TableViewer tv = new TableViewer(new Table(c,SWT.NONE|SWT.SINGLE
>> SWT.H_SCROLL|SWT.V_SCROLL|SWT.FULL_SELECTION));
>>
>> tv.setContentProvider(new IContentProvider(){
>> public void dispose() {}
>> public void inputChanged(Viewer viewer, Object arg1, Object arg2) {}
>> });
>>
>> Also, I am confused about how the IContentProvider is supposed to provide
>> content.
>> inputChanged doesn't seem like a method name to get the initial content.
>>
>> Should I just manipulate the SWT control directly?
>>
>> thanks
Re: problem implementing content provider for a table viewer [message #439324 is a reply to message #439319] Fri, 09 July 2004 17:43 Go to previous messageGo to next message
Paul Davis is currently offline Paul DavisFriend
Messages: 11
Registered: July 2009
Junior Member
Ok, maybe I'm not "getting it".
So, I've implemented getObjects to return an array of strings.
However, nothing ever shows up in the table.

If the IStructeredContentProvider is the model in MVC, and the TableViewer
is the controller, how do I get the View to look like the Model?

Paul Keyser wrote:

> 0) Think of the ContentProvider as being rather like the "Subject"
> (patterns sense) or "Model" (MVC-sense) of the Viewer.
>
> 1) For TableViewer, one must provide not IContentProvider, but
> IStructuredContentProvider
>
> 2) You will also need to provide a LabelProvider, in particular, one
> that implements ITableLabelProvider
>
> 3) Whether or not the method-name makes sense is a question I'll evade;
> but in fact, within inputChanged() you should take the third parameter,
> usually called "newInput", and do something with it -- that is the input
> value that you set via Viewer.setInput(); in particular, you should use
> it to return something suitable in the method getElements() of the
> interface IStructuredContentProvider ...
>
> HTH,
> Paul
>
> Paul Davis wrote:
>> I am getting an assertion exception trying to add a content provider to a
>> TableViewer with the following code:
>>
>> TableViewer tv = new TableViewer(new Table(c,SWT.NONE|SWT.SINGLE
>> SWT.H_SCROLL|SWT.V_SCROLL|SWT.FULL_SELECTION));
>>
>> tv.setContentProvider(new IContentProvider(){
>> public void dispose() {}
>> public void inputChanged(Viewer viewer, Object arg1, Object arg2) {}
>> });
>>
>> Also, I am confused about how the IContentProvider is supposed to provide
>> content.
>> inputChanged doesn't seem like a method name to get the initial content.
>>
>> Should I just manipulate the SWT control directly?
>>
>> thanks
Re: problem implementing content provider for a table viewer [message #440229 is a reply to message #439324] Mon, 26 July 2004 22:47 Go to previous message
Paul E. Keyser is currently offline Paul E. KeyserFriend
Messages: 878
Registered: July 2009
Senior Member
Um, possibly silly question -- did you call the TableViewer
instance-method "setInput()"? And did you pass in to that method some
object that your IStructureContentProvider implementation of
"inputChanged()" knows what to do with, when it receives that same
object as "newInput"? (Or are you always returning the same String[]
from the getElements() method?)

If you did all that, you may need to call the "layout()" method on the
Composite that hold the Table of your TableViewer.

If that doesn't work, I'm not sure what's up ...

HTH,
Paul

Paul Davis wrote:
> Ok, maybe I'm not "getting it".
> So, I've implemented getObjects to return an array of strings.
> However, nothing ever shows up in the table.
>
> If the IStructeredContentProvider is the model in MVC, and the TableViewer
> is the controller, how do I get the View to look like the Model?
>
> Paul Keyser wrote:
>
>
>>0) Think of the ContentProvider as being rather like the "Subject"
>>(patterns sense) or "Model" (MVC-sense) of the Viewer.
>>
>>1) For TableViewer, one must provide not IContentProvider, but
>>IStructuredContentProvider
>>
>>2) You will also need to provide a LabelProvider, in particular, one
>>that implements ITableLabelProvider
>>
>>3) Whether or not the method-name makes sense is a question I'll evade;
>>but in fact, within inputChanged() you should take the third parameter,
>>usually called "newInput", and do something with it -- that is the input
>>value that you set via Viewer.setInput(); in particular, you should use
>>it to return something suitable in the method getElements() of the
>>interface IStructuredContentProvider ...
>>
>>HTH,
>>Paul
>>
>>Paul Davis wrote:
>>
>>>I am getting an assertion exception trying to add a content provider to a
>>>TableViewer with the following code:
>>>
>>>TableViewer tv = new TableViewer(new Table(c,SWT.NONE|SWT.SINGLE
>>>SWT.H_SCROLL|SWT.V_SCROLL|SWT.FULL_SELECTION));
>>>
>>>tv.setContentProvider(new IContentProvider(){
>>> public void dispose() {}
>>> public void inputChanged(Viewer viewer, Object arg1, Object arg2) {}
>>>});
>>>
>>>Also, I am confused about how the IContentProvider is supposed to provide
>>>content.
>>>inputChanged doesn't seem like a method name to get the initial content.
>>>
>>>Should I just manipulate the SWT control directly?
>>>
>>>thanks
>
>
Previous Topic:[HowTo] cause selection-change in widget during drag?
Next Topic:Complex cells in Table and TreeTable
Goto Forum:
  


Current Time: Fri Apr 19 20:45:06 GMT 2024

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

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

Back to the top