Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » [OT?] TableViewer with multiple colums
[OT?] TableViewer with multiple colums [message #144870] Thu, 16 October 2003 09:58 Go to next message
Eclipse UserFriend
Originally posted by: tcn.spamgourmet.com

Hi!

Well, this probably does not belong to this group but there are no
appropriate ones...

I tried to write a plugin for eclipse. So, I have a TableViewer and I even
already have two colums:

TableColumn column;

column = new TableColumn(viewer.getTable(), SWT.LEFT);
column.setText("One");

column = new TableColumn(viewer.getTable(), SWT.LEFT);
column.setText("Two");

Works. But how do I add text to the various columns? The following code in
the Provider does not work:

public String getColumnText(Object obj, int index)
{
Line l = (Line)obj;

switch (index)
{
case 0 :
return getText(l.getLevel());
case 1 :
return getText(l.getMessage());
}
return "N/A";
}

Only the first column is filled with l.getLevel(), the second remains empty.

Why?

And by the way how do I dynamically add lines to the table?

Thanks :)
Timo
Re: [OT?] TableViewer with multiple colums [message #144879 is a reply to message #144870] Thu, 16 October 2003 10:15 Go to previous messageGo to next message
Eclipse UserFriend
Hi Timo,

I just compared your code to something similar that's working and it
looks pretty much identical, so:

1. Have you tried returning a "test" string from case 1... you say the
column remains empty, but I would expect it to contain "N/A" if this was
not being successfully matched.

2. could getText(l.getMessage()) be returning a null or empty string?

cheers
Rich


Timo Nentwig wrote:
> Hi!
>
> Well, this probably does not belong to this group but there are no
> appropriate ones...
>
> I tried to write a plugin for eclipse. So, I have a TableViewer and I even
> already have two colums:
>
> TableColumn column;
>
> column = new TableColumn(viewer.getTable(), SWT.LEFT);
> column.setText("One");
>
> column = new TableColumn(viewer.getTable(), SWT.LEFT);
> column.setText("Two");
>
> Works. But how do I add text to the various columns? The following code in
> the Provider does not work:
>
> public String getColumnText(Object obj, int index)
> {
> Line l = (Line)obj;
>
> switch (index)
> {
> case 0 :
> return getText(l.getLevel());
> case 1 :
> return getText(l.getMessage());
> }
> return "N/A";
> }
>
> Only the first column is filled with l.getLevel(), the second remains empty.
>
> Why?
>
> And by the way how do I dynamically add lines to the table?
>
> Thanks :)
> Timo
Re: [OT?] TableViewer with multiple colums [message #145057 is a reply to message #144879] Thu, 16 October 2003 12:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tcn.spamgourmet.com

rich boakes wrote:
> 1. Have you tried returning a "test" string from case 1... you say the

Yes :-(

> 2. could getText(l.getMessage()) be returning a null or empty string?

Nope, l.getMessage() returns "message".

The problem must be something like "enabling" the second column or something
since despite two columns are shown

public String getColumnText(Object obj, int index)

is never called with a index != 0. That's actually the problem, everytime
getColumnText() is called, it is called with index == 0.

Cheers
Timo
Re: [OT?] TableViewer with multiple colums [message #145070 is a reply to message #144879] Thu, 16 October 2003 12:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tcn.spamgourmet.com

rich boakes wrote:

> I just compared your code to something similar that's working and it
> looks pretty much identical, so:

Simply create a sample View plugin using eclipse' wizard and add

TableColumn column;

column = new TableColumn(viewer.getTable(), SWT.LEFT);
column.setText("Name");
column.setWidth(200);

column = new TableColumn(viewer.getTable(), SWT.LEFT);
column.setText("Size");
column.setWidth(100);

in createPartControl() directly after the viewer stuff.
Re: [OT?] TableViewer with multiple colums [message #145102 is a reply to message #145057] Thu, 16 October 2003 13:01 Go to previous messageGo to next message
Eclipse UserFriend
Timo Nentwig wrote:
> Nope, l.getMessage() returns "message".
>
> The problem must be something like "enabling" the second column or
something
> since despite two columns are shown
>
> public String getColumnText(Object obj, int index)
>
> is never called with a index != 0. That's actually the problem, everytime
> getColumnText() is called, it is called with index == 0.

Another long shot... I recall seeing something similar once; I think it
was down to me connecting the the wrong label provider.

Where: MyTableLP (implemented ITableLabelProvider) and extended
MyListLP which extended
LabelProvider

I just tested this by replacing the MyTableLP with a MyListLP and saw
exactly the behaviour you describe. If it's not that you're somehow
connected to an old (non ITableLabelProvider) label provider then I'm
right out of ideas!

rich
Re: [OT?] TableViewer with multiple colums [message #145495 is a reply to message #145102] Fri, 17 October 2003 03:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tcn.spamgourmet.com

rich boakes wrote:
> Where: MyTableLP (implemented ITableLabelProvider) and extended
> MyListLP which extended
> LabelProvider
>
> I just tested this by replacing the MyTableLP with a MyListLP and saw
> exactly the behaviour you describe. If it's not that you're somehow
> connected to an old (non ITableLabelProvider) label provider then I'm
> right out of ideas!


class ViewLabelProvider extends LabelProvider
implements
ITableLabelProvider
{
public String getColumnText(Object obj, int index)
{
Line l = (Line)obj;

switch (index)
{
case 0 :
return getText(l.getLevel());
case 1 :
return getText(l.getMessage());
}
return "N/A";
}
public Image getColumnImage(Object obj, int index)
{
return getImage(obj);
}
public Image getImage(Object obj)
{
return PlatformUI.getWorkbench().getSharedImages()
.getImage(ISharedImages.IMG_OBJ_ELEMENT);
}
}

public void createPartControl(Composite parent)
{
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL);
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new ViewLabelProvider());
viewer.setSorter(new NameSorter());
viewer.setInput(ResourcesPlugin.getWorkspace());

TableColumn column;

column = new TableColumn(viewer.getTable(), SWT.LEFT);
column.setText("Name");
column.setWidth(200);

column = new TableColumn(viewer.getTable(), SWT.LEFT);
column.setText("Size");
column.setWidth(100);

viewer.getTable().setHeaderVisible(true);

makeActions();
hookContextMenu();
hookDoubleClickAction();
contributeToActionBars();
}

:-(
--
uggc://avgjvg.qr
Re: [OT?] TableViewer with multiple colums [message #145521 is a reply to message #145495] Fri, 17 October 2003 04:38 Go to previous messageGo to next message
Eclipse UserFriend
Hi Timo - Got it :)

The problem was the position of setLabelProvider()... I re-jigged your
sample code and which now works on the my "TestPlugin".

Solved?

Rich

public void createPartControl(Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
viewer.setContentProvider(new ViewContentProvider());
viewer.setSorter(new NameSorter());
viewer.setInput(ResourcesPlugin.getWorkspace());

TableColumn column;

column = new TableColumn(viewer.getTable(), SWT.LEFT);
column.setText("Name");
column.setWidth(200);

column = new TableColumn(viewer.getTable(), SWT.LEFT);
column.setText("Size");
column.setWidth(100);

// moved to below column addition
viewer.setLabelProvider(new ViewLabelProvider());

viewer.getTable().setHeaderVisible(true);

makeActions();
hookContextMenu();
hookDoubleClickAction();
contributeToActionBars();
}
Re: [OT?] TableViewer with multiple colums [message #145560 is a reply to message #145521] Fri, 17 October 2003 05:52 Go to previous message
Eclipse UserFriend
Originally posted by: tcn.spamgourmet.com

rich boakes wrote:
> The problem was the position of setLabelProvider()... I re-jigged your
> sample code and which now works on the my "TestPlugin".
>
> Solved?

YES! Cool, thanks!

....but the wizard should generate a comment for such stuff...

Timo
Previous Topic:breakpoints visible across projects?
Next Topic:Changing IDE background colour under Motif
Goto Forum:
  


Current Time: Sat Jun 07 16:03:08 EDT 2025

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

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

Back to the top