Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Wrong order after inserting a row into a NatTable
Wrong order after inserting a row into a NatTable [message #1811098] Mon, 26 August 2019 20:43 Go to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 234
Registered: July 2009
Senior Member
Hi all,
if I insert a row into a previously reordered NatTable, the origin order is restored (at least in the view). If I save the View and re-open it the re-ordered rows appear in the correct ordering. This leads to some confusion...
I have the following Layer stack:

  • DataLayer (with an underlying GlazedList) => "bodyDataLayer"
  • GlazedListsEventLayer
  • RowReorderLayer
  • SelectionLayer
  • ViewportLayer

The row header data layer is a DefaultRowHeaderDataLayer.

I'm adding a new row with the following method:
    public void addNewItem(myDTO newItem) {
        getMyListData().add(newItem);
	getBodyDataLayer().fireLayerEvent(new RowInsertEvent(getBodyDataLayer(), newPos)); 
    }

Now I do the following steps:

  1. open an existing list
  2. change row ordering
  3. add a new list item => result: previous ordering is displayed
  4. save the document
  5. open the document again => the new row order is applied and the added row is at the end of the list

How can I get the intended behavior (ordering remains stable after inserting an element)?

Thanks in advance,
Ralf.
Re: Wrong order after inserting a row into a NatTable [message #1811107 is a reply to message #1811098] Tue, 27 August 2019 04:55 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2814
Registered: July 2012
Senior Member
I tried the same in one of our examples and I do not see the same issue. But I am running the example with the current code base. Which version do you use?

Also what value has your newPos variable?

My code looks like this:
int newPos = persons.size();
persons.add(new Person(newPos, "Ralph", "Wiggum", Gender.MALE, false, new Date()));
bodyDataLayer.fireLayerEvent(new RowInsertEvent(bodyDataLayer, newPos));


The point is that the RowReorderLayer handles structural changes. If it is able to determine a change with details it tries to update the local states. If it is not able to determine the details the event handling assumes it is a complete change and therefore forgets the current states. This is for example needed in case the whole underlying data structure is replaced. In such a case we need to reset any reordering.

I assume the value of newPos is incorrect in your use case which leads to resetting the reorder. Or you have not the most current code base and you suffer from a bug that has been fixed in the meanwhile.
Re: Wrong order after inserting a row into a NatTable [message #1811109 is a reply to message #1811107] Tue, 27 August 2019 06:03 Go to previous messageGo to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 234
Registered: July 2009
Senior Member
Hi Dirk,
thanks for your fast reply. I've seen that there is a cleanup of all indexes is triggered in case of adding a new line. Then, the new index is taken from underlying layer (in populateIndexOrder()), which is the GlazedList (EventList). Initially, the indexes do have the correct ordering (I've seen it in RowReorderLayer#handleLayerEvent and afterwards in populateIndexOrder).
I'm using version 1.5.0. Could you please tell me which example did you use? I've looked into _5082_RowReorderExample and in the RowReorderLayerStructuralChangeEventTest.
The newPos has the value completeDataList.size(). I want it to place it on the bottom of the table view.

Regards,
Ralf.
Re: Wrong order after inserting a row into a NatTable [message #1811116 is a reply to message #1811109] Tue, 27 August 2019 06:57 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2814
Registered: July 2012
Senior Member
I used the _5083_ColumnAndRowReorderExample but also tested now with _5082_RowReorderExample where it works as expected. Do you see the same issue in those examples? For testing I simply added a header configuration to add a menu to the corner region.

        final NatTable natTable = new NatTable(panel, gridLayer, false);

        // as the autoconfiguration of the NatTable is turned off, we have to
        // add the DefaultNatTableStyleConfiguration manually
        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());

        // add the corner menu configuration for adding the view management
        // action
        natTable.addConfiguration(new AbstractHeaderMenuConfiguration(natTable) {
            @Override
            protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
                return super.createCornerMenu(natTable)
                        .withStateManagerMenuItemProvider()
                        .withMenuItemProvider(new IMenuItemProvider() {

                            @Override
                            public void addMenuItem(NatTable natTable, Menu popupMenu) {
                                // TODO Auto-generated method stub
                                MenuItem menuItem = new MenuItem(popupMenu, SWT.PUSH);
                                menuItem.setText("add");
                                menuItem.setEnabled(true);

                                menuItem.addSelectionListener(new SelectionAdapter() {
                                    @Override
                                    public void widgetSelected(SelectionEvent event) {
                                        int newPos = persons.size();
                                        persons.add(new Person(newPos, "Ralph", "Wiggum", Gender.MALE, false, new Date()));
                                        bodyDataLayer.fireLayerEvent(new RowInsertEvent(bodyDataLayer, newPos));
                                    }
                                });

                            }
                        });
            }
        });
        natTable.configure();


But those examples do not use GlazedLists. And it looks like the GlazedListsEventLayer is actually responsible for the behavior. That layer is a listener on the GlazedLists instance and fires a structural change event without details in case of changes.

You could try to use the DetailGlazedListsEventLayer which is creating events with detail information for list changes. Using that it worked for me in a modified example.

If you see an issue with that layer, please let me know soon. I am about to finish 1.6. But while preparing the release documents I could fix smaller things.
Re: Wrong order after inserting a row into a NatTable [message #1811123 is a reply to message #1811116] Tue, 27 August 2019 08:07 Go to previous message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 234
Registered: July 2009
Senior Member
Hi Dirk,
I found the mistake. The problem was that I've fired a RowInsertEvent after inserting the new element. Since the GlazedListLayer already fired that event the layers gets confused a little ;-) I've removed the additional event, now it works (with DetailGlazedListsEventLayer). Thanks for your help.

Regards,
Ralf.
Previous Topic:excel export
Next Topic:How to correctly register an Action on the GridRegion.Body Mouse.RMB
Goto Forum:
  


Current Time: Fri Jun 25 08:10:46 GMT 2021

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

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

Back to the top