Skip to main content



      Home
Home » Eclipse Projects » Remote Application Platform (RAP) » TreeViewer sorts elements by name
TreeViewer sorts elements by name [message #7292] Wed, 14 March 2007 13:38 Go to next message
Eclipse UserFriend
Hi,
I use a TreeViewer to navigate through my Data. Everything is fine,
without the order. So i add a special ViewSorter.
Code Snip
>>>

private ViewerSorter getRevisionSorter() {
return new ViewerSorter(){

protected Comparator getComparator() {
return new Comparator() {
public int compare(Object arg0, Object arg1) {
System.out.println(arg0.getClass() + " -> " + arg0);
if(arg0 instanceof Revision && arg1 instanceof Revision) {
return (int) (((Revision) arg0).getRevisionNumber() - ((Revision)
arg1)
.getRevisionNumber());
}
else
return arg0.toString().compareTo(arg1.toString());
}
};
}

};
}
<<< Snap

The System out shows me that the Objects passed to the Comparator are
Strings. After looking at my ContentProvider I am sure that I have not
Strings in the Tree.
Is this a limitation in Milestone2?
Regards
Karsten
Re: TreeViewer sorts elements by name [message #7998 is a reply to message #7292] Wed, 14 March 2007 16:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jkrause.innoopract.com

Hi,

The ViewerSorter works as expected from our experience, here is a code
snippet from our online demo and the output:

viewer.setSorter( new ViewerSorter() {
public int compare( final Viewer viewer,
final Object e1,
final Object e2 )
{
System.out.println( e1.getClass() + " -> " + e1 );
String name1 = Util.getName( ( ( IUser )e1 ) );
String name2 = Util.getName( ( ( IUser )e2 ) );
return name1.compareTo( name2 );
}
} );

class org.eclipse.rap.showcase.model.User ->
org.eclipse.rap.showcase.model.User@57807a

It seems to be a problem on your end.

Cheers,

Jochen

Karsten Panier wrote:
> Hi,
> I use a TreeViewer to navigate through my Data. Everything is fine,
> without the order. So i add a special ViewSorter.
> Code Snip
> >>>
>
> private ViewerSorter getRevisionSorter() {
> return new ViewerSorter(){
>
> protected Comparator getComparator() {
> return new Comparator() {
> public int compare(Object arg0, Object arg1) {
> System.out.println(arg0.getClass() + " -> " +
> arg0);
> if(arg0 instanceof Revision && arg1 instanceof
> Revision) {
> return (int) (((Revision)
> arg0).getRevisionNumber() - ((Revision) arg1)
> .getRevisionNumber());
> }
> else
> return
> arg0.toString().compareTo(arg1.toString());
> }
> };
> }
>
> };
> }
> <<< Snap
>
> The System out shows me that the Objects passed to the Comparator are
> Strings. After looking at my ContentProvider I am sure that I have not
> Strings in the Tree.
> Is this a limitation in Milestone2?
> Regards
> Karsten
Re: TreeViewer sorts elements by name [message #8274 is a reply to message #7998] Thu, 15 March 2007 06:13 Go to previous message
Eclipse UserFriend
Hi,
I found my mistake. I override the method getComparer of ViewerSorter.
Now I override the method compare(Viewer,Object,Object) of the
ViewerComparator.
Thanks.
Karsten


Jochen Krause schrieb:
> Hi,
>
> The ViewerSorter works as expected from our experience, here is a code
> snippet from our online demo and the output:
>
> viewer.setSorter( new ViewerSorter() {
> public int compare( final Viewer viewer,
> final Object e1,
> final Object e2 )
> {
> System.out.println( e1.getClass() + " -> " + e1 );
> String name1 = Util.getName( ( ( IUser )e1 ) );
> String name2 = Util.getName( ( ( IUser )e2 ) );
> return name1.compareTo( name2 );
> }
> } );
>
> class org.eclipse.rap.showcase.model.User ->
> org.eclipse.rap.showcase.model.User@57807a
>
> It seems to be a problem on your end.
>
> Cheers,
>
> Jochen
>
> Karsten Panier wrote:
>> Hi,
>> I use a TreeViewer to navigate through my Data. Everything is fine,
>> without the order. So i add a special ViewSorter.
>> Code Snip
>> >>>
>>
>> private ViewerSorter getRevisionSorter() {
>> return new ViewerSorter(){
>>
>> protected Comparator getComparator() {
>> return new Comparator() {
>> public int compare(Object arg0, Object arg1) {
>> System.out.println(arg0.getClass() + " -> " +
>> arg0);
>> if(arg0 instanceof Revision && arg1 instanceof
>> Revision) {
>> return (int) (((Revision)
>> arg0).getRevisionNumber() - ((Revision) arg1)
>> .getRevisionNumber());
>> }
>> else
>> return
>> arg0.toString().compareTo(arg1.toString());
>> }
>> };
>> }
>> };
>> }
>> <<< Snap
>>
>> The System out shows me that the Objects passed to the Comparator are
>> Strings. After looking at my ContentProvider I am sure that I have not
>> Strings in the Tree.
>> Is this a limitation in Milestone2?
>> Regards
>> Karsten
Previous Topic:Restore minimized application or shell
Next Topic:Browser Buttons and Menue
Goto Forum:
  


Current Time: Fri Apr 25 00:25:36 EDT 2025

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

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

Back to the top