Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » RowReorderCommand not working
RowReorderCommand not working [message #1693071] Tue, 21 April 2015 14:09 Go to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
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 #1693090 is a reply to message #1693071] Tue, 21 April 2015 15:17 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
The error is in the creation of the RowReorderCommand. You are specifying the positions related to the RowReorderLayer, but executing the command on the NatTable. So the position is internally translated which leads to a wrong result.

Since we are taking care of the position translation, this should be the code to go:

int pos = natEventData.getRowPosition();
if (natTable.getRowCount() > 2 && pos > 0) {  
       ILayerCommand cmd = new RowReorderCommand(natTable, pos, pos - 1);
       natTable.doCommand(cmd);
}

Re: RowReorderCommand not working [message #1693125 is a reply to message #1693090] Tue, 21 April 2015 23:32 Go to previous messageGo to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
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.
Re: RowReorderCommand not working [message #1693138 is a reply to message #1693125] Wed, 22 April 2015 04:19 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
So you want to perform row selection and opening the context menu on right click? Is that correct?

This is possible, but not the way you are trying to. It is not possible to register and execute several actions for the same interaction. Only the first found will be executed, which is because of the configuration concept.

That means you need to create a custom action that performs both, selection and opening the menu.
Re: RowReorderCommand not working [message #1693151 is a reply to message #1693138] Wed, 22 April 2015 06:31 Go to previous message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 235
Registered: July 2009
Senior Member
Hm. I'm afraid of it... I'll try it. The problem is that the user don't get a feedback about the row which is meant by right-clicking if you don't highlight it or mark it anyway. But perhaps the Hoverlayer could also help in this case. I'll post my solution if I found one Smile

Regards,
Ralf.
Previous Topic:RowPostSelectionProvider doesn't fire if selection is programmatically executed
Next Topic:changed data in nabula nattable(Cell Value changed) or how to effect from database side
Goto Forum:
  


Current Time: Wed Apr 24 22:29:00 GMT 2024

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

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

Back to the top