The Source for Java Technology Collaboration

Home » java.net Forums » Java Desktop Technologies » SwingLabs

Thread: JXTable with Java 1.6 sorting/filtering

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 4 - Last Post: Apr 13, 2008 12:14 AM by: rturnbull
rturnbull

Posts: 460
JXTable with Java 1.6 sorting/filtering
Posted: Apr 10, 2008 1:17 AM
  Click to reply to this thread Reply

I have uploaded to the incubator at
https://jdnc-incubator.dev.java.net/source/browse/jdnc-incubator/src/rturnbull/java/org/jdesktop/swingx/
modified versions of JXTable and JXTableHeader enabled for Java 1.6 sorting/filtering

I have java version 1.6.0_03

I have removed all references to sorting/filtering from both classes, except for shift-click
to remove sorting from a column, and double-click to pack a column.

The only additional reference to sorting now in JXTable is a convenience method
setSortOrder(), which builds a SortKey and resets the RowSorter. Most of the 'sort'
methods in the current JXTable are now available via the RowSorter. Convenience
methods could be written for them, but I don't know how many would actually be used.

It is more a proof of concept than a a final modification as the mouse click capturing in
JXTable header should probably be done with the rest in BasicTableHeaderUI, (see
double-click point below) but any class with UI in the name is mysterious territory to me,
peopled with wizards using arcane arts and curious magic.
(I could probably do the mod to BasicTableHeaderUI, but have no idea how to force use
of the modded version)

A case in point is that the current double-click to pack a column seems to only
be done if it is the 'resizing column' I don't understand this, so I pack the column
regardless. Also (in Windows XP anyway) when you do a double-click, you also get a
single-click event also, so when one tries to pack a column, you also toggle the sort.

Another interesting fact I found, is that if you click to sort on column 1, then click on
column 2, it actually sorts column 1 within column 2. If you then shift-click on column 2
to remove the sort, it reverts to sorting on column 1.

I have also uploaded two other classes ExtendableDefaultRowSorter, which is a copy of
DefaultRowSorter with a couple of methods changed from private to protected, and
SummaryTableRowSorter, which is a copy of TableRowSorter with a few mods.
The point of these is to enable a table to have the last n rows always sort at the end of
the table, and never be filtered out. n applies to the last n rows of the model and can be
specified in the SummaryTableRowSorter constructor, or defaults to 1.

There is also a demo program (I know it's under java/ rather than demo/, but I have
enough trouble getting things in the right place as it is)

I would be interested in any comments. I have done minimal testing, but am using it in
my project so will see how it goes.

Also, it upsets my sortable tree table.

Kleopatra
Re: JXTable with Java 1.6 sorting/filtering
Posted: Apr 10, 2008 1:22 AM   in response to: rturnbull
  Click to reply to this thread Reply


Hi Ray,

just a quick note for now: there's a wiki page about what's
required/tricky to get 1.6-style sorting in SwingX which you probably
are aware of :-)

Will have a thorough look at your code asap.

Cheers
Jeanette

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net


rturnbull

Posts: 460
Re: JXTable with Java 1.6 sorting/filtering
Posted: Apr 10, 2008 11:08 PM   in response to: Kleopatra
  Click to reply to this thread Reply

>
> Hi Ray,
>
> just a quick note for now: there's a wiki page about
> what's
> required/tricky to get 1.6-style sorting in SwingX
> which you probably
> are aware of :-)
>
> Will have a thorough look at your code asap.
>
> Cheers
> Jeanette
>


Thanks Jeanette
I wasn't aware of this. It gave me a few things to think about.
Just a few quick observations (without too much thought)

>SwingX goes Mustang ...
It would be fairly easy to add the sorting API to the JXTable - everything just delegates to
the sorter. But I don't see this as a problem (from a non-purist point of view ;) ).
As I implied before, I think the click changes should be done in BasicTableUI.
Either (IMO) we add changes to BasicTableUI or remove them and put them somewhere
else (currently they are in the header). Either way we need a swingX version of
BasicTableUI. As I also said, UI (including headers) is one area I have difficulty
understanding

> SortGestureRecognizer
I wondered why it was done like that.

>Bug Regressions (due to core bugs)
* Issue 1-swingx: must not sort after click into resize area of the column header
* Issue 2-swingx: must not sort after click if table is disabled
* Issue 3-swingx: model selection must be kept on removing/setting RowSorter
* Issue 4-swingx: model rowHeight must be kept on removing/setting RowSorter

Issue 1 - needs to be done with other click processing.
Two methods I can think of (can anyone explain this resize area thing :( ) I'm talking
about double-click here (is it just windows that gives a single-click with a double-click, or
is it everywhere)
a) save the sort keys on a single click before changing, and restore them if it was a
double click. This may cause a flicker.
b) put the toggle sort in a SwingUtilities.invokeLater, and set a flag on a double click to
abort.

Issues 2 and 3 - I'll look into them
Issue 4 - thats UI - not me

>TBD (incomplete migration)
* respect sortable property of tableColumn
* respect comparator property of tableColumn
* cope with different comparable types in cells of a column
* support custom toggle sort order policy (default is ascending/descending, client
requirement might be f.i. ascending/descending/unsorted) A pluggable SortController
would do that.

I'll look at incorporating the first two points. There is provision for setting them in
DefaultRowSorter.
Don't know about the third point. Can we have that?
Will think about a pluggable SortController

JTable allows sorting on multiple columns and I think it will flow into JXTable
automatically.

Whew - what have I let myself in for. It was supposed to be something I tried for a
bit of fun.

rturnbull

Posts: 460
Re: JXTable with Java 1.6 sorting/filtering
Posted: Apr 10, 2008 8:10 PM   in response to: rturnbull
  Click to reply to this thread Reply

I have moved TestJXTable to demo at
https://jdnc-incubator.dev.java.net/source/browse/jdnc-incubator/src/rturnbull/demo/tablesort/
and updated it to set sortOnUpdate(true) in the sorter.
The vegitarian column is editable.

rturnbull

Posts: 460
Re: JXTable with Java 1.6 sorting/filtering
Posted: Apr 13, 2008 12:14 AM   in response to: rturnbull
  Click to reply to this thread Reply

I have reworked the way 1.6 sorting has been enabled in JXTabel, and uploaded new
versions of JXTable, JXTableHeader and a new class JXTableRowSorter.
There is also a slightly modified version of TestJXTable (these changes have broken
SummaryTableRowSorter, and I will have to look at that again)

The changes were as a result of reading the Wiki Jeanette pointed me to, and I have
tried to include as many of the points as possible.

A summary of the changes follows:

JXTable:
a) load defaults (Comparator and column sortable) from TableColumnExt when setting sorter
b) added or reinstated API - toggleSortOrder(int column), removeSort(int column) and
setSortOrder(int column, SortOrder sortOrder). Column is in view coordinates
c) if sorter autocreated is now JXTableRowSorter

JXTableHeader:
a)reinstated SortGestureRecognizer, now called MouseGestureRecognizer, as an
internal class, now public, so it may be extended to override options.
b) added method setMouseGestureRecognizer, so mouse options are now truly
pluggable. If not set, the default will be created with defaults as follows
left click to toggle sort
shift left click to remove sort
right click to pack column
NOTE not using resize column as I don't understand it.
c) all mouse sorting clicks now captured here

JXTableRowSorter - new class extends TableRowSorter. Now the default for JXTable
a) by overriding toggleSortOrder to do nothing I have switched off the sorting click from
BasicTableHeaderUI
b) added method toggleToUnsorted(boolean). If set sort toggles ascending, descending,
unsorted. Default is false to toggle ascending, descending
c) added methods toggleSort(int column) to replace toggleSortOrder, and
removeSort(int column). Column is in model coordinates

I feel I have covered most of the points in the wiki.

As before, this has not been extensively tested. That is an ongoing task, although
some of the more obscure things like changing the datamodel in a table will
probably never be tested by me unless an issue is raised.

This has broken the SummaryTableSort although it is a minor fix.

It has seriously broken my JXTrreTable sort.




 XML java.net RSS