Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

TableSorter.java v2.1

Thread view: 
ouroborus - 29 Apr 2006 21:44 GMT
As part of another project, I spent some time updating TableSorter.java so that it compiles cleanly under Java 1.5. The file can be retrieved from:

    http://ouroborus.org/java/

I would appreciate any constructive comments regarding the results.
Andrew McDonagh - 29 Apr 2006 22:26 GMT
> As part of another project, I spent some time updating TableSorter.java
> so that it compiles cleanly under Java 1.5. The file can be retrieved from:
>
>     http://ouroborus.org/java/
>
> I would appreciate any constructive comments regarding the results.

Where's the JUnit unit tests for it?
Andrew McDonagh - 29 Apr 2006 22:28 GMT
> As part of another project, I spent some time updating TableSorter.java
> so that it compiles cleanly under Java 1.5. The file can be retrieved from:
>
>     http://ouroborus.org/java/
>
> I would appreciate any constructive comments regarding the results.

Why use reflcection to search for a method 'compareTo' when you could
use instanceOf?
Andrew McDonagh - 29 Apr 2006 23:02 GMT
> As part of another project, I spent some time updating TableSorter.java
> so that it compiles cleanly under Java 1.5. The file can be retrieved from:
>
>     http://ouroborus.org/java/
>
> I would appreciate any constructive comments regarding the results.

At my last company we tried all sorts of way of making the adapter work
in all conditions and found the best approach for this task - is to use
the same as JTable does for allowing columns to be moved by the user.

JTable & TableColumnModel keeps tract of where columns are and doesn't
have any problems with any changes to the data, even whilst the columns
are being moved.

We ended up create a derived JTable class - SortingTable.

It worked the tree and with surprisingly little code.
Andrew McDonagh - 29 Apr 2006 23:07 GMT
>> As part of another project, I spent some time updating
>> TableSorter.java so that it compiles cleanly under Java 1.5. The file
[quoted text clipped - 15 lines]
>
> It worked the tree and with surprisingly little code.

see
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JTable.html#convertColumnInd
exToView(int
)

We realized the problem with adapting the TableModel, was that we were
trying to make our Model presentable.  Whereas in the MVC pattern that
JTable (tries) to use the model should remain unaware of how its viewed.
So by putting the presentation logic in the JTable itself this not only
made more sense from the design pattern point of view (JTable is a mix
of the controller and view) it also worked in a far easier manner.
ouroborus - 30 Apr 2006 01:25 GMT
> ouroborus wrote:
>> As part of another project, I spent some time updating
[quoted text clipped - 6 lines]
>
> Where's the JUnit unit tests for it?

There aren't any. However, feel free to volunteer for this task.

> Why use reflcection to search for a method 'compareTo' when you could
> use instanceOf?

I'm not a programmer by profession. My knowledge in the areas relating
to reflection and related were very minimal a few days ago before I had
started working on this. Thank you for the idea though, I'll have to
look into this.

> At my last company we tried all sorts of way of making the adapter work
> in all conditions and found the best approach for this task - is to use
[quoted text clipped - 7 lines]
>
> It worked the tree and with surprisingly little code.

> see http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JTable.html#convertColumnInd
exToView(int
)
>
[quoted text clipped - 4 lines]
> made more sense from the design pattern point of view (JTable is a mix
> of the controller and view) it also worked in a far easier manner.

Now that you mention it, it seems that was/is my problem to. I'm glad you
said this as it presents me with a new view of this whole thing. My
initial goal was to simply make TableSorter work and compile without
warnings. Since it turned out to be reasonably presentable, I decided to
post it.
Rhino - 29 Apr 2006 23:38 GMT
> As part of another project, I spent some time updating TableSorter.java so
> that it compiles cleanly under Java 1.5. The file can be retrieved from:
>
> http://ouroborus.org/java/
>
> I would appreciate any constructive comments regarding the results.

Well, if you really want to make my day, you could add the ability to sort
on multiple columns.

I'm thinking of something analagous to the ORDER BY clause of the SQL SELECT
statement, which lets you say something like:

   ORDER BY CITY ASC, LASTNAME DESC

If you could make the sort work on any number of columns, that would be
brilliant but even if you could only do up to 4 columns, it would be
wonderful.

I've always had this in the back of mind to do myself someday but never
quite get around to it. But, if you could figure out how to do it, I think
it would be very useful.

--
Rhino
David Segall - 30 Apr 2006 06:19 GMT
>> As part of another project, I spent some time updating TableSorter.java so
>> that it compiles cleanly under Java 1.5. The file can be retrieved from:
[quoted text clipped - 5 lines]
>Well, if you really want to make my day, you could add the ability to sort
>on multiple columns.
I haven't looked at the code so I don't know if it qualifies but the
easy way to do this is to use a sorting algorithm that maintains the
existing order on equal keys. The user can then sort on multiple
columns by requesting a sort on each key column from least to most
significant.
Oliver Wong - 01 May 2006 22:17 GMT
>>> As part of another project, I spent some time updating TableSorter.java
>>> so
[quoted text clipped - 11 lines]
> columns by requesting a sort on each key column from least to most
> significant.

I did this for an older project, and I vaguely remember that the basic
design idea was to have a comparator maintained a linked list of other
comparators. The class  would delegate to the first element in its list, and
upon ties, go down the list.

<UntestedCode strictnessLevel="off the top of my head">
public class MultiComparator implements Compatator<T> {
 private List<Compatator<? super T>> myDelegates = new
LinkedList<Compatator<? super T>>();

 /*Put various methods to manipulate the "myDelegates" list here.*/

 public int compareTo(T a, T b) {
   for(Comparator<? super T> c : myDelegates) {
     int returnValue = c.compareTo(a, b);
     if (returnValue != 0) {
       return returnValue;
     }
   }
   return 0;
 }
}
</UntestedCode>

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.