Skip to main content



      Home
Home » Eclipse Projects » NatTable » UpdateDataCommand + ViewportLayer
UpdateDataCommand + ViewportLayer [message #1843536] Thu, 05 August 2021 01:32 Go to next message
Eclipse UserFriend
Hello,

In one of my previous posts (https://www.eclipse.org/forums/index.php/t/1107637/), you helped me figuring out what I was doing wrong in regards to implementing the data tracking changes and using the UpdateDataCommand did the trick.

What I found out now is that the UpdateDataCommand doesn't work properly when the column that I'm trying to update is not fitting/is not visible in the screen.

Based on some debugging in the code that calculates the coordinates and so on, my assumption is that this happens because when it comes to the ViewportLayer, the columnCount will be always the number of the columns visible.

Is there a way in which I should reconfigure the layers or am I missing something?

Attached the example updated.

Thank you!

Kind Regards,

Alexandra
Re: UpdateDataCommand + ViewportLayer [message #1843540 is a reply to message #1843536] Thu, 05 August 2021 03:53 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

the thing you are missing is the concept of the virtual table added by the ViewportLayer. :)

A viewport means that you only process what is visible. This is especially important for huge tables and the rendering. Without the ViewportLayer the renderers would paint and process everything, even if it is not visible.

That said, if the column you want to modify is not visible, the ViewportLayer would drop the command and would not further process it, as it is not visible. As the NatTable is the top-most layer above the ViewportLayer, you can't trigger an UpdateDataCommand on a command that is not visible.
Another reason for this is the concept of index-position-transformation. The parameters for the UpdateDataCommand are positions. This means they are relative to the layer on which the command is executed. This might not be the index of the row or column on the bottom-most layer.

The issue in your example is that you want to trigger an UpdateDataCommand on a NatTable with the assumption that column 5 means the fifth column in the DataLayer. But using the ViewportLayer in a scrolled or resized state where the column 5 is not visible, will fail. In short, you want to use the column position as a column index.

So you need to shift your execution on the SelectionLayer for example, so the update is even executed if the column is not visible.

SelectionLayer selectionLayer = bodyLayerStack.getSelectionLayer();
int rowPosition = MenuItemProviders.getNatEventData(event).getRowPosition();
int selectionLayerRowPosition = LayerUtil.convertRowPosition(natTable, rowPosition, selectionLayer);
selectionLayer.doCommand(new UpdateDataCommand(
        selectionLayer,
        4,
        selectionLayerRowPosition,
        Boolean.TRUE));
natTable.refresh(false);


The refresh() call is by the way necessary for the same reason. By design it would not be necessary to re-render the table again if something out of the visible area has changed.

Hope that helps.

Re: UpdateDataCommand + ViewportLayer [message #1843544 is a reply to message #1843540] Thu, 05 August 2021 08:45 Go to previous messageGo to next message
Eclipse UserFriend
You're right, my knowledge is pretty limited and I'm more of a copy-cat. :)

I really appreciate the awesome explanation. The solution that you proposed works like a charm.

Thank you very much!

Kind Regards,

Alexandra



Re: UpdateDataCommand + ViewportLayer [message #1843550 is a reply to message #1843544] Thu, 05 August 2021 10:04 Go to previous message
Eclipse UserFriend
Missing knowledge is not a problem as long as you ask to close the knowledge gap. :)

Glad I was able to help!
Previous Topic:Is Nattable Java 11 compatible ?
Next Topic:Drag and Drop in a TreeLayer
Goto Forum:
  


Current Time: Sat May 24 07:08:15 EDT 2025

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

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

Back to the top