TableSorter.java v2.1

Discussion in 'Java' started by ouroborus, Apr 29, 2006.

  1. ouroborus

    ouroborus Guest

    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.
     
    ouroborus, Apr 29, 2006
    #1
    1. Advertising

  2. ouroborus wrote:
    > 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, Apr 29, 2006
    #2
    1. Advertising

  3. ouroborus wrote:
    > 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, Apr 29, 2006
    #3
  4. ouroborus wrote:
    > 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, Apr 29, 2006
    #4
  5. Andrew McDonagh wrote:
    > ouroborus wrote:
    >> 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.


    see
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JTable.html#convertColumnIndexToView(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.
     
    Andrew McDonagh, Apr 29, 2006
    #5
  6. ouroborus

    Rhino Guest

    "ouroborus" <> wrote in message
    news:D...
    > 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
     
    Rhino, Apr 29, 2006
    #6
  7. ouroborus

    ouroborus Guest

    Andrew McDonagh wrote:
    > ouroborus wrote:
    >> 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?


    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
    > 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.


    > see http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JTable.html#convertColumnIndexToView(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.


    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.
     
    ouroborus, Apr 30, 2006
    #7
  8. ouroborus

    David Segall Guest

    "Rhino" <> wrote:

    >
    >"ouroborus" <> wrote in message
    >news:D...
    >> 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 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.
     
    David Segall, Apr 30, 2006
    #8
  9. ouroborus

    Oliver Wong Guest

    "David Segall" <> wrote in message
    news:...
    > "Rhino" <> wrote:
    >
    >>
    >>"ouroborus" <> wrote in message
    >>news:D...
    >>> 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 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.


    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
     
    Oliver Wong, May 1, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert
    Replies:
    3
    Views:
    599
    Tris Orendorff
    Oct 6, 2003
  2. Tim
    Replies:
    1
    Views:
    462
    Tim Ward
    May 19, 2004
  3. VisionSet

    Sun's swing TableSorter

    VisionSet, Jun 2, 2004, in forum: Java
    Replies:
    8
    Views:
    843
    Shane Petroff
    Jun 7, 2004
  4. cm
    Replies:
    2
    Views:
    2,034
  5. farseer

    TableSorter NPE exception

    farseer, Jun 23, 2005, in forum: Java
    Replies:
    7
    Views:
    782
    suvacodecobra
    Nov 16, 2006
Loading...

Share This Page