Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to set the number of visible rows in Table?
How to set the number of visible rows in Table? [message #521315] Wed, 17 March 2010 05:04 Go to next message
balcerman  is currently offline balcerman
Messages: 17
Registered: March 2010
Junior Member
Hello,

I have a table:

Table table = new Table(myComposite, SWT.MULTI);
//table.setItemCount(3);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false);
table.setLinesVisible(true);
table.setHeaderVisible(true);
TableColumn tableColumn = new TableColumn(table, SWT.LEAD);
tableColumn.setText("Name");
tableColumn.setWidth(100);
tableColumn = new TableColumn(table, SWT.LEAD);
tableColumn.setText("Value");
tableColumn.setWidth(100);

viewer = new TableViewer(table);
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new ViewLabelProvider());
//viewer.setItemCount(3);
viewer.setInput(produktAnzahlList);
viewer.refresh();

How can I set the number of displayed rows to i.e. 3, independently from number of rows filled by user data?

I tried to do it in two ways - using method setItemCount() on Table object and on TableViewer object (see commented lines in the code above). The problem is, that while performing the line:

viewer.refresh();

an exception appears:

AssertionFailedException: null argument

which disappears when I comment out the setItemCount() call....
Is this method bugged or am I using it in wrong way?



Whether it's strange behavior and I'd like to understand it, most important to me is to know, how can I actually set the number of displayed rows?

[Updated on: Tue, 23 March 2010 04:38]

Report message to a moderator

Re: Exception while setting number of rows in Table [message #521905 is a reply to message #521315] Fri, 19 March 2010 05:05 Go to previous messageGo to next message
balcerman  is currently offline balcerman
Messages: 17
Registered: March 2010
Junior Member
Nobody knows? Sad

I suspect that the method Table.setItemCount() is not a correct way of fixing the number of displayed rows in the table.

While debugging the code I noticed that inside the RCP code there is an items table size of which is set to 3 but the contents are nulls only. This is why the null pointer assertion in further part of the code appears.


Maybe you know the correct way to fix the number of displayed rows?

I can't believe that nobody needed that Smile

[Updated on: Fri, 19 March 2010 05:07]

Report message to a moderator

Re: Exception while setting number of rows in Table [message #521939 is a reply to message #521905] Fri, 19 March 2010 07:52 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel Krügler
Messages: 853
Registered: July 2009
Senior Member
On 19.03.2010 10:05, balcerman wrote:
> Nobody knows? :(
>
> I suspect that the method Table.setItemCount() is not a correct way of
> fixing the number of displayed rows in the table.
>
> Maybe you know the correct way to achieve it?

The question is *what* are you going to achieve?

In a non-virtual table viewer design I see no reason
to change the item count via setItemCount, because
the viewer uses the IStructuredContentProvider to
derive the number of items. This follows from
the interface function

Object[] getElements(Object inputElement);

So, if you want to change the item number, you
should do that indirectly via the content provider.

In a table viewer with lazy-virtual mode, you would
be required to set the item count manually, see

http://wiki.eclipse.org/JFaceSnippets#Snippet030VirtualLazyT ableViewer

HTH & Greetings from Bremen,

Daniel Krügler
Re: Exception while setting number of rows in Table [message #521973 is a reply to message #521905] Fri, 19 March 2010 09:55 Go to previous messageGo to next message
Grant Gayed is currently offline Grant Gayed
Messages: 2148
Registered: July 2009
Senior Member
To confirm, you're saying you want the Table's height to be what ever is
needed to show exactly three items, right? If so, you need to compute this
height and set the Table's size accordingly. For an example that's related
to this (it gives the number of visible rows based on the current size) see
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet253 .java .
One thing to keep in mind is the horizontal scrollbar. Will your items ever
be too wide to fit in the viewport? If not then you may wish to create your
Table with style SWT.NO_SCROLL | SWT.V_SCROLL so that space will not be
reserved for the horizontal scrollbar.

Grant


"balcerman" <balcerman@wp.pl> wrote in message
news:hnveo1$o09$1@build.eclipse.org...
> Nobody knows? :(
>
> I suspect that the method Table.setItemCount() is not a correct way of
fixing the number of displayed rows in the table.
>
> Maybe you know the correct way to achieve it?
Re: Exception while setting number of rows in Table [message #522348 is a reply to message #521973] Mon, 22 March 2010 09:15 Go to previous messageGo to next message
balcerman  is currently offline balcerman
Messages: 17
Registered: March 2010
Junior Member
Thank you guys for your posts.

What is my goal:

Right now I have a table which is empty in the beginning. What I see on the screen is a very small table, with columns names and only one empty row below. When I add more and more data to the table, the table grows - I can see that additional row appears each time I add the new data.

What I want to have is a table with 5 visible rows, no matter if there is no rows with data or if there are 100 rows with data.


@Grant Gayed: I tried to use setBounds() method from your example but it does not work:

Rectangle rect = table.getClientArea();
rect.height = 200; //this should make table taller (?)
table.setBounds(rect);

The table still has only 1 empty visible row in the beginning.
the method:

table.setSize(100, 200);

also does not help..
Re: Exception while setting number of rows in Table [message #522578 is a reply to message #521315] Tue, 23 March 2010 04:37 Go to previous messageGo to next message
balcerman  is currently offline balcerman
Messages: 17
Registered: March 2010
Junior Member
Here's the code I use to create the table:



private void prepareTable(Composite composite) {

Table table = new Table(composite, SWT.SINGLE | SWT.FULL_SELECTION)

TableViewer viewer = new TableViewer(table);

TableViewerColumn column = new TableViewerColumn(viewer, SWT.LEFT);
column.getColumn().setText("Name");
column.getColumn().setWidth(100);
column = new TableViewerColumn(viewer, SWT.LEFT);
column.getColumn().setText("Surname");
column.getColumn().setWidth(100);
column.setEditingSupport(new ProduktAnzahlEditingSupport(viewer, 1));

table.setHeaderVisible(true);
table.setLinesVisible(true);

viewer.refresh();

}
Re: Exception while setting number of rows in Table [message #522682 is a reply to message #522348] Tue, 23 March 2010 11:19 Go to previous messageGo to next message
Grant Gayed is currently offline Grant Gayed
Messages: 2148
Registered: July 2009
Senior Member
I think it's just a layout issue. If the parent Composite has a layout set
on it then invoking setSize()/setBounds() on the Table won't help because
the layout will change the Table's bounds the next time it's run. The
following snippet should demonstrate what you want.

public static void main (String [] args) {
final int ITEM_COUNT = 1;
Display display = new Display ();
Shell shell = new Shell(display);
// shell.setLayout(new GridLayout()); // uncomment to use a layout
instead
Table table = new Table(shell, SWT.NONE /*SWT.NO_SCROLL |
SWT.V_SCROLL*/);
table.setHeaderVisible(true);
table.setLinesVisible(true);
int desiredHeight = table.getItemHeight() * 5 + table.getHeaderHeight();
if (shell.getLayout() == null) { // <---
table.setSize(200,desiredHeight);
} else {
table.setLayoutData(new GridData(200, desiredHeight)); // assumes
GridLayout
}
for (int i = 0; i < ITEM_COUNT; i++) {
new TableItem(table, SWT.NONE).setText("item " + i);
}
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}

Grant


"balcerman" <balcerman@wp.pl> wrote in message
news:ho7qi6$e85$1@build.eclipse.org...
> Thank you guys for your posts.
>
> What is my goal:
>
> Right now I have a table which is empty in the beginning. What I see on
the screen is a very small table, with columns names and only one empty row
below. When I add more and more data to the table, the table grows - I can
see that additional row appears each time I add the new data.
>
> What I want to have is a table with 5 visible rows, no matter if there is
no rows with data or if there are 100 rows with data.
>
>
> @Grant Gayed: I tried to use setBounds() method from your example but it
does not work:
>
> Rectangle rect = table.getClientArea();
> rect.height = 200; //this should make table taller (?)
> table.setBounds(rect);
>
> The table still has only 1 empty visible row in the beginning.
> the method:
>
> table.setSize(100, 200);
>
> also does not help..
Re: Exception while setting number of rows in Table [message #522857 is a reply to message #522682] Wed, 24 March 2010 04:56 Go to previous message
balcerman  is currently offline balcerman
Messages: 17
Registered: March 2010
Junior Member
It works perfectly Smile

I cannot have an empty GridData in parent Composite but making GridData with width and height works, and I still can set other parametwers in it:

int desiredHeight = table.getItemHeight() * 5 + table.getHeaderHeight();
GridData doubleColumnGridData = new GridData(200, desiredHeight);
doubleColumnGridData.grabExcessHorizontalSpace = false;
doubleColumnGridData.grabExcessVerticalSpace = false;
doubleColumnGridData.horizontalAlignment = SWT.FILL;
doubleColumnGridData.verticalAlignment = SWT.FILL;
doubleColumnGridData.horizontalSpan = 2;

I must say that the order of overwriting parameters and layouts are still a bit magical and obfuscated to me.


Thanks a lot for your help Smile
Previous Topic:how to restart an RCP application?
Next Topic:Errorlog View problem
Goto Forum:
  


Current Time: Wed Jul 30 01:17:33 EDT 2014

Powered by FUDForum. Page generated in 0.02972 seconds