Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » RowReorderCommand works only in one direction
RowReorderCommand works only in one direction [message #1745082] Tue, 04 October 2016 21:11 Go to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 186
Registered: July 2009
Senior Member
Hi all,
I've created a table and registered a popup menu for reordering rows. If I do a right click on a row in the table and select "Move up" the row is moved up. If I select "Move down", nothing happens. If I change the row ordering "by hand" (i.e., drag a row to a new position), all things are ok. I think the mistake lies inside my handler, but I cannot get the point...

Here's some code. At first, the MoveEntryUpMenuItem (which works):
        MenuItem moveRowUp = new MenuItem(popupMenu, SWT.PUSH);
        moveRowUp.addSelectionListener(new SelectionAdapter() {

            /**
             * Move an item up
             */
            @Override
            public void widgetSelected(SelectionEvent e) {
                NatEventData natEventData = MenuItemProviders.getNatEventData(e);
                // Get the position of the selected element
                NatTable natTable = natEventData.getNatTable();
                int pos = natEventData.getRowPosition();  // count without header row
                // Do not move one single item
                if (natTable.getRowCount() > 2 && pos > 0) {  // the header row has to be added for this calculation!
                    ILayerCommand cmd = new RowReorderCommand(natTable, pos, pos - 1);
                    natTable.doCommand(cmd);
                }
           }
        });


Now the MoveEntryDownMenuItem, which doesn't work:

        moveRowDown.addSelectionListener(new SelectionAdapter() {
        @Override
            public void widgetSelected(SelectionEvent e) {
                NatEventData natEventData = MenuItemProviders.getNatEventData(e);
                // Get the position of the selected element
                NatTable natTable = natEventData.getNatTable();
                int pos = natEventData.getRowPosition();  // count without header row
                // Do not move one single item
                if (natTable.getRowCount() > 2 && pos < natTable.getRowCount()) {  // the header row has to be added for this calculation!
                    ILayerCommand cmd = new RowReorderCommand(natTable, pos, pos + 1);
                    natTable.doCommand(cmd);
                }
            }
        });


I think it's quite the same code (though I wanted to consolidate it later). Btw., the selection (highlighting) of a whole row is never moved, only the content (if "moved up"). Furthermore, I can't set an accelerator for the menu item (doesn't has any effect).

Any help is appreciated...

TIA,
Ralf.
Re: RowReorderCommand works only in one direction [message #1745125 is a reply to message #1745082] Wed, 05 October 2016 12:39 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2614
Registered: July 2012
Senior Member
IIRC on moving down you need to use +2. Seems to be related to RowReorderLayer#moveRowDown where the internal reordering is performed. Actually the handling as it is right now avoids row reordering in case of dragging to the same position, e.g. take row 3 drag it slightly down so the reorder indicator is shown below the current row. Dropping will do nothing, which is correct IMHO.

If you think this is incorrect (and yes it feels incorrect) feel free to open a ticket. And if you could provide a fix that doesn't break the existing use cases it would be perfect.

Regarding the selection, well the selection is bound to the cell coordinate, not the content by default. If the selection should also move you need to use another SelectionModel, either RowSelectionModel or PreserveSelectionModel.

Regarding the accelerator I have no clue and not time to check.
Re: RowReorderCommand works only in one direction [message #1745156 is a reply to message #1745125] Wed, 05 October 2016 19:01 Go to previous message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 186
Registered: July 2009
Senior Member
Hi Dirk,
thanks for your reply, this is the solution! I've to add +2. It's ok if one knows it Smile

To the selection: I use the RowSelectionModel, but perhaps at the wrong layer, I'll check this.

The accelerator key isn't urgent, I can omit this.

Regards,
Ralf.
Previous Topic:GroupBy - how to refresh groups after data changed?
Next Topic:[Help] Freeze Rows/Colums freezes all indexes down to 0
Goto Forum:
  


Current Time: Thu Sep 20 20:53:29 GMT 2018

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

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

Back to the top