Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » How to get preferred size for a custom cell correctly?
How to get preferred size for a custom cell correctly? [message #1005736] Mon, 28 January 2013 13:24 Go to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 257
Registered: July 2012
Senior Member
For getting a preferred size of a cell - I am doing:
ILayerCell cell = natTable.getCellByPosition(colIndex, rowIndex);

ICellPainter cellPainter = natTable.getCellPainter(colIndex, rowIndex, cell, configRegistry);
int preferredColWidth = cellPainter.getPreferredWidth(cell, gc, configRegistry);


This returnes another values, than the values which I get, when doubleclicking the cell border.

How do I get the correct preferred cell width?
Re: How to get preferred size for a custom cell correctly? [message #1005745 is a reply to message #1005736] Mon, 28 January 2013 14:02 Go to previous messageGo to next message
Dirk Fauth is currently online Dirk FauthFriend
Messages: 1406
Registered: July 2012
Senior Member
Well if you double click on the cell border, the AutoResizeColumnCommand is executed. This will check every cell for that column and resize it for autoresize. Without that command executed you should get the current cell width.
Re: How to get preferred size for a custom cell correctly? [message #1005749 is a reply to message #1005745] Mon, 28 January 2013 14:38 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 257
Registered: July 2012
Senior Member
I analized the AutoResizeColumnCommand - it ends up in triggerg the
MaxCellBoundsHelper.getPreferedColumnWidths(IConfigRegistry configRegistry, GCFactory gcFactory, ILayer layer, int[]columnPositions) {


Is that the correct way of getting the preferred column width, or is there a more easy one?

I do not want to use the AutoResizeColumnCommand, because I have a lot of data and AutoResizeColumnCommand walks over each row in the column (not virtual visible rows only).
I would like to restrict the autoColumnWidth to the visible rows only. (I want go over visible Rows, and find the max width for each column)

[Updated on: Mon, 28 January 2013 14:38]

Report message to a moderator

Re: How to get preferred size for a custom cell correctly? [message #1005828 is a reply to message #1005749] Mon, 28 January 2013 21:12 Go to previous messageGo to next message
Dirk Fauth is currently online Dirk FauthFriend
Messages: 1406
Registered: July 2012
Senior Member
Quote:
I want go over visible Rows, and find the max width for each column


As said in another thread, currently there is no way to find out which rows/columns are visible in the viewport. So what you are requesting is not possible at the moment. Feel free to create an enhancement bug on this so we can keep track on that while working on the viewport.
Re: How to get preferred size for a custom cell correctly? [message #1006031 is a reply to message #1005828] Tue, 29 January 2013 15:31 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 257
Registered: July 2012
Senior Member
Getting the values, currently visible in the viewport is not the problem - I am monitorind the IDataProvider and keep know, about visible rows.

The problem is getting the preferred size of a cell correctly.
Is that possible, without triggering the "AutoResizeColumnCommand" ?
Re: How to get preferred size for a custom cell correctly? [message #1006043 is a reply to message #1006031] Tue, 29 January 2013 15:46 Go to previous messageGo to next message
Dirk Fauth is currently online Dirk FauthFriend
Messages: 1406
Registered: July 2012
Senior Member
ATM I don't know about such a possibility. I guess if you need it now, you will have to implement something similar to MaxCellBoundsHelper, limitating the calculation to only the rows and columns that are visible. At least this is what I would suggest to implement in general in NatTable when we know about the visible cells.
Re: How to get preferred size for a custom cell correctly? [message #1006068 is a reply to message #1006043] Tue, 29 January 2013 17:24 Go to previous message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 257
Registered: July 2012
Senior Member
Thnx Dirk.

here is the code, which gets the visible rows:

    /**
     * @return the index of the first visible row
     */
    private int getFirstVisibleRow() {
        int firstRowIndex = viewportLayer.getRowPositionByIndex(0) * -1;
        return firstRowIndex;
    }

    /**
     * @return the index of the last visible row
     */
    private int getLastVisibleRow() {
        int firstVisibleRow = getFirstVisibleRow();
        int lastVisibleRow = firstVisibleRow + viewportLayer.getRowCount() - 1;
        return lastVisibleRow;
    }
Previous Topic:The ICellEditor is never triggered?
Next Topic:Updating a single row?
Goto Forum:
  


Current Time: Mon Nov 24 20:30:10 GMT 2014

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

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