RowReorderCommand works only in one direction [message #1745082] |
Tue, 04 October 2016 21:11 |
Ralf Heydenreich Messages: 235 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.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03263 seconds