Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Is it possible to sort a TableViewer without refreshing the model?
Is it possible to sort a TableViewer without refreshing the model? [message #548314] Wed, 21 July 2010 13:00 Go to next message
Alexey Romanov is currently offline Alexey RomanovFriend
Messages: 263
Registered: May 2010
Senior Member
I've tried to do this in my ViewerComparator subclass:
public void resort() {
    viewer.setComparator(null);
    viewer.setComparator(this);
}

but this calls getElements twice (and simply
    viewer.setComparator(this);

doesn't trigger resorting, if `this` is already the comparator).

Is there a way to resort elements without getElements being called?

[Updated on: Wed, 21 July 2010 13:01]

Report message to a moderator

Re: Is it possible to sort a TableViewer without refreshing the model? [message #555920 is a reply to message #548314] Mon, 30 August 2010 08:56 Go to previous messageGo to next message
Magnus Rundlof is currently offline Magnus RundlofFriend
Messages: 3
Registered: July 2009
Junior Member
I've been struggeling the same problem, and I can't find a way to re-sort without calling getElements(). However, I managed to minimize the number of calls to getElements() by re-sorting only when necessary.

public final static String SORTER_PROPERTY = "sorterProperty";

tableViewer.setComparator(new ViewerSorter() {
    @Override
    public int compare(Viewer viewer, Object e1, Object e2) {
        [...]
    }
    
    @Override
    public boolean isSorterProperty(Object element, String property) {
        return SORTER_PROPERTY.equals(property);
    }
});

// Update a specific element and trigger re-sorting.
tableViewer.update(element, new String[] { SORTER_PROPERTY });

// Same thing but without re-sorting.
tableViewer.update(element, null);


With reservations for errors... I typed the code, no copy/paste...

Cheers
Re: Is it possible to sort a TableViewer without refreshing the model? [message #556037 is a reply to message #548314] Mon, 30 August 2010 15:58 Go to previous message
Alexey Romanov is currently offline Alexey RomanovFriend
Messages: 263
Registered: May 2010
Senior Member
I ended up just caching the elements array in my class (so getElements() is trivial and it doesn't matter how many times it's called) and updating it manually. It won't work in all cases, but it does in mine.
Previous Topic:TreeViewer PendingUpdateAdapter Refresh Problem
Next Topic:ComboViewer doesn't support images?
Goto Forum:
  


Current Time: Thu Apr 25 20:35:53 GMT 2024

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

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

Back to the top