Skip to main content



      Home
Home » Eclipse Projects » NatTable » MoveSelectionCommand with multiple cells selected
MoveSelectionCommand with multiple cells selected [message #1724541] Wed, 24 February 2016 08:48 Go to next message
Eclipse UserFriend
Hi,

is there a way to move all selected cells by MoveSelectionCommand? Or is there may be another way to
move all selections?

As fare as I noticed only one cell is selected after the MoveSelectionCommand command was done.

Any hints are appreciated, Martin
Re: MoveSelectionCommand with multiple cells selected [message #1724547 is a reply to message #1724541] Wed, 24 February 2016 09:58 Go to previous messageGo to next message
Eclipse UserFriend
Not supported out of the box. You need to implement this yourself. The default implementation only considers the selection anchor that would move on UI interactions.
Re: MoveSelectionCommand with multiple cells selected [message #1724667 is a reply to message #1724547] Thu, 25 February 2016 06:08 Go to previous messageGo to next message
Eclipse UserFriend
OK noted, thanks.

My task is to move rows up and down. All selected rows shall move and I want to keep the selection
on the moved rows. As my underlying model has to reflect this moved row order I modified the EMF
model by a command and the issue an NatTable command to move the selection.
May be my way to implement the task (moving row up/down) is not perfect. What you be your
recommendation?

Martin

Dirk Fauth schrieb am 24.02.2016 um 15:58:
> Not supported out of the box. You need to implement this yourself. The default implementation only
> considers the selection anchor that would move on UI interactions.
Re: MoveSelectionCommand with multiple cells selected [message #1724675 is a reply to message #1724667] Thu, 25 February 2016 06:49 Go to previous messageGo to next message
Eclipse UserFriend
So it is only to keep the selection on moved rows? Do you have row selection enabled? In that case it is quite simple. Use the RowSelectionModel which tracks the selection by unique row id you have to specify. On cell level it is the PreserveSelectionModel (I think that is the name).
Re: MoveSelectionCommand with multiple cells selected [message #1724727 is a reply to message #1724675] Thu, 25 February 2016 10:36 Go to previous messageGo to next message
Eclipse UserFriend
Yes it is only to keep the selection on moved rows.
After looking up the examples found at github I added the PreserveSelectionModel but now I cant
select cells/rows any more.

The BodyLayerStack code is as follow:
public class BodyLayerStack extends AbstractLayerTransform {
private SelectionLayer mSelectionLayer;
private DataLayer mBodyDataLayer;

public BodyLayerStack(IDataProvider dataProvider) {
mBodyDataLayer = new DataLayer(dataProvider);
mBodyDataLayer.setColumnPercentageSizing(true);
mBodyDataLayer.setColumnWidthPercentageByPosition(0, 20);
mBodyDataLayer.setColumnWidthPercentageByPosition(1, 20);
mBodyDataLayer.setColumnWidthPercentageByPosition(2, 20);
mBodyDataLayer.setColumnWidthPercentageByPosition(3, 13);
mBodyDataLayer.setColumnWidthPercentageByPosition(4, 13);
mBodyDataLayer.setColumnWidthPercentageByPosition(5, 14);
mSelectionLayer = new SelectionLayer(mBodyDataLayer,false);
mSelectionLayer.setSelectionModel(new
PreserveSelectionModel<CorridorItem>(mSelectionLayer, (IRowDataProvider<CorridorItem>) dataProvider,
new IRowIdAccessor<CorridorItem>() {

@Override
public Serializable getRowId(CorridorItem rowObject) {
return rowObject.getClass().hashCode();
}

}));

ViewportLayer viewportLayer = new ViewportLayer(mSelectionLayer);
setUnderlyingLayer(viewportLayer);
}

public SelectionLayer getSelectionLayer() {
return mSelectionLayer;
}

public DataLayer getBodyDataLayer() {
return mBodyDataLayer;
}
}


May be it has to do with enable row selection. But how to do this?

Martin

Dirk Fauth schrieb am 25.02.2016 um 12:49:
> So it is only to keep the selection on moved rows? Do you have row selection enabled? In that case
> it is quite simple. Use the RowSelectionModel which tracks the selection by unique row id you have
> to specify. On cell level it is the PreserveSelectionModel (I think that is the name).
Re: MoveSelectionCommand with multiple cells selected [message #1724729 is a reply to message #1724727] Thu, 25 February 2016 10:44 Go to previous messageGo to next message
Eclipse UserFriend
my mistake was to use

mSelectionLayer = new SelectionLayer(mBodyDataLayer,false);

bu should have used
mSelectionLayer = new SelectionLayer(mBodyDataLayer); //without the false parameter

Now I am able to select a single cell but the whole column is highlighted. Without the selection
model I can select individual cells which I prefer. But how to do this with PreserveSelectionModel?

Martin

Martin Jacob schrieb am 25.02.2016 um 16:36:
> Yes it is only to keep the selection on moved rows.
> After looking up the examples found at github I added the PreserveSelectionModel but now I cant
> select cells/rows any more.
>
> The BodyLayerStack code is as follow:
> public class BodyLayerStack extends AbstractLayerTransform {
> private SelectionLayer mSelectionLayer;
> private DataLayer mBodyDataLayer;
>
> public BodyLayerStack(IDataProvider dataProvider) {
> mBodyDataLayer = new DataLayer(dataProvider);
> mBodyDataLayer.setColumnPercentageSizing(true);
> mBodyDataLayer.setColumnWidthPercentageByPosition(0, 20);
> mBodyDataLayer.setColumnWidthPercentageByPosition(1, 20);
> mBodyDataLayer.setColumnWidthPercentageByPosition(2, 20);
> mBodyDataLayer.setColumnWidthPercentageByPosition(3, 13);
> mBodyDataLayer.setColumnWidthPercentageByPosition(4, 13);
> mBodyDataLayer.setColumnWidthPercentageByPosition(5, 14);
> mSelectionLayer = new SelectionLayer(mBodyDataLayer,false);
> mSelectionLayer.setSelectionModel(new
> PreserveSelectionModel<CorridorItem>(mSelectionLayer, (IRowDataProvider<CorridorItem>)
> dataProvider, new IRowIdAccessor<CorridorItem>() {
>
> @Override
> public Serializable getRowId(CorridorItem rowObject) {
> return rowObject.getClass().hashCode();
> }
>
> }));
>
> ViewportLayer viewportLayer = new ViewportLayer(mSelectionLayer);
> setUnderlyingLayer(viewportLayer);
> }
>
> public SelectionLayer getSelectionLayer() {
> return mSelectionLayer;
> }
>
> public DataLayer getBodyDataLayer() {
> return mBodyDataLayer;
> }
> }
>
>
> May be it has to do with enable row selection. But how to do this?
>
> Martin
>
> Dirk Fauth schrieb am 25.02.2016 um 12:49:
>> So it is only to keep the selection on moved rows? Do you have row selection enabled? In that
>> case it is quite simple. Use the RowSelectionModel which tracks the selection by unique row id
>> you have to specify. On cell level it is the PreserveSelectionModel (I think that is the name).
>
Re: MoveSelectionCommand with multiple cells selected [message #1724734 is a reply to message #1724729] Thu, 25 February 2016 10:57 Go to previous messageGo to next message
Eclipse UserFriend
The whole column is highlighted? Sounds more like an issue regarding your IRowIdAccessor implementation. And looking into it, that is exactly the case. Why should the hashCode of the class of your row object differ between objects?
Re: MoveSelectionCommand with multiple cells selected [message #1724739 is a reply to message #1724734] Thu, 25 February 2016 11:08 Go to previous messageGo to next message
Eclipse UserFriend
The hashCode is individually per row, each row has an individual CorridorItem object instance. Still
problematic?

Dirk Fauth schrieb am 25.02.2016 um 16:57:
> The whole column is highlighted? Sounds more like an issue regarding your IRowIdAccessor
> implementation. And looking into it, that is exactly the case. Why should the hashCode of the
> class of your row object differ between objects?
Re: MoveSelectionCommand with multiple cells selected [message #1724741 is a reply to message #1724739] Thu, 25 February 2016 11:10 Go to previous messageGo to next message
Eclipse UserFriend
And by click at the row header the whole table gets highlighted.
Re: MoveSelectionCommand with multiple cells selected [message #1724744 is a reply to message #1724734] Thu, 25 February 2016 11:25 Go to previous message
Eclipse UserFriend
oh man, what a rookie mistake!


@Override
public Serializable getRowId(CorridorItem rowObject) {
return rowObject.getClass().hashCode();
}

is changed to

@Override
public Serializable getRowId(CorridorItem rowObject) {
return rowObject.toString();
}

thanks for your help!
Previous Topic:Insert new Row in the nattable
Next Topic:Print & fit to page
Goto Forum:
  


Current Time: Sun Jun 15 06:06:06 EDT 2025

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

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

Back to the top