RowReorderCommand not working [message #1693071] |
Tue, 21 April 2015 14:09 |
Ralf Heydenreich Messages: 235 Registered: July 2009 |
Senior Member |
|
|
Hi all,
I've a layer stack with a RowReorderLayer (and others like SelectionLayer, HoverLayer etc). If I move a row via row header anchors this row is displayed correctly at the new position. This shows me that the stack seems to be ok.
Now I've created a context menu with two items ("up", "down"). If I click "up" on a table row the RowReorderCommand gets fired but the Nattable itself doesn't update the view. The definition of the menu item is as follows:
MenuItem moveRowUp = new MenuItem(popupMenu, SWT.PUSH);
moveRowUp.setText(msg.commandDocumentsMoveUpName);
moveRowUp.setImage(Icon.COMMAND_UP.getImage(IconSize.DefaultIconSize));
moveRowUp.setEnabled(true);
moveRowUp.setAccelerator(SWT.ALT + SWT.ARROW_UP); // doesn't work at the moment
moveRowUp.addSelectionListener(new SelectionAdapter() {
/**
* Move an item up or down
*/
@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() - 1; // 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(gridListLayer.getBodyLayerStack().getRowReorderLayer(), pos, pos - 1);
natTable.doCommand(cmd);natTable.refresh();
}
}
});
Even the refresh() call on the NatTable doesn't lead to the new view. Only the selection is moved one row up.
My layer stack is as follows (inside a separate class):
this.sortedList = new SortedList<T>(rowObjectsGlazedList, null);
this.bodyDataProvider = new GlazedListsDataProvider<T>(sortedList, columnPropertyAccessor);
this.bodyDataLayer = new DataLayer(bodyDataProvider);
HoverLayer hoverLayer = new HoverLayer(bodyDataLayer);
glazedListsEventLayer = new GlazedListsEventLayer<T>(hoverLayer, sortedList);
rowReorderLayer = new RowReorderLayer(hoverLayer);
this.selectionLayer = new SelectionLayer(rowReorderLayer);
RowSelectionModel<T> selectionModel = new RowSelectionModel<T>(selectionLayer, bodyDataProvider, rowIdAccessor, false);
selectionLayer.setSelectionModel(selectionModel);
selectionLayer.addConfiguration(new RowOnlySelectionConfiguration<T>());
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
setUnderlyingLayer(viewportLayer);
Even if I set the RowReorderLayer on top of the glazedListsEventLayer the result remains the same. Does anybody see where the mistake is?
TIA,
Ralf.
|
|
|
|
Re: RowReorderCommand not working [message #1693125 is a reply to message #1693090] |
Tue, 21 April 2015 23:32 |
Ralf Heydenreich Messages: 235 Registered: July 2009 |
Senior Member |
|
|
Cool. Works! Thx. Only one more thing... I want to highlight the selected rows. Therefore I've registered a MouseDownBinding:
natTable.getUiBindingRegistry().registerFirstMouseDownBinding(
new MouseEventMatcher(SWT.NONE, GridRegion.BODY, MouseEventMatcher.RIGHT_BUTTON),
new IMouseAction() {
ViewportSelectRowAction selectRowAction = new ViewportSelectRowAction(false, false);
@Override
public void run(NatTable natTable, MouseEvent event) {
int rowPosition = natTable.getRowPositionByY(event.y);
if(!selectionLayer.isRowPositionSelected(rowPosition)) {
selectRowAction.run(natTable, event);
}
}
});
Then I've registered the Popup menu binding:
natTable.getUiBindingRegistry().registerMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.BODY, MouseEventMatcher.RIGHT_BUTTON), new PopupMenuAction(e4Menu));
e4Menu is got from ApplicationModel. Now, if I click on a row in the table it gets only highlighted, but the popup doesn't come up. If I comment out the binding for selection then the popup is displayed correctly (and works). But I want to get both - selected row via right click AND a popup menu. Is this possible?
Regards,
Ralf.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02926 seconds