Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Selecting the entire row
Selecting the entire row [message #1403242] Tue, 22 July 2014 15:18 Go to next message
Panisha RN is currently offline Panisha RNFriend
Messages: 35
Registered: May 2013
Member
How can i implement complete row selection, Multi row selection

Only cell is getting selected.

I have a context menu contribution to Nattable which is on a view.

I would like the entire row selection whenever i left click or right click on a row.

Can any help me to solve.
Re: Selecting the entire row [message #1403245 is a reply to message #1403242] Tue, 22 July 2014 15:21 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1545
Registered: July 2012
Senior Member
Use the RowSelectionModel. There are several examples in the examples application.
Re: Selecting the entire row [message #1403566 is a reply to message #1403245] Thu, 24 July 2014 12:39 Go to previous messageGo to next message
Panisha RN is currently offline Panisha RNFriend
Messages: 35
Registered: May 2013
Member
Thanks for the reply. It worked.

Now i have a another problem where in i have to select the entire row on right click.

I tried

natTable.getUiBindingRegistry().registerMouseDownBinding(MouseEventMatcher.bodyRightClick(SWT.NONE), new SelectRowAction());

It does not call the action all.

Also tried this one.

uiBindingRegistry.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 = LayerUtil.convertRowPosition(natTable, natTable.getRowPositionByY(event.y), selectionLayer);
if (!selectionLayer.isRowPositionSelected(rowPosition))
{
selectRowAction.run(natTable, event);
}

}
});
}

Run method itself doesnot get called.


Can someone help me.
Re: Selecting the entire row [message #1403572 is a reply to message #1403566] Thu, 24 July 2014 13:06 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1545
Registered: July 2012
Senior Member
Not sure but I think the following code should work. Or using registerFirstSingleClickBinding when you want to override already registered actions.

uiBindingRegistry.registerSingleClickBinding(new MouseEventMatcher(MouseEventMatcher.RIGHT_BUTTON), new ViewportSelectRowCommand(natTable,
    natTable.getRowPositionByY(event.y),
    false,
    false));
Re: Selecting the entire row [message #1403585 is a reply to message #1403572] Thu, 24 July 2014 13:52 Go to previous messageGo to next message
Panisha RN is currently offline Panisha RNFriend
Messages: 35
Registered: May 2013
Member
It works but another question.

If i have mutiple Mouse event binding registered how does it work?

Eg i have some thing like following:

natTable.addConfiguration(new AbstractUiBindingConfiguration()
{
public void configureUiBindings(UiBindingRegistry uiBindingRegistry)
{

uiBindingRegistry.registerFirstMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.BODY, MouseEventMatcher.RIGHT_BUTTON), new
PopupMenuAction(bodyMenu));

uiBindingRegistry.registerFirstSingleClickBinding(new MouseEventMatcher(SWT.NONE, GridRegion.BODY, MouseEventMatcher.RIGHT_BUTTON), new IMouseAction()
{

@Override
public void run(NatTable natTable, MouseEvent event)
{
int rowPosition = LayerUtil.convertRowPosition(natTable,
natTable.getRowPositionByY(event.y), selectionLayer);
System.out.println("Position is " + rowPosition);

}
});

}
});

In this case if i right click on the row it does not get selected.

If i have only one binding it works fine, m oment i inroduce other one it just shows the popup menu, but does not get selected.

I want both action to be preformed when i right click on the row\

i.e row selection and context menu popup.

Please help me to achieve that.

Re: Selecting the entire row [message #1403589 is a reply to message #1403585] Thu, 24 July 2014 14:05 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1545
Registered: July 2012
Senior Member
It doesn't work that way. You need to create a custom action that performs both, selecting the row and opening the menu.
Re: Selecting the entire row [message #1403596 is a reply to message #1403589] Thu, 24 July 2014 14:13 Go to previous messageGo to next message
Panisha RN is currently offline Panisha RNFriend
Messages: 35
Registered: May 2013
Member
Can you please help me hpw the custom actions looks like?

As you already seen i tried using the custom action bu implementing IMouseAction like as shown below.

uiBindingRegistry.registerFirstSingleClickBinding(new MouseEventMatcher(SWT.NONE, GridRegion.BODY, MouseEventMatcher.RIGHT_BUTTON), new IMouseAction()
{

@Override
public void run(NatTable natTable, MouseEvent event)
{
int rowPosition = LayerUtil.convertRowPosition(natTable,
natTable.getRowPositionByY(event.y), selectionLayer);
System.out.println("Position is " + rowPosition);

}
});

But in this case run method is never get called.

Please let me know if i am worng in implementing custom action.
Re: Selecting the entire row [message #1403599 is a reply to message #1403596] Thu, 24 July 2014 14:18 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1545
Registered: July 2012
Senior Member
Create an action like this

public class SelectAndOpenMenuAction implements IMouseAction {

  private Menu menu;

  public SelectAndOpenMenuAction(Menu menu) {
    this.menu = menu;
  }

  @Override
  public void run(NatTable natTable, MouseEvent event) {
    //execute the command for selecting a row
    if (natTable.doCommand(new ViewportSelectRowCommand(natTable,
        natTable.getRowPositionByY(event.y),
        false,
        false))) {
        //open the configured menu (identical to PopupMenuAction)
        menu.setData(event.data);
        menu.setVisible(true);
    }
  }
}


and register like this

uiBindingRegistry.registerSingleClickBinding(new MouseEventMatcher(GridRegion.ROW_HEADER, MouseEventMatcher.RIGHT_BUTTON), new SelectAndOpenMenuAction(deleteMenu));


Thats how it will look like in my upcoming tutorial.
Re: Selecting the entire row [message #1403600 is a reply to message #1403599] Thu, 24 July 2014 14:22 Go to previous message
Panisha RN is currently offline Panisha RNFriend
Messages: 35
Registered: May 2013
Member
Thank you so much i did it in this way and it is working.

natTable.getUiBindingRegistry().registerMouseDownBinding(MouseEventMatcher.bodyRightClick(SWT.NONE), new IMouseAction()
{

@Override
public void run(NatTable natTable, MouseEvent event)
{
bodyMenu.setVisible(true);
int rowPosition = LayerUtil.convertRowPosition(natTable,
natTable.getRowPositionByY(event.y), selectionLayer);
new SelectRowAction().run(natTable, event);

}
});
Previous Topic:Dynamically show and hide column
Next Topic:Mutiple selection By holding control Key
Goto Forum:
  


Current Time: Mon Mar 30 02:32:45 GMT 2015

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

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