Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » Preserving cell selection and focus in GridTableViewer
Preserving cell selection and focus in GridTableViewer [message #589243] Sat, 12 April 2008 22:58
Jacek Kolodziejczyk is currently offline Jacek KolodziejczykFriend
Messages: 37
Registered: July 2009
Hi there,

It may seem to be a lower priority to some of you, but I could not stand
the cell selection and focus get messed up after for example sorting the

Don't you think it'd be good to have in the official implementation?

Anyway I attach a quick work around I currently employ. May be someone
would like to use it as it is for the time being or include it into main
branch eventually.


final GridTableViewer v = new GridTableViewer(grid) {
* Represents the cell in the model terms.
* Translates back and forth between model cell and
* current grid coordinates where it's prsented.
class ModelCell {
Object element;
String property;
public ModelCell(Point p) {
property = getColumnProperties()[p.x].toString();
element = getElementAt(p.y);
public Point getPoint() {
return new Point(
grid.indexOf((GridItem) findItem(element)));

protected void preservingSelection(Runnable updateCode) {
if (!getGrid().getCellSelectionEnabled()) {

ArrayList<ModelCell> oldCellSelection = new ArrayList<ModelCell>();
ModelCell oldFocus = null;

boolean restoreSelection = true;
try {
// preserve cell selection
for (Point p: getGrid().getCellSelection()) {
oldCellSelection.add(new ModelCell(p));

// preserve cell focus
if (grid.getFocusItem() != null)
oldFocus = new ModelCell(grid.getFocusCell());

// perform the update

} finally {
// restore selection
if (restoreSelection) {

// set cell selection
for (ModelCell sel: oldCellSelection) {

// set focus
if (oldFocus != null) {
Point p = oldFocus.getPoint();
Previous Topic:[CompositeTable] a question of size
Next Topic:Date selection widgets and DataBinding
Goto Forum:

Current Time: Fri May 25 09:14:19 GMT 2018

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

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

Back to the top