How to get access to the sortedList of a glazedLists SortedTable?

17 views
Skip to first unread message

Martin

unread,
Dec 17, 2010, 7:41:13 AM12/17/10
to JavaBuilders
I need to select a row that displays a given entity in a sortedTable.
As far as I can see access to the sortedList containing the data is
required. Please excuse if I miss something, but I could not find a
way to get hold of that list.

Is there a way to access the sortedList or is there another way to
select the table row with the given entity?
If that is not possible a it could easily be implemented:
With the yml-file

JPanel:
- JTable(name=list):

EventTableModel(name=model,source=values,columns=[firstName,lastName],sort=multi)

pass “values” directly to the constructor of EventTableModel if it is
an instance of SortedList. An additional benefit would be that the
user can instantiate the sortedList with a Comparator.

Actually version RC4 is checked in the maven repository as 1.1-RC4 and
not as 1.1.RC4 as indicated on the project page.

Martin

Jacek Furmankiewicz

unread,
Dec 17, 2010, 9:29:27 AM12/17/10
to JavaBuilders
You can't...I generate them all on the fly, compile objects on the fly
using an embedded Java compiler, etc.

So it's all intermediate objects that are not exposed. It's all a
result of trying to reduce the verbose GL API
to the least possible amount of code.

There may be a way to expose it if you define a list in your Java
class and I could use that reference
instead of creating a new one.

Create an enhancement request for that.

Your only other way in the meantime is grabbing a reference to the
EventTableModel and seeing if you
can access it via the raw GL API in any way :-(

Martin

unread,
Dec 17, 2010, 3:39:40 PM12/17/10
to JavaBuilders
That's exactly what I meant. I created the issue 127 (http://
code.google.com/p/javabuilders/issues/detail?id=127)

Thank you
Martin

Martin

unread,
Dec 18, 2010, 5:09:46 PM12/18/10
to JavaBuilders
> Your only other way in the meantime is grabbing a reference to the
> EventTableModel and seeing if you
> can access it via the raw GL API in any way :-(

Unfortunately the field is protected and the jar is sealed, therefore
access is not possible. Seems I have to wait till you find time to
implement this small enhancement.

Martin

Jacek Furmankiewicz

unread,
Dec 21, 2010, 10:08:10 AM12/21/10
to JavaBuilders
protected is just a suggestion in Java. :-)

Get access to the Field via reflection, then:

setAccessible(true);

and voila! all Java private/protected restrictions are lifted. You can
access the field value via reflection just as if it was public.

How do you think I manage to update references to private fields on
your Swing class? :-)

Martin

unread,
Dec 21, 2010, 3:10:09 PM12/21/10
to JavaBuilders
Thank you for the hint. Incredible how stupid I was: I forgot to set
accessible to true.
Not it works fine.

Martin

Jacek Furmankiewicz

unread,
Dec 21, 2010, 3:12:42 PM12/21/10
to JavaBuilders
I will try to figure out a nice way to handle it natively for 1.2

Jacek Furmankiewicz

unread,
Dec 23, 2010, 1:20:08 PM12/23/10
to JavaBuilders
Fixed in 1.2.0. Updated your hand-made solution with the built-in
support and let me know if that fulfills your needs

Martin

unread,
Dec 24, 2010, 10:19:19 AM12/24/10
to JavaBuilders
Thank you Jacek for the quick fix.
Unfortunately it does not work as expected.

Let's use the following definitions:
- myList = SortedList referenced in the EventTableModel when the table
is built
- listOfModel = list that the EventTableModel uses, accessed via
reflection

Then myList==listOfModel should be true. In my program this is not the
case.
I checked that myList is an instance of SortedList.

Did I make again a silly mistake?

Martin

Jacek Furmankiewicz

unread,
Dec 24, 2010, 10:27:10 AM12/24/10
to JavaBuilders
It's based of a naming convention (see the docs),

so it should be

listOfModel - your list
listOfModelSortedList - the name JB will look for to see if an
existing one exists or if a reference to it should be set

it works off the "SortedList" suffix based on the source list (i.e.
what you specify in source= in YAML)

Martin

unread,
Dec 25, 2010, 8:41:19 AM12/25/10
to JavaBuilders
OK I admit, I have not consulted the docs (I am using maven).

It works as described, thank you.

Why do you use a naming convention? In my application I have a
ListHandler which creates already sorted lists. With your construct I
either have to get a reference to the basic = unsorted list as well as
the sorted one or I have only a reference to the unsorted list and a
second sorted one will be created. At least I did not manage to make
the program work with only the sorted list.

For me it would be clearer just to check if the list is an instance of
a sorted list. In the Java program the creation of a sorted list is
just one statement but it gives more flexibility. And the naming
convention can lead to awkward names: for the unsorted list I use
entityList and for the sorted one entityListSortedList.

But again, thank you for your quick reply. And your solution works.
Martin

Jacek Furmankiewicz

unread,
Dec 25, 2010, 10:21:42 AM12/25/10
to JavaBuilders
OK, so let's do this for 1.2.1

a) change naming convention to use just "Sorted" suffix (instead of
SortedList)

b) if the source is already a SortedList then just use it as is and do
nothing extra. But in that case...why do you even need our
SortedList functionality if you are doing all the sorting yourself?
I seem to be missing the point here, so let me know
more about your context

Jacek

Jason S

unread,
Jan 12, 2011, 12:56:42 PM1/12/11
to JavaBuilders
Just a side comment -- there's some uneasy assumptions going on here.

The way I use JavaBuilders right now is to merely instantiate the
JTable in question (or even just a JPanel that I fill), and I *always*
setup the table in my Java code. This is probably in part because I'm
not familiar with the new JavaBuilders functions for GlazedLists, but
in part it's because the processing to setup tables is very variable
and usually has a degree of complexity that doesn't correspond well to
declarative syntaxes.

I use GlazedLists a lot and the design/setup sequence usually goes
something like this:

1. Declare and create an object/interface type (e.g. Foo) that is the
generic type parameter T for EventList<T> (e.g. EventList<Foo>)
2. Declare and create a BasicEventList<T> in a model object, wrapping
it with GlazedLists's threadsafe list wrapper if necessary.
3. Create a getter in my model object that returns the EventList.
4. In my view object, do the following steps:
5. create an EventList pipeline that does sorting or filtering or
whatever.
6. create a TableFormat to extract the relevant fields from each
item object of type T.
7. create an EventTableModel from the EventList and the TableFormat.
8. find the JTable in question and call setModel() using my
EventTableModel.
9. create TableCellRenderers if necessary for some columns (e.g. for
weird things like buttons and progress bars)
10. setup TableComparatorChoosers & other decorators if necessary

I just don't see how steps 5,6,9, and 10 could be automated or made
easier, except in the very simplest of cases. Steps 7 and 8 are
trivial and could be in JavaBuilders, but in Java it's one or two
lines of code, so the benefit of using Javabuilders to automate
doesn't seem that much. (Whereas for the task of creating the GUI
components, Javabuilders is a *huge* win.)

If I'm missing something obvious here, then I'm sorry for butting in
-- but otherwise it seems to me that investments made in JavaBuilders
w/r/t special uses of GlazedLists have a very limited audience.
Reply all
Reply to author
Forward
0 new messages