A selection model that preserves selection during resort? [message #1334044] |
Mon, 05 May 2014 07:09  |
Eclipse User |
|
|
|
Using org.eclipse.nebula.widgets.nattable.selection.SelectionModel causes the wrong cells to be selected after a sort. org.eclipse.nebula.widgets.nattable.selection.RowSelectionPreserver is depreacated and says that one should use org.eclipse.nebula.widgets.nattable.selection.RowSelectionModel to preserve the selected row when the underlying data changes or column is sorted.
However RowSelectionModel does not fit the bill if you want to be able to select individual cells, rather than complete rows. So a new variant of org.eclipse.nebula.widgets.nattable.selection.SelectionModel is needed that remembers which cells on which rows are selected, so that the selection is still valid after a sort.
Is there such a sort model? Is it a bug that SelectionModel does not preserve selection on sort? Should SelectionModel be modified or should a new selection model be created (RowPreserveringSelectionModel<R>)?
|
|
|
|
|
|
Re: A selection model that preserves selection during resort? [message #1343731 is a reply to message #1343292] |
Fri, 09 May 2014 08:32   |
Eclipse User |
|
|
|
We can't find any discussion on priorities or on the topic on how we can convince you. Can you direct us to where that is discussed?
Do you think this is a bug? Should we report it as a bug? If so, where? What priority should we give that bug if we report it?
We have another proposal:
1. Add new interface
/**
* Selection model that holds two pieces of anchor: the selection anchor and last
* selected cell, in order to correct them after the sort order of the underlying data has changed.
*/
public interface IAnchorSelectionModel extends ISelectionModel {
/**
* Retrieves the position coordinates of selectionAnchor
*/
PositionCoordinate getSelectionAnchor();
/**
* Retrieves the position coordinates of the last selected cell
*/
PositionCoordinate getLastSelectedCell();
/**
* Corrects the coordinates of the selection anchor and the last
* selected cell. Takes resorting into account, by finding the new
* coordinates depending on stored ID:s
*/
void updateAnchors();
}
2. Modify SelectionLayer doCommand(ILayerCommand) to update the anchors upon StructuralRefreshCommand and VisualRefreshCommand:
@Override
public boolean doCommand(ILayerCommand command) {
....
} else if (command instanceof StructuralRefreshCommand && command.convertToTargetLayer(this)) {
if(selectionModel instanceof IAnchorSelectionModel) {
((IAnchorSelectionModel) selectionModel).updateAnchors();
}
} else if (command instanceof VisualRefreshCommand && command.convertToTargetLayer(this)) {
if(selectionModel instanceof IAnchorSelectionModel) {
((IAnchorSelectionModel) selectionModel).updateAnchors();
}
}
return super.doCommand(command);
}
3. Modify SelectionLayer constructor:
public SelectionLayer(IUniqueIndexLayer underlyingLayer, ISelectionModel selectionModel,
boolean useDefaultConfiguration, boolean registerDefaultEventHandler) {
.....
this.selectionModel = selectionModel != null ? selectionModel : new SelectionModel(this);
if(selectionModel instanceof IAnchorSelectionModel) {
lastSelectedCell = ((IAnchorSelectionModel) selectionModel).getLastSelectedCell();
selectionAnchor = ((IAnchorSelectionModel) selectionModel).getSelectionAnchor();
} else {
lastSelectedCell = new PositionCoordinate(this, NO_SELECTION, NO_SELECTION);
selectionAnchor = new PositionCoordinate(this, NO_SELECTION, NO_SELECTION);
}
.....
}
We are happy to implement and contribute this to version 1.1.x. We know this will not affect any existing code since our proposal effectively adds a new mode to SelectionLayer, and the existing uses of SelectionLayer will still use the old mode.
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: A selection model that preserves selection during resort? [message #1368570 is a reply to message #1366916] |
Tue, 20 May 2014 03:16   |
Eclipse User |
|
|
|
Nice idea, but I would modify it a bit for a better API and understandable process. This has of course impact on the API, but in that case it seems to me better.
Try the following:
1. Change the visibility of lastSelectedCell, selectionAnchor, lastSelectedRegion from protected to private
2. Update every reference (in SelectionLayer and other selection related classes) to the corresponding getters (which is a way better API than directly operating on the members themselves)
3. In case the ISelectionModel is of type IAnchorSelectionModel, the getters will return the values from there instead of the local members.
I haven't tested this, but for me this seems to be a better approach than listening to various events and call an update.
In terms of backwards compatibility maybe we should not change the visibility of the fields in the end, as there are users out there that extended SelectionLayer and an API change would cause a minor release instead of a bugfix release. But to find the necessary places to change the implementation, it might be a good way to start and to be sure nothing is missed.
Greez,
Dirk
P.S. could you please try to configure the images so they are not expanding the whole page?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|