Sorting Chinese characters in Jide Grids

This forum is used by users to request and discuss new product features. Please do not use this forum for technical support including bug reports.

Moderator: JIDE Support

Forum rules
Product suggestions only. Please do not use this forum for technical support including bug reports.

Sorting Chinese characters in Jide Grids

Postby ak.the.coolest.one » Thu Apr 15, 2010 5:31 am

Hi,

We are currently using Jide Grids and we need to sort the contents inside the Jide Grids based on our convenience.
It appears to work pretty well in case of English characters.
But we also need to sort Chinese characters that appear in our search.
We need either phonetic sorting or stroke based sorting to work, since they are widely used in the Chinese language.
Currently the sort works and does not throw any errors, but the Chinese letters get sorted according to their ASCII values which is incorrect.

We searched on various forums about some ways to sort the Chinese characters in an ideal manner and found that using Collator is the best possible way.

Does Jide provide any functionality that is similar to the Collator so that we can use it in our Jide Grids to sort the Chinese characters?
ak.the.coolest.one
 
Posts: 4
Joined: Thu Apr 15, 2010 4:59 am

Re: Sorting Chinese characters in Jide Grids

Postby JIDE Support » Thu Apr 15, 2010 6:45 am

Sure. Since Collator implements the class Comparator already, you could achieve your goal by two steps:
1, register a Collator as your Comparator with ObjectComparatorManager#registerComparator(String.class, yourCollator, yourComparatorContext).
2, invoke SortabeTableModel#setColumnComparatorContextProvider() to return the yourComparatorContext.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Sorting Chinese characters in Jide Grids

Postby ak.the.coolest.one » Fri Apr 16, 2010 5:02 am

Hi,

Thanks for your prompt reply.

Based on your inputs, we have written the following code.
We are currently making changes in a class that is extended from the SortableTableModel.

Following is the code snippet.
Code: Select all
Collator myCollator = Collator.getInstance(new Locale("zh"));
ObjectComparatorManager objCompMgr = new ObjectComparatorManager();
ComparatorContext compContext = (ComparatorContext) this.getColumnComparatorContextProvider();
objCompMgr.registerComparator(String.class, myCollator, compContext);


When we applied the above snippet, we are getting a ClassCastException at the initialization of the compContext.
Is there any issue in the code written above. Also for sorting purpose, do we need to add anything more to the code written above?
ak.the.coolest.one
 
Posts: 4
Joined: Thu Apr 15, 2010 4:59 am

Re: Sorting Chinese characters in Jide Grids

Postby JIDE Support » Fri Apr 16, 2010 6:20 am

Please try the following sample code. Please also make sure your originalTableModel#getColumnClass(column) will return String.class.
Code: Select all
        ObjectComparatorManager.registerComparator(String.class, Collator.getInstance(new Locale("zh")), new ComparatorContext("test"));
        SortableTableModel sortableTableModel = (SortableTableModel) TableModelWrapperUtils.getActualTableModel(_sortableTable.getModel(), SortableTableModel.class);
        sortableTableModel.setColumnComparatorContextProvider(new SortableTableModel.ColumnComparatorContextProvider() {
            @Override
            public ComparatorContext getColumnComparatorContext(SortableTableModel tableModel, int column) {
                return new ComparatorContext("test"); // for the column containing Chinese only
            }
        });

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Sorting Chinese characters in Jide Grids

Postby ak.the.coolest.one » Mon Apr 19, 2010 6:10 am

Hi,
Using the code that you provided, we managed to get rid of the ClassCastException.
But the grid does not get sorted at all.
It actually does not do anything, neither does it throw any error nor does it sort.

We also tried calling the super.sort() after the code you provided, then sorting takes place but according to ASCII values.

We have the following sample where sorting is done correctly.

Do we need to write anything more apart from the above code, like calling some other method or writing some more lines of code?

We have attached a zip file that contains an excel sheet that we received from our client, which shows a sample way in which phonetic as well as stroke based sorting is done.
sort-chinese.zip
The way in which sorting is to be done
(6.3 KiB) Downloaded 1752 times
Last edited by ak.the.coolest.one on Mon Apr 19, 2010 6:27 am, edited 1 time in total.
ak.the.coolest.one
 
Posts: 4
Joined: Thu Apr 15, 2010 4:59 am

Re: Sorting Chinese characters in Jide Grids

Postby JIDE Support » Mon Apr 19, 2010 6:27 am

Please make sure the getColumnClass(thatColumn) returns String.class so that all the codes above could take effect.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Sorting Chinese characters in Jide Grids

Postby ak.the.coolest.one » Thu May 06, 2010 9:52 pm

Sorry for the delay in replying you, we were busy in some other activities....
Actually, the getColumnClass(thatColumn) is indeed returning the String.class, but still we are stuck up at the same point....
The grid does not throw any errors, but it does not do any sorting...

Do you have any working example of jide grid along with its source code, where this has been implemented?
If you can provide that to us, it will be of great help.... since if there is some framework level problem from our side, we can ask our product engineering team to make the necessary changes in our source code...
ak.the.coolest.one
 
Posts: 4
Joined: Thu Apr 15, 2010 4:59 am

Re: Sorting Chinese characters in Jide Grids

Postby JIDE Support » Fri May 07, 2010 8:47 am

Sorry about that. The code should work. Anyway, you could try to replace the Collator.getInstance() code to your own comparator to verify if the compare() method get invoked. As long as you verified it, the only problem left will be Collator.

I googled Collator class and it should be able to sort Chinese characters so I provided you that as comparator. Please check if you can find other Chinese character comparator from your experience.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to Product Suggestions

Who is online

Users browsing this forum: Google [Bot] and 12 guests