« Return to Thread: EventListJXTableSorting

Re: EventListJXTableSorting

by James Lemieux :: Rate this Message:

Reply to Author | View in Thread

Steve,

1. I am not seeing your results. My table is always ordered by size initially (regardless of whether I use EventListJXTableSorting.install or not), as should be the case with the ImageSizeComparator passed to the constructor of SortedList.

The jars I am using are exactly these:
https://glazedlists.dev.java.net/servlets/ProjectDocumentList?folderID=3916&expandFolder=3916&folderID=0 (download glazedlists_java15.jar)
https://swingx.dev.java.net/files/documents/2981/62446/swingx-2007_07_22-bin.zip (download and extract swingx2007_07_22.jar)


2. Note that EventListJXTableSorting is a way to bind a JXTable header to a SortedList. It is NOT NECESSARY for sorting a JXTable. JXTable and GL both do table sorting, but use different mechanisms to accomplish it. JXTable does all of its sorting in the view, and as such can work with an EventTableModel normally (and without the need for a SortedList or an EventListJXTableSorting object). If all you are looking for is table sorting, you can use JXTable sorting without any problems.

EventListJXTableSorting was invented because GL is able to preserve row selections when the table sort order changes (as is also the case with TableComparatorChooser). We do this via a special selection model: EventSelectionModel. But, to use this functionality, GL must *also* control the sorting functionality (with a SortedList). EventListJXTableSorting is a way to wire up the JXTable sorting mechanism to the GL SortedList (which can actually impose the sort order)


3. Perhaps the wiki / class doc should be changed to make it clear *why* you *may* want to use EventListJXTableSorting. It doesn't do that, and perhaps gives you the impression that you *must* do that.


4. GL has a lot of convenience factory methods that make use of reflection to reduce your implementation burdens. You could, for example, replace your TableFormat implementation with the following code:

String[] propertyNames = {"directory", "filename", "filesize"};
String[] columnLabels = {"Directory", "Filename", "Size"};
TableFormat tf = GlazedLists.tableFormat(propertyNames, columnLabels);
EventTableModel<ImageSignature> tableModel = new EventTableModel<ImageSignature>(sortedList, tf);

and save yourself some tedious coding, if you like.

James

On 7/30/07, Steve Newell <newellista@...> wrote:

James,

Thanks for you response.  Indeed, your #1 below solved the lockup problem,
and #3 seemed to solve my other problems, EXCEPT...

Even though I specified a Comparator in the SortedList constructor, when I
install an EventListJXTableSorting the list is unsorted initially.  If I do
not install it, the list is sorted properly.  That leads me to the $64K
question...

Do I need the EventListJXTableSorting installed if I use a JXTable?

From my reading of the wiki, I understood that if I was going to use a
JXTable instead of a JTable,  and I wanted sorting, I had to either install
EventListJXTableSorting OR use a TableComparatorChooser.

My experience leads me to believe that this is not the case.  It appears
that if I create an EventTableModel with a SortedList and create a JXTable
with the EventTableModel, everything works.

I'm sure I'm missing something, and I appreciate your help in clarifying all
this.

Steve

Steve,

1. Your test class fails to work reliably because you're not building /
showing your Swing components on the EDT. Wrap everything in your main
method in a Runnable and post it to the EDT like so:

SwingUtilities.invokeLater(new Runnable() {
   public void run() {
      GlazedListJXTableProblem frame = null;

      if( args.length > 0 ) {
         frame = new GlazedListJXTableProblem( args[ 0 ] );
      } else {
         System.out.println( "specify List as first parameter: { JTable |
JXTableJXSorting | JXTableGLSorting }");
         System.exit( 0 );
      }

      frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
      frame.setVisible( true );
   }
});


2. I read the class doc for EventListJXTableSorting and it explains how to
use it:

a) Create a {@link SortedList} and {@link EventTableModel} that depends on
that {@link SortedList}.
b) Create a {@link JXTable} using the {@link EventTableModel} as its model.
c) Run the {@link EventListJXTableSorting#install} method to bind the {@link
JXTable}'s headers to the {@link SortedList}'s {@link Comparator}.

Notice that it says nothing about TableComparatorChooser. In fact, later in
the class doc it even mentions this:

"The behaviour of multiple column sorting in JXTable is not particularly
flexible. For different configuration options, consider using a {@link
TableComparatorChooser} instead of {@link EventListJXTableSorting}."


3. Removing the call to TableComparatorChooser.install seems to produce the
behaviour you are looking for.


4. I was using the latest jar of GL and the latest jar of swingx and I never
saw two sort icons like the snapshots you pointed at. That said, I'd guess
they are caused by having two different table sorting mechanisms in play
(TableComparatorChooser and EventListJXTableSorting).

Hope this helps,

James

--
View this message in context: http://www.nabble.com/EventListJXTableSorting-tf4148508.html#a11884471
Sent from the GlazedLists - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


 « Return to Thread: EventListJXTableSorting